about summary refs log tree commit diff
path: root/sysdeps/posix/euidaccess.c
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2004-12-22 20:10:10 +0000
committerUlrich Drepper <drepper@redhat.com>2004-12-22 20:10:10 +0000
commita334319f6530564d22e775935d9c91663623a1b4 (patch)
treeb5877475619e4c938e98757d518bb1e9cbead751 /sysdeps/posix/euidaccess.c
parent0ecb606cb6cf65de1d9fc8a919bceb4be476c602 (diff)
downloadglibc-a334319f6530564d22e775935d9c91663623a1b4.tar.gz
glibc-a334319f6530564d22e775935d9c91663623a1b4.tar.xz
glibc-a334319f6530564d22e775935d9c91663623a1b4.zip
(CFLAGS-tst-align.c): Add -mpreferred-stack-boundary=4.
Diffstat (limited to 'sysdeps/posix/euidaccess.c')
-rw-r--r--sysdeps/posix/euidaccess.c96
1 files changed, 47 insertions, 49 deletions
diff --git a/sysdeps/posix/euidaccess.c b/sysdeps/posix/euidaccess.c
index 333870cdde..8a2d826e95 100644
--- a/sysdeps/posix/euidaccess.c
+++ b/sysdeps/posix/euidaccess.c
@@ -1,5 +1,5 @@
 /* Check if effective user id can access file
-   Copyright (C) 1990,1991,1995-2001,2005,2007 Free Software Foundation, Inc.
+   Copyright (C) 1990,91,95,96,97,98,99,2000,01 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
@@ -21,26 +21,26 @@
    Adapted for GNU C library by Roland McGrath.  */
 
 #ifdef HAVE_CONFIG_H
-# include <config.h>
+#include <config.h>
 #endif
 
 #include <sys/types.h>
 #include <sys/stat.h>
 
 #ifdef S_IEXEC
-# ifndef S_IXUSR
-#  define S_IXUSR S_IEXEC
-# endif
-# ifndef S_IXGRP
-#  define S_IXGRP (S_IEXEC >> 3)
-# endif
-# ifndef S_IXOTH
-#  define S_IXOTH (S_IEXEC >> 6)
-# endif
+#ifndef S_IXUSR
+#define S_IXUSR S_IEXEC
+#endif
+#ifndef S_IXGRP
+#define S_IXGRP (S_IEXEC >> 3)
+#endif
+#ifndef S_IXOTH
+#define S_IXOTH (S_IEXEC >> 6)
+#endif
 #endif /* S_IEXEC */
 
-#if defined HAVE_UNISTD_H || defined _LIBC
-# include <unistd.h>
+#if defined (HAVE_UNISTD_H) || defined (_LIBC)
+#include <unistd.h>
 #endif
 
 #ifndef _POSIX_VERSION
@@ -55,35 +55,35 @@ gid_t getegid ();
 extern int errno;
 #endif
 #ifndef __set_errno
-# define __set_errno(val) errno = (val)
+#define __set_errno(val) errno = (val)
 #endif
 
-#if defined EACCES && !defined EACCESS
-# define EACCESS EACCES
+#if defined(EACCES) && !defined(EACCESS)
+#define EACCESS EACCES
 #endif
 
 #ifndef F_OK
-# define F_OK 0
-# define X_OK 1
-# define W_OK 2
-# define R_OK 4
+#define F_OK 0
+#define X_OK 1
+#define W_OK 2
+#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
 
 
 #ifdef _LIBC
 
-# define group_member __group_member
-# define euidaccess __euidaccess
+#define group_member __group_member
+#define euidaccess __euidaccess
 
 #else
 
@@ -93,6 +93,14 @@ 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;
 
@@ -102,14 +110,6 @@ 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,8 +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);
 #else
   if (have_ids == 0)
     {
@@ -156,12 +157,12 @@ euidaccess (path, mode)
 
 #ifdef	_LIBC
   /* Now we need the IDs.  */
-  euid = __geteuid ();
-  egid = __getegid ();
-
-  if (__getuid () == euid && __getgid () == egid)
-    /* If we are not set-uid or set-gid, access does the same.  */
-    return __access (path, mode);
+  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
@@ -171,28 +172,25 @@ euidaccess (path, mode)
     return 0;
 
   if (euid == stats.st_uid)
-    granted = (unsigned int) (stats.st_mode & (mode << 6)) >> 6;
+    granted = (unsigned) (stats.st_mode & (mode << 6)) >> 6;
   else if (egid == stats.st_gid || group_member (stats.st_gid))
-    granted = (unsigned int) (stats.st_mode & (mode << 3)) >> 3;
+    granted = (unsigned) (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);
   return -1;
 }
 #undef euidaccess
-#undef eaccess
 #ifdef weak_alias
 weak_alias (__euidaccess, euidaccess)
-weak_alias (__euidaccess, eaccess)
 #endif
 
 #ifdef TEST
-# include <stdio.h>
-# include <errno.h>
-# include "error.h"
+#include <stdio.h>
+#include <errno.h>
+#include "error.h"
 
 char *program_name;