teknoraver / rpms / systemd

Forked from rpms/systemd 2 months ago
Clone

Blame SOURCES/0474-user-util-rework-how-we-validate-user-names.patch

21255d
From 33b851f0c30e47fe71a293e2c990ef26573efe86 Mon Sep 17 00:00:00 2001
21255d
From: Lennart Poettering <lennart@poettering.net>
21255d
Date: Sat, 4 Apr 2020 12:23:02 +0200
21255d
Subject: [PATCH] user-util: rework how we validate user names
21255d
MIME-Version: 1.0
21255d
Content-Type: text/plain; charset=UTF-8
21255d
Content-Transfer-Encoding: 8bit
21255d
21255d
This reworks the user validation infrastructure. There are now two
21255d
modes. In regular mode we are strict and test against a strict set of
21255d
valid chars. And in "relaxed" mode we just filter out some really
21255d
obvious, dangerous stuff. i.e. strict is whitelisting what is OK, but
21255d
"relaxed" is blacklisting what is really not OK.
21255d
21255d
The idea is that we use strict mode whenver we allocate a new user
21255d
(i.e. in sysusers.d or homed), while "relaxed" mode is when we process
21255d
users registered elsewhere, (i.e. userdb, logind, …)
21255d
21255d
The requirements on user name validity vary wildly. SSSD thinks its fine
21255d
to embedd "@" for example, while the suggested NAME_REGEX field on
21255d
Debian does not even allow uppercase chars…
21255d
21255d
This effectively liberaralizes a lot what we expect from usernames.
21255d
21255d
The code that warns about questionnable user names is now optional and
21255d
only used at places such as unit file parsing, so that it doesn't show
21255d
up on every userdb query, but only when processing configuration files
21255d
that know better.
21255d
21255d
Fixes: #15149 #15090
21255d
(cherry picked from commit 7a8867abfab10e5bbca10590ec2aa40c5b27d8fb)
21255d
21255d
Resolves: #1848373
21255d
---
21255d
 src/basic/user-util.c         | 185 +++++++++++++----------
21255d
 src/basic/user-util.h         |  21 +--
21255d
 src/core/dbus-execute.c       |   6 +-
21255d
 src/core/dbus-manager.c       |   2 +-
21255d
 src/core/dbus-socket.c        |   4 +-
21255d
 src/core/dbus-util.c          |   7 +-
21255d
 src/core/dbus-util.h          |   2 +-
21255d
 src/core/dynamic-user.c       |   2 +-
21255d
 src/core/load-fragment.c      |   4 +-
21255d
 src/core/unit.c               |   2 +-
21255d
 src/nss-systemd/nss-systemd.c |   6 +-
21255d
 src/systemd/sd-messages.h     |   3 +
21255d
 src/sysusers/sysusers.c       |   4 +-
21255d
 src/test/test-user-util.c     | 271 ++++++++++++++++++----------------
21255d
 14 files changed, 287 insertions(+), 232 deletions(-)
21255d
21255d
diff --git a/src/basic/user-util.c b/src/basic/user-util.c
21255d
index 68a924770b..cd870c4361 100644
21255d
--- a/src/basic/user-util.c
21255d
+++ b/src/basic/user-util.c
21255d
@@ -14,6 +14,8 @@
21255d
 #include <unistd.h>
21255d
 #include <utmp.h>
21255d
 
21255d
+#include "sd-messages.h"
21255d
+
21255d
 #include "alloc-util.h"
21255d
 #include "fd-util.h"
21255d
 #include "fileio.h"
21255d
@@ -576,92 +578,125 @@ int take_etc_passwd_lock(const char *root) {
21255d
         return fd;
21255d
 }
21255d
 
21255d
-bool valid_user_group_name_full(const char *u, bool strict) {
21255d
+bool valid_user_group_name(const char *u, ValidUserFlags flags) {
21255d
         const char *i;
21255d
-        long sz;
21255d
-        bool warned = false;
21255d
 
21255d
-        /* Checks if the specified name is a valid user/group name. Also see POSIX IEEE Std 1003.1-2008, 2016 Edition,
21255d
-         * 3.437. We are a bit stricter here however. Specifically we deviate from POSIX rules:
21255d
-         *
21255d
-         * - We require that names fit into the appropriate utmp field
21255d
-         * - We don't allow empty user names
21255d
-         * - No dots in the first character
21255d
+        /* Checks if the specified name is a valid user/group name. There are two flavours of this call:
21255d
+         * strict mode is the default which is POSIX plus some extra rules; and relaxed mode where we accept
21255d
+         * pretty much everything except the really worst offending names.
21255d
          *
21255d
-         * If strict==true, additionally:
21255d
-         * - We don't allow any dots (this conflicts with chown syntax which permits dots as user/group name separator)
21255d
-         * - We don't allow a digit as the first character
21255d
-         *
21255d
-         * Note that other systems are even more restrictive, and don't permit underscores or uppercase characters.
21255d
-         */
21255d
+         * Whenever we synthesize users ourselves we should use the strict mode. But when we process users
21255d
+         * created by other stuff, let's be more liberal. */
21255d
 
21255d
-        if (isempty(u))
21255d
+        if (isempty(u)) /* An empty user name is never valid */
21255d
                 return false;
21255d
 
21255d
-        if (!(u[0] >= 'a' && u[0] <= 'z') &&
21255d
-            !(u[0] >= 'A' && u[0] <= 'Z') &&
21255d
-            !(u[0] >= '0' && u[0] <= '9' && !strict) &&
21255d
-            u[0] != '_')
21255d
-                return false;
21255d
-
21255d
-        bool only_digits_seen = u[0] >= '0' && u[0] <= '9';
21255d
-
21255d
-        if (only_digits_seen) {
21255d
-                log_warning("User or group name \"%s\" starts with a digit, accepting for compatibility.", u);
21255d
-                warned = true;
21255d
-        }
21255d
-
21255d
-        for (i = u+1; *i; i++) {
21255d
-                if (((*i >= 'a' && *i <= 'z') ||
21255d
-                     (*i >= 'A' && *i <= 'Z') ||
21255d
-                     (*i >= '0' && *i <= '9') ||
21255d
-                     IN_SET(*i, '_', '-'))) {
21255d
-                        if (!(*i >= '0' && *i <= '9'))
21255d
-                                only_digits_seen = false;
21255d
-                        continue;
21255d
-                        }
21255d
-
21255d
-                if (*i == '.' && !strict) {
21255d
-                        if (!warned) {
21255d
-                                log_warning("Bad user or group name \"%s\", accepting for compatibility.", u);
21255d
-                                warned = true;
21255d
-                        }
21255d
-
21255d
-                        continue;
21255d
-                }
21255d
-
21255d
-                return false;
21255d
+        if (parse_uid(u, NULL) >= 0) /* Something that parses as numeric UID string is valid exactly when the
21255d
+                                      * flag for it is set */
21255d
+                return FLAGS_SET(flags, VALID_USER_ALLOW_NUMERIC);
21255d
+
21255d
+        if (FLAGS_SET(flags, VALID_USER_RELAX)) {
21255d
+
21255d
+                /* In relaxed mode we just check very superficially. Apparently SSSD and other stuff is
21255d
+                 * extremely liberal (way too liberal if you ask me, even inserting "@" in user names, which
21255d
+                 * is bound to cause problems for example when used with an MTA), hence only filter the most
21255d
+                 * obvious cases, or where things would result in an invalid entry if such a user name would
21255d
+                 * show up in /etc/passwd (or equivalent getent output).
21255d
+                 *
21255d
+                 * Note that we stepped far out of POSIX territory here. It's not our fault though, but
21255d
+                 * SSSD's, Samba's and everybody else who ignored POSIX on this. (I mean, I am happy to step
21255d
+                 * outside of POSIX' bounds any day, but I must say in this case I probably wouldn't
21255d
+                 * have...) */
21255d
+
21255d
+                if (startswith(u, " ") || endswith(u, " ")) /* At least expect whitespace padding is removed
21255d
+                                                             * at front and back (accept in the middle, since
21255d
+                                                             * that's apparently a thing on Windows). Note
21255d
+                                                             * that this also blocks usernames consisting of
21255d
+                                                             * whitespace only. */
21255d
+                        return false;
21255d
+
21255d
+                if (!utf8_is_valid(u)) /* We want to synthesize JSON from this, hence insist on UTF-8 */
21255d
+                        return false;
21255d
+
21255d
+                if (string_has_cc(u, NULL)) /* CC characters are just dangerous (and \n in particular is the
21255d
+                                             * record separator in /etc/passwd), so we can't allow that. */
21255d
+                        return false;
21255d
+
21255d
+                if (strpbrk(u, ":/")) /* Colons are the field separator in /etc/passwd, we can't allow
21255d
+                                       * that. Slashes are special to file systems paths and user names
21255d
+                                       * typically show up in the file system as home directories, hence
21255d
+                                       * don't allow slashes. */
21255d
+                        return false;
21255d
+
21255d
+                if (in_charset(u, "0123456789")) /* Don't allow fully numeric strings, they might be confused
21255d
+                                                  * with with UIDs (note that this test is more broad than
21255d
+                                                  * the parse_uid() test above, as it will cover more than
21255d
+                                                  * the 32bit range, and it will detect 65535 (which is in
21255d
+                                                  * invalid UID, even though in the unsigned 32 bit range) */
21255d
+                        return false;
21255d
+
21255d
+                if (u[0] == '-' && in_charset(u + 1, "0123456789")) /* Don't allow negative fully numeric
21255d
+                                                                     * strings either. After all some people
21255d
+                                                                     * write 65535 as -1 (even though that's
21255d
+                                                                     * not even true on 32bit uid_t
21255d
+                                                                     * anyway) */
21255d
+                        return false;
21255d
+
21255d
+                if (dot_or_dot_dot(u)) /* User names typically become home directory names, and these two are
21255d
+                                        * special in that context, don't allow that. */
21255d
+                        return false;
21255d
+
21255d
+                /* Compare with strict result and warn if result doesn't match */
21255d
+                if (FLAGS_SET(flags, VALID_USER_WARN) && !valid_user_group_name(u, 0))
21255d
+                        log_struct(LOG_NOTICE,
21255d
+                                   "MESSAGE=Accepting user/group name '%s', which does not match strict user/group name rules.", u,
21255d
+                                   "USER_GROUP_NAME=%s", u,
21255d
+                                   "MESSAGE_ID=" SD_MESSAGE_UNSAFE_USER_NAME_STR);
21255d
+
21255d
+                /* Note that we make no restrictions on the length in relaxed mode! */
21255d
+        } else {
21255d
+                long sz;
21255d
+                size_t l;
21255d
+
21255d
+                /* Also see POSIX IEEE Std 1003.1-2008, 2016 Edition, 3.437. We are a bit stricter here
21255d
+                 * however. Specifically we deviate from POSIX rules:
21255d
+                 *
21255d
+                 * - We don't allow empty user names (see above)
21255d
+                 * - We require that names fit into the appropriate utmp field
21255d
+                 * - We don't allow any dots (this conflicts with chown syntax which permits dots as user/group name separator)
21255d
+                 * - We don't allow dashes or digit as the first character
21255d
+                 *
21255d
+                 * Note that other systems are even more restrictive, and don't permit underscores or uppercase characters.
21255d
+                 */
21255d
+
21255d
+                if (!(u[0] >= 'a' && u[0] <= 'z') &&
21255d
+                    !(u[0] >= 'A' && u[0] <= 'Z') &&
21255d
+                    u[0] != '_')
21255d
+                        return false;
21255d
+
21255d
+                for (i = u+1; *i; i++)
21255d
+                        if (!(*i >= 'a' && *i <= 'z') &&
21255d
+                            !(*i >= 'A' && *i <= 'Z') &&
21255d
+                            !(*i >= '0' && *i <= '9') &&
21255d
+                            !IN_SET(*i, '_', '-'))
21255d
+                                return false;
21255d
+
21255d
+                l = i - u;
21255d
+
21255d
+                sz = sysconf(_SC_LOGIN_NAME_MAX);
21255d
+                assert_se(sz > 0);
21255d
+
21255d
+                if (l > (size_t) sz)
21255d
+                        return false;
21255d
+                if (l > FILENAME_MAX)
21255d
+                        return false;
21255d
+                if (l > UT_NAMESIZE - 1)
21255d
+                        return false;
21255d
         }
21255d
 
21255d
-        if (only_digits_seen)
21255d
-                return false;
21255d
-
21255d
-        sz = sysconf(_SC_LOGIN_NAME_MAX);
21255d
-        assert_se(sz > 0);
21255d
-
21255d
-        if ((size_t) (i-u) > (size_t) sz)
21255d
-                return false;
21255d
-
21255d
-        if ((size_t) (i-u) > UT_NAMESIZE - 1)
21255d
-                return false;
21255d
-
21255d
         return true;
21255d
 }
21255d
 
21255d
-bool valid_user_group_name_or_id_full(const char *u, bool strict) {
21255d
-
21255d
-        /* Similar as above, but is also fine with numeric UID/GID specifications, as long as they are in the
21255d
-         * right range, and not the invalid user ids. */
21255d
-
21255d
-        if (isempty(u))
21255d
-                return false;
21255d
-
21255d
-        if (parse_uid(u, NULL) >= 0)
21255d
-                return true;
21255d
-
21255d
-        return valid_user_group_name_full(u, strict);
21255d
-}
21255d
-
21255d
 bool valid_gecos(const char *d) {
21255d
 
21255d
         if (!d)
21255d
diff --git a/src/basic/user-util.h b/src/basic/user-util.h
21255d
index 5ad0b2a2f9..939bded40d 100644
21255d
--- a/src/basic/user-util.h
21255d
+++ b/src/basic/user-util.h
21255d
@@ -78,20 +78,13 @@ static inline bool userns_supported(void) {
21255d
         return access("/proc/self/uid_map", F_OK) >= 0;
21255d
 }
21255d
 
21255d
-bool valid_user_group_name_full(const char *u, bool strict);
21255d
-bool valid_user_group_name_or_id_full(const char *u, bool strict);
21255d
-static inline bool valid_user_group_name(const char *u) {
21255d
-        return valid_user_group_name_full(u, true);
21255d
-}
21255d
-static inline bool valid_user_group_name_or_id(const char *u) {
21255d
-        return valid_user_group_name_or_id_full(u, true);
21255d
-}
21255d
-static inline bool valid_user_group_name_compat(const char *u) {
21255d
-        return valid_user_group_name_full(u, false);
21255d
-}
21255d
-static inline bool valid_user_group_name_or_id_compat(const char *u) {
21255d
-        return valid_user_group_name_or_id_full(u, false);
21255d
-}
21255d
+typedef enum ValidUserFlags {
21255d
+        VALID_USER_RELAX         = 1 << 0,
21255d
+        VALID_USER_WARN          = 1 << 1,
21255d
+        VALID_USER_ALLOW_NUMERIC = 1 << 2,
21255d
+} ValidUserFlags;
21255d
+
21255d
+bool valid_user_group_name(const char *u, ValidUserFlags flags);
21255d
 bool valid_gecos(const char *d);
21255d
 bool valid_home(const char *p);
21255d
 
21255d
diff --git a/src/core/dbus-execute.c b/src/core/dbus-execute.c
21255d
index e004fb55c9..8348663000 100644
21255d
--- a/src/core/dbus-execute.c
21255d
+++ b/src/core/dbus-execute.c
21255d
@@ -1113,10 +1113,10 @@ int bus_exec_context_set_transient_property(
21255d
         flags |= UNIT_PRIVATE;
21255d
 
21255d
         if (streq(name, "User"))
21255d
-                return bus_set_transient_user_compat(u, name, &c->user, message, flags, error);
21255d
+                return bus_set_transient_user_relaxed(u, name, &c->user, message, flags, error);
21255d
 
21255d
         if (streq(name, "Group"))
21255d
-                return bus_set_transient_user_compat(u, name, &c->group, message, flags, error);
21255d
+                return bus_set_transient_user_relaxed(u, name, &c->group, message, flags, error);
21255d
 
21255d
         if (streq(name, "TTYPath"))
21255d
                 return bus_set_transient_path(u, name, &c->tty_path, message, flags, error);
21255d
@@ -1298,7 +1298,7 @@ int bus_exec_context_set_transient_property(
21255d
                         return r;
21255d
 
21255d
                 STRV_FOREACH(p, l)
21255d
-                        if (!isempty(*p) && !valid_user_group_name_or_id_compat(*p))
21255d
+                        if (!isempty(*p) && !valid_user_group_name(*p, VALID_USER_ALLOW_NUMERIC|VALID_USER_RELAX|VALID_USER_WARN))
21255d
                                 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS,
21255d
                                                          "Invalid supplementary group names");
21255d
 
21255d
diff --git a/src/core/dbus-manager.c b/src/core/dbus-manager.c
21255d
index 0a1d3df42f..7488f22116 100644
21255d
--- a/src/core/dbus-manager.c
21255d
+++ b/src/core/dbus-manager.c
21255d
@@ -1762,7 +1762,7 @@ static int method_lookup_dynamic_user_by_name(sd_bus_message *message, void *use
21255d
 
21255d
         if (!MANAGER_IS_SYSTEM(m))
21255d
                 return sd_bus_error_setf(error, SD_BUS_ERROR_NOT_SUPPORTED, "Dynamic users are only supported in the system instance.");
21255d
-        if (!valid_user_group_name(name))
21255d
+        if (!valid_user_group_name(name, VALID_USER_RELAX))
21255d
                 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "User name invalid: %s", name);
21255d
 
21255d
         r = dynamic_user_lookup_name(m, name, &uid);
21255d
diff --git a/src/core/dbus-socket.c b/src/core/dbus-socket.c
21255d
index 8fdbc05409..fa6bbe2c6f 100644
21255d
--- a/src/core/dbus-socket.c
21255d
+++ b/src/core/dbus-socket.c
21255d
@@ -281,10 +281,10 @@ static int bus_socket_set_transient_property(
21255d
                 return bus_set_transient_fdname(u, name, &s->fdname, message, flags, error);
21255d
 
21255d
         if (streq(name, "SocketUser"))
21255d
-                return bus_set_transient_user_compat(u, name, &s->user, message, flags, error);
21255d
+                return bus_set_transient_user_relaxed(u, name, &s->user, message, flags, error);
21255d
 
21255d
         if (streq(name, "SocketGroup"))
21255d
-                return bus_set_transient_user_compat(u, name, &s->group, message, flags, error);
21255d
+                return bus_set_transient_user_relaxed(u, name, &s->group, message, flags, error);
21255d
 
21255d
         if (streq(name, "BindIPv6Only"))
21255d
                 return bus_set_transient_bind_ipv6_only(u, name, &s->bind_ipv6_only, message, flags, error);
21255d
diff --git a/src/core/dbus-util.c b/src/core/dbus-util.c
21255d
index 7862beaacb..951450e53d 100644
21255d
--- a/src/core/dbus-util.c
21255d
+++ b/src/core/dbus-util.c
21255d
@@ -30,7 +30,12 @@ int bus_property_get_triggered_unit(
21255d
 
21255d
 BUS_DEFINE_SET_TRANSIENT(mode_t, "u", uint32_t, mode_t, "%040o");
21255d
 BUS_DEFINE_SET_TRANSIENT(unsigned, "u", uint32_t, unsigned, "%" PRIu32);
21255d
-BUS_DEFINE_SET_TRANSIENT_STRING_WITH_CHECK(user_compat, valid_user_group_name_or_id_compat);
21255d
+
21255d
+static inline bool valid_user_group_name_or_id_relaxed(const char *u) {
21255d
+        return valid_user_group_name(u, VALID_USER_ALLOW_NUMERIC|VALID_USER_RELAX);
21255d
+}
21255d
+
21255d
+BUS_DEFINE_SET_TRANSIENT_STRING_WITH_CHECK(user_relaxed, valid_user_group_name_or_id_relaxed);
21255d
 BUS_DEFINE_SET_TRANSIENT_STRING_WITH_CHECK(path, path_is_absolute);
21255d
 
21255d
 int bus_set_transient_string(
21255d
diff --git a/src/core/dbus-util.h b/src/core/dbus-util.h
21255d
index a3316c6701..713b464dd9 100644
21255d
--- a/src/core/dbus-util.h
21255d
+++ b/src/core/dbus-util.h
21255d
@@ -235,7 +235,7 @@ int bus_property_get_triggered_unit(sd_bus *bus, const char *path, const char *i
21255d
 
21255d
 int bus_set_transient_mode_t(Unit *u, const char *name, mode_t *p, sd_bus_message *message, UnitWriteFlags flags, sd_bus_error *error);
21255d
 int bus_set_transient_unsigned(Unit *u, const char *name, unsigned *p, sd_bus_message *message, UnitWriteFlags flags, sd_bus_error *error);
21255d
-int bus_set_transient_user_compat(Unit *u, const char *name, char **p, sd_bus_message *message, UnitWriteFlags flags, sd_bus_error *error);
21255d
+int bus_set_transient_user_relaxed(Unit *u, const char *name, char **p, sd_bus_message *message, UnitWriteFlags flags, sd_bus_error *error);
21255d
 int bus_set_transient_path(Unit *u, const char *name, char **p, sd_bus_message *message, UnitWriteFlags flags, sd_bus_error *error);
21255d
 int bus_set_transient_string(Unit *u, const char *name, char **p, sd_bus_message *message, UnitWriteFlags flags, sd_bus_error *error);
21255d
 int bus_set_transient_bool(Unit *u, const char *name, bool *p, sd_bus_message *message, UnitWriteFlags flags, sd_bus_error *error);
21255d
diff --git a/src/core/dynamic-user.c b/src/core/dynamic-user.c
21255d
index 021fd93a76..548b3cc9df 100644
21255d
--- a/src/core/dynamic-user.c
21255d
+++ b/src/core/dynamic-user.c
21255d
@@ -108,7 +108,7 @@ static int dynamic_user_acquire(Manager *m, const char *name, DynamicUser** ret)
21255d
                 return 0;
21255d
         }
21255d
 
21255d
-        if (!valid_user_group_name_or_id(name))
21255d
+        if (!valid_user_group_name(name, VALID_USER_ALLOW_NUMERIC))
21255d
                 return -EINVAL;
21255d
 
21255d
         if (socketpair(AF_UNIX, SOCK_DGRAM|SOCK_CLOEXEC, 0, storage_socket) < 0)
21255d
diff --git a/src/core/load-fragment.c b/src/core/load-fragment.c
21255d
index ba81d94504..e0d7b8f7f8 100644
21255d
--- a/src/core/load-fragment.c
21255d
+++ b/src/core/load-fragment.c
21255d
@@ -1932,7 +1932,7 @@ int config_parse_user_group_compat(
21255d
                 return -ENOEXEC;
21255d
         }
21255d
 
21255d
-        if (!valid_user_group_name_or_id_compat(k)) {
21255d
+        if (!valid_user_group_name(k, VALID_USER_ALLOW_NUMERIC|VALID_USER_RELAX|VALID_USER_WARN)) {
21255d
                 log_syntax(unit, LOG_ERR, filename, line, 0, "Invalid user/group name or numeric ID: %s", k);
21255d
                 return -ENOEXEC;
21255d
         }
21255d
@@ -1986,7 +1986,7 @@ int config_parse_user_group_strv_compat(
21255d
                         return -ENOEXEC;
21255d
                 }
21255d
 
21255d
-                if (!valid_user_group_name_or_id_compat(k)) {
21255d
+                if (!valid_user_group_name(k, VALID_USER_ALLOW_NUMERIC|VALID_USER_RELAX|VALID_USER_WARN)) {
21255d
                         log_syntax(unit, LOG_ERR, filename, line, 0, "Invalid user/group name or numeric ID: %s", k);
21255d
                         return -ENOEXEC;
21255d
                 }
21255d
diff --git a/src/core/unit.c b/src/core/unit.c
21255d
index ffbf3cfd48..cd3e7c806d 100644
21255d
--- a/src/core/unit.c
21255d
+++ b/src/core/unit.c
21255d
@@ -4088,7 +4088,7 @@ static int user_from_unit_name(Unit *u, char **ret) {
21255d
         if (r < 0)
21255d
                 return r;
21255d
 
21255d
-        if (valid_user_group_name(n)) {
21255d
+        if (valid_user_group_name(n, 0)) {
21255d
                 *ret = TAKE_PTR(n);
21255d
                 return 0;
21255d
         }
21255d
diff --git a/src/nss-systemd/nss-systemd.c b/src/nss-systemd/nss-systemd.c
21255d
index f8db27ae27..615c710257 100644
21255d
--- a/src/nss-systemd/nss-systemd.c
21255d
+++ b/src/nss-systemd/nss-systemd.c
21255d
@@ -123,7 +123,7 @@ static int direct_lookup_uid(uid_t uid, char **ret) {
21255d
         r = readlink_malloc(path, &s);
21255d
         if (r < 0)
21255d
                 return r;
21255d
-        if (!valid_user_group_name(s)) { /* extra safety check */
21255d
+        if (!valid_user_group_name(s, VALID_USER_RELAX)) { /* extra safety check */
21255d
                 free(s);
21255d
                 return -EINVAL;
21255d
         }
21255d
@@ -153,7 +153,7 @@ enum nss_status _nss_systemd_getpwnam_r(
21255d
 
21255d
         /* If the username is not valid, then we don't know it. Ideally libc would filter these for us anyway. We don't
21255d
          * generate EINVAL here, because it isn't really out business to complain about invalid user names. */
21255d
-        if (!valid_user_group_name(name))
21255d
+        if (!valid_user_group_name(name, VALID_USER_RELAX))
21255d
                 return NSS_STATUS_NOTFOUND;
21255d
 
21255d
         /* Synthesize entries for the root and nobody users, in case they are missing in /etc/passwd */
21255d
@@ -356,7 +356,7 @@ enum nss_status _nss_systemd_getgrnam_r(
21255d
         assert(name);
21255d
         assert(gr);
21255d
 
21255d
-        if (!valid_user_group_name(name))
21255d
+        if (!valid_user_group_name(name, VALID_USER_RELAX))
21255d
                 return NSS_STATUS_NOTFOUND;
21255d
 
21255d
         /* Synthesize records for root and nobody, in case they are missing form /etc/group */
21255d
diff --git a/src/systemd/sd-messages.h b/src/systemd/sd-messages.h
21255d
index bdd4fd3974..847b698ba4 100644
21255d
--- a/src/systemd/sd-messages.h
21255d
+++ b/src/systemd/sd-messages.h
21255d
@@ -152,6 +152,9 @@ _SD_BEGIN_DECLARATIONS;
21255d
 #define SD_MESSAGE_DNSSEC_DOWNGRADE       SD_ID128_MAKE(36,db,2d,fa,5a,90,45,e1,bd,4a,f5,f9,3e,1c,f0,57)
21255d
 #define SD_MESSAGE_DNSSEC_DOWNGRADE_STR   SD_ID128_MAKE_STR(36,db,2d,fa,5a,90,45,e1,bd,4a,f5,f9,3e,1c,f0,57)
21255d
 
21255d
+#define SD_MESSAGE_UNSAFE_USER_NAME       SD_ID128_MAKE(b6,1f,da,c6,12,e9,4b,91,82,28,5b,99,88,43,06,1f)
21255d
+#define SD_MESSAGE_UNSAFE_USER_NAME_STR   SD_ID128_MAKE_STR(b6,1f,da,c6,12,e9,4b,91,82,28,5b,99,88,43,06,1f)
21255d
+
21255d
 _SD_END_DECLARATIONS;
21255d
 
21255d
 #endif
21255d
diff --git a/src/sysusers/sysusers.c b/src/sysusers/sysusers.c
21255d
index 33959d3c11..a374ebaaf4 100644
21255d
--- a/src/sysusers/sysusers.c
21255d
+++ b/src/sysusers/sysusers.c
21255d
@@ -1413,7 +1413,7 @@ static int parse_line(const char *fname, unsigned line, const char *buffer) {
21255d
                         return r;
21255d
                 }
21255d
 
21255d
-                if (!valid_user_group_name(resolved_name)) {
21255d
+                if (!valid_user_group_name(resolved_name, 0)) {
21255d
                         log_error("[%s:%u] '%s' is not a valid user or group name.", fname, line, resolved_name);
21255d
                         return -EINVAL;
21255d
                 }
21255d
@@ -1524,7 +1524,7 @@ static int parse_line(const char *fname, unsigned line, const char *buffer) {
21255d
                         return -EINVAL;
21255d
                 }
21255d
 
21255d
-                if (!valid_user_group_name(resolved_id)) {
21255d
+                if (!valid_user_group_name(resolved_id, 0)) {
21255d
                         log_error("[%s:%u] '%s' is not a valid user or group name.", fname, line, resolved_id);
21255d
                         return -EINVAL;
21255d
                 }
21255d
diff --git a/src/test/test-user-util.c b/src/test/test-user-util.c
21255d
index 56079f1486..31ac018da9 100644
21255d
--- a/src/test/test-user-util.c
21255d
+++ b/src/test/test-user-util.c
21255d
@@ -131,144 +131,163 @@ static void test_uid_ptr(void) {
21255d
         assert_se(PTR_TO_UID(UID_TO_PTR(1000)) == 1000);
21255d
 }
21255d
 
21255d
-static void test_valid_user_group_name_compat(void) {
21255d
+static void test_valid_user_group_name_relaxed(void) {
21255d
         log_info("/* %s */", __func__);
21255d
 
21255d
-        assert_se(!valid_user_group_name_compat(NULL));
21255d
-        assert_se(!valid_user_group_name_compat(""));
21255d
-        assert_se(!valid_user_group_name_compat("1"));
21255d
-        assert_se(!valid_user_group_name_compat("65535"));
21255d
-        assert_se(!valid_user_group_name_compat("-1"));
21255d
-        assert_se(!valid_user_group_name_compat("-kkk"));
21255d
-        assert_se(!valid_user_group_name_compat("rööt"));
21255d
-        assert_se(!valid_user_group_name_compat("."));
21255d
-        assert_se(!valid_user_group_name_compat(".eff"));
21255d
-        assert_se(!valid_user_group_name_compat("foo\nbar"));
21255d
-        assert_se(!valid_user_group_name_compat("0123456789012345678901234567890123456789"));
21255d
-        assert_se(!valid_user_group_name_or_id_compat("aaa:bbb"));
21255d
-        assert_se(!valid_user_group_name_compat("."));
21255d
-        assert_se(!valid_user_group_name_compat(".1"));
21255d
-        assert_se(!valid_user_group_name_compat(".65535"));
21255d
-        assert_se(!valid_user_group_name_compat(".-1"));
21255d
-        assert_se(!valid_user_group_name_compat(".-kkk"));
21255d
-        assert_se(!valid_user_group_name_compat(".rööt"));
21255d
-        assert_se(!valid_user_group_name_or_id_compat(".aaa:bbb"));
21255d
-
21255d
-        assert_se(valid_user_group_name_compat("root"));
21255d
-        assert_se(valid_user_group_name_compat("lennart"));
21255d
-        assert_se(valid_user_group_name_compat("LENNART"));
21255d
-        assert_se(valid_user_group_name_compat("_kkk"));
21255d
-        assert_se(valid_user_group_name_compat("kkk-"));
21255d
-        assert_se(valid_user_group_name_compat("kk-k"));
21255d
-        assert_se(valid_user_group_name_compat("eff.eff"));
21255d
-        assert_se(valid_user_group_name_compat("eff."));
21255d
-
21255d
-        assert_se(valid_user_group_name_compat("some5"));
21255d
-        assert_se(valid_user_group_name_compat("5some"));
21255d
-        assert_se(valid_user_group_name_compat("INNER5NUMBER"));
21255d
+        assert_se(!valid_user_group_name(NULL, VALID_USER_RELAX));
21255d
+        assert_se(!valid_user_group_name("", VALID_USER_RELAX));
21255d
+        assert_se(!valid_user_group_name("1", VALID_USER_RELAX));
21255d
+        assert_se(!valid_user_group_name("65535", VALID_USER_RELAX));
21255d
+        assert_se(!valid_user_group_name("-1", VALID_USER_RELAX));
21255d
+        assert_se(!valid_user_group_name("foo\nbar", VALID_USER_RELAX));
21255d
+        assert_se(!valid_user_group_name("0123456789012345678901234567890123456789", VALID_USER_RELAX));
21255d
+        assert_se(!valid_user_group_name("aaa:bbb", VALID_USER_RELAX|VALID_USER_ALLOW_NUMERIC));
21255d
+        assert_se(!valid_user_group_name(".aaa:bbb", VALID_USER_RELAX|VALID_USER_ALLOW_NUMERIC));
21255d
+        assert_se(!valid_user_group_name(".", VALID_USER_RELAX));
21255d
+        assert_se(!valid_user_group_name("..", VALID_USER_RELAX));
21255d
+
21255d
+        assert_se(valid_user_group_name("root", VALID_USER_RELAX));
21255d
+        assert_se(valid_user_group_name("lennart", VALID_USER_RELAX));
21255d
+        assert_se(valid_user_group_name("LENNART", VALID_USER_RELAX));
21255d
+        assert_se(valid_user_group_name("_kkk", VALID_USER_RELAX));
21255d
+        assert_se(valid_user_group_name("kkk-", VALID_USER_RELAX));
21255d
+        assert_se(valid_user_group_name("kk-k", VALID_USER_RELAX));
21255d
+        assert_se(valid_user_group_name("eff.eff", VALID_USER_RELAX));
21255d
+        assert_se(valid_user_group_name("eff.", VALID_USER_RELAX));
21255d
+        assert_se(valid_user_group_name("-kkk", VALID_USER_RELAX));
21255d
+        assert_se(valid_user_group_name("rööt", VALID_USER_RELAX));
21255d
+        assert_se(valid_user_group_name(".eff", VALID_USER_RELAX));
21255d
+        assert_se(valid_user_group_name(".1", VALID_USER_RELAX));
21255d
+        assert_se(valid_user_group_name(".65535", VALID_USER_RELAX));
21255d
+        assert_se(valid_user_group_name(".-1", VALID_USER_RELAX));
21255d
+        assert_se(valid_user_group_name(".-kkk", VALID_USER_RELAX));
21255d
+        assert_se(valid_user_group_name(".rööt", VALID_USER_RELAX));
21255d
+        assert_se(valid_user_group_name("...", VALID_USER_RELAX));
21255d
+
21255d
+        assert_se(valid_user_group_name("some5", VALID_USER_RELAX));
21255d
+        assert_se(valid_user_group_name("5some", VALID_USER_RELAX));
21255d
+        assert_se(valid_user_group_name("INNER5NUMBER", VALID_USER_RELAX));
21255d
+
21255d
+        assert_se(valid_user_group_name("piff.paff@ad.domain.example", VALID_USER_RELAX));
21255d
+        assert_se(valid_user_group_name("Dāvis", VALID_USER_RELAX));
21255d
 }
21255d
 
21255d
 static void test_valid_user_group_name(void) {
21255d
         log_info("/* %s */", __func__);
21255d
 
21255d
-        assert_se(!valid_user_group_name(NULL));
21255d
-        assert_se(!valid_user_group_name(""));
21255d
-        assert_se(!valid_user_group_name("1"));
21255d
-        assert_se(!valid_user_group_name("65535"));
21255d
-        assert_se(!valid_user_group_name("-1"));
21255d
-        assert_se(!valid_user_group_name("-kkk"));
21255d
-        assert_se(!valid_user_group_name("rööt"));
21255d
-        assert_se(!valid_user_group_name("."));
21255d
-        assert_se(!valid_user_group_name(".eff"));
21255d
-        assert_se(!valid_user_group_name("foo\nbar"));
21255d
-        assert_se(!valid_user_group_name("0123456789012345678901234567890123456789"));
21255d
-        assert_se(!valid_user_group_name_or_id("aaa:bbb"));
21255d
-        assert_se(!valid_user_group_name("."));
21255d
-        assert_se(!valid_user_group_name(".1"));
21255d
-        assert_se(!valid_user_group_name(".65535"));
21255d
-        assert_se(!valid_user_group_name(".-1"));
21255d
-        assert_se(!valid_user_group_name(".-kkk"));
21255d
-        assert_se(!valid_user_group_name(".rööt"));
21255d
-        assert_se(!valid_user_group_name_or_id(".aaa:bbb"));
21255d
-
21255d
-        assert_se(valid_user_group_name("root"));
21255d
-        assert_se(valid_user_group_name("lennart"));
21255d
-        assert_se(valid_user_group_name("LENNART"));
21255d
-        assert_se(valid_user_group_name("_kkk"));
21255d
-        assert_se(valid_user_group_name("kkk-"));
21255d
-        assert_se(valid_user_group_name("kk-k"));
21255d
-        assert_se(!valid_user_group_name("eff.eff"));
21255d
-        assert_se(!valid_user_group_name("eff."));
21255d
-
21255d
-        assert_se(valid_user_group_name("some5"));
21255d
-        assert_se(!valid_user_group_name("5some"));
21255d
-        assert_se(valid_user_group_name("INNER5NUMBER"));
21255d
+        assert_se(!valid_user_group_name(NULL, 0));
21255d
+        assert_se(!valid_user_group_name("", 0));
21255d
+        assert_se(!valid_user_group_name("1", 0));
21255d
+        assert_se(!valid_user_group_name("65535", 0));
21255d
+        assert_se(!valid_user_group_name("-1", 0));
21255d
+        assert_se(!valid_user_group_name("-kkk", 0));
21255d
+        assert_se(!valid_user_group_name("rööt", 0));
21255d
+        assert_se(!valid_user_group_name(".", 0));
21255d
+        assert_se(!valid_user_group_name(".eff", 0));
21255d
+        assert_se(!valid_user_group_name("foo\nbar", 0));
21255d
+        assert_se(!valid_user_group_name("0123456789012345678901234567890123456789", 0));
21255d
+        assert_se(!valid_user_group_name("aaa:bbb", VALID_USER_ALLOW_NUMERIC));
21255d
+        assert_se(!valid_user_group_name(".", 0));
21255d
+        assert_se(!valid_user_group_name("..", 0));
21255d
+        assert_se(!valid_user_group_name("...", 0));
21255d
+        assert_se(!valid_user_group_name(".1", 0));
21255d
+        assert_se(!valid_user_group_name(".65535", 0));
21255d
+        assert_se(!valid_user_group_name(".-1", 0));
21255d
+        assert_se(!valid_user_group_name(".-kkk", 0));
21255d
+        assert_se(!valid_user_group_name(".rööt", 0));
21255d
+        assert_se(!valid_user_group_name(".aaa:bbb", VALID_USER_ALLOW_NUMERIC));
21255d
+
21255d
+        assert_se(valid_user_group_name("root", 0));
21255d
+        assert_se(valid_user_group_name("lennart", 0));
21255d
+        assert_se(valid_user_group_name("LENNART", 0));
21255d
+        assert_se(valid_user_group_name("_kkk", 0));
21255d
+        assert_se(valid_user_group_name("kkk-", 0));
21255d
+        assert_se(valid_user_group_name("kk-k", 0));
21255d
+        assert_se(!valid_user_group_name("eff.eff", 0));
21255d
+        assert_se(!valid_user_group_name("eff.", 0));
21255d
+
21255d
+        assert_se(valid_user_group_name("some5", 0));
21255d
+        assert_se(!valid_user_group_name("5some", 0));
21255d
+        assert_se(valid_user_group_name("INNER5NUMBER", 0));
21255d
+
21255d
+        assert_se(!valid_user_group_name("piff.paff@ad.domain.example", 0));
21255d
+        assert_se(!valid_user_group_name("Dāvis", 0));
21255d
 }
21255d
 
21255d
-static void test_valid_user_group_name_or_id_compat(void) {
21255d
+static void test_valid_user_group_name_or_numeric_relaxed(void) {
21255d
         log_info("/* %s */", __func__);
21255d
 
21255d
-        assert_se(!valid_user_group_name_or_id_compat(NULL));
21255d
-        assert_se(!valid_user_group_name_or_id_compat(""));
21255d
-        assert_se(valid_user_group_name_or_id_compat("0"));
21255d
-        assert_se(valid_user_group_name_or_id_compat("1"));
21255d
-        assert_se(valid_user_group_name_or_id_compat("65534"));
21255d
-        assert_se(!valid_user_group_name_or_id_compat("65535"));
21255d
-        assert_se(valid_user_group_name_or_id_compat("65536"));
21255d
-        assert_se(!valid_user_group_name_or_id_compat("-1"));
21255d
-        assert_se(!valid_user_group_name_or_id_compat("-kkk"));
21255d
-        assert_se(!valid_user_group_name_or_id_compat("rööt"));
21255d
-        assert_se(!valid_user_group_name_or_id_compat("."));
21255d
-        assert_se(!valid_user_group_name_or_id_compat(".eff"));
21255d
-        assert_se(valid_user_group_name_or_id_compat("eff.eff"));
21255d
-        assert_se(valid_user_group_name_or_id_compat("eff."));
21255d
-        assert_se(!valid_user_group_name_or_id_compat("foo\nbar"));
21255d
-        assert_se(!valid_user_group_name_or_id_compat("0123456789012345678901234567890123456789"));
21255d
-        assert_se(!valid_user_group_name_or_id_compat("aaa:bbb"));
21255d
-
21255d
-        assert_se(valid_user_group_name_or_id_compat("root"));
21255d
-        assert_se(valid_user_group_name_or_id_compat("lennart"));
21255d
-        assert_se(valid_user_group_name_or_id_compat("LENNART"));
21255d
-        assert_se(valid_user_group_name_or_id_compat("_kkk"));
21255d
-        assert_se(valid_user_group_name_or_id_compat("kkk-"));
21255d
-        assert_se(valid_user_group_name_or_id_compat("kk-k"));
21255d
-
21255d
-        assert_se(valid_user_group_name_or_id_compat("some5"));
21255d
-        assert_se(valid_user_group_name_or_id_compat("5some"));
21255d
-        assert_se(valid_user_group_name_or_id_compat("INNER5NUMBER"));
21255d
+        assert_se(!valid_user_group_name(NULL, VALID_USER_ALLOW_NUMERIC|VALID_USER_RELAX));
21255d
+        assert_se(!valid_user_group_name("", VALID_USER_ALLOW_NUMERIC|VALID_USER_RELAX));
21255d
+        assert_se(valid_user_group_name("0", VALID_USER_ALLOW_NUMERIC|VALID_USER_RELAX));
21255d
+        assert_se(valid_user_group_name("1", VALID_USER_ALLOW_NUMERIC|VALID_USER_RELAX));
21255d
+        assert_se(valid_user_group_name("65534", VALID_USER_ALLOW_NUMERIC|VALID_USER_RELAX));
21255d
+        assert_se(!valid_user_group_name("65535", VALID_USER_ALLOW_NUMERIC|VALID_USER_RELAX));
21255d
+        assert_se(valid_user_group_name("65536", VALID_USER_ALLOW_NUMERIC|VALID_USER_RELAX));
21255d
+        assert_se(!valid_user_group_name("-1", VALID_USER_ALLOW_NUMERIC|VALID_USER_RELAX));
21255d
+        assert_se(!valid_user_group_name("foo\nbar", VALID_USER_ALLOW_NUMERIC|VALID_USER_RELAX));
21255d
+        assert_se(!valid_user_group_name("0123456789012345678901234567890123456789", VALID_USER_ALLOW_NUMERIC|VALID_USER_RELAX));
21255d
+        assert_se(!valid_user_group_name("aaa:bbb", VALID_USER_ALLOW_NUMERIC|VALID_USER_RELAX));
21255d
+        assert_se(!valid_user_group_name(".", VALID_USER_ALLOW_NUMERIC|VALID_USER_RELAX));
21255d
+        assert_se(!valid_user_group_name("..", VALID_USER_ALLOW_NUMERIC|VALID_USER_RELAX));
21255d
+
21255d
+        assert_se(valid_user_group_name("root", VALID_USER_ALLOW_NUMERIC|VALID_USER_RELAX));
21255d
+        assert_se(valid_user_group_name("lennart", VALID_USER_ALLOW_NUMERIC|VALID_USER_RELAX));
21255d
+        assert_se(valid_user_group_name("LENNART", VALID_USER_ALLOW_NUMERIC|VALID_USER_RELAX));
21255d
+        assert_se(valid_user_group_name("_kkk", VALID_USER_ALLOW_NUMERIC|VALID_USER_RELAX));
21255d
+        assert_se(valid_user_group_name("kkk-", VALID_USER_ALLOW_NUMERIC|VALID_USER_RELAX));
21255d
+        assert_se(valid_user_group_name("kk-k", VALID_USER_ALLOW_NUMERIC|VALID_USER_RELAX));
21255d
+        assert_se(valid_user_group_name("-kkk", VALID_USER_ALLOW_NUMERIC|VALID_USER_RELAX));
21255d
+        assert_se(valid_user_group_name("rööt", VALID_USER_ALLOW_NUMERIC|VALID_USER_RELAX));
21255d
+        assert_se(valid_user_group_name(".eff", VALID_USER_ALLOW_NUMERIC|VALID_USER_RELAX));
21255d
+        assert_se(valid_user_group_name("eff.eff", VALID_USER_ALLOW_NUMERIC|VALID_USER_RELAX));
21255d
+        assert_se(valid_user_group_name("eff.", VALID_USER_ALLOW_NUMERIC|VALID_USER_RELAX));
21255d
+        assert_se(valid_user_group_name("...", VALID_USER_ALLOW_NUMERIC|VALID_USER_RELAX));
21255d
+
21255d
+        assert_se(valid_user_group_name("some5", VALID_USER_ALLOW_NUMERIC|VALID_USER_RELAX));
21255d
+        assert_se(valid_user_group_name("5some", VALID_USER_ALLOW_NUMERIC|VALID_USER_RELAX));
21255d
+        assert_se(valid_user_group_name("INNER5NUMBER", VALID_USER_ALLOW_NUMERIC|VALID_USER_RELAX));
21255d
+
21255d
+        assert_se(valid_user_group_name("piff.paff@ad.domain.example", VALID_USER_ALLOW_NUMERIC|VALID_USER_RELAX));
21255d
+        assert_se(valid_user_group_name("Dāvis", VALID_USER_ALLOW_NUMERIC|VALID_USER_RELAX));
21255d
 }
21255d
 
21255d
-static void test_valid_user_group_name_or_id(void) {
21255d
+static void test_valid_user_group_name_or_numeric(void) {
21255d
         log_info("/* %s */", __func__);
21255d
 
21255d
-        assert_se(!valid_user_group_name_or_id(NULL));
21255d
-        assert_se(!valid_user_group_name_or_id(""));
21255d
-        assert_se(valid_user_group_name_or_id("0"));
21255d
-        assert_se(valid_user_group_name_or_id("1"));
21255d
-        assert_se(valid_user_group_name_or_id("65534"));
21255d
-        assert_se(!valid_user_group_name_or_id("65535"));
21255d
-        assert_se(valid_user_group_name_or_id("65536"));
21255d
-        assert_se(!valid_user_group_name_or_id("-1"));
21255d
-        assert_se(!valid_user_group_name_or_id("-kkk"));
21255d
-        assert_se(!valid_user_group_name_or_id("rööt"));
21255d
-        assert_se(!valid_user_group_name_or_id("."));
21255d
-        assert_se(!valid_user_group_name_or_id(".eff"));
21255d
-        assert_se(!valid_user_group_name_or_id("eff.eff"));
21255d
-        assert_se(!valid_user_group_name_or_id("eff."));
21255d
-        assert_se(!valid_user_group_name_or_id("foo\nbar"));
21255d
-        assert_se(!valid_user_group_name_or_id("0123456789012345678901234567890123456789"));
21255d
-        assert_se(!valid_user_group_name_or_id("aaa:bbb"));
21255d
-
21255d
-        assert_se(valid_user_group_name_or_id("root"));
21255d
-        assert_se(valid_user_group_name_or_id("lennart"));
21255d
-        assert_se(valid_user_group_name_or_id("LENNART"));
21255d
-        assert_se(valid_user_group_name_or_id("_kkk"));
21255d
-        assert_se(valid_user_group_name_or_id("kkk-"));
21255d
-        assert_se(valid_user_group_name_or_id("kk-k"));
21255d
-
21255d
-        assert_se(valid_user_group_name_or_id("some5"));
21255d
-        assert_se(!valid_user_group_name_or_id("5some"));
21255d
-        assert_se(valid_user_group_name_or_id("INNER5NUMBER"));
21255d
+        assert_se(!valid_user_group_name(NULL, VALID_USER_ALLOW_NUMERIC));
21255d
+        assert_se(!valid_user_group_name("", VALID_USER_ALLOW_NUMERIC));
21255d
+        assert_se(valid_user_group_name("0", VALID_USER_ALLOW_NUMERIC));
21255d
+        assert_se(valid_user_group_name("1", VALID_USER_ALLOW_NUMERIC));
21255d
+        assert_se(valid_user_group_name("65534", VALID_USER_ALLOW_NUMERIC));
21255d
+        assert_se(!valid_user_group_name("65535", VALID_USER_ALLOW_NUMERIC));
21255d
+        assert_se(valid_user_group_name("65536", VALID_USER_ALLOW_NUMERIC));
21255d
+        assert_se(!valid_user_group_name("-1", VALID_USER_ALLOW_NUMERIC));
21255d
+        assert_se(!valid_user_group_name("-kkk", VALID_USER_ALLOW_NUMERIC));
21255d
+        assert_se(!valid_user_group_name("rööt", VALID_USER_ALLOW_NUMERIC));
21255d
+        assert_se(!valid_user_group_name(".", VALID_USER_ALLOW_NUMERIC));
21255d
+        assert_se(!valid_user_group_name("..", VALID_USER_ALLOW_NUMERIC));
21255d
+        assert_se(!valid_user_group_name("...", VALID_USER_ALLOW_NUMERIC));
21255d
+        assert_se(!valid_user_group_name(".eff", VALID_USER_ALLOW_NUMERIC));
21255d
+        assert_se(!valid_user_group_name("eff.eff", VALID_USER_ALLOW_NUMERIC));
21255d
+        assert_se(!valid_user_group_name("eff.", VALID_USER_ALLOW_NUMERIC));
21255d
+        assert_se(!valid_user_group_name("foo\nbar", VALID_USER_ALLOW_NUMERIC));
21255d
+        assert_se(!valid_user_group_name("0123456789012345678901234567890123456789", VALID_USER_ALLOW_NUMERIC));
21255d
+        assert_se(!valid_user_group_name("aaa:bbb", VALID_USER_ALLOW_NUMERIC));
21255d
+
21255d
+        assert_se(valid_user_group_name("root", VALID_USER_ALLOW_NUMERIC));
21255d
+        assert_se(valid_user_group_name("lennart", VALID_USER_ALLOW_NUMERIC));
21255d
+        assert_se(valid_user_group_name("LENNART", VALID_USER_ALLOW_NUMERIC));
21255d
+        assert_se(valid_user_group_name("_kkk", VALID_USER_ALLOW_NUMERIC));
21255d
+        assert_se(valid_user_group_name("kkk-", VALID_USER_ALLOW_NUMERIC));
21255d
+        assert_se(valid_user_group_name("kk-k", VALID_USER_ALLOW_NUMERIC));
21255d
+
21255d
+        assert_se(valid_user_group_name("some5", VALID_USER_ALLOW_NUMERIC));
21255d
+        assert_se(!valid_user_group_name("5some", VALID_USER_ALLOW_NUMERIC));
21255d
+        assert_se(valid_user_group_name("INNER5NUMBER", VALID_USER_ALLOW_NUMERIC));
21255d
+
21255d
+        assert_se(!valid_user_group_name("piff.paff@ad.domain.example", VALID_USER_ALLOW_NUMERIC));
21255d
+        assert_se(!valid_user_group_name("Dāvis", VALID_USER_ALLOW_NUMERIC));
21255d
 }
21255d
 
21255d
 static void test_valid_gecos(void) {
21255d
@@ -367,10 +386,10 @@ int main(int argc, char*argv[]) {
21255d
         test_parse_uid();
21255d
         test_uid_ptr();
21255d
 
21255d
-        test_valid_user_group_name_compat();
21255d
+        test_valid_user_group_name_relaxed();
21255d
         test_valid_user_group_name();
21255d
-        test_valid_user_group_name_or_id_compat();
21255d
-        test_valid_user_group_name_or_id();
21255d
+        test_valid_user_group_name_or_numeric_relaxed();
21255d
+        test_valid_user_group_name_or_numeric();
21255d
         test_valid_gecos();
21255d
         test_valid_home();
21255d