Skip to content

Commit

Permalink
Little Bobby Tables
Browse files Browse the repository at this point in the history
  • Loading branch information
alejandro-colomar committed Dec 26, 2024
1 parent fe5172f commit c892957
Show file tree
Hide file tree
Showing 9 changed files with 9 additions and 116 deletions.
11 changes: 1 addition & 10 deletions lib/chkname.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* false - bad name
* errors:
* EINVAL Invalid name
* EILSEQ Invalid name character sequence (acceptable with --badname)
* EILSEQ Invalid name character sequence
* EOVERFLOW Name longer than maximum size
*/

Expand All @@ -41,9 +41,6 @@
#include "string/strcmp/strprefix.h"


int allow_bad_names = false;


size_t
login_name_max_size(void)
{
Expand All @@ -64,19 +61,13 @@ is_valid_name(const char *name)
if (streq(name, "")
|| streq(name, ".")
|| streq(name, "..")
|| strpbrk(name, ",: /")
|| strprefix(name, "-")
|| strchriscntrl(name)
|| strisdigit(name))
{
errno = EINVAL;
return false;
}

if (allow_bad_names) {
return true;
}

/*
* User/group names must match BRE regex:
* [a-zA-Z0-9_.][a-zA-Z0-9_.-]*$\?
Expand Down
12 changes: 0 additions & 12 deletions man/newusers.8.xml
Original file line number Diff line number Diff line change
Expand Up @@ -253,18 +253,6 @@
<para>
The options which apply to the <command>newusers</command> command are:
</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">
<varlistentry>
<term><option>-c</option>, <option>--crypt-method</option></term>
Expand Down
10 changes: 0 additions & 10 deletions man/pwck.8.xml
Original file line number Diff line number Diff line change
Expand Up @@ -159,16 +159,6 @@
The options which apply to the <command>pwck</command> command are:
</para>
<variablelist remap='IP'>
<varlistentry>
<term>
<option>--badname</option>&nbsp;
</term>
<listitem>
<para>
Allow names that do not conform to standards.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><option>-h</option>, <option>--help</option></term>
<listitem>
Expand Down
10 changes: 0 additions & 10 deletions man/useradd.8.xml
Original file line number Diff line number Diff line change
Expand Up @@ -103,16 +103,6 @@
<para>The options which apply to the <command>useradd</command> command are:
</para>
<variablelist remap='IP'>
<varlistentry>
<term>
<option>--badname</option>&nbsp;
</term>
<listitem>
<para>
Allow names that do not conform to standards.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>
<option>-b</option>, <option>--base-dir</option>&nbsp;<replaceable>BASE_DIR</replaceable>
Expand Down
10 changes: 0 additions & 10 deletions man/usermod.8.xml
Original file line number Diff line number Diff line change
Expand Up @@ -84,16 +84,6 @@
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>
<option>-b</option>, <option>--badname</option>
</term>
<listitem>
<para>
Allow names that do not conform to standards.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>
<option>-c</option>, <option>--comment</option>&nbsp;<replaceable>COMMENT</replaceable>
Expand Down
17 changes: 1 addition & 16 deletions src/newusers.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ static void check_perms (void);
static void open_files (void);
static void close_files (void);

extern int allow_bad_names;

/*
* usage - display usage message and exit
Expand All @@ -125,7 +124,6 @@ static void usage (int status)
"\n"
"Options:\n"),
Prog);
(void) fputs (_(" -b, --badname allow bad names\n"), usageout);
#ifndef USE_PAM
(void) fprintf (usageout,
_(" -c, --crypt-method METHOD the crypt method (one of %s)\n"),
Expand Down Expand Up @@ -386,17 +384,8 @@ static int add_user (const char *name, uid_t uid, gid_t gid)
{
struct passwd pwent;

/* Check if this is a valid user name */
if (!is_valid_user_name(name)) {
if (errno == EILSEQ) {
fprintf(stderr,
_("%s: invalid user name '%s': use --badname to ignore\n"),
Prog, name);
} else {
fprintf(stderr,
_("%s: invalid user name '%s'\n"),
Prog, name);
}
fprintf(stderr, _("%s: invalid user name '%s'\n"), Prog, name);
return -1;
}

Expand Down Expand Up @@ -629,7 +618,6 @@ static void process_flags (int argc, char **argv)
#endif /* USE_SHA_CRYPT || USE_BCRYPT || USE_YESCRYPT */
#endif /* !USE_PAM */
static struct option long_options[] = {
{"badname", no_argument, NULL, 'b'},
#ifndef USE_PAM
{"crypt-method", required_argument, NULL, 'c'},
#endif /* !USE_PAM */
Expand All @@ -656,9 +644,6 @@ static void process_flags (int argc, char **argv)
#endif
long_options, NULL)) != -1) {
switch (c) {
case 'b':
allow_bad_names = true;
break;
#ifndef USE_PAM
case 'c':
crypt_method = optarg;
Expand Down
18 changes: 1 addition & 17 deletions src/pwck.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ static void close_files (bool changed);
static void check_pw_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
Expand Down Expand Up @@ -133,7 +132,6 @@ usage (int status)
"Options:\n"),
Prog);
}
(void) fputs (_(" -b, --badname allow bad names\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 (_(" -r, --read-only display errors and warnings\n"
Expand All @@ -158,7 +156,6 @@ static void process_flags (int argc, char **argv)
{
int c;
static struct option long_options[] = {
{"badname", no_argument, NULL, 'b'},
{"help", no_argument, NULL, 'h'},
{"quiet", no_argument, NULL, 'q'},
{"read-only", no_argument, NULL, 'r'},
Expand All @@ -173,9 +170,6 @@ static void process_flags (int argc, char **argv)
while ((c = getopt_long (argc, argv, "behqrR:s",
long_options, NULL)) != -1) {
switch (c) {
case 'b':
allow_bad_names = true;
break;
case 'h':
usage (E_SUCCESS);
/*@notreached@*/break;
Expand Down Expand Up @@ -470,18 +464,8 @@ static void check_pw_file (int *errors, bool *changed)
}
}

/*
* Check for invalid usernames. --marekm
*/

if (!is_valid_user_name(pwd->pw_name)) {
if (errno == EILSEQ) {
printf(_("invalid user name '%s': use --badname to ignore\n"),
pwd->pw_name);
} else {
printf(_("invalid user name '%s'\n"),
pwd->pw_name);
}
printf(_("invalid user name '%s'\n"), pwd->pw_name);
*errors += 1;
}

Expand Down
18 changes: 3 additions & 15 deletions src/useradd.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@ static char **user_groups; /* NULL-terminated list */
static long sys_ngroups;
static bool do_grp_update = false; /* group files need to be updated */

extern int allow_bad_names;

static bool
bflg = false, /* new default root of home directory */
Expand Down Expand Up @@ -893,7 +892,6 @@ static void usage (int status)
"\n"
"Options:\n"),
Prog, Prog, Prog);
(void) fputs (_(" --badname do not check for bad names\n"), usageout);
(void) fputs (_(" -b, --base-dir BASE_DIR base directory for the home directory of the\n"
" new account\n"), usageout);
#ifdef WITH_BTRFS
Expand Down Expand Up @@ -1180,7 +1178,6 @@ static void process_flags (int argc, char **argv)
#ifdef WITH_BTRFS
{"btrfs-subvolume-home", no_argument, NULL, 200},
#endif
{"badname", no_argument, NULL, 201},
{"comment", required_argument, NULL, 'c'},
{"home-dir", required_argument, NULL, 'd'},
{"defaults", no_argument, NULL, 'D'},
Expand Down Expand Up @@ -1237,9 +1234,6 @@ static void process_flags (int argc, char **argv)
case 200:
subvolflg = true;
break;
case 201:
allow_bad_names = true;
break;
case 'c':
if (!VALID (optarg)) {
fprintf (stderr,
Expand Down Expand Up @@ -1534,15 +1528,9 @@ static void process_flags (int argc, char **argv)

user_name = argv[optind];
if (!is_valid_user_name(user_name)) {
if (errno == EILSEQ) {
fprintf(stderr,
_("%s: invalid user name '%s': use --badname to ignore\n"),
Prog, user_name);
} else {
fprintf(stderr,
_("%s: invalid user name '%s'\n"),
Prog, user_name);
}
fprintf(stderr,
_("%s: invalid user name '%s'\n"),
Prog, user_name);
#ifdef WITH_AUDIT
audit_logger (AUDIT_ADD_USER, Prog,
"adding user",
Expand Down
19 changes: 3 additions & 16 deletions src/usermod.c
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,6 @@ static void update_faillog (void);
static void move_mailbox (void);
#endif

extern int allow_bad_names;

/*
* get_groups - convert a list of group names to an array of group IDs
Expand Down Expand Up @@ -383,7 +382,6 @@ usage (int status)
(void) fputs (_(" -a, --append append the user to the supplemental GROUPS\n"
" mentioned by the -G option without removing\n"
" the user from other groups\n"), usageout);
(void) fputs (_(" -b, --badname allow bad names\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 (_(" -e, --expiredate EXPIRE_DATE set account expiration date to EXPIRE_DATE\n"), usageout);
Expand Down Expand Up @@ -996,8 +994,6 @@ process_flags(int argc, char **argv)
int c;
static struct option long_options[] = {
{"append", no_argument, NULL, 'a'},
{"badname", no_argument, NULL, 'b'},
{"badnames", no_argument, NULL, 'b'},
{"comment", required_argument, NULL, 'c'},
{"home", required_argument, NULL, 'd'},
{"expiredate", required_argument, NULL, 'e'},
Expand Down Expand Up @@ -1041,9 +1037,6 @@ process_flags(int argc, char **argv)
case 'a':
aflg = true;
break;
case 'b':
allow_bad_names = true;
break;
case 'c':
if (!VALID (optarg)) {
fprintf (stderr,
Expand Down Expand Up @@ -1118,15 +1111,9 @@ process_flags(int argc, char **argv)
/*@notreached@*/break;
case 'l':
if (!is_valid_user_name(optarg)) {
if (errno == EILSEQ) {
fprintf(stderr,
_("%s: invalid user name '%s': use --badname to ignore\n"),
Prog, optarg);
} else {
fprintf(stderr,
_("%s: invalid user name '%s'\n"),
Prog, optarg);
}
fprintf(stderr,
_("%s: invalid user name '%s'\n"),
Prog, optarg);
exit (E_BAD_ARG);
}
lflg = true;
Expand Down

0 comments on commit c892957

Please sign in to comment.