Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ libshadow_la_SOURCES = \
console.c \
copydir.c \
csrand.c \
ctype/ispfchar.c \
ctype/ispfchar.h \
defines.h \
encrypt.c \
env.c \
Expand Down
35 changes: 10 additions & 25 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 @@ -33,6 +33,7 @@

#include "defines.h"
#include "chkname.h"
#include "ctype/ispfchar.h"
#include "string/ctype/strchrisascii/strchriscntrl.h"
#include "string/ctype/strisascii/strisdigit.h"
#include "string/strcmp/streq.h"
Expand All @@ -44,9 +45,6 @@
#endif


int allow_bad_names = false;


size_t
login_name_max_size(void)
{
Expand All @@ -66,19 +64,16 @@ is_valid_name(const char *name)
if (streq(name, "")
|| streq(name, ".")
|| streq(name, "..")
|| strcaseeq(name, "all") // access.conf(5)
|| strcaseeq(name, "except") // access.conf(5)
|| strcaseeq(name, "none") // access.conf(5)
|| strspn(name, "-")
|| strpbrk(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 All @@ -87,26 +82,16 @@ is_valid_name(const char *name)
* sake of Samba 3.x "add machine script"
*/

if (!((*name >= 'a' && *name <= 'z') ||
(*name >= 'A' && *name <= 'Z') ||
(*name >= '0' && *name <= '9') ||
*name == '_' ||
*name == '.'))
{
if (!ispfchar(*name)) {
errno = EILSEQ;
return false;
}

while (!streq(++name, "")) {
if (!((*name >= 'a' && *name <= 'z') ||
(*name >= 'A' && *name <= 'Z') ||
(*name >= '0' && *name <= '9') ||
*name == '_' ||
*name == '.' ||
*name == '-' ||
streq(name, "$")
))
{
if (streq(name, "$")) // Samba
return true;

if (!ispfchar(*name)) {
errno = EILSEQ;
return false;
}
Expand Down
12 changes: 12 additions & 0 deletions lib/ctype/ispfchar.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// SPDX-FileCopyrightText: 2024, Alejandro Colomar <alx@kernel.org>
// SPDX-License-Identifier: BSD-3-Clause


#include <config.h>

#include "ctype/ispfchar.h"

#include <stdbool.h>


extern inline bool ispfchar(unsigned char c);
27 changes: 27 additions & 0 deletions lib/ctype/ispfchar.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// SPDX-FileCopyrightText: 2024, Alejandro Colomar <alx@kernel.org>
// SPDX-License-Identifier: BSD-3-Clause


#ifndef SHADOW_INCLUDE_LIB_CTYPE_ISPFCHAR_H_
#define SHADOW_INCLUDE_LIB_CTYPE_ISPFCHAR_H_


#include <config.h>

#include <ctype.h>
#include <stdbool.h>


inline bool ispfchar(unsigned char c);


// is portable filename character
// Return true if 'c' is a character from the Portable Filename Character Set.
inline bool
ispfchar(unsigned char c)
{
return isalnum(c) || c == '.' || c == '_' || c == '-';
}


#endif // include guard
12 changes: 0 additions & 12 deletions man/newusers.8.xml
Original file line number Diff line number Diff line change
Expand Up @@ -254,18 +254,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
6 changes: 3 additions & 3 deletions src/chfn.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@

#include "config.h"

#ident "$Id$"

#include <fcntl.h>
#include <pwd.h>
#include <signal.h>
Expand Down Expand Up @@ -39,6 +37,8 @@
#include "string/strcmp/streq.h"
#include "string/strcpy/strtcpy.h"
#include "string/strdup/strdup.h"
#include "string/strerrno.h"


struct option_flags {
bool chroot;
Expand Down Expand Up @@ -605,7 +605,7 @@ int main (int argc, char **argv)
*/
if (optind < argc) {
if (!is_valid_user_name (argv[optind])) {
fprintf (stderr, _("%s: Provided user name is not a valid name\n"), Prog);
fprintf(stderr, _("%s: user: %s\n"), Prog, strerrno());
fail_exit (E_NOPERM, process_selinux);
}
user = argv[optind];
Expand Down
5 changes: 2 additions & 3 deletions src/chsh.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@

#include "config.h"

#ident "$Id$"

#include <fcntl.h>
#include <getopt.h>
#include <pwd.h>
Expand All @@ -35,6 +33,7 @@
#include "string/strcmp/streq.h"
#include "string/strcpy/strtcpy.h"
#include "string/strdup/strdup.h"
#include "string/strerrno.h"


#ifndef SHELLS_FILE
Expand Down Expand Up @@ -494,7 +493,7 @@ int main (int argc, char **argv)
*/
if (optind < argc) {
if (!is_valid_user_name (argv[optind])) {
fprintf (stderr, _("%s: Provided user name is not a valid name\n"), Prog);
fprintf(stderr, _("%s: user: %s\n"), Prog, strerrno());
fail_exit (1, process_selinux);
}
user = argv[optind];
Expand Down
4 changes: 1 addition & 3 deletions src/groupadd.c
Original file line number Diff line number Diff line change
Expand Up @@ -268,9 +268,7 @@ static void
check_new_name(void)
{
if (!is_valid_group_name(group_name)) {
fprintf(stderr, _("%s: '%s' is not a valid group name\n"),
Prog, group_name);

fprintf(stderr, _("%s: group: %s\n"), Prog, strerrno());
fail_exit (E_BAD_ARG);
}

Expand Down
7 changes: 2 additions & 5 deletions src/groupmod.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@

#include "config.h"

#ident "$Id$"

#include <ctype.h>
#include <fcntl.h>
#include <getopt.h>
Expand Down Expand Up @@ -45,6 +43,7 @@
#include "string/strcmp/streq.h"
#include "string/strcpy/stpecpy.h"
#include "string/strdup/strdup.h"
#include "string/strerrno.h"


/*
Expand Down Expand Up @@ -389,9 +388,7 @@ check_new_name(void)
}

if (!is_valid_group_name(group_newname)) {
fprintf(stderr,
_("%s: invalid group name '%s'\n"),
Prog, group_newname);
fprintf(stderr, _("%s: group: %s\n"), Prog, strerrno());
exit(E_BAD_ARG);
}

Expand Down
5 changes: 3 additions & 2 deletions src/grpck.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
#include "config.h"

#include <fcntl.h>
#include <getopt.h>
#include <grp.h>
#include <paths.h>
#include <pwd.h>
#include <stdio.h>
#include <getopt.h>

#include "chkname.h"
#include "commonio.h"
Expand All @@ -29,6 +29,7 @@
#include "sssd.h"
#include "string/strcmp/streq.h"
#include "string/strcmp/strprefix.h"
#include "string/strerrno.h"

#ifdef SHADOWGRP
#include "sgroupio.h"
Expand Down Expand Up @@ -583,7 +584,7 @@ static void check_grp_file(bool *errors, bool *changed, const struct option_flag
*/
if (!is_valid_group_name (grp->gr_name)) {
*errors = true;
printf (_("invalid group name '%s'\n"), grp->gr_name);
printf(_("group: %s\n"), strerrno());
}

/*
Expand Down
10 changes: 4 additions & 6 deletions src/newgrp.c
Original file line number Diff line number Diff line change
Expand Up @@ -482,9 +482,8 @@ int main (int argc, char **argv)
*/
if ((argc > 0) && (argv[0][0] != '-')) {
if (!is_valid_group_name (argv[0])) {
fprintf (
stderr, _("%s: provided group is not a valid group name\n"),
Prog);
fprintf(stderr, _("%s: group: %s\n"),
Prog, strerrno());
goto failure;
}
group = argv[0];
Expand Down Expand Up @@ -518,9 +517,8 @@ int main (int argc, char **argv)
goto failure;
} else if (argv[0] != NULL) {
if (!is_valid_group_name (argv[0])) {
fprintf (
stderr, _("%s: provided group is not a valid group name\n"),
Prog);
fprintf(stderr, _("%s: group: %s\n"),
Prog, strerrno());
goto failure;
}
group = argv[0];
Expand Down
Loading
Loading