initial import
[patches.git] / shadow-4.0.16-fix-useradd-usergroups.patch
1 --- src/useradd.c
2 +++ src/useradd.c
3 @@ -114,7 +114,7 @@ static int do_grp_update = 0; /* group f
4 static char *Prog;
5
6 static int
7 - bflg = 0, /* new default root of home directory */
8 + bflg = 0, /* new default root of home directory */
9 cflg = 0, /* comment (GECOS) field for new account */
10 dflg = 0, /* home directory for new account */
11 Dflg = 0, /* set/show new user default values */
12 @@ -253,6 +253,12 @@ static void get_defaults (void)
13 const struct group *grp;
14
15 /*
16 + * Pull relevant settings from login.defs first.
17 + */
18 + if (getdef_bool ("USERGROUPS_ENAB"))
19 + nflg = -1;
20 +
21 + /*
22 * Open the defaults file for reading.
23 */
24
25 @@ -628,6 +634,8 @@ static void usage (void)
26 " -K, --key KEY=VALUE overrides /etc/login.defs defaults\n"
27 " -m, --create-home create home directory for the new user\n"
28 " account\n"
29 + " -n, --user-group create a new group with the same name as the\n"
30 + " new user\n"
31 " -o, --non-unique allow create user with duplicate\n"
32 " (non-unique) UID\n"
33 " -p, --password PASSWORD use encrypted password for the new user\n"
34 @@ -1009,6 +1017,7 @@ static void process_flags (int argc, cha
35 {"skel", required_argument, NULL, 'k'},
36 {"key", required_argument, NULL, 'K'},
37 {"create-home", no_argument, NULL, 'm'},
38 + {"user-group", no_argument, NULL, 'n'},
39 {"non-unique", no_argument, NULL, 'o'},
40 {"password", required_argument, NULL, 'p'},
41 {"shell", required_argument, NULL, 's'},
42 @@ -1016,7 +1025,7 @@ static void process_flags (int argc, cha
43 {NULL, 0, NULL, '\0'}
44 };
45 while ((c =
46 - getopt_long (argc, argv, "b:c:d:De:f:g:G:k:K:mMop:s:u:",
47 + getopt_long (argc, argv, "b:c:d:De:f:g:G:k:K:mMnop:s:u:",
48 long_options, NULL)) != -1) {
49 switch (c) {
50 case 'b':
51 @@ -1156,6 +1165,9 @@ static void process_flags (int argc, cha
52 case 'm':
53 mflg++;
54 break;
55 + case 'n':
56 + nflg = 1;
57 + break;
58 case 'o':
59 oflg++;
60 break;
61 @@ -1203,6 +1215,16 @@ static void process_flags (int argc, cha
62 usage ();
63
64 /*
65 + * Using --gid and --user-group doesn't make sense.
66 + */
67 + if (nflg == -1 && gflg)
68 + nflg = 0;
69 + if (nflg && gflg) {
70 + fprintf (stderr, _("%s: options -g and -n conflict\n"), Prog);
71 + exit (E_BAD_ARG);
72 + }
73 +
74 + /*
75 * Either -D or username is required. Defaults can be set with -D
76 * for the -b, -e, -f, -g, -s options only.
77 */
78 @@ -1725,7 +1747,7 @@ int main (int argc, char **argv)
79 * to that group, use useradd -g username username.
80 * --bero
81 */
82 - if (!gflg) {
83 + if (nflg) {
84 if (getgrnam (user_name)) {
85 fprintf (stderr,
86 _
87 @@ -1759,7 +1781,7 @@ int main (int argc, char **argv)
88
89 /* do we have to add a group for that user? This is why we need to
90 * open the group files in the open_files() function --gafton */
91 - if (!(nflg || gflg)) {
92 + if (nflg) {
93 find_new_gid ();
94 grp_add ();
95 }