daandemeyer / rpms / systemd

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