Mercurial > hg > octave-shane > gnulib-hg
annotate lib/euidaccess.c @ 15727:144db791c6fa
Ensure EBADF returns for socket functions on mingw.
* lib/accept.c (rpl_accept): Fail with error EBADF if the file
descriptor is invalid.
* lib/bind.c (rpl_bind): Likewise.
* lib/connect.c (rpl_connect): Likewise.
* lib/getpeername.c (rpl_getpeername): Likewise.
* lib/getsockname.c (rpl_getsockname): Likewise.
* lib/getsockopt.c (rpl_getsockopt): Likewise.
* lib/listen.c (rpl_listen): Likewise.
* lib/recv.c (rpl_recv): Likewise.
* lib/recvfrom.c (rpl_recvfrom): Likewise.
* lib/send.c (rpl_send): Likewise.
* lib/sendto.c (rpl_sendto): Likewise.
* lib/setsockopt.c (rpl_setsockopt): Likewise.
* lib/shutdown.c (rpl_shutdown): Likewise.
author | Bruno Haible <bruno@clisp.org> |
---|---|
date | Wed, 21 Sep 2011 00:20:59 +0200 |
parents | 8d8a6d8151f4 |
children | afdff76137f9 |
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 |
14079
97fc9a21a8fb
maint: update almost all copyright ranges to include 2011
Jim Meyering <meyering@redhat.com>
parents:
12919
diff
changeset
|
3 Copyright (C) 1990-1991, 1995, 1998, 2000, 2003-2006, 2008-2011 Free |
12518
b5e42ef33b49
update nearly all FSF copyright year lists to include 2009
Jim Meyering <meyering@redhat.com>
parents:
12421
diff
changeset
|
4 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 |
9309
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
7581
diff
changeset
|
8 This program is free software: you can redistribute it and/or modify |
4422 | 9 it under the terms of the GNU General Public License as published by |
9309
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
7581
diff
changeset
|
10 the Free Software Foundation; either version 3 of the License, or |
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
7581
diff
changeset
|
11 (at your option) 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 |
9309
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
7581
diff
changeset
|
18 You should have received a copy of the GNU General Public License |
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
7581
diff
changeset
|
19 along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
341 | 20 |
509 | 21 /* Written by David MacKenzie and Torbjorn Granlund. |
22 Adapted for GNU C library by Roland McGrath. */ | |
341 | 23 |
7302
8a1a9361108c
* _fpending.c: Include <config.h> unconditionally, since we no
Paul Eggert <eggert@cs.ucla.edu>
parents:
6275
diff
changeset
|
24 #ifndef _LIBC |
615
1f485b09b153
(euidaccess) [!S_IROTH]: Define.
Jim Meyering <jim@meyering.net>
parents:
509
diff
changeset
|
25 # include <config.h> |
4531
67c56a27d86c
Merge euidaccess etc. from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4422
diff
changeset
|
26 #endif |
67c56a27d86c
Merge euidaccess etc. from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4422
diff
changeset
|
27 |
11977
4f551695bc4c
euidaccess: fix compilation error
Eric Blake <ebb9@byu.net>
parents:
11944
diff
changeset
|
28 #include <fcntl.h> |
341 | 29 #include <sys/types.h> |
30 #include <sys/stat.h> | |
6275 | 31 #include <unistd.h> |
341 | 32 |
5157
62fa339919f4
[HAVE_LIBGEN_H]: Include <libgen.h>, for
Paul Eggert <eggert@cs.ucla.edu>
parents:
4637
diff
changeset
|
33 #if HAVE_LIBGEN_H |
62fa339919f4
[HAVE_LIBGEN_H]: Include <libgen.h>, for
Paul Eggert <eggert@cs.ucla.edu>
parents:
4637
diff
changeset
|
34 # include <libgen.h> |
62fa339919f4
[HAVE_LIBGEN_H]: Include <libgen.h>, for
Paul Eggert <eggert@cs.ucla.edu>
parents:
4637
diff
changeset
|
35 #endif |
341 | 36 |
37 #include <errno.h> | |
2094
92c4b5c4b148
Sync with the GNU C library.
Jim Meyering <jim@meyering.net>
parents:
1557
diff
changeset
|
38 #ifndef __set_errno |
92c4b5c4b148
Sync with the GNU C library.
Jim Meyering <jim@meyering.net>
parents:
1557
diff
changeset
|
39 # define __set_errno(val) errno = (val) |
92c4b5c4b148
Sync with the GNU C library.
Jim Meyering <jim@meyering.net>
parents:
1557
diff
changeset
|
40 #endif |
341 | 41 |
5157
62fa339919f4
[HAVE_LIBGEN_H]: Include <libgen.h>, for
Paul Eggert <eggert@cs.ucla.edu>
parents:
4637
diff
changeset
|
42 #if defined EACCES && !defined EACCESS |
615
1f485b09b153
(euidaccess) [!S_IROTH]: Define.
Jim Meyering <jim@meyering.net>
parents:
509
diff
changeset
|
43 # define EACCESS EACCES |
341 | 44 #endif |
45 | |
46 #ifndef F_OK | |
615
1f485b09b153
(euidaccess) [!S_IROTH]: Define.
Jim Meyering <jim@meyering.net>
parents:
509
diff
changeset
|
47 # define F_OK 0 |
1f485b09b153
(euidaccess) [!S_IROTH]: Define.
Jim Meyering <jim@meyering.net>
parents:
509
diff
changeset
|
48 # define X_OK 1 |
1f485b09b153
(euidaccess) [!S_IROTH]: Define.
Jim Meyering <jim@meyering.net>
parents:
509
diff
changeset
|
49 # define W_OK 2 |
1f485b09b153
(euidaccess) [!S_IROTH]: Define.
Jim Meyering <jim@meyering.net>
parents:
509
diff
changeset
|
50 # define R_OK 4 |
341 | 51 #endif |
52 | |
509 | 53 |
54 #ifdef _LIBC | |
55 | |
5157
62fa339919f4
[HAVE_LIBGEN_H]: Include <libgen.h>, for
Paul Eggert <eggert@cs.ucla.edu>
parents:
4637
diff
changeset
|
56 # define access __access |
62fa339919f4
[HAVE_LIBGEN_H]: Include <libgen.h>, for
Paul Eggert <eggert@cs.ucla.edu>
parents:
4637
diff
changeset
|
57 # define getuid __getuid |
62fa339919f4
[HAVE_LIBGEN_H]: Include <libgen.h>, for
Paul Eggert <eggert@cs.ucla.edu>
parents:
4637
diff
changeset
|
58 # define getgid __getgid |
62fa339919f4
[HAVE_LIBGEN_H]: Include <libgen.h>, for
Paul Eggert <eggert@cs.ucla.edu>
parents:
4637
diff
changeset
|
59 # define geteuid __geteuid |
62fa339919f4
[HAVE_LIBGEN_H]: Include <libgen.h>, for
Paul Eggert <eggert@cs.ucla.edu>
parents:
4637
diff
changeset
|
60 # define getegid __getegid |
615
1f485b09b153
(euidaccess) [!S_IROTH]: Define.
Jim Meyering <jim@meyering.net>
parents:
509
diff
changeset
|
61 # define group_member __group_member |
2094
92c4b5c4b148
Sync with the GNU C library.
Jim Meyering <jim@meyering.net>
parents:
1557
diff
changeset
|
62 # define euidaccess __euidaccess |
5157
62fa339919f4
[HAVE_LIBGEN_H]: Include <libgen.h>, for
Paul Eggert <eggert@cs.ucla.edu>
parents:
4637
diff
changeset
|
63 # undef stat |
62fa339919f4
[HAVE_LIBGEN_H]: Include <libgen.h>, for
Paul Eggert <eggert@cs.ucla.edu>
parents:
4637
diff
changeset
|
64 # define stat stat64 |
509 | 65 |
2094
92c4b5c4b148
Sync with the GNU C library.
Jim Meyering <jim@meyering.net>
parents:
1557
diff
changeset
|
66 #endif |
92c4b5c4b148
Sync with the GNU C library.
Jim Meyering <jim@meyering.net>
parents:
1557
diff
changeset
|
67 |
5907 | 68 /* 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
|
69 otherwise, return -1 and set `errno'. |
341 | 70 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
|
71 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
|
72 file system, text busy, etc. */ |
341 | 73 |
74 int | |
5907 | 75 euidaccess (const char *file, int mode) |
341 | 76 { |
12919
dc644566d7ab
Clarify access, euidaccess, faccessat.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
77 #if HAVE_FACCESSAT /* glibc */ |
11944
660d7f74a5e8
euidaccess: prefer POSIX over non-standard implementation
Eric Blake <ebb9@byu.net>
parents:
10662
diff
changeset
|
78 return faccessat (AT_FDCWD, file, mode, AT_EACCESS); |
12919
dc644566d7ab
Clarify access, euidaccess, faccessat.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
79 #elif defined EFF_ONLY_OK /* IRIX, OSF/1, Interix */ |
5907 | 80 return access (file, mode | EFF_ONLY_OK); |
12919
dc644566d7ab
Clarify access, euidaccess, faccessat.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
81 #elif defined ACC_SELF /* AIX */ |
5907 | 82 return accessx (file, mode, ACC_SELF); |
12919
dc644566d7ab
Clarify access, euidaccess, faccessat.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
83 #elif HAVE_EACCESS /* FreeBSD */ |
5907 | 84 return eaccess (file, mode); |
12919
dc644566d7ab
Clarify access, euidaccess, faccessat.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
85 #else /* MacOS X, NetBSD, OpenBSD, HP-UX, Solaris, Cygwin, mingw, BeOS */ |
5157
62fa339919f4
[HAVE_LIBGEN_H]: Include <libgen.h>, for
Paul Eggert <eggert@cs.ucla.edu>
parents:
4637
diff
changeset
|
86 |
62fa339919f4
[HAVE_LIBGEN_H]: Include <libgen.h>, for
Paul Eggert <eggert@cs.ucla.edu>
parents:
4637
diff
changeset
|
87 uid_t uid = getuid (); |
62fa339919f4
[HAVE_LIBGEN_H]: Include <libgen.h>, for
Paul Eggert <eggert@cs.ucla.edu>
parents:
4637
diff
changeset
|
88 gid_t gid = getgid (); |
62fa339919f4
[HAVE_LIBGEN_H]: Include <libgen.h>, for
Paul Eggert <eggert@cs.ucla.edu>
parents:
4637
diff
changeset
|
89 uid_t euid = geteuid (); |
62fa339919f4
[HAVE_LIBGEN_H]: Include <libgen.h>, for
Paul Eggert <eggert@cs.ucla.edu>
parents:
4637
diff
changeset
|
90 gid_t egid = getegid (); |
62fa339919f4
[HAVE_LIBGEN_H]: Include <libgen.h>, for
Paul Eggert <eggert@cs.ucla.edu>
parents:
4637
diff
changeset
|
91 struct stat stats; |
62fa339919f4
[HAVE_LIBGEN_H]: Include <libgen.h>, for
Paul Eggert <eggert@cs.ucla.edu>
parents:
4637
diff
changeset
|
92 |
62fa339919f4
[HAVE_LIBGEN_H]: Include <libgen.h>, for
Paul Eggert <eggert@cs.ucla.edu>
parents:
4637
diff
changeset
|
93 # 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
|
94 |
62fa339919f4
[HAVE_LIBGEN_H]: Include <libgen.h>, for
Paul Eggert <eggert@cs.ucla.edu>
parents:
4637
diff
changeset
|
95 /* 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
|
96 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
|
97 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
|
98 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
|
99 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
|
100 safe. */ |
62fa339919f4
[HAVE_LIBGEN_H]: Include <libgen.h>, for
Paul Eggert <eggert@cs.ucla.edu>
parents:
4637
diff
changeset
|
101 |
62fa339919f4
[HAVE_LIBGEN_H]: Include <libgen.h>, for
Paul Eggert <eggert@cs.ucla.edu>
parents:
4637
diff
changeset
|
102 if (mode == F_OK) |
5907 | 103 return stat (file, &stats); |
5157
62fa339919f4
[HAVE_LIBGEN_H]: Include <libgen.h>, for
Paul Eggert <eggert@cs.ucla.edu>
parents:
4637
diff
changeset
|
104 else |
341 | 105 { |
5157
62fa339919f4
[HAVE_LIBGEN_H]: Include <libgen.h>, for
Paul Eggert <eggert@cs.ucla.edu>
parents:
4637
diff
changeset
|
106 int result; |
62fa339919f4
[HAVE_LIBGEN_H]: Include <libgen.h>, for
Paul Eggert <eggert@cs.ucla.edu>
parents:
4637
diff
changeset
|
107 int saved_errno; |
5421 | 108 |
5157
62fa339919f4
[HAVE_LIBGEN_H]: Include <libgen.h>, for
Paul Eggert <eggert@cs.ucla.edu>
parents:
4637
diff
changeset
|
109 if (uid != euid) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11977
diff
changeset
|
110 setreuid (euid, uid); |
5157
62fa339919f4
[HAVE_LIBGEN_H]: Include <libgen.h>, for
Paul Eggert <eggert@cs.ucla.edu>
parents:
4637
diff
changeset
|
111 if (gid != egid) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11977
diff
changeset
|
112 setregid (egid, gid); |
5157
62fa339919f4
[HAVE_LIBGEN_H]: Include <libgen.h>, for
Paul Eggert <eggert@cs.ucla.edu>
parents:
4637
diff
changeset
|
113 |
5907 | 114 result = access (file, mode); |
5157
62fa339919f4
[HAVE_LIBGEN_H]: Include <libgen.h>, for
Paul Eggert <eggert@cs.ucla.edu>
parents:
4637
diff
changeset
|
115 saved_errno = errno; |
5421 | 116 |
5157
62fa339919f4
[HAVE_LIBGEN_H]: Include <libgen.h>, for
Paul Eggert <eggert@cs.ucla.edu>
parents:
4637
diff
changeset
|
117 /* Restore them. */ |
62fa339919f4
[HAVE_LIBGEN_H]: Include <libgen.h>, for
Paul Eggert <eggert@cs.ucla.edu>
parents:
4637
diff
changeset
|
118 if (uid != euid) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11977
diff
changeset
|
119 setreuid (uid, euid); |
5157
62fa339919f4
[HAVE_LIBGEN_H]: Include <libgen.h>, for
Paul Eggert <eggert@cs.ucla.edu>
parents:
4637
diff
changeset
|
120 if (gid != egid) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11977
diff
changeset
|
121 setregid (gid, egid); |
5157
62fa339919f4
[HAVE_LIBGEN_H]: Include <libgen.h>, for
Paul Eggert <eggert@cs.ucla.edu>
parents:
4637
diff
changeset
|
122 |
62fa339919f4
[HAVE_LIBGEN_H]: Include <libgen.h>, for
Paul Eggert <eggert@cs.ucla.edu>
parents:
4637
diff
changeset
|
123 errno = saved_errno; |
62fa339919f4
[HAVE_LIBGEN_H]: Include <libgen.h>, for
Paul Eggert <eggert@cs.ucla.edu>
parents:
4637
diff
changeset
|
124 return result; |
341 | 125 } |
126 | |
5157
62fa339919f4
[HAVE_LIBGEN_H]: Include <libgen.h>, for
Paul Eggert <eggert@cs.ucla.edu>
parents:
4637
diff
changeset
|
127 # else |
62fa339919f4
[HAVE_LIBGEN_H]: Include <libgen.h>, for
Paul Eggert <eggert@cs.ucla.edu>
parents:
4637
diff
changeset
|
128 |
62fa339919f4
[HAVE_LIBGEN_H]: Include <libgen.h>, for
Paul Eggert <eggert@cs.ucla.edu>
parents:
4637
diff
changeset
|
129 /* 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
|
130 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
|
131 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
|
132 |
62fa339919f4
[HAVE_LIBGEN_H]: Include <libgen.h>, for
Paul Eggert <eggert@cs.ucla.edu>
parents:
4637
diff
changeset
|
133 unsigned int granted; |
341 | 134 if (uid == euid && gid == egid) |
509 | 135 /* If we are not set-uid or set-gid, access does the same. */ |
5907 | 136 return access (file, mode); |
341 | 137 |
5907 | 138 if (stat (file, &stats) != 0) |
341 | 139 return -1; |
140 | |
509 | 141 /* 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
|
142 that anyone can execute. */ |
509 | 143 if (euid == 0 && ((mode & X_OK) == 0 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11977
diff
changeset
|
144 || (stats.st_mode & (S_IXUSR | S_IXGRP | S_IXOTH)))) |
509 | 145 return 0; |
341 | 146 |
5157
62fa339919f4
[HAVE_LIBGEN_H]: Include <libgen.h>, for
Paul Eggert <eggert@cs.ucla.edu>
parents:
4637
diff
changeset
|
147 /* 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
|
148 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
|
149 mode &= 7; |
62fa339919f4
[HAVE_LIBGEN_H]: Include <libgen.h>, for
Paul Eggert <eggert@cs.ucla.edu>
parents:
4637
diff
changeset
|
150 else |
62fa339919f4
[HAVE_LIBGEN_H]: Include <libgen.h>, for
Paul Eggert <eggert@cs.ucla.edu>
parents:
4637
diff
changeset
|
151 mode = ((mode & R_OK ? 4 : 0) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11977
diff
changeset
|
152 + (mode & W_OK ? 2 : 0) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11977
diff
changeset
|
153 + (mode & X_OK ? 1 : 0)); |
5157
62fa339919f4
[HAVE_LIBGEN_H]: Include <libgen.h>, for
Paul Eggert <eggert@cs.ucla.edu>
parents:
4637
diff
changeset
|
154 |
62fa339919f4
[HAVE_LIBGEN_H]: Include <libgen.h>, for
Paul Eggert <eggert@cs.ucla.edu>
parents:
4637
diff
changeset
|
155 if (mode == 0) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11977
diff
changeset
|
156 return 0; /* The file exists. */ |
5157
62fa339919f4
[HAVE_LIBGEN_H]: Include <libgen.h>, for
Paul Eggert <eggert@cs.ucla.edu>
parents:
4637
diff
changeset
|
157 |
62fa339919f4
[HAVE_LIBGEN_H]: Include <libgen.h>, for
Paul Eggert <eggert@cs.ucla.edu>
parents:
4637
diff
changeset
|
158 /* 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
|
159 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
|
160 && 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
|
161 && 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
|
162 granted = stats.st_mode; |
62fa339919f4
[HAVE_LIBGEN_H]: Include <libgen.h>, for
Paul Eggert <eggert@cs.ucla.edu>
parents:
4637
diff
changeset
|
163 else |
62fa339919f4
[HAVE_LIBGEN_H]: Include <libgen.h>, for
Paul Eggert <eggert@cs.ucla.edu>
parents:
4637
diff
changeset
|
164 granted = ((stats.st_mode & S_IRUSR ? 4 << 6 : 0) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11977
diff
changeset
|
165 + (stats.st_mode & S_IWUSR ? 2 << 6 : 0) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11977
diff
changeset
|
166 + (stats.st_mode & S_IXUSR ? 1 << 6 : 0) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11977
diff
changeset
|
167 + (stats.st_mode & S_IRGRP ? 4 << 3 : 0) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11977
diff
changeset
|
168 + (stats.st_mode & S_IWGRP ? 2 << 3 : 0) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11977
diff
changeset
|
169 + (stats.st_mode & S_IXGRP ? 1 << 3 : 0) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11977
diff
changeset
|
170 + (stats.st_mode & S_IROTH ? 4 << 0 : 0) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11977
diff
changeset
|
171 + (stats.st_mode & S_IWOTH ? 2 << 0 : 0) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11977
diff
changeset
|
172 + (stats.st_mode & S_IXOTH ? 1 << 0 : 0)); |
5157
62fa339919f4
[HAVE_LIBGEN_H]: Include <libgen.h>, for
Paul Eggert <eggert@cs.ucla.edu>
parents:
4637
diff
changeset
|
173 |
509 | 174 if (euid == stats.st_uid) |
5157
62fa339919f4
[HAVE_LIBGEN_H]: Include <libgen.h>, for
Paul Eggert <eggert@cs.ucla.edu>
parents:
4637
diff
changeset
|
175 granted >>= 6; |
509 | 176 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
|
177 granted >>= 3; |
62fa339919f4
[HAVE_LIBGEN_H]: Include <libgen.h>, for
Paul Eggert <eggert@cs.ucla.edu>
parents:
4637
diff
changeset
|
178 |
62fa339919f4
[HAVE_LIBGEN_H]: Include <libgen.h>, for
Paul Eggert <eggert@cs.ucla.edu>
parents:
4637
diff
changeset
|
179 if ((mode & ~granted) == 0) |
509 | 180 return 0; |
2094
92c4b5c4b148
Sync with the GNU C library.
Jim Meyering <jim@meyering.net>
parents:
1557
diff
changeset
|
181 __set_errno (EACCESS); |
509 | 182 return -1; |
5157
62fa339919f4
[HAVE_LIBGEN_H]: Include <libgen.h>, for
Paul Eggert <eggert@cs.ucla.edu>
parents:
4637
diff
changeset
|
183 |
62fa339919f4
[HAVE_LIBGEN_H]: Include <libgen.h>, for
Paul Eggert <eggert@cs.ucla.edu>
parents:
4637
diff
changeset
|
184 # endif |
62fa339919f4
[HAVE_LIBGEN_H]: Include <libgen.h>, for
Paul Eggert <eggert@cs.ucla.edu>
parents:
4637
diff
changeset
|
185 #endif |
341 | 186 } |
2094
92c4b5c4b148
Sync with the GNU C library.
Jim Meyering <jim@meyering.net>
parents:
1557
diff
changeset
|
187 #undef euidaccess |
92c4b5c4b148
Sync with the GNU C library.
Jim Meyering <jim@meyering.net>
parents:
1557
diff
changeset
|
188 #ifdef weak_alias |
92c4b5c4b148
Sync with the GNU C library.
Jim Meyering <jim@meyering.net>
parents:
1557
diff
changeset
|
189 weak_alias (__euidaccess, euidaccess) |
92c4b5c4b148
Sync with the GNU C library.
Jim Meyering <jim@meyering.net>
parents:
1557
diff
changeset
|
190 #endif |
92c4b5c4b148
Sync with the GNU C library.
Jim Meyering <jim@meyering.net>
parents:
1557
diff
changeset
|
191 |
92c4b5c4b148
Sync with the GNU C library.
Jim Meyering <jim@meyering.net>
parents:
1557
diff
changeset
|
192 #ifdef TEST |
5157
62fa339919f4
[HAVE_LIBGEN_H]: Include <libgen.h>, for
Paul Eggert <eggert@cs.ucla.edu>
parents:
4637
diff
changeset
|
193 # include <error.h> |
2094
92c4b5c4b148
Sync with the GNU C library.
Jim Meyering <jim@meyering.net>
parents:
1557
diff
changeset
|
194 # include <stdio.h> |
5157
62fa339919f4
[HAVE_LIBGEN_H]: Include <libgen.h>, for
Paul Eggert <eggert@cs.ucla.edu>
parents:
4637
diff
changeset
|
195 # include <stdlib.h> |
2094
92c4b5c4b148
Sync with the GNU C library.
Jim Meyering <jim@meyering.net>
parents:
1557
diff
changeset
|
196 |
92c4b5c4b148
Sync with the GNU C library.
Jim Meyering <jim@meyering.net>
parents:
1557
diff
changeset
|
197 char *program_name; |
92c4b5c4b148
Sync with the GNU C library.
Jim Meyering <jim@meyering.net>
parents:
1557
diff
changeset
|
198 |
92c4b5c4b148
Sync with the GNU C library.
Jim Meyering <jim@meyering.net>
parents:
1557
diff
changeset
|
199 int |
4637
f736e2167837
(main): Define with a prototype.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4531
diff
changeset
|
200 main (int argc, char **argv) |
2094
92c4b5c4b148
Sync with the GNU C library.
Jim Meyering <jim@meyering.net>
parents:
1557
diff
changeset
|
201 { |
92c4b5c4b148
Sync with the GNU C library.
Jim Meyering <jim@meyering.net>
parents:
1557
diff
changeset
|
202 char *file; |
92c4b5c4b148
Sync with the GNU C library.
Jim Meyering <jim@meyering.net>
parents:
1557
diff
changeset
|
203 int mode; |
92c4b5c4b148
Sync with the GNU C library.
Jim Meyering <jim@meyering.net>
parents:
1557
diff
changeset
|
204 int err; |
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 program_name = argv[0]; |
92c4b5c4b148
Sync with the GNU C library.
Jim Meyering <jim@meyering.net>
parents:
1557
diff
changeset
|
207 if (argc < 3) |
92c4b5c4b148
Sync with the GNU C library.
Jim Meyering <jim@meyering.net>
parents:
1557
diff
changeset
|
208 abort (); |
92c4b5c4b148
Sync with the GNU C library.
Jim Meyering <jim@meyering.net>
parents:
1557
diff
changeset
|
209 file = argv[1]; |
92c4b5c4b148
Sync with the GNU C library.
Jim Meyering <jim@meyering.net>
parents:
1557
diff
changeset
|
210 mode = atoi (argv[2]); |
92c4b5c4b148
Sync with the GNU C library.
Jim Meyering <jim@meyering.net>
parents:
1557
diff
changeset
|
211 |
92c4b5c4b148
Sync with the GNU C library.
Jim Meyering <jim@meyering.net>
parents:
1557
diff
changeset
|
212 err = euidaccess (file, mode); |
92c4b5c4b148
Sync with the GNU C library.
Jim Meyering <jim@meyering.net>
parents:
1557
diff
changeset
|
213 printf ("%d\n", err); |
92c4b5c4b148
Sync with the GNU C library.
Jim Meyering <jim@meyering.net>
parents:
1557
diff
changeset
|
214 if (err != 0) |
92c4b5c4b148
Sync with the GNU C library.
Jim Meyering <jim@meyering.net>
parents:
1557
diff
changeset
|
215 error (0, errno, "%s", file); |
92c4b5c4b148
Sync with the GNU C library.
Jim Meyering <jim@meyering.net>
parents:
1557
diff
changeset
|
216 exit (0); |
92c4b5c4b148
Sync with the GNU C library.
Jim Meyering <jim@meyering.net>
parents:
1557
diff
changeset
|
217 } |
92c4b5c4b148
Sync with the GNU C library.
Jim Meyering <jim@meyering.net>
parents:
1557
diff
changeset
|
218 #endif |