* sysdeps/posix/euidaccess.c [_LIBC] (euidaccess): Don't cache

euid and egid.
This commit is contained in:
Ulrich Drepper 2005-11-27 17:14:28 +00:00
parent 9d55da2be7
commit fec53fc575
2 changed files with 47 additions and 44 deletions

View File

@ -1,5 +1,8 @@
2005-11-27 Ulrich Drepper <drepper@redhat.com>
* sysdeps/posix/euidaccess.c [_LIBC] (euidaccess): Don't cache
euid and egid.
* nis/nis_table.c (nis_list): Add more free calls in error cases.
2005-11-26 Richard Henderson <rth@redhat.com>

View File

@ -1,5 +1,5 @@
/* Check if effective user id can access file
Copyright (C) 1990,91,95,96,97,98,99,2000,01 Free Software Foundation, Inc.
Copyright (C) 1990,1991,1995-2001,2005 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
@ -39,7 +39,7 @@
# endif
#endif /* S_IEXEC */
#if defined (HAVE_UNISTD_H) || defined (_LIBC)
#if defined HAVE_UNISTD_H || defined _LIBC
# include <unistd.h>
#endif
@ -58,7 +58,7 @@ extern int errno;
# define __set_errno(val) errno = (val)
#endif
#if defined(EACCES) && !defined(EACCESS)
#if defined EACCES && !defined EACCESS
# define EACCESS EACCES
#endif
@ -69,13 +69,13 @@ extern int errno;
# define R_OK 4
#endif
#if !defined (S_IROTH) && defined (R_OK)
#if !defined S_IROTH && defined R_OK
# define S_IROTH R_OK
#endif
#if !defined (S_IWOTH) && defined (W_OK)
#if !defined S_IWOTH && defined W_OK
# define S_IWOTH W_OK
#endif
#if !defined (S_IXOTH) && defined (X_OK)
#if !defined S_IXOTH && defined X_OK
# define S_IXOTH X_OK
#endif
@ -93,14 +93,6 @@ static uid_t uid;
/* The user's real group id. */
static gid_t gid;
#ifdef HAVE_GETGROUPS
int group_member ();
#else
#define group_member(gid) 0
#endif
#endif
/* The user's effective user id. */
static uid_t euid;
@ -110,6 +102,14 @@ static gid_t egid;
/* Nonzero if UID, GID, EUID, and EGID have valid values. */
static int have_ids;
# ifdef HAVE_GETGROUPS
int group_member ();
# else
# define group_member(gid) 0
# endif
#endif
/* Return 0 if the user has permission of type MODE on file PATH;
otherwise, return -1 and set `errno' to EACCESS.
@ -126,6 +126,9 @@ euidaccess (path, mode)
int granted;
#ifdef _LIBC
uid_t euid;
gid_t egid;
if (! __libc_enable_secure)
/* If we are not set-uid or set-gid, access does the same. */
return __access (path, mode);
@ -157,12 +160,8 @@ euidaccess (path, mode)
#ifdef _LIBC
/* Now we need the IDs. */
if (have_ids == 0)
{
have_ids = 1;
euid = __geteuid ();
egid = __getegid ();
}
#endif
/* The super-user can read and write any file, and execute any file
@ -172,11 +171,12 @@ euidaccess (path, mode)
return 0;
if (euid == stats.st_uid)
granted = (unsigned) (stats.st_mode & (mode << 6)) >> 6;
granted = (unsigned int) (stats.st_mode & (mode << 6)) >> 6;
else if (egid == stats.st_gid || group_member (stats.st_gid))
granted = (unsigned) (stats.st_mode & (mode << 3)) >> 3;
granted = (unsigned int) (stats.st_mode & (mode << 3)) >> 3;
else
granted = (stats.st_mode & mode);
/* XXX Add support for ACLs. */
if (granted == mode)
return 0;
__set_errno (EACCESS);