daandemeyer / rpms / systemd

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