teknoraver / rpms / systemd

Forked from rpms/systemd 2 months ago
Clone

Blame SOURCES/0470-shared-user-util-emit-a-warning-on-names-with-dots.patch

21255d
From fa1fa19951fdadd63f2b5df6224678f91753f260 Mon Sep 17 00:00:00 2001
21255d
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
21255d
Date: Wed, 28 Aug 2019 12:05:52 +0200
21255d
Subject: [PATCH] shared/user-util: emit a warning on names with dots
21255d
21255d
(cherry picked from commit 88e2ed0b5bf6f08f5a2d4d64b1fefdc7192b9aac)
21255d
21255d
Related: #1848373
21255d
---
21255d
 src/basic/user-util.c | 27 ++++++++++++++++++++-------
21255d
 1 file changed, 20 insertions(+), 7 deletions(-)
21255d
21255d
diff --git a/src/basic/user-util.c b/src/basic/user-util.c
21255d
index 03cbbc2503..359da08a83 100644
21255d
--- a/src/basic/user-util.c
21255d
+++ b/src/basic/user-util.c
21255d
@@ -601,13 +601,26 @@ bool valid_user_group_name_full(const char *u, bool strict) {
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
-                      (!strict && *i == '.')))
21255d
-                        return false;
21255d
+        bool warned = 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
+                        continue;
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
+        }
21255d
 
21255d
         sz = sysconf(_SC_LOGIN_NAME_MAX);
21255d
         assert_se(sz > 0);