Hello, On GNU, processes can have zero or more UIDs/GIDs. In the case of a process with zero UIDs, for instance, ‘getuid’ returns -1 and sets ERRNO [0] (as an extension to POSIX [1].)
Currently ‘id’ would print (unsigned int) -1 as the UID in that case, whereas it should rather print an error. The attached patch does that. (Note that the Hurd comes with another utility, called ‘ids’, which prints all the (E)[UG]IDs of the process and gracefully handles the zero-UID/GID case [2].) Thanks, Ludo’. [0] http://git.savannah.gnu.org/cgit/hurd/glibc.git/tree/sysdeps/mach/hurd/getuid.c [1] http://pubs.opengroup.org/onlinepubs/9699919799/functions/getuid.html [2] http://git.savannah.gnu.org/cgit/hurd/hurd.git/tree/utils/ids.c
diff --git a/src/id.c b/src/id.c index f80fcd1..824a471 100644 --- a/src/id.c +++ b/src/id.c @@ -202,9 +202,28 @@ main (int argc, char **argv) else { euid = geteuid (); +#ifdef __GNU__ + if (euid == -1) + error (EXIT_FAILURE, errno, _("Cannot get effective UID")); +#endif + ruid = getuid (); +#ifdef __GNU__ + if (ruid == -1) + error (EXIT_FAILURE, errno, _("Cannot get real UID")); +#endif + egid = getegid (); +#ifdef __GNU__ + if (egid == -1) + error (EXIT_FAILURE, errno, _("Cannot get effective GID")); +#endif + rgid = getgid (); +#ifdef __GNU__ + if (rgid == -1) + error (EXIT_FAILURE, errno, _("Cannot get real GID")); +#endif } if (just_user)