chkname.c, pwck.c, useradd.c, usermod.c, newusers.c: Allow names that do not conform to standards

Closes #121.

Changelog: squashed commits fixing tab style
Changelog: update 'return true' to match file's style (no parens).
This commit is contained in:
ed 2019-08-23 21:42:37 +01:00 committed by Serge Hallyn
parent 5687be5f31
commit a2cd3e9ef0
9 changed files with 93 additions and 5 deletions

View File

@ -46,11 +46,18 @@
#include "defines.h" #include "defines.h"
#include "chkname.h" #include "chkname.h"
int allow_bad_names = false;
static bool is_valid_name (const char *name) static bool is_valid_name (const char *name)
{ {
if (allow_bad_names) {
return true;
}
/* /*
* User/group names must match [a-z_][a-z0-9_-]*[$] * User/group names must match [a-z_][a-z0-9_-]*[$]
*/ */
if (('\0' == *name) || if (('\0' == *name) ||
!((('a' <= *name) && ('z' >= *name)) || ('_' == *name))) { !((('a' <= *name) && ('z' >= *name)) || ('_' == *name))) {
return false; return false;

View File

@ -266,6 +266,18 @@
<para> <para>
The options which apply to the <command>newusers</command> command are: The options which apply to the <command>newusers</command> command are:
</para> </para>
<variablelist remap='IP'>
<varlistentry>
<term>
<option>--badname</option>&nbsp;
</term>
<listitem>
<para>
Allow names that do not conform to standards.
</para>
</listitem>
</varlistentry>
</variablelist>
<variablelist remap='IP' condition="no_pam"> <variablelist remap='IP' condition="no_pam">
<varlistentry> <varlistentry>
<term><option>-c</option>, <option>--crypt-method</option></term> <term><option>-c</option>, <option>--crypt-method</option></term>

View File

@ -182,6 +182,16 @@
The options which apply to the <command>pwck</command> command are: The options which apply to the <command>pwck</command> command are:
</para> </para>
<variablelist remap='IP'> <variablelist remap='IP'>
<varlistentry>
<term>
<option>--badname</option>&nbsp;
</term>
<listitem>
<para>
Allow names that do not conform to standards.
</para>
</listitem>
</varlistentry>
<varlistentry> <varlistentry>
<term><option>-h</option>, <option>--help</option></term> <term><option>-h</option>, <option>--help</option></term>
<listitem> <listitem>

View File

@ -126,6 +126,16 @@
<para>The options which apply to the <command>useradd</command> command are: <para>The options which apply to the <command>useradd</command> command are:
</para> </para>
<variablelist remap='IP'> <variablelist remap='IP'>
<varlistentry>
<term>
<option>--badname</option>&nbsp;
</term>
<listitem>
<para>
Allow names that do not conform to standards.
</para>
</listitem>
</varlistentry>
<varlistentry> <varlistentry>
<term> <term>
<option>-b</option>, <option>--base-dir</option>&nbsp;<replaceable>BASE_DIR</replaceable> <option>-b</option>, <option>--base-dir</option>&nbsp;<replaceable>BASE_DIR</replaceable>

View File

@ -108,6 +108,26 @@
</para> </para>
</listitem> </listitem>
</varlistentry> </varlistentry>
<varlistentry>
<term>
<option>-b</option>, <option>--badnames</option>
</term>
<listitem>
<para>
Allow names that do not conform to standards.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>
<option>-b</option>, <option>--badnames</option>
</term>
<listitem>
<para>
Allow names that do not conform to standards.
</para>
</listitem>
</varlistentry>
<varlistentry> <varlistentry>
<term> <term>
<option>-c</option>, <option>--comment</option>&nbsp;<replaceable>COMMENT</replaceable> <option>-c</option>, <option>--comment</option>&nbsp;<replaceable>COMMENT</replaceable>

View File

@ -117,6 +117,8 @@ static void check_perms (void);
static void open_files (void); static void open_files (void);
static void close_files (void); static void close_files (void);
extern int allow_bad_names;
/* /*
* usage - display usage message and exit * usage - display usage message and exit
*/ */
@ -128,6 +130,7 @@ static void usage (int status)
"\n" "\n"
"Options:\n"), "Options:\n"),
Prog); Prog);
(void) fputs (_(" -b, --badnames allow bad names\n"), usageout);
#ifndef USE_PAM #ifndef USE_PAM
(void) fprintf (usageout, (void) fprintf (usageout,
_(" -c, --crypt-method METHOD the crypt method (one of %s)\n"), _(" -c, --crypt-method METHOD the crypt method (one of %s)\n"),
@ -580,6 +583,7 @@ static void process_flags (int argc, char **argv)
{ {
int c; int c;
static struct option long_options[] = { static struct option long_options[] = {
{"badnames", no_argument, NULL, 'b'},
#ifndef USE_PAM #ifndef USE_PAM
{"crypt-method", required_argument, NULL, 'c'}, {"crypt-method", required_argument, NULL, 'c'},
#endif /* !USE_PAM */ #endif /* !USE_PAM */
@ -597,15 +601,18 @@ static void process_flags (int argc, char **argv)
while ((c = getopt_long (argc, argv, while ((c = getopt_long (argc, argv,
#ifndef USE_PAM #ifndef USE_PAM
#ifdef USE_SHA_CRYPT #ifdef USE_SHA_CRYPT
"c:hrs:", "c:bhrs:",
#else /* !USE_SHA_CRYPT */ #else /* !USE_SHA_CRYPT */
"c:hr", "c:bhr",
#endif /* !USE_SHA_CRYPT */ #endif /* !USE_SHA_CRYPT */
#else /* USE_PAM */ #else /* USE_PAM */
"hr", "bhr",
#endif #endif
long_options, NULL)) != -1) { long_options, NULL)) != -1) {
switch (c) { switch (c) {
case 'b':
allow_bad_names = true;
break;
#ifndef USE_PAM #ifndef USE_PAM
case 'c': case 'c':
crypt_method = optarg; crypt_method = optarg;

View File

@ -95,6 +95,8 @@ static void close_files (bool changed);
static void check_pw_file (int *errors, bool *changed); static void check_pw_file (int *errors, bool *changed);
static void check_spw_file (int *errors, bool *changed); static void check_spw_file (int *errors, bool *changed);
extern int allow_bad_names;
/* /*
* fail_exit - do some cleanup and exit with the given error code * fail_exit - do some cleanup and exit with the given error code
*/ */
@ -148,6 +150,7 @@ static /*@noreturn@*/void usage (int status)
"Options:\n"), "Options:\n"),
Prog); Prog);
} }
(void) fputs (_(" -b, --badnames allow bad names\n"), usageout);
(void) fputs (_(" -h, --help display this help message and exit\n"), usageout); (void) fputs (_(" -h, --help display this help message and exit\n"), usageout);
(void) fputs (_(" -q, --quiet report errors only\n"), usageout); (void) fputs (_(" -q, --quiet report errors only\n"), usageout);
(void) fputs (_(" -r, --read-only display errors and warnings\n" (void) fputs (_(" -r, --read-only display errors and warnings\n"
@ -172,6 +175,7 @@ static void process_flags (int argc, char **argv)
{ {
int c; int c;
static struct option long_options[] = { static struct option long_options[] = {
{"badnames", no_argument, NULL, 'b'},
{"help", no_argument, NULL, 'h'}, {"help", no_argument, NULL, 'h'},
{"quiet", no_argument, NULL, 'q'}, {"quiet", no_argument, NULL, 'q'},
{"read-only", no_argument, NULL, 'r'}, {"read-only", no_argument, NULL, 'r'},
@ -183,9 +187,12 @@ static void process_flags (int argc, char **argv)
/* /*
* Parse the command line arguments * Parse the command line arguments
*/ */
while ((c = getopt_long (argc, argv, "ehqrR:s", while ((c = getopt_long (argc, argv, "behqrR:s",
long_options, NULL)) != -1) { long_options, NULL)) != -1) {
switch (c) { switch (c) {
case 'b':
allow_bad_names = true;
break;
case 'h': case 'h':
usage (E_SUCCESS); usage (E_SUCCESS);
/*@notreached@*/break; /*@notreached@*/break;
@ -481,6 +488,7 @@ static void check_pw_file (int *errors, bool *changed)
/* /*
* Check for invalid usernames. --marekm * Check for invalid usernames. --marekm
*/ */
if (!is_valid_user_name (pwd->pw_name)) { if (!is_valid_user_name (pwd->pw_name)) {
printf (_("invalid user name '%s'\n"), pwd->pw_name); printf (_("invalid user name '%s'\n"), pwd->pw_name);
*errors += 1; *errors += 1;

View File

@ -148,6 +148,8 @@ static char **user_groups; /* NULL-terminated list */
static long sys_ngroups; static long sys_ngroups;
static bool do_grp_update = false; /* group files need to be updated */ static bool do_grp_update = false; /* group files need to be updated */
extern int allow_bad_names;
static bool static bool
bflg = false, /* new default root of home directory */ bflg = false, /* new default root of home directory */
cflg = false, /* comment (GECOS) field for new account */ cflg = false, /* comment (GECOS) field for new account */
@ -821,6 +823,7 @@ static void usage (int status)
"\n" "\n"
"Options:\n"), "Options:\n"),
Prog, Prog, Prog); Prog, Prog, Prog);
(void) fputs (_(" --badnames do not check for bad names\n"), usageout);
(void) fputs (_(" -b, --base-dir BASE_DIR base directory for the home directory of the\n" (void) fputs (_(" -b, --base-dir BASE_DIR base directory for the home directory of the\n"
" new account\n"), usageout); " new account\n"), usageout);
#ifdef WITH_BTRFS #ifdef WITH_BTRFS
@ -1109,6 +1112,7 @@ static void process_flags (int argc, char **argv)
#ifdef WITH_BTRFS #ifdef WITH_BTRFS
{"btrfs-subvolume-home", no_argument, NULL, 200}, {"btrfs-subvolume-home", no_argument, NULL, 200},
#endif #endif
{"badnames", no_argument, NULL, 201},
{"comment", required_argument, NULL, 'c'}, {"comment", required_argument, NULL, 'c'},
{"home-dir", required_argument, NULL, 'd'}, {"home-dir", required_argument, NULL, 'd'},
{"defaults", no_argument, NULL, 'D'}, {"defaults", no_argument, NULL, 'D'},
@ -1158,6 +1162,9 @@ static void process_flags (int argc, char **argv)
case 200: case 200:
subvolflg = true; subvolflg = true;
break; break;
case 201:
allow_bad_names = true;
break;
case 'c': case 'c':
if (!VALID (optarg)) { if (!VALID (optarg)) {
fprintf (stderr, fprintf (stderr,

View File

@ -206,6 +206,8 @@ static void update_faillog (void);
static void move_mailbox (void); static void move_mailbox (void);
#endif #endif
extern int allow_bad_names;
static void date_to_str (/*@unique@*//*@out@*/char *buf, size_t maxsize, static void date_to_str (/*@unique@*//*@out@*/char *buf, size_t maxsize,
long int date) long int date)
{ {
@ -408,6 +410,7 @@ static /*@noreturn@*/void usage (int status)
"\n" "\n"
"Options:\n"), "Options:\n"),
Prog); Prog);
(void) fputs (_(" -b, --badnames allow bad names\n"), usageout);
(void) fputs (_(" -c, --comment COMMENT new value of the GECOS field\n"), usageout); (void) fputs (_(" -c, --comment COMMENT new value of the GECOS field\n"), usageout);
(void) fputs (_(" -d, --home HOME_DIR new home directory for the user account\n"), usageout); (void) fputs (_(" -d, --home HOME_DIR new home directory for the user account\n"), usageout);
(void) fputs (_(" -e, --expiredate EXPIRE_DATE set account expiration date to EXPIRE_DATE\n"), usageout); (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)
int c; int c;
static struct option long_options[] = { static struct option long_options[] = {
{"append", no_argument, NULL, 'a'}, {"append", no_argument, NULL, 'a'},
{"badnames", no_argument, NULL, 'b'},
{"comment", required_argument, NULL, 'c'}, {"comment", required_argument, NULL, 'c'},
{"home", required_argument, NULL, 'd'}, {"home", required_argument, NULL, 'd'},
{"expiredate", required_argument, NULL, 'e'}, {"expiredate", required_argument, NULL, 'e'},
@ -1020,7 +1024,7 @@ static void process_flags (int argc, char **argv)
{NULL, 0, NULL, '\0'} {NULL, 0, NULL, '\0'}
}; };
while ((c = getopt_long (argc, argv, while ((c = getopt_long (argc, argv,
"ac:d:e:f:g:G:hl:Lmop:R:s:u:UP:" "abc:d:e:f:g:G:hl:Lmop:R:s:u:UP:"
#ifdef ENABLE_SUBIDS #ifdef ENABLE_SUBIDS
"v:w:V:W:" "v:w:V:W:"
#endif /* ENABLE_SUBIDS */ #endif /* ENABLE_SUBIDS */
@ -1032,6 +1036,9 @@ static void process_flags (int argc, char **argv)
case 'a': case 'a':
aflg = true; aflg = true;
break; break;
case 'b':
allow_bad_names = true;
break;
case 'c': case 'c':
if (!VALID (optarg)) { if (!VALID (optarg)) {
fprintf (stderr, fprintf (stderr,