2006-09-08 17:15:18 +02:00
|
|
|
Taken from
|
|
|
|
http://sources.gentoo.org/viewcvs.py/gentoo-x86/sys-apps/shadow/files/shadow-4.0.18.1-useradd-usermod.patch?rev=1.1&view=markup
|
2006-04-08 16:39:04 +02:00
|
|
|
|
2006-09-08 17:15:18 +02:00
|
|
|
http://bugs.gentoo.org/128715
|
2006-04-08 16:39:04 +02:00
|
|
|
|
2006-09-08 17:15:18 +02:00
|
|
|
exact implementation details are still in discussion upstream, but this fixes
|
|
|
|
the behavior to not suck like current code
|
|
|
|
|
|
|
|
Index: src/useradd.c
|
|
|
|
===================================================================
|
|
|
|
RCS file: /cvsroot/shadow/src/useradd.c,v
|
|
|
|
retrieving revision 1.96
|
|
|
|
diff -u -p -r1.96 useradd.c
|
|
|
|
--- src/useradd.c 30 May 2006 18:28:45 -0000 1.96
|
|
|
|
+++ src/useradd.c 10 Jun 2006 22:13:32 -0000
|
2006-04-08 16:39:04 +02:00
|
|
|
@@ -114,7 +114,7 @@ static int do_grp_update = 0; /* group f
|
|
|
|
static char *Prog;
|
|
|
|
|
|
|
|
static int
|
|
|
|
- bflg = 0, /* new default root of home directory */
|
|
|
|
+ bflg = 0, /* new default root of home directory */
|
|
|
|
cflg = 0, /* comment (GECOS) field for new account */
|
|
|
|
dflg = 0, /* home directory for new account */
|
|
|
|
Dflg = 0, /* set/show new user default values */
|
2006-09-08 17:15:18 +02:00
|
|
|
@@ -253,6 +253,12 @@ static void get_defaults (void)
|
2006-04-08 16:39:04 +02:00
|
|
|
const struct group *grp;
|
|
|
|
|
|
|
|
/*
|
|
|
|
+ * Pull relevant settings from login.defs first.
|
|
|
|
+ */
|
2006-09-08 17:15:18 +02:00
|
|
|
+ if (getdef_bool ("USERGROUPS_ENAB"))
|
|
|
|
+ nflg = -1;
|
|
|
|
+
|
2006-04-08 16:39:04 +02:00
|
|
|
+ /*
|
|
|
|
* Open the defaults file for reading.
|
|
|
|
*/
|
|
|
|
|
2006-09-08 17:15:18 +02:00
|
|
|
@@ -628,6 +634,8 @@ static void usage (void)
|
2006-04-08 16:39:04 +02:00
|
|
|
" -K, --key KEY=VALUE overrides /etc/login.defs defaults\n"
|
|
|
|
" -m, --create-home create home directory for the new user\n"
|
|
|
|
" account\n"
|
|
|
|
+ " -n, --user-group create a new group with the same name as the\n"
|
|
|
|
+ " new user\n"
|
|
|
|
" -o, --non-unique allow create user with duplicate\n"
|
|
|
|
" (non-unique) UID\n"
|
|
|
|
" -p, --password PASSWORD use encrypted password for the new user\n"
|
2006-09-08 17:15:18 +02:00
|
|
|
@@ -1009,6 +1017,7 @@ static void process_flags (int argc, cha
|
2006-04-08 16:39:04 +02:00
|
|
|
{"skel", required_argument, NULL, 'k'},
|
|
|
|
{"key", required_argument, NULL, 'K'},
|
|
|
|
{"create-home", no_argument, NULL, 'm'},
|
|
|
|
+ {"user-group", no_argument, NULL, 'n'},
|
|
|
|
{"non-unique", no_argument, NULL, 'o'},
|
|
|
|
{"password", required_argument, NULL, 'p'},
|
|
|
|
{"shell", required_argument, NULL, 's'},
|
2006-09-08 17:15:18 +02:00
|
|
|
@@ -1016,7 +1025,7 @@ static void process_flags (int argc, cha
|
2006-04-08 16:39:04 +02:00
|
|
|
{NULL, 0, NULL, '\0'}
|
|
|
|
};
|
|
|
|
while ((c =
|
|
|
|
- getopt_long (argc, argv, "b:c:d:De:f:g:G:k:K:mMop:s:u:",
|
|
|
|
+ getopt_long (argc, argv, "b:c:d:De:f:g:G:k:K:mMnop:s:u:",
|
|
|
|
long_options, NULL)) != -1) {
|
|
|
|
switch (c) {
|
|
|
|
case 'b':
|
2006-09-08 17:15:18 +02:00
|
|
|
@@ -1156,6 +1165,9 @@ static void process_flags (int argc, cha
|
2006-04-08 16:39:04 +02:00
|
|
|
case 'm':
|
|
|
|
mflg++;
|
|
|
|
break;
|
|
|
|
+ case 'n':
|
2006-09-08 17:15:18 +02:00
|
|
|
+ nflg = 1;
|
2006-04-08 16:39:04 +02:00
|
|
|
+ break;
|
|
|
|
case 'o':
|
|
|
|
oflg++;
|
|
|
|
break;
|
2006-09-08 17:15:18 +02:00
|
|
|
@@ -1203,6 +1215,16 @@ static void process_flags (int argc, cha
|
|
|
|
usage ();
|
|
|
|
|
|
|
|
/*
|
|
|
|
+ * Using --gid and --user-group doesn't make sense.
|
|
|
|
+ */
|
|
|
|
+ if (nflg == -1 && gflg)
|
|
|
|
+ nflg = 0;
|
|
|
|
+ if (nflg && gflg) {
|
|
|
|
+ fprintf (stderr, _("%s: options -g and -n conflict\n"), Prog);
|
|
|
|
+ exit (E_BAD_ARG);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /*
|
|
|
|
* Either -D or username is required. Defaults can be set with -D
|
|
|
|
* for the -b, -e, -f, -g, -s options only.
|
|
|
|
*/
|
|
|
|
@@ -1725,7 +1747,7 @@ int main (int argc, char **argv)
|
|
|
|
* to that group, use useradd -g username username.
|
|
|
|
* --bero
|
|
|
|
*/
|
|
|
|
- if (!gflg) {
|
|
|
|
+ if (nflg) {
|
|
|
|
if (getgrnam (user_name)) {
|
|
|
|
fprintf (stderr,
|
|
|
|
_
|
|
|
|
@@ -1759,7 +1781,7 @@ int main (int argc, char **argv)
|
2006-04-08 16:39:04 +02:00
|
|
|
|
|
|
|
/* do we have to add a group for that user? This is why we need to
|
|
|
|
* open the group files in the open_files() function --gafton */
|
|
|
|
- if (!(nflg || gflg)) {
|
2006-09-08 17:15:18 +02:00
|
|
|
+ if (nflg) {
|
2006-04-08 16:39:04 +02:00
|
|
|
find_new_gid ();
|
|
|
|
grp_add ();
|
|
|
|
}
|