[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: |
Jim Meyering |
Subject: |
bug#10021: [PATCH id] Add error-checking on GNU |
Date: |
Fri, 11 Nov 2011 21:03:43 +0100 |
Ludovic Courtès wrote:
> 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
Hi Ludo,
Thanks for the patch.
However, wouldn't that fail unnecessarily for a process without
one ID even though id is being asked to print some other(s)?
E.g., it'd fail for a process with no EUID even when id
is being asked to print only the real UID or GIDs.
Also, if you send another version, please indent only with spaces
and change each diagnostic to start with lower case letter.
You may want to run "make syntax-check" to check for things like that.
> 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)