Skip to content

Commit 3a51b90

Browse files
authored
Merge pull request #176 from edneville/force_bad_name
chkname.c, pwck.c, useradd.c, usermod.c, newusers.c: Allow names that…
2 parents 1cbb562 + a2cd3e9 commit 3a51b90

File tree

9 files changed

+93
-5
lines changed

9 files changed

+93
-5
lines changed

libmisc/chkname.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,18 @@
4646
#include "defines.h"
4747
#include "chkname.h"
4848

49+
int allow_bad_names = false;
50+
4951
static bool is_valid_name (const char *name)
5052
{
53+
if (allow_bad_names) {
54+
return true;
55+
}
56+
5157
/*
5258
* User/group names must match [a-z_][a-z0-9_-]*[$]
5359
*/
60+
5461
if (('\0' == *name) ||
5562
!((('a' <= *name) && ('z' >= *name)) || ('_' == *name))) {
5663
return false;

man/newusers.8.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,18 @@
266266
<para>
267267
The options which apply to the <command>newusers</command> command are:
268268
</para>
269+
<variablelist remap='IP'>
270+
<varlistentry>
271+
<term>
272+
<option>--badname</option>&nbsp;
273+
</term>
274+
<listitem>
275+
<para>
276+
Allow names that do not conform to standards.
277+
</para>
278+
</listitem>
279+
</varlistentry>
280+
</variablelist>
269281
<variablelist remap='IP' condition="no_pam">
270282
<varlistentry>
271283
<term><option>-c</option>, <option>--crypt-method</option></term>

man/pwck.8.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,16 @@
182182
The options which apply to the <command>pwck</command> command are:
183183
</para>
184184
<variablelist remap='IP'>
185+
<varlistentry>
186+
<term>
187+
<option>--badname</option>&nbsp;
188+
</term>
189+
<listitem>
190+
<para>
191+
Allow names that do not conform to standards.
192+
</para>
193+
</listitem>
194+
</varlistentry>
185195
<varlistentry>
186196
<term><option>-h</option>, <option>--help</option></term>
187197
<listitem>

man/useradd.8.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,16 @@
126126
<para>The options which apply to the <command>useradd</command> command are:
127127
</para>
128128
<variablelist remap='IP'>
129+
<varlistentry>
130+
<term>
131+
<option>--badname</option>&nbsp;
132+
</term>
133+
<listitem>
134+
<para>
135+
Allow names that do not conform to standards.
136+
</para>
137+
</listitem>
138+
</varlistentry>
129139
<varlistentry>
130140
<term>
131141
<option>-b</option>, <option>--base-dir</option>&nbsp;<replaceable>BASE_DIR</replaceable>

man/usermod.8.xml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,26 @@
108108
</para>
109109
</listitem>
110110
</varlistentry>
111+
<varlistentry>
112+
<term>
113+
<option>-b</option>, <option>--badnames</option>
114+
</term>
115+
<listitem>
116+
<para>
117+
Allow names that do not conform to standards.
118+
</para>
119+
</listitem>
120+
</varlistentry>
121+
<varlistentry>
122+
<term>
123+
<option>-b</option>, <option>--badnames</option>
124+
</term>
125+
<listitem>
126+
<para>
127+
Allow names that do not conform to standards.
128+
</para>
129+
</listitem>
130+
</varlistentry>
111131
<varlistentry>
112132
<term>
113133
<option>-c</option>, <option>--comment</option>&nbsp;<replaceable>COMMENT</replaceable>

src/newusers.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@ static void check_perms (void);
117117
static void open_files (void);
118118
static void close_files (void);
119119

120+
extern int allow_bad_names;
121+
120122
/*
121123
* usage - display usage message and exit
122124
*/
@@ -128,6 +130,7 @@ static void usage (int status)
128130
"\n"
129131
"Options:\n"),
130132
Prog);
133+
(void) fputs (_(" -b, --badnames allow bad names\n"), usageout);
131134
#ifndef USE_PAM
132135
(void) fprintf (usageout,
133136
_(" -c, --crypt-method METHOD the crypt method (one of %s)\n"),
@@ -580,6 +583,7 @@ static void process_flags (int argc, char **argv)
580583
{
581584
int c;
582585
static struct option long_options[] = {
586+
{"badnames", no_argument, NULL, 'b'},
583587
#ifndef USE_PAM
584588
{"crypt-method", required_argument, NULL, 'c'},
585589
#endif /* !USE_PAM */
@@ -597,15 +601,18 @@ static void process_flags (int argc, char **argv)
597601
while ((c = getopt_long (argc, argv,
598602
#ifndef USE_PAM
599603
#ifdef USE_SHA_CRYPT
600-
"c:hrs:",
604+
"c:bhrs:",
601605
#else /* !USE_SHA_CRYPT */
602-
"c:hr",
606+
"c:bhr",
603607
#endif /* !USE_SHA_CRYPT */
604608
#else /* USE_PAM */
605-
"hr",
609+
"bhr",
606610
#endif
607611
long_options, NULL)) != -1) {
608612
switch (c) {
613+
case 'b':
614+
allow_bad_names = true;
615+
break;
609616
#ifndef USE_PAM
610617
case 'c':
611618
crypt_method = optarg;

src/pwck.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ static void close_files (bool changed);
9595
static void check_pw_file (int *errors, bool *changed);
9696
static void check_spw_file (int *errors, bool *changed);
9797

98+
extern int allow_bad_names;
99+
98100
/*
99101
* fail_exit - do some cleanup and exit with the given error code
100102
*/
@@ -148,6 +150,7 @@ static /*@noreturn@*/void usage (int status)
148150
"Options:\n"),
149151
Prog);
150152
}
153+
(void) fputs (_(" -b, --badnames allow bad names\n"), usageout);
151154
(void) fputs (_(" -h, --help display this help message and exit\n"), usageout);
152155
(void) fputs (_(" -q, --quiet report errors only\n"), usageout);
153156
(void) fputs (_(" -r, --read-only display errors and warnings\n"
@@ -172,6 +175,7 @@ static void process_flags (int argc, char **argv)
172175
{
173176
int c;
174177
static struct option long_options[] = {
178+
{"badnames", no_argument, NULL, 'b'},
175179
{"help", no_argument, NULL, 'h'},
176180
{"quiet", no_argument, NULL, 'q'},
177181
{"read-only", no_argument, NULL, 'r'},
@@ -183,9 +187,12 @@ static void process_flags (int argc, char **argv)
183187
/*
184188
* Parse the command line arguments
185189
*/
186-
while ((c = getopt_long (argc, argv, "ehqrR:s",
190+
while ((c = getopt_long (argc, argv, "behqrR:s",
187191
long_options, NULL)) != -1) {
188192
switch (c) {
193+
case 'b':
194+
allow_bad_names = true;
195+
break;
189196
case 'h':
190197
usage (E_SUCCESS);
191198
/*@notreached@*/break;
@@ -481,6 +488,7 @@ static void check_pw_file (int *errors, bool *changed)
481488
/*
482489
* Check for invalid usernames. --marekm
483490
*/
491+
484492
if (!is_valid_user_name (pwd->pw_name)) {
485493
printf (_("invalid user name '%s'\n"), pwd->pw_name);
486494
*errors += 1;

src/useradd.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,8 @@ static char **user_groups; /* NULL-terminated list */
148148
static long sys_ngroups;
149149
static bool do_grp_update = false; /* group files need to be updated */
150150

151+
extern int allow_bad_names;
152+
151153
static bool
152154
bflg = false, /* new default root of home directory */
153155
cflg = false, /* comment (GECOS) field for new account */
@@ -821,6 +823,7 @@ static void usage (int status)
821823
"\n"
822824
"Options:\n"),
823825
Prog, Prog, Prog);
826+
(void) fputs (_(" --badnames do not check for bad names\n"), usageout);
824827
(void) fputs (_(" -b, --base-dir BASE_DIR base directory for the home directory of the\n"
825828
" new account\n"), usageout);
826829
#ifdef WITH_BTRFS
@@ -1109,6 +1112,7 @@ static void process_flags (int argc, char **argv)
11091112
#ifdef WITH_BTRFS
11101113
{"btrfs-subvolume-home", no_argument, NULL, 200},
11111114
#endif
1115+
{"badnames", no_argument, NULL, 201},
11121116
{"comment", required_argument, NULL, 'c'},
11131117
{"home-dir", required_argument, NULL, 'd'},
11141118
{"defaults", no_argument, NULL, 'D'},
@@ -1158,6 +1162,9 @@ static void process_flags (int argc, char **argv)
11581162
case 200:
11591163
subvolflg = true;
11601164
break;
1165+
case 201:
1166+
allow_bad_names = true;
1167+
break;
11611168
case 'c':
11621169
if (!VALID (optarg)) {
11631170
fprintf (stderr,

src/usermod.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,8 @@ static void update_faillog (void);
206206
static void move_mailbox (void);
207207
#endif
208208

209+
extern int allow_bad_names;
210+
209211
static void date_to_str (/*@unique@*//*@out@*/char *buf, size_t maxsize,
210212
long int date)
211213
{
@@ -408,6 +410,7 @@ static /*@noreturn@*/void usage (int status)
408410
"\n"
409411
"Options:\n"),
410412
Prog);
413+
(void) fputs (_(" -b, --badnames allow bad names\n"), usageout);
411414
(void) fputs (_(" -c, --comment COMMENT new value of the GECOS field\n"), usageout);
412415
(void) fputs (_(" -d, --home HOME_DIR new home directory for the user account\n"), usageout);
413416
(void) fputs (_(" -e, --expiredate EXPIRE_DATE set account expiration date to EXPIRE_DATE\n"), usageout);
@@ -991,6 +994,7 @@ static void process_flags (int argc, char **argv)
991994
int c;
992995
static struct option long_options[] = {
993996
{"append", no_argument, NULL, 'a'},
997+
{"badnames", no_argument, NULL, 'b'},
994998
{"comment", required_argument, NULL, 'c'},
995999
{"home", required_argument, NULL, 'd'},
9961000
{"expiredate", required_argument, NULL, 'e'},
@@ -1020,7 +1024,7 @@ static void process_flags (int argc, char **argv)
10201024
{NULL, 0, NULL, '\0'}
10211025
};
10221026
while ((c = getopt_long (argc, argv,
1023-
"ac:d:e:f:g:G:hl:Lmop:R:s:u:UP:"
1027+
"abc:d:e:f:g:G:hl:Lmop:R:s:u:UP:"
10241028
#ifdef ENABLE_SUBIDS
10251029
"v:w:V:W:"
10261030
#endif /* ENABLE_SUBIDS */
@@ -1032,6 +1036,9 @@ static void process_flags (int argc, char **argv)
10321036
case 'a':
10331037
aflg = true;
10341038
break;
1039+
case 'b':
1040+
allow_bad_names = true;
1041+
break;
10351042
case 'c':
10361043
if (!VALID (optarg)) {
10371044
fprintf (stderr,

0 commit comments

Comments
 (0)