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

2011-11-20 Thread Paul Eggert
No further comment to so I pushed that patch to groups, install, su, test, whoami. This should fix all the problems that coreutils has with getuid etc. returning -1. (Now all we have to do is fix all the other packages that assume getuid etc

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

2011-11-16 Thread Eric Blake
On 11/15/2011 10:09 AM, Eric Blake wrote: > Still debatable. POSIX explicitly states that the condition of errno > after a successful call to a standardized function is unspecified; that > is, a successful geteuid() may pollute errno, but it's okay, because the > user shouldn't be inspecting errno

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

2011-11-16 Thread Paul Eggert
Here are proposed patches for the other coreutils applications that invoke getuid et al. 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

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

2011-11-15 Thread Paul Eggert
On 11/15/11 09:10, Jim Meyering wrote: > I like that. Thanks! You're welcome; I pushed it. Similar fixes are needed for groups.c, install.c, su.c, test.c, and whoami.c, due to the possibility of getuid etc. failing on GNU/Hurd. I'll add this to my list of things to do, and post a patch here, un

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

2011-11-15 Thread Jim Meyering
Paul Eggert wrote: > On 11/15/11 05:07, Ludovic Courtès wrote: > >> On GNU/Hurd, no error would ever be raised (since uid_t is unsigned), > > Ouch. Thanks, now I understand Roland's suggestion. > How about this patch instead? > > id: handle (uid_t) -1 more portably > * src/id.c (GETID_MAY_FAIL): R

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

2011-11-15 Thread Eric Blake
On 11/15/2011 09:59 AM, Paul Eggert wrote: > On 11/15/11 05:07, Ludovic Courtès wrote: > >> On GNU/Hurd, no error would ever be raised (since uid_t is unsigned), > > Ouch. Thanks, now I understand Roland's suggestion. > How about this patch instead? >else > { > + /* POSIX says get

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

2011-11-15 Thread Paul Eggert
On 11/15/11 05:07, Ludovic Courtès wrote: > On GNU/Hurd, no error would ever be raised (since uid_t is unsigned), Ouch. Thanks, now I understand Roland's suggestion. How about this patch instead? id: handle (uid_t) -1 more portably * src/id.c (GETID_MAY_FAIL): Remove. (main): Check for nonzero

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

2011-11-15 Thread Ludovic Courtès
Hi Paul, Paul Eggert skribis: > - if (GETID_MAY_FAIL && euid == -1 && !use_real > + if (euid < 0 && !use_real >&& !just_group && !just_group_list && !just_context) > error (EXIT_FAILURE, errno, _("cannot get effective UID")); On GNU/Hurd, no error would ever be ra

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

2011-11-14 Thread Paul Eggert
On 11/14/11 11:12, Eric Blake wrote: > POSIX explicitly rejects (uid_t)(-1) as a valid UID. That depends on what one means by "valid". You're right about chown of course, but it's not clear that POSIX absolutely prohibits getuid from returning (uid_t) -1. And even if POSIX did prohibit that, GNU

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

2011-11-14 Thread Ludovic Courtès
Hi, Eric Blake skribis: > On 11/14/2011 11:54 AM, Paul Eggert wrote: [...] >>euid = geteuid (); >> - if (GETID_MAY_FAIL && euid == -1 && !use_real >> + if (euid < 0 && !use_real > > That is, how can this work? On systems where uid_t is signed, it makes > sense, but on system

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

2011-11-14 Thread Eric Blake
On 11/14/2011 11:54 AM, Paul Eggert wrote: >else > { > + /* On GNU hosts, getuid etc. can fail and return -1. On POSIX > + hosts, such failures are not allowed and (uid_t) -1 may be a > + valid UID if uid_t is unsigned. That doesn't read correctly. You are correct t

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

2011-11-14 Thread Roland McGrath
I think you can portably detect the failure case with the errno=0 method, rather than relying on #ifdef.

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

2011-11-14 Thread Paul Eggert
On 11/14/11 00:52, Jim Meyering wrote: > I tested this on a gnu/linux system and found that I could indeed create a > user with a UID of 2^32-1 If we really want to support that, there would be a lot of other coreutils code that would need fixing, no? For example, the command chown 4294967295

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

2011-11-14 Thread Jim Meyering
Ludovic Courtès wrote: ... >> However, with the patch below, it does this: >> >> $ ./id -u >> 4294967295 > > OK, good to know. Thank *you* for persevering! I'll take that as an ACK ;-) Pushed.

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

2011-11-14 Thread Ludovic Courtès
Hi, "Alan Curry" skribis: > Ludovic =?UTF-8?Q?Court=C3=A8s?= writes: >> >> OTOH, on POSIX-conforming systems (which includes GNU/Linux, so it may >> be the majority of systems in use), -1 may well be a valid UID/GID. > > That's a bizarre statement. > > 3.428 User ID > > A non-negative integ

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

2011-11-14 Thread Ludovic Courtès
Hi Jim, Jim Meyering skribis: > Ludovic Courtès wrote: > >> Hi Paul, >> >> Paul Eggert skribis: >> >>> On 11/12/11 13:48, Ludovic Courtès wrote: +#ifdef __GNU__ + if (euid == -1 && !use_real + && !just_group && !just_group_list && !just_context) +error

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

2011-11-14 Thread Jim Meyering
Ludovic Courtès wrote: > Hi Paul, > > Paul Eggert skribis: > >> On 11/12/11 13:48, Ludovic Courtès wrote: >>> +#ifdef __GNU__ >>> + if (euid == -1 && !use_real >>> + && !just_group && !just_group_list && !just_context) >>> +error (EXIT_FAILURE, errno, _("cannot get effective

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

2011-11-13 Thread Jim Meyering
Ludovic Courtès wrote: > Jim Meyering skribis: > >> Oh, I also had to make the new test script executable, >> or else "make check" would fail. > > It works for me even if it’s not executable when I run “make check > TESTS=id/gnu-zero-uids”, apparently because it’s run this way: > > execve("/bin/

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

2011-11-13 Thread Alan Curry
Ludovic =?UTF-8?Q?Court=C3=A8s?= writes: > > OTOH, on POSIX-conforming systems (which includes GNU/Linux, so it may > be the majority of systems in use), -1 may well be a valid UID/GID. That's a bizarre statement. 3.428 User ID A non-negative integer that is used to identify a system user.

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

2011-11-13 Thread Ludovic Courtès
Hi Paul, Paul Eggert skribis: > On 11/12/11 13:48, Ludovic Courtès wrote: >> +#ifdef __GNU__ >> + if (euid == -1 && !use_real >> + && !just_group && !just_group_list && !just_context) >> +error (EXIT_FAILURE, errno, _("cannot get effective UID")); >> +#endif > > I suggest r

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

2011-11-13 Thread Ludovic Courtès
Hi Jim, Jim Meyering skribis: > Oh, I also had to make the new test script executable, > or else "make check" would fail. It works for me even if it’s not executable when I run “make check TESTS=id/gnu-zero-uids”, apparently because it’s run this way: execve("/bin/sh", ["/bin/sh", "./shell-o

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

2011-11-13 Thread Jim Meyering
Ludovic Courtès wrote: > Thanks for the quick review! > > Jim Meyering skribis: > >> 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

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

2011-11-12 Thread Paul Eggert
On 11/12/11 13:48, Ludovic Courtès wrote: > +#ifdef __GNU__ > + if (euid == -1 && !use_real > + && !just_group && !just_group_list && !just_context) > +error (EXIT_FAILURE, errno, _("cannot get effective UID")); > +#endif I suggest removing the "#ifdef __GNU__" here and in it

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

2011-11-12 Thread Ludovic Courtès
Hi Jim, Thanks for the quick review! Jim Meyering skribis: > 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 GI

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

2011-11-11 Thread Jim Meyering
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 shoul