~ubuntu-branches/ubuntu/utopic/coreutils/utopic-proposed

« back to all changes in this revision

Viewing changes to lib/euidaccess.c

  • Committer: Package Import Robot
  • Author(s): Colin Watson
  • Date: 2012-11-28 03:03:42 UTC
  • mfrom: (8.3.4 sid)
  • Revision ID: package-import@ubuntu.com-20121128030342-21zanj8354gas5gr
Tags: 8.20-3ubuntu1
* Resynchronise with Debian.  Remaining changes:
  - Make 'uname -i -p' return the real processor/hardware, instead of
    unknown.
  - Build-depend on gettext:any instead of on gettext, so that apt-get can
    properly resolve build-dependencies on the tool when cross-building.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* euidaccess -- check if effective user id can access file
2
2
 
3
 
   Copyright (C) 1990-1991, 1995, 1998, 2000, 2003-2006, 2008-2011 Free
 
3
   Copyright (C) 1990-1991, 1995, 1998, 2000, 2003-2006, 2008-2012 Free
4
4
   Software Foundation, Inc.
5
5
 
6
6
   This file is part of the GNU C Library.
30
30
#include <sys/stat.h>
31
31
#include <unistd.h>
32
32
 
 
33
#include "root-uid.h"
 
34
 
33
35
#if HAVE_LIBGEN_H
34
36
# include <libgen.h>
35
37
#endif
66
68
#endif
67
69
 
68
70
/* Return 0 if the user has permission of type MODE on FILE;
69
 
   otherwise, return -1 and set `errno'.
 
71
   otherwise, return -1 and set 'errno'.
70
72
   Like access, except that it uses the effective user and group
71
73
   id's instead of the real ones, and it does not always check for read-only
72
74
   file system, text busy, etc.  */
74
76
int
75
77
euidaccess (const char *file, int mode)
76
78
{
77
 
#if HAVE_FACCESSAT                      /* glibc */
 
79
#if HAVE_FACCESSAT                   /* glibc, AIX 7, Solaris 11, Cygwin 1.7 */
78
80
  return faccessat (AT_FDCWD, file, mode, AT_EACCESS);
79
81
#elif defined EFF_ONLY_OK               /* IRIX, OSF/1, Interix */
80
82
  return access (file, mode | EFF_ONLY_OK);
82
84
  return accessx (file, mode, ACC_SELF);
83
85
#elif HAVE_EACCESS                      /* FreeBSD */
84
86
  return eaccess (file, mode);
85
 
#else       /* MacOS X, NetBSD, OpenBSD, HP-UX, Solaris, Cygwin, mingw, BeOS */
 
87
#else       /* Mac OS X, NetBSD, OpenBSD, HP-UX, Solaris, Cygwin, mingw, BeOS */
86
88
 
87
89
  uid_t uid = getuid ();
88
90
  gid_t gid = getgid ();
140
142
 
141
143
  /* The super-user can read and write any file, and execute any file
142
144
     that anyone can execute.  */
143
 
  if (euid == 0 && ((mode & X_OK) == 0
144
 
                    || (stats.st_mode & (S_IXUSR | S_IXGRP | S_IXOTH))))
 
145
  if (euid == ROOT_UID
 
146
      && ((mode & X_OK) == 0
 
147
          || (stats.st_mode & (S_IXUSR | S_IXGRP | S_IXOTH))))
145
148
    return 0;
146
149
 
147
150
  /* Convert the mode to traditional form, clearing any bogus bits.  */