[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#10021: [PATCH id] Add error-checking on GNU

From: Ludovic Courtès
Subject: bug#10021: [PATCH id] Add error-checking on GNU
Date: Fri, 11 Nov 2011 20:31:57 +0100
User-agent: Gnus/5.110018 (No Gnus v0.18) Emacs/24.0.90 (gnu/linux)


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].)


[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)
       euid = geteuid ();
+#ifdef __GNU__
+      if (euid == -1)
+       error (EXIT_FAILURE, errno, _("Cannot get effective UID"));
       ruid = getuid ();
+#ifdef __GNU__
+      if (ruid == -1)
+       error (EXIT_FAILURE, errno, _("Cannot get real UID"));
       egid = getegid ();
+#ifdef __GNU__
+      if (egid == -1)
+       error (EXIT_FAILURE, errno, _("Cannot get effective GID"));
       rgid = getgid ();
+#ifdef __GNU__
+      if (rgid == -1)
+       error (EXIT_FAILURE, errno, _("Cannot get real GID"));
   if (just_user)

reply via email to

[Prev in Thread] Current Thread [Next in Thread]