Mercurial > hg > octave-shane > gnulib-hg
annotate lib/euidaccess.c @ 7302:8a1a9361108c
* _fpending.c: Include <config.h> unconditionally, since we no
longer worry about uses that don't define HAVE_CONFIG_H.
* acl.c, alloca.c, argmatch.c, atexit.c, backupfile.c:
* basename.c, c-stack.c, c-strtod.c, calloc.c, canon-host.c:
* canonicalize.c, chdir-long.c, chdir-safer.c, chown.c:
* cloexec.c, close-stream.c, closeout.c, creat-safer.c:
* cycle-check.c, diacrit.c, dirchownmod.c, dirfd.c, dirname.c:
* dup-safer.c, dup2.c, error.c, euidaccess.c, exclude.c:
* exitfail.c, fchmodat.c, fchown-stub.c, fd-safer.c:
* file-type.c, fileblocks.c, filemode.c, filenamecat.c:
* fnmatch.c, fopen-safer.c, fprintftime.c, free.c, fsusage.c:
* ftruncate.c, fts-cycle.c, fts.c, full-write.c, gai_strerror.c:
* getcwd.c, getdate.y, getdomainname.c, getgroups.c:
* gethostname.c, gethrxtime.c, getloadavg.c, getlogin_r.c:
* getndelim2.c, getnline.c, getopt.c, getopt1.c, getpass.c:
* gettime.c, gettimeofday.c, getugroups.c, getusershell.c:
* glob.c, group-member.c, hard-locale.c, hash-pjw.c, hash.c:
* human.c, idcache.c, inet_ntop.c, inet_pton.c, inttostr.c:
* isdir.c, lchown.c, linebuffer.c, long-options.c, lstat.c:
* malloc.c, md5.c, memcasecmp.c, memchr.c, memcmp.c, memcoll.c:
* memcpy.c, memmove.c, memrchr.c, mkancesdirs.c, mkdir-p.c:
* mkdir.c, mkdirat.c, mkstemp-safer.c, mkstemp.c, modechange.c:
* mountlist.c, nanosleep.c, obstack.c, open-safer.c:
* openat-die.c, openat.c, pagealign_alloc.c, physmem.c:
* pipe-safer.c, posixtm.c, posixver.c, putenv.c, quote.c:
* quotearg.c, raise.c, readtokens.c, readtokens0.c, readutmp.c:
* realloc.c, regex.c, rename.c, rmdir.c, rpmatch.c, safe-read.c:
* same.c, save-cwd.c, savedir.c, setenv.c, settime.c, sha1.c:
* sig2str.c, snprintf.c, strdup.c, strerror.c, strftime.c:
* stripslash.c, strndup.c, strnlen.c, strpbrk.c, strtod.c:
* strtoimax.c, strtol.c, strverscmp.c, tempname.c, time_r.c:
* timegm.c, tmpfile-safer.c, unlinkdir.c, userspec.c, utime.c:
* utimecmp.c, utimens.c, version-etc-fsf.c, version-etc.c:
* xalloc-die.c, xgetcwd.c, xgethostname.c, xmalloc.c:
* xmemcoll.c, xnanosleep.c, xreadlink.c, xstrtod.c:
* xstrtoimax.c, xstrtol.c, xstrtoumax.c, yesno.c:
Likewise.
author | Paul Eggert <eggert@cs.ucla.edu> |
---|---|
date | Wed, 13 Sep 2006 22:38:14 +0000 |
parents | fd0ccce602e4 |
children | 45c727466eb8 |
rev | line source |
---|---|
341 | 1 /* euidaccess -- check if effective user id can access file |
4531
67c56a27d86c
Merge euidaccess etc. from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4422
diff
changeset
|
2 |
7302
8a1a9361108c
* _fpending.c: Include <config.h> unconditionally, since we no
Paul Eggert <eggert@cs.ucla.edu>
parents:
6275
diff
changeset
|
3 Copyright (C) 1990, 1991, 1995, 1998, 2000, 2003, 2004, 2005, 2006 |
8a1a9361108c
* _fpending.c: Include <config.h> unconditionally, since we no
Paul Eggert <eggert@cs.ucla.edu>
parents:
6275
diff
changeset
|
4 Free Software Foundation, Inc. |
4531
67c56a27d86c
Merge euidaccess etc. from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4422
diff
changeset
|
5 |
4422 | 6 This file is part of the GNU C Library. |
341 | 7 |
4422 | 8 This program is free software; you can redistribute it and/or modify |
9 it under the terms of the GNU General Public License as published by | |
10 the Free Software Foundation; either version 2, or (at your option) | |
11 any later version. | |
341 | 12 |
4422 | 13 This program is distributed in the hope that it will be useful, |
14 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 GNU General Public License for more details. | |
341 | 17 |
4422 | 18 You should have received a copy of the GNU General Public License along |
19 with this program; if not, write to the Free Software Foundation, | |
5848
a48fb0e98c8c
*** empty log message ***
Paul Eggert <eggert@cs.ucla.edu>
parents:
5421
diff
changeset
|
20 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ |
341 | 21 |
509 | 22 /* Written by David MacKenzie and Torbjorn Granlund. |
23 Adapted for GNU C library by Roland McGrath. */ | |
341 | 24 |
7302
8a1a9361108c
* _fpending.c: Include <config.h> unconditionally, since we no
Paul Eggert <eggert@cs.ucla.edu>
parents:
6275
diff
changeset
|
25 #ifndef _LIBC |
615
1f485b09b153
(euidaccess) [!S_IROTH]: Define.
Jim Meyering <jim@meyering.net>
parents:
509
diff
changeset
|
26 # include <config.h> |
4531
67c56a27d86c
Merge euidaccess etc. from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4422
diff
changeset
|
27 # include "euidaccess.h" |
67c56a27d86c
Merge euidaccess etc. from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4422
diff
changeset
|
28 #endif |
67c56a27d86c
Merge euidaccess etc. from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4422
diff
changeset
|
29 |
341 | 30 #include <sys/types.h> |
31 #include <sys/stat.h> | |
6275 | 32 #include <unistd.h> |
341 | 33 |
5157
62fa339919f4
[HAVE_LIBGEN_H]: Include <libgen.h>, for
Paul Eggert <eggert@cs.ucla.edu>
parents:
4637
diff
changeset
|
34 #if HAVE_LIBGEN_H |
62fa339919f4
[HAVE_LIBGEN_H]: Include <libgen.h>, for
Paul Eggert <eggert@cs.ucla.edu>
parents:
4637
diff
changeset
|
35 # include <libgen.h> |
62fa339919f4
[HAVE_LIBGEN_H]: Include <libgen.h>, for
Paul Eggert <eggert@cs.ucla.edu>
parents:
4637
diff
changeset
|
36 #endif |
341 | 37 |
38 #include <errno.h> | |
2094
92c4b5c4b148
Sync with the GNU C library.
Jim Meyering <jim@meyering.net>
parents:
1557
diff
changeset
|
39 #ifndef __set_errno |
92c4b5c4b148
Sync with the GNU C library.
Jim Meyering <jim@meyering.net>
parents:
1557
diff
changeset
|
40 # define __set_errno(val) errno = (val) |
92c4b5c4b148
Sync with the GNU C library.
Jim Meyering <jim@meyering.net>
parents:
1557
diff
changeset
|
41 #endif |
341 | 42 |
5157
62fa339919f4
[HAVE_LIBGEN_H]: Include <libgen.h>, for
Paul Eggert <eggert@cs.ucla.edu>
parents:
4637
diff
changeset
|
43 #if defined EACCES && !defined EACCESS |
615
1f485b09b153
(euidaccess) [!S_IROTH]: Define.
Jim Meyering <jim@meyering.net>
parents:
509
diff
changeset
|
44 # define EACCESS EACCES |
341 | 45 #endif |
46 | |
47 #ifndef F_OK | |
615
1f485b09b153
(euidaccess) [!S_IROTH]: Define.
Jim Meyering <jim@meyering.net>
parents:
509
diff
changeset
|
48 # define F_OK 0 |
1f485b09b153
(euidaccess) [!S_IROTH]: Define.
Jim Meyering <jim@meyering.net>
parents:
509
diff
changeset
|
49 # define X_OK 1 |
1f485b09b153
(euidaccess) [!S_IROTH]: Define.
Jim Meyering <jim@meyering.net>
parents:
509
diff
changeset
|
50 # define W_OK 2 |
1f485b09b153
(euidaccess) [!S_IROTH]: Define.
Jim Meyering <jim@meyering.net>
parents:
509
diff
changeset
|
51 # define R_OK 4 |
341 | 52 #endif |
53 | |
509 | 54 |
55 #ifdef _LIBC | |
56 | |
5157
62fa339919f4
[HAVE_LIBGEN_H]: Include <libgen.h>, for
Paul Eggert <eggert@cs.ucla.edu>
parents:
4637
diff
changeset
|
57 # define access __access |
62fa339919f4
[HAVE_LIBGEN_H]: Include <libgen.h>, for
Paul Eggert <eggert@cs.ucla.edu>
parents:
4637
diff
changeset
|
58 # define getuid __getuid |
62fa339919f4
[HAVE_LIBGEN_H]: Include <libgen.h>, for
Paul Eggert <eggert@cs.ucla.edu>
parents:
4637
diff
changeset
|
59 # define getgid __getgid |
62fa339919f4
[HAVE_LIBGEN_H]: Include <libgen.h>, for
Paul Eggert <eggert@cs.ucla.edu>
parents:
4637
diff
changeset
|
60 # define geteuid __geteuid |
62fa339919f4
[HAVE_LIBGEN_H]: Include <libgen.h>, for
Paul Eggert <eggert@cs.ucla.edu>
parents:
4637
diff
changeset
|
61 # define getegid __getegid |
615
1f485b09b153
(euidaccess) [!S_IROTH]: Define.
Jim Meyering <jim@meyering.net>
parents:
509
diff
changeset
|
62 # define group_member __group_member |
2094
92c4b5c4b148
Sync with the GNU C library.
Jim Meyering <jim@meyering.net>
parents:
1557
diff
changeset
|
63 # define euidaccess __euidaccess |
5157
62fa339919f4
[HAVE_LIBGEN_H]: Include <libgen.h>, for
Paul Eggert <eggert@cs.ucla.edu>
parents:
4637
diff
changeset
|
64 # undef stat |
62fa339919f4
[HAVE_LIBGEN_H]: Include <libgen.h>, for
Paul Eggert <eggert@cs.ucla.edu>
parents:
4637
diff
changeset
|
65 # define stat stat64 |
509 | 66 |
67 #else | |
68 | |
5157
62fa339919f4
[HAVE_LIBGEN_H]: Include <libgen.h>, for
Paul Eggert <eggert@cs.ucla.edu>
parents:
4637
diff
changeset
|
69 # include "group-member.h" |
62fa339919f4
[HAVE_LIBGEN_H]: Include <libgen.h>, for
Paul Eggert <eggert@cs.ucla.edu>
parents:
4637
diff
changeset
|
70 # include "stat-macros.h" |
2094
92c4b5c4b148
Sync with the GNU C library.
Jim Meyering <jim@meyering.net>
parents:
1557
diff
changeset
|
71 |
92c4b5c4b148
Sync with the GNU C library.
Jim Meyering <jim@meyering.net>
parents:
1557
diff
changeset
|
72 #endif |
92c4b5c4b148
Sync with the GNU C library.
Jim Meyering <jim@meyering.net>
parents:
1557
diff
changeset
|
73 |
5907 | 74 /* Return 0 if the user has permission of type MODE on FILE; |
5157
62fa339919f4
[HAVE_LIBGEN_H]: Include <libgen.h>, for
Paul Eggert <eggert@cs.ucla.edu>
parents:
4637
diff
changeset
|
75 otherwise, return -1 and set `errno'. |
341 | 76 Like access, except that it uses the effective user and group |
5157
62fa339919f4
[HAVE_LIBGEN_H]: Include <libgen.h>, for
Paul Eggert <eggert@cs.ucla.edu>
parents:
4637
diff
changeset
|
77 id's instead of the real ones, and it does not always check for read-only |
62fa339919f4
[HAVE_LIBGEN_H]: Include <libgen.h>, for
Paul Eggert <eggert@cs.ucla.edu>
parents:
4637
diff
changeset
|
78 file system, text busy, etc. */ |
341 | 79 |
80 int | |
5907 | 81 euidaccess (const char *file, int mode) |
341 | 82 { |
5157
62fa339919f4
[HAVE_LIBGEN_H]: Include <libgen.h>, for
Paul Eggert <eggert@cs.ucla.edu>
parents:
4637
diff
changeset
|
83 #if defined EFF_ONLY_OK |
5907 | 84 return access (file, mode | EFF_ONLY_OK); |
5157
62fa339919f4
[HAVE_LIBGEN_H]: Include <libgen.h>, for
Paul Eggert <eggert@cs.ucla.edu>
parents:
4637
diff
changeset
|
85 #elif defined ACC_SELF |
5907 | 86 return accessx (file, mode, ACC_SELF); |
5157
62fa339919f4
[HAVE_LIBGEN_H]: Include <libgen.h>, for
Paul Eggert <eggert@cs.ucla.edu>
parents:
4637
diff
changeset
|
87 #elif HAVE_EACCESS |
5907 | 88 return eaccess (file, mode); |
509 | 89 #else |
5157
62fa339919f4
[HAVE_LIBGEN_H]: Include <libgen.h>, for
Paul Eggert <eggert@cs.ucla.edu>
parents:
4637
diff
changeset
|
90 |
62fa339919f4
[HAVE_LIBGEN_H]: Include <libgen.h>, for
Paul Eggert <eggert@cs.ucla.edu>
parents:
4637
diff
changeset
|
91 uid_t uid = getuid (); |
62fa339919f4
[HAVE_LIBGEN_H]: Include <libgen.h>, for
Paul Eggert <eggert@cs.ucla.edu>
parents:
4637
diff
changeset
|
92 gid_t gid = getgid (); |
62fa339919f4
[HAVE_LIBGEN_H]: Include <libgen.h>, for
Paul Eggert <eggert@cs.ucla.edu>
parents:
4637
diff
changeset
|
93 uid_t euid = geteuid (); |
62fa339919f4
[HAVE_LIBGEN_H]: Include <libgen.h>, for
Paul Eggert <eggert@cs.ucla.edu>
parents:
4637
diff
changeset
|
94 gid_t egid = getegid (); |
62fa339919f4
[HAVE_LIBGEN_H]: Include <libgen.h>, for
Paul Eggert <eggert@cs.ucla.edu>
parents:
4637
diff
changeset
|
95 struct stat stats; |
62fa339919f4
[HAVE_LIBGEN_H]: Include <libgen.h>, for
Paul Eggert <eggert@cs.ucla.edu>
parents:
4637
diff
changeset
|
96 |
62fa339919f4
[HAVE_LIBGEN_H]: Include <libgen.h>, for
Paul Eggert <eggert@cs.ucla.edu>
parents:
4637
diff
changeset
|
97 # if HAVE_DECL_SETREGID && PREFER_NONREENTRANT_EUIDACCESS |
62fa339919f4
[HAVE_LIBGEN_H]: Include <libgen.h>, for
Paul Eggert <eggert@cs.ucla.edu>
parents:
4637
diff
changeset
|
98 |
62fa339919f4
[HAVE_LIBGEN_H]: Include <libgen.h>, for
Paul Eggert <eggert@cs.ucla.edu>
parents:
4637
diff
changeset
|
99 /* Define PREFER_NONREENTRANT_EUIDACCESS if you prefer euidaccess to |
62fa339919f4
[HAVE_LIBGEN_H]: Include <libgen.h>, for
Paul Eggert <eggert@cs.ucla.edu>
parents:
4637
diff
changeset
|
100 return the correct result even if this would make it |
62fa339919f4
[HAVE_LIBGEN_H]: Include <libgen.h>, for
Paul Eggert <eggert@cs.ucla.edu>
parents:
4637
diff
changeset
|
101 nonreentrant. Define this only if your entire application is |
62fa339919f4
[HAVE_LIBGEN_H]: Include <libgen.h>, for
Paul Eggert <eggert@cs.ucla.edu>
parents:
4637
diff
changeset
|
102 safe even if the uid or gid might temporarily change. If your |
62fa339919f4
[HAVE_LIBGEN_H]: Include <libgen.h>, for
Paul Eggert <eggert@cs.ucla.edu>
parents:
4637
diff
changeset
|
103 application uses signal handlers or threads it is probably not |
62fa339919f4
[HAVE_LIBGEN_H]: Include <libgen.h>, for
Paul Eggert <eggert@cs.ucla.edu>
parents:
4637
diff
changeset
|
104 safe. */ |
62fa339919f4
[HAVE_LIBGEN_H]: Include <libgen.h>, for
Paul Eggert <eggert@cs.ucla.edu>
parents:
4637
diff
changeset
|
105 |
62fa339919f4
[HAVE_LIBGEN_H]: Include <libgen.h>, for
Paul Eggert <eggert@cs.ucla.edu>
parents:
4637
diff
changeset
|
106 if (mode == F_OK) |
5907 | 107 return stat (file, &stats); |
5157
62fa339919f4
[HAVE_LIBGEN_H]: Include <libgen.h>, for
Paul Eggert <eggert@cs.ucla.edu>
parents:
4637
diff
changeset
|
108 else |
341 | 109 { |
5157
62fa339919f4
[HAVE_LIBGEN_H]: Include <libgen.h>, for
Paul Eggert <eggert@cs.ucla.edu>
parents:
4637
diff
changeset
|
110 int result; |
62fa339919f4
[HAVE_LIBGEN_H]: Include <libgen.h>, for
Paul Eggert <eggert@cs.ucla.edu>
parents:
4637
diff
changeset
|
111 int saved_errno; |
5421 | 112 |
5157
62fa339919f4
[HAVE_LIBGEN_H]: Include <libgen.h>, for
Paul Eggert <eggert@cs.ucla.edu>
parents:
4637
diff
changeset
|
113 if (uid != euid) |
62fa339919f4
[HAVE_LIBGEN_H]: Include <libgen.h>, for
Paul Eggert <eggert@cs.ucla.edu>
parents:
4637
diff
changeset
|
114 setreuid (euid, uid); |
62fa339919f4
[HAVE_LIBGEN_H]: Include <libgen.h>, for
Paul Eggert <eggert@cs.ucla.edu>
parents:
4637
diff
changeset
|
115 if (gid != egid) |
62fa339919f4
[HAVE_LIBGEN_H]: Include <libgen.h>, for
Paul Eggert <eggert@cs.ucla.edu>
parents:
4637
diff
changeset
|
116 setregid (egid, gid); |
62fa339919f4
[HAVE_LIBGEN_H]: Include <libgen.h>, for
Paul Eggert <eggert@cs.ucla.edu>
parents:
4637
diff
changeset
|
117 |
5907 | 118 result = access (file, mode); |
5157
62fa339919f4
[HAVE_LIBGEN_H]: Include <libgen.h>, for
Paul Eggert <eggert@cs.ucla.edu>
parents:
4637
diff
changeset
|
119 saved_errno = errno; |
5421 | 120 |
5157
62fa339919f4
[HAVE_LIBGEN_H]: Include <libgen.h>, for
Paul Eggert <eggert@cs.ucla.edu>
parents:
4637
diff
changeset
|
121 /* Restore them. */ |
62fa339919f4
[HAVE_LIBGEN_H]: Include <libgen.h>, for
Paul Eggert <eggert@cs.ucla.edu>
parents:
4637
diff
changeset
|
122 if (uid != euid) |
62fa339919f4
[HAVE_LIBGEN_H]: Include <libgen.h>, for
Paul Eggert <eggert@cs.ucla.edu>
parents:
4637
diff
changeset
|
123 setreuid (uid, euid); |
62fa339919f4
[HAVE_LIBGEN_H]: Include <libgen.h>, for
Paul Eggert <eggert@cs.ucla.edu>
parents:
4637
diff
changeset
|
124 if (gid != egid) |
62fa339919f4
[HAVE_LIBGEN_H]: Include <libgen.h>, for
Paul Eggert <eggert@cs.ucla.edu>
parents:
4637
diff
changeset
|
125 setregid (gid, egid); |
62fa339919f4
[HAVE_LIBGEN_H]: Include <libgen.h>, for
Paul Eggert <eggert@cs.ucla.edu>
parents:
4637
diff
changeset
|
126 |
62fa339919f4
[HAVE_LIBGEN_H]: Include <libgen.h>, for
Paul Eggert <eggert@cs.ucla.edu>
parents:
4637
diff
changeset
|
127 errno = saved_errno; |
62fa339919f4
[HAVE_LIBGEN_H]: Include <libgen.h>, for
Paul Eggert <eggert@cs.ucla.edu>
parents:
4637
diff
changeset
|
128 return result; |
341 | 129 } |
130 | |
5157
62fa339919f4
[HAVE_LIBGEN_H]: Include <libgen.h>, for
Paul Eggert <eggert@cs.ucla.edu>
parents:
4637
diff
changeset
|
131 # else |
62fa339919f4
[HAVE_LIBGEN_H]: Include <libgen.h>, for
Paul Eggert <eggert@cs.ucla.edu>
parents:
4637
diff
changeset
|
132 |
62fa339919f4
[HAVE_LIBGEN_H]: Include <libgen.h>, for
Paul Eggert <eggert@cs.ucla.edu>
parents:
4637
diff
changeset
|
133 /* The following code assumes the traditional Unix model, and is not |
62fa339919f4
[HAVE_LIBGEN_H]: Include <libgen.h>, for
Paul Eggert <eggert@cs.ucla.edu>
parents:
4637
diff
changeset
|
134 correct on systems that have ACLs or the like. However, it's |
62fa339919f4
[HAVE_LIBGEN_H]: Include <libgen.h>, for
Paul Eggert <eggert@cs.ucla.edu>
parents:
4637
diff
changeset
|
135 better than nothing, and it is reentrant. */ |
62fa339919f4
[HAVE_LIBGEN_H]: Include <libgen.h>, for
Paul Eggert <eggert@cs.ucla.edu>
parents:
4637
diff
changeset
|
136 |
62fa339919f4
[HAVE_LIBGEN_H]: Include <libgen.h>, for
Paul Eggert <eggert@cs.ucla.edu>
parents:
4637
diff
changeset
|
137 unsigned int granted; |
341 | 138 if (uid == euid && gid == egid) |
509 | 139 /* If we are not set-uid or set-gid, access does the same. */ |
5907 | 140 return access (file, mode); |
341 | 141 |
5907 | 142 if (stat (file, &stats) != 0) |
341 | 143 return -1; |
144 | |
509 | 145 /* The super-user can read and write any file, and execute any file |
5157
62fa339919f4
[HAVE_LIBGEN_H]: Include <libgen.h>, for
Paul Eggert <eggert@cs.ucla.edu>
parents:
4637
diff
changeset
|
146 that anyone can execute. */ |
509 | 147 if (euid == 0 && ((mode & X_OK) == 0 |
148 || (stats.st_mode & (S_IXUSR | S_IXGRP | S_IXOTH)))) | |
149 return 0; | |
341 | 150 |
5157
62fa339919f4
[HAVE_LIBGEN_H]: Include <libgen.h>, for
Paul Eggert <eggert@cs.ucla.edu>
parents:
4637
diff
changeset
|
151 /* Convert the mode to traditional form, clearing any bogus bits. */ |
62fa339919f4
[HAVE_LIBGEN_H]: Include <libgen.h>, for
Paul Eggert <eggert@cs.ucla.edu>
parents:
4637
diff
changeset
|
152 if (R_OK == 4 && W_OK == 2 && X_OK == 1 && F_OK == 0) |
62fa339919f4
[HAVE_LIBGEN_H]: Include <libgen.h>, for
Paul Eggert <eggert@cs.ucla.edu>
parents:
4637
diff
changeset
|
153 mode &= 7; |
62fa339919f4
[HAVE_LIBGEN_H]: Include <libgen.h>, for
Paul Eggert <eggert@cs.ucla.edu>
parents:
4637
diff
changeset
|
154 else |
62fa339919f4
[HAVE_LIBGEN_H]: Include <libgen.h>, for
Paul Eggert <eggert@cs.ucla.edu>
parents:
4637
diff
changeset
|
155 mode = ((mode & R_OK ? 4 : 0) |
62fa339919f4
[HAVE_LIBGEN_H]: Include <libgen.h>, for
Paul Eggert <eggert@cs.ucla.edu>
parents:
4637
diff
changeset
|
156 + (mode & W_OK ? 2 : 0) |
62fa339919f4
[HAVE_LIBGEN_H]: Include <libgen.h>, for
Paul Eggert <eggert@cs.ucla.edu>
parents:
4637
diff
changeset
|
157 + (mode & X_OK ? 1 : 0)); |
62fa339919f4
[HAVE_LIBGEN_H]: Include <libgen.h>, for
Paul Eggert <eggert@cs.ucla.edu>
parents:
4637
diff
changeset
|
158 |
62fa339919f4
[HAVE_LIBGEN_H]: Include <libgen.h>, for
Paul Eggert <eggert@cs.ucla.edu>
parents:
4637
diff
changeset
|
159 if (mode == 0) |
62fa339919f4
[HAVE_LIBGEN_H]: Include <libgen.h>, for
Paul Eggert <eggert@cs.ucla.edu>
parents:
4637
diff
changeset
|
160 return 0; /* The file exists. */ |
62fa339919f4
[HAVE_LIBGEN_H]: Include <libgen.h>, for
Paul Eggert <eggert@cs.ucla.edu>
parents:
4637
diff
changeset
|
161 |
62fa339919f4
[HAVE_LIBGEN_H]: Include <libgen.h>, for
Paul Eggert <eggert@cs.ucla.edu>
parents:
4637
diff
changeset
|
162 /* Convert the file's permission bits to traditional form. */ |
62fa339919f4
[HAVE_LIBGEN_H]: Include <libgen.h>, for
Paul Eggert <eggert@cs.ucla.edu>
parents:
4637
diff
changeset
|
163 if (S_IRUSR == (4 << 6) && S_IWUSR == (2 << 6) && S_IXUSR == (1 << 6) |
62fa339919f4
[HAVE_LIBGEN_H]: Include <libgen.h>, for
Paul Eggert <eggert@cs.ucla.edu>
parents:
4637
diff
changeset
|
164 && S_IRGRP == (4 << 3) && S_IWGRP == (2 << 3) && S_IXGRP == (1 << 3) |
62fa339919f4
[HAVE_LIBGEN_H]: Include <libgen.h>, for
Paul Eggert <eggert@cs.ucla.edu>
parents:
4637
diff
changeset
|
165 && S_IROTH == (4 << 0) && S_IWOTH == (2 << 0) && S_IXOTH == (1 << 0)) |
62fa339919f4
[HAVE_LIBGEN_H]: Include <libgen.h>, for
Paul Eggert <eggert@cs.ucla.edu>
parents:
4637
diff
changeset
|
166 granted = stats.st_mode; |
62fa339919f4
[HAVE_LIBGEN_H]: Include <libgen.h>, for
Paul Eggert <eggert@cs.ucla.edu>
parents:
4637
diff
changeset
|
167 else |
62fa339919f4
[HAVE_LIBGEN_H]: Include <libgen.h>, for
Paul Eggert <eggert@cs.ucla.edu>
parents:
4637
diff
changeset
|
168 granted = ((stats.st_mode & S_IRUSR ? 4 << 6 : 0) |
62fa339919f4
[HAVE_LIBGEN_H]: Include <libgen.h>, for
Paul Eggert <eggert@cs.ucla.edu>
parents:
4637
diff
changeset
|
169 + (stats.st_mode & S_IWUSR ? 2 << 6 : 0) |
62fa339919f4
[HAVE_LIBGEN_H]: Include <libgen.h>, for
Paul Eggert <eggert@cs.ucla.edu>
parents:
4637
diff
changeset
|
170 + (stats.st_mode & S_IXUSR ? 1 << 6 : 0) |
62fa339919f4
[HAVE_LIBGEN_H]: Include <libgen.h>, for
Paul Eggert <eggert@cs.ucla.edu>
parents:
4637
diff
changeset
|
171 + (stats.st_mode & S_IRGRP ? 4 << 3 : 0) |
62fa339919f4
[HAVE_LIBGEN_H]: Include <libgen.h>, for
Paul Eggert <eggert@cs.ucla.edu>
parents:
4637
diff
changeset
|
172 + (stats.st_mode & S_IWGRP ? 2 << 3 : 0) |
62fa339919f4
[HAVE_LIBGEN_H]: Include <libgen.h>, for
Paul Eggert <eggert@cs.ucla.edu>
parents:
4637
diff
changeset
|
173 + (stats.st_mode & S_IXGRP ? 1 << 3 : 0) |
62fa339919f4
[HAVE_LIBGEN_H]: Include <libgen.h>, for
Paul Eggert <eggert@cs.ucla.edu>
parents:
4637
diff
changeset
|
174 + (stats.st_mode & S_IROTH ? 4 << 0 : 0) |
62fa339919f4
[HAVE_LIBGEN_H]: Include <libgen.h>, for
Paul Eggert <eggert@cs.ucla.edu>
parents:
4637
diff
changeset
|
175 + (stats.st_mode & S_IWOTH ? 2 << 0 : 0) |
62fa339919f4
[HAVE_LIBGEN_H]: Include <libgen.h>, for
Paul Eggert <eggert@cs.ucla.edu>
parents:
4637
diff
changeset
|
176 + (stats.st_mode & S_IXOTH ? 1 << 0 : 0)); |
62fa339919f4
[HAVE_LIBGEN_H]: Include <libgen.h>, for
Paul Eggert <eggert@cs.ucla.edu>
parents:
4637
diff
changeset
|
177 |
509 | 178 if (euid == stats.st_uid) |
5157
62fa339919f4
[HAVE_LIBGEN_H]: Include <libgen.h>, for
Paul Eggert <eggert@cs.ucla.edu>
parents:
4637
diff
changeset
|
179 granted >>= 6; |
509 | 180 else if (egid == stats.st_gid || group_member (stats.st_gid)) |
5157
62fa339919f4
[HAVE_LIBGEN_H]: Include <libgen.h>, for
Paul Eggert <eggert@cs.ucla.edu>
parents:
4637
diff
changeset
|
181 granted >>= 3; |
62fa339919f4
[HAVE_LIBGEN_H]: Include <libgen.h>, for
Paul Eggert <eggert@cs.ucla.edu>
parents:
4637
diff
changeset
|
182 |
62fa339919f4
[HAVE_LIBGEN_H]: Include <libgen.h>, for
Paul Eggert <eggert@cs.ucla.edu>
parents:
4637
diff
changeset
|
183 if ((mode & ~granted) == 0) |
509 | 184 return 0; |
2094
92c4b5c4b148
Sync with the GNU C library.
Jim Meyering <jim@meyering.net>
parents:
1557
diff
changeset
|
185 __set_errno (EACCESS); |
509 | 186 return -1; |
5157
62fa339919f4
[HAVE_LIBGEN_H]: Include <libgen.h>, for
Paul Eggert <eggert@cs.ucla.edu>
parents:
4637
diff
changeset
|
187 |
62fa339919f4
[HAVE_LIBGEN_H]: Include <libgen.h>, for
Paul Eggert <eggert@cs.ucla.edu>
parents:
4637
diff
changeset
|
188 # endif |
62fa339919f4
[HAVE_LIBGEN_H]: Include <libgen.h>, for
Paul Eggert <eggert@cs.ucla.edu>
parents:
4637
diff
changeset
|
189 #endif |
341 | 190 } |
2094
92c4b5c4b148
Sync with the GNU C library.
Jim Meyering <jim@meyering.net>
parents:
1557
diff
changeset
|
191 #undef euidaccess |
92c4b5c4b148
Sync with the GNU C library.
Jim Meyering <jim@meyering.net>
parents:
1557
diff
changeset
|
192 #ifdef weak_alias |
92c4b5c4b148
Sync with the GNU C library.
Jim Meyering <jim@meyering.net>
parents:
1557
diff
changeset
|
193 weak_alias (__euidaccess, euidaccess) |
92c4b5c4b148
Sync with the GNU C library.
Jim Meyering <jim@meyering.net>
parents:
1557
diff
changeset
|
194 #endif |
92c4b5c4b148
Sync with the GNU C library.
Jim Meyering <jim@meyering.net>
parents:
1557
diff
changeset
|
195 |
92c4b5c4b148
Sync with the GNU C library.
Jim Meyering <jim@meyering.net>
parents:
1557
diff
changeset
|
196 #ifdef TEST |
5157
62fa339919f4
[HAVE_LIBGEN_H]: Include <libgen.h>, for
Paul Eggert <eggert@cs.ucla.edu>
parents:
4637
diff
changeset
|
197 # include <error.h> |
2094
92c4b5c4b148
Sync with the GNU C library.
Jim Meyering <jim@meyering.net>
parents:
1557
diff
changeset
|
198 # include <stdio.h> |
5157
62fa339919f4
[HAVE_LIBGEN_H]: Include <libgen.h>, for
Paul Eggert <eggert@cs.ucla.edu>
parents:
4637
diff
changeset
|
199 # include <stdlib.h> |
2094
92c4b5c4b148
Sync with the GNU C library.
Jim Meyering <jim@meyering.net>
parents:
1557
diff
changeset
|
200 |
92c4b5c4b148
Sync with the GNU C library.
Jim Meyering <jim@meyering.net>
parents:
1557
diff
changeset
|
201 char *program_name; |
92c4b5c4b148
Sync with the GNU C library.
Jim Meyering <jim@meyering.net>
parents:
1557
diff
changeset
|
202 |
92c4b5c4b148
Sync with the GNU C library.
Jim Meyering <jim@meyering.net>
parents:
1557
diff
changeset
|
203 int |
4637
f736e2167837
(main): Define with a prototype.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4531
diff
changeset
|
204 main (int argc, char **argv) |
2094
92c4b5c4b148
Sync with the GNU C library.
Jim Meyering <jim@meyering.net>
parents:
1557
diff
changeset
|
205 { |
92c4b5c4b148
Sync with the GNU C library.
Jim Meyering <jim@meyering.net>
parents:
1557
diff
changeset
|
206 char *file; |
92c4b5c4b148
Sync with the GNU C library.
Jim Meyering <jim@meyering.net>
parents:
1557
diff
changeset
|
207 int mode; |
92c4b5c4b148
Sync with the GNU C library.
Jim Meyering <jim@meyering.net>
parents:
1557
diff
changeset
|
208 int err; |
92c4b5c4b148
Sync with the GNU C library.
Jim Meyering <jim@meyering.net>
parents:
1557
diff
changeset
|
209 |
92c4b5c4b148
Sync with the GNU C library.
Jim Meyering <jim@meyering.net>
parents:
1557
diff
changeset
|
210 program_name = argv[0]; |
92c4b5c4b148
Sync with the GNU C library.
Jim Meyering <jim@meyering.net>
parents:
1557
diff
changeset
|
211 if (argc < 3) |
92c4b5c4b148
Sync with the GNU C library.
Jim Meyering <jim@meyering.net>
parents:
1557
diff
changeset
|
212 abort (); |
92c4b5c4b148
Sync with the GNU C library.
Jim Meyering <jim@meyering.net>
parents:
1557
diff
changeset
|
213 file = argv[1]; |
92c4b5c4b148
Sync with the GNU C library.
Jim Meyering <jim@meyering.net>
parents:
1557
diff
changeset
|
214 mode = atoi (argv[2]); |
92c4b5c4b148
Sync with the GNU C library.
Jim Meyering <jim@meyering.net>
parents:
1557
diff
changeset
|
215 |
92c4b5c4b148
Sync with the GNU C library.
Jim Meyering <jim@meyering.net>
parents:
1557
diff
changeset
|
216 err = euidaccess (file, mode); |
92c4b5c4b148
Sync with the GNU C library.
Jim Meyering <jim@meyering.net>
parents:
1557
diff
changeset
|
217 printf ("%d\n", err); |
92c4b5c4b148
Sync with the GNU C library.
Jim Meyering <jim@meyering.net>
parents:
1557
diff
changeset
|
218 if (err != 0) |
92c4b5c4b148
Sync with the GNU C library.
Jim Meyering <jim@meyering.net>
parents:
1557
diff
changeset
|
219 error (0, errno, "%s", file); |
92c4b5c4b148
Sync with the GNU C library.
Jim Meyering <jim@meyering.net>
parents:
1557
diff
changeset
|
220 exit (0); |
92c4b5c4b148
Sync with the GNU C library.
Jim Meyering <jim@meyering.net>
parents:
1557
diff
changeset
|
221 } |
92c4b5c4b148
Sync with the GNU C library.
Jim Meyering <jim@meyering.net>
parents:
1557
diff
changeset
|
222 #endif |