Skip to content

Commit

Permalink
src/: Recommend --badname only if it is useful
Browse files Browse the repository at this point in the history
(Review with -w (--ignore-all-space).)

Closes: <shadow-maint#1067>
Reported-by: Anselm Schüler <[email protected]>
Signed-off-by: Alejandro Colomar <[email protected]>
  • Loading branch information
alejandro-colomar authored and hallyn committed Sep 1, 2024
1 parent 0663c91 commit 1f11a5c
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 15 deletions.
14 changes: 10 additions & 4 deletions src/newusers.c
Original file line number Diff line number Diff line change
Expand Up @@ -386,10 +386,16 @@ 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)) {
fprintf (stderr,
_("%s: invalid user name '%s': use --badname to ignore\n"),
Prog, name);
if (!is_valid_user_name(name)) {
if (errno == EINVAL) {
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);
}
return -1;
}

Expand Down
11 changes: 8 additions & 3 deletions src/pwck.c
Original file line number Diff line number Diff line change
Expand Up @@ -471,9 +471,14 @@ static void check_pw_file (int *errors, bool *changed)
* Check for invalid usernames. --marekm
*/

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

Expand Down
14 changes: 10 additions & 4 deletions src/useradd.c
Original file line number Diff line number Diff line change
Expand Up @@ -1523,10 +1523,16 @@ static void process_flags (int argc, char **argv)
}

user_name = argv[optind];
if (!is_valid_user_name (user_name)) {
fprintf (stderr,
_("%s: invalid user name '%s': use --badname to ignore\n"),
Prog, user_name);
if (!is_valid_user_name(user_name)) {
if (errno == EINVAL) {
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);
}
#ifdef WITH_AUDIT
audit_logger (AUDIT_ADD_USER, Prog,
"adding user",
Expand Down
14 changes: 10 additions & 4 deletions src/usermod.c
Original file line number Diff line number Diff line change
Expand Up @@ -1116,10 +1116,16 @@ process_flags(int argc, char **argv)
usage (E_SUCCESS);
/*@notreached@*/break;
case 'l':
if (!is_valid_user_name (optarg)) {
fprintf (stderr,
_("%s: invalid user name '%s': use --badname to ignore\n"),
Prog, optarg);
if (!is_valid_user_name(optarg)) {
if (errno == EINVAL) {
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);
}
exit (E_BAD_ARG);
}
lflg = true;
Expand Down

0 comments on commit 1f11a5c

Please sign in to comment.