shadow 4.0.18.1: useradd -g broken (patch incl.)
"Brandon Peirce" <[email protected]> Tue, 19 Sep 2006 01:06:02 +0200
| Newsgroups | gmane.linux.pld.shadow.general |
|---|---|
| Message-ID | <[email protected]> |
Hello,
The fix from http://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=198920
seems
to have completely broken the -g option of useradd. (src/usradd.c $Id:
1.100)
The way getgr_nam_gid() is now working (in 4.0.18.1), if the numeric
conversion
succeeds then it doesn't call getgrgid() at all but it tries to lookup the
group
using getgrnam() with gid number which obviously fails. And if you give a
name
then the numeric conversion fails and it just exits without trying
getgrnam().
I also think that it's unclean to exit the program from the middle of the
function
for an out-of-range numeric but to exit after the function returns for any
other
kind of non-matching or badly formated argument. It also means that if you
call
the function getgr_nam_gid() in some other context, e.g. in get_defaults()
then
E_BAD_ARG would probably be the wrong exit code.
In the patch, I have preserved the new numeric range check but not the error
message. I've also kept the type change of the gid variable from gid_t to
long.
There are many things to consider and I'm not sure it's the right decision.
It may be problematic in 64-bit environments.
Regards,
Brandon
--- shadow-4.0.18.1/src/useradd.c 2006-07-28 19:42:48.000000000 +0200
+++ src0/src/useradd.c 2006-09-18 21:14:36.000000000 +0200
@@ -203,11 +203,14 @@
long gid;
char *errptr;
+ errno = 0;
gid = strtol (grname, &errptr, 10);
- if (*errptr || errno == ERANGE || gid < 0) {
- fprintf (stderr,
- _("%s: invalid numeric argument '%s'\n"), Prog, grname);
- exit (E_BAD_ARG);
+ if (*grname != '\0' && *errptr == '\0') {
+ if (errno == ERANGE || gid < 0) {
+ return (struct group*) NULL;
+ } else {
+ return getgrgid (gid);
+ }
}
return getgrnam (grname);
}
=== EOF ===