| http://bugs.gentoo.org/128715 |
| |
| exact implementation details are still in discussion upstream, but this fixes |
| the behavior to not suck like current code |
| |
| --- src/useradd.c |
| +++ src/useradd.c |
| @@ -254,6 +254,12 @@ |
| char *cp, *ep; |
| |
| /* |
| + * Pull relevant settings from login.defs first. |
| + */ |
| + if (getdef_bool ("USERGROUPS_ENAB")) |
| + nflg = -1; |
| + |
| + /* |
| * Open the defaults file for reading. |
| */ |
| |
| @@ -632,6 +638,8 @@ |
| " -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" |
| @@ -1001,6 +1009,7 @@ |
| {"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'}, |
| @@ -1008,7 +1017,7 @@ |
| {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': |
| @@ -1145,6 +1154,9 @@ |
| case 'm': |
| mflg++; |
| break; |
| + case 'n': |
| + nflg = 1; |
| + break; |
| case 'o': |
| oflg++; |
| break; |
| @@ -1192,6 +1204,16 @@ |
| 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. |
| */ |
| @@ -1728,7 +1750,7 @@ |
| * to that group, use useradd -g username username. |
| * --bero |
| */ |
| - if (!gflg) { |
| + if (nflg) { |
| if (getgrnam (user_name)) { /* local, no need for xgetgrnam */ |
| fprintf (stderr, |
| _ |
| @@ -1762,7 +1784,7 @@ |
| |
| /* 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)) { |
| + if (nflg) { |
| find_new_gid (); |
| grp_add (); |
| } |