primary group in useradd >= 4.0.14
Johannes Winkelmann <[email protected]> Fri, 7 Apr 2006 11:20:41 +0200
| Newsgroups | gmane.linux.pld.shadow.general |
|---|---|
| Message-ID | <[email protected]> |
Hi,
We [1] ran into an interesting problem with useradd today: when adding users
without -g switch (`useradd tester`), der User gets his own group, even
though useradd -D prints gid=100 as default group, and even if
/etc/default/useradd is provided.
Looking a bit closer, the change "merge PUG fixes from RedHat patch."
introduced the following code (useradd.c rev 1.86, merged before the
release of 4.0.14), line 1770 in 4.0.15:
+ if (!(nflg || gflg)) {
+ find_new_gid ();
+ grp_add ();
+ }
However, nflg is never touched after its definition, and gflg is only
set if the -g switch has been specified. So if I understand that
correctly, unless a primary group is specified via -g switch, a new one
is created and set. This behaviour is different from the one in 4.0.13,
and differs from the description in the man page.
As this comes from Redhat, I checked their source RPM for 4.0.14, and
found that they actually invert the meaning of nflg:
- nflg = 0, /* create a group having the same name as the user */
+ nflg = 0, /* do NOT create a group having the same name as the user */
plus they parse for a -n option on the command line, which optionally
makes useradd use /etc/default/useradd or its internal defaults.
[shadow-4.0.14-redhat.patch from]
http://download.fedora.redhat.com/pub/fedora/linux/core/updates/5/SRPMS/shadow-utils-4.0.14-5.FC5.src.rpm
After seeing that, the above contruct makes sense; on Redhat the user
can call useradd with the -n option to make it _not_ create a new group,
while the default is to create one, with a third option to specify an
existing one via -g.
Our current solution is to disable the code block in question:
http://crux.nu/svnweb/CRUX/view/crux-2.2/ports/core/shadow/useradd-4.0.15.diff
The LFS guys just invert nflg (which seems sensible, even though the
code then has no effect):
http://wiki.linuxfromscratch.org/patches/browser/trunk/shadow/shadow-4.0.14-useradd_addgroup-1.patch?rev=1416
I personally would prefer to have a '-n' option which would create a
private group per user and otherwise using the defaults from
/etc/default/useradd (or shadows internal ones) like before .14, however
this would obviously make it act differently than RedHat's version.
Tomasz, what's your plan here? I'd be more than happy to provide a patch
for the behaviour mentioned above if that's what you'd like to see too.
Thanks in advance,
Johannes
References:
1. http://crux.nu
--
Johannes Winkelmann mailto:[email protected]
Zurich, Switzerland http://jw.tks6.net