diff options
author | Paul Eggert <eggert@cs.ucla.edu> | 2011-11-20 14:08:33 -0800 |
---|---|---|
committer | Paul Eggert <eggert@cs.ucla.edu> | 2011-11-20 14:09:53 -0800 |
commit | 71b7ddcdd5c473f9eaf6035b96acc68c14cb379e (patch) | |
tree | a4d7544dc4ed5123a2ffaf40105fc8d0049ddf22 /src/test.c | |
parent | 8ffc159611db3443282aee42465afc8a1597519c (diff) | |
download | coreutils-71b7ddcdd5c473f9eaf6035b96acc68c14cb379e.tar.xz |
port to GNU hosts, where getuid and friends can fail
* src/groups.c (main):
* src/install.c (need_copy):
* src/su.c (log_su):
* src/test.c (unary_operator):
* src/whoami.c (main):
Don't assume that getuid and friends always succeed.
This fixes the same problem that we recently fixed with 'id'.
Diffstat (limited to 'src/test.c')
-rw-r--r-- | src/test.c | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/src/test.c b/src/test.c index 362df65d8..1b06ca86e 100644 --- a/src/test.c +++ b/src/test.c @@ -414,13 +414,21 @@ unary_operator (void) case 'O': /* File is owned by you? */ unary_advance (); - return (stat (argv[pos - 1], &stat_buf) == 0 - && (geteuid () == stat_buf.st_uid)); + if (stat (argv[pos - 1], &stat_buf) != 0) + return false; + errno = 0; + uid_t euid = geteuid (); + uid_t NO_UID = -1; + return ! (euid == NO_UID && errno) && euid == stat_buf.st_uid; case 'G': /* File is owned by your group? */ unary_advance (); - return (stat (argv[pos - 1], &stat_buf) == 0 - && (getegid () == stat_buf.st_gid)); + if (stat (argv[pos - 1], &stat_buf) != 0) + return false; + errno = 0; + gid_t egid = getegid (); + gid_t NO_GID = -1; + return ! (egid == NO_GID && errno) && egid == stat_buf.st_gid; case 'f': /* File is a file? */ unary_advance (); |