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