From 71b7ddcdd5c473f9eaf6035b96acc68c14cb379e Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Sun, 20 Nov 2011 14:08:33 -0800 Subject: 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'. --- src/groups.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'src/groups.c') diff --git a/src/groups.c b/src/groups.c index abb7bc7c7..279b83168 100644 --- a/src/groups.c +++ b/src/groups.c @@ -97,9 +97,23 @@ main (int argc, char **argv) if (optind == argc) { /* No arguments. Divulge the details of the current process. */ + uid_t NO_UID = -1; + gid_t NO_GID = -1; + + errno = 0; ruid = getuid (); + if (ruid == NO_UID && errno) + error (EXIT_FAILURE, errno, _("cannot get real UID")); + + errno = 0; egid = getegid (); + if (egid == NO_GID && errno) + error (EXIT_FAILURE, errno, _("cannot get effective GID")); + + errno = 0; rgid = getgid (); + if (rgid == NO_GID && errno) + error (EXIT_FAILURE, errno, _("cannot get real GID")); if (!print_group_list (NULL, ruid, rgid, egid, true)) ok = false; -- cgit v1.2.3-54-g00ecf