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