ryantimwilson / rpms / systemd

Forked from rpms/systemd a month ago
Clone
4fbe94
From 76176de0889c3e8b9b3a176da24e4f8dbbd380a3 Mon Sep 17 00:00:00 2001
4fbe94
From: Jan Synacek <jsynacek@redhat.com>
4fbe94
Date: Wed, 2 Oct 2019 11:59:41 +0200
4fbe94
Subject: [PATCH] basic/user-util: allow dots in user names
4fbe94
4fbe94
(based on commit 1a29610f5fa1bcb2eeb37d2c6b79d8d1a6dbb865)
4fbe94
4fbe94
Resolves: #1717603
4fbe94
---
4fbe94
 src/basic/user-util.c     | 9 ++++++---
4fbe94
 src/test/test-user-util.c | 8 ++++----
4fbe94
 2 files changed, 10 insertions(+), 7 deletions(-)
4fbe94
4fbe94
diff --git a/src/basic/user-util.c b/src/basic/user-util.c
4fbe94
index c533f67025..d92969c966 100644
4fbe94
--- a/src/basic/user-util.c
4fbe94
+++ b/src/basic/user-util.c
4fbe94
@@ -575,11 +575,14 @@ bool valid_user_group_name(const char *u) {
4fbe94
         /* Checks if the specified name is a valid user/group name. Also see POSIX IEEE Std 1003.1-2008, 2016 Edition,
4fbe94
          * 3.437. We are a bit stricter here however. Specifically we deviate from POSIX rules:
4fbe94
          *
4fbe94
-         * - We don't allow any dots (this would break chown syntax which permits dots as user/group name separator)
4fbe94
          * - We require that names fit into the appropriate utmp field
4fbe94
          * - We don't allow empty user names
4fbe94
          *
4fbe94
          * Note that other systems are even more restrictive, and don't permit underscores or uppercase characters.
4fbe94
+         *
4fbe94
+         * jsynacek: We now allow dots in user names. The checks are not exhaustive as user names like "..." are allowed
4fbe94
+         * and valid according to POSIX, but can't be created using useradd. However, ".user" can be created. Let's not
4fbe94
+         * complicate the code by adding additional checks for weird corner cases like these,  as they don't really matter here.
4fbe94
          */
4fbe94
 
4fbe94
         if (isempty(u))
4fbe94
@@ -587,14 +590,14 @@ bool valid_user_group_name(const char *u) {
4fbe94
 
4fbe94
         if (!(u[0] >= 'a' && u[0] <= 'z') &&
4fbe94
             !(u[0] >= 'A' && u[0] <= 'Z') &&
4fbe94
-            u[0] != '_')
4fbe94
+            u[0] != '_' && u[0] != '.')
4fbe94
                 return false;
4fbe94
 
4fbe94
         for (i = u+1; *i; i++) {
4fbe94
                 if (!(*i >= 'a' && *i <= 'z') &&
4fbe94
                     !(*i >= 'A' && *i <= 'Z') &&
4fbe94
                     !(*i >= '0' && *i <= '9') &&
4fbe94
-                    !IN_SET(*i, '_', '-'))
4fbe94
+                    !IN_SET(*i, '_', '-', '.'))
4fbe94
                         return false;
4fbe94
         }
4fbe94
 
4fbe94
diff --git a/src/test/test-user-util.c b/src/test/test-user-util.c
4fbe94
index c1428fab02..9114d30b8c 100644
4fbe94
--- a/src/test/test-user-util.c
4fbe94
+++ b/src/test/test-user-util.c
4fbe94
@@ -71,8 +71,6 @@ static void test_valid_user_group_name(void) {
4fbe94
         assert_se(!valid_user_group_name("-1"));
4fbe94
         assert_se(!valid_user_group_name("-kkk"));
4fbe94
         assert_se(!valid_user_group_name("rööt"));
4fbe94
-        assert_se(!valid_user_group_name("."));
4fbe94
-        assert_se(!valid_user_group_name("eff.eff"));
4fbe94
         assert_se(!valid_user_group_name("foo\nbar"));
4fbe94
         assert_se(!valid_user_group_name("0123456789012345678901234567890123456789"));
4fbe94
         assert_se(!valid_user_group_name_or_id("aaa:bbb"));
4fbe94
@@ -83,6 +81,8 @@ static void test_valid_user_group_name(void) {
4fbe94
         assert_se(valid_user_group_name("_kkk"));
4fbe94
         assert_se(valid_user_group_name("kkk-"));
4fbe94
         assert_se(valid_user_group_name("kk-k"));
4fbe94
+        assert_se(valid_user_group_name(".moo"));
4fbe94
+        assert_se(valid_user_group_name("eff.eff"));
4fbe94
 
4fbe94
         assert_se(valid_user_group_name("some5"));
4fbe94
         assert_se(!valid_user_group_name("5some"));
4fbe94
@@ -102,8 +102,6 @@ static void test_valid_user_group_name_or_id(void) {
4fbe94
         assert_se(!valid_user_group_name_or_id("-1"));
4fbe94
         assert_se(!valid_user_group_name_or_id("-kkk"));
4fbe94
         assert_se(!valid_user_group_name_or_id("rööt"));
4fbe94
-        assert_se(!valid_user_group_name_or_id("."));
4fbe94
-        assert_se(!valid_user_group_name_or_id("eff.eff"));
4fbe94
         assert_se(!valid_user_group_name_or_id("foo\nbar"));
4fbe94
         assert_se(!valid_user_group_name_or_id("0123456789012345678901234567890123456789"));
4fbe94
         assert_se(!valid_user_group_name_or_id("aaa:bbb"));
4fbe94
@@ -114,6 +112,8 @@ static void test_valid_user_group_name_or_id(void) {
4fbe94
         assert_se(valid_user_group_name_or_id("_kkk"));
4fbe94
         assert_se(valid_user_group_name_or_id("kkk-"));
4fbe94
         assert_se(valid_user_group_name_or_id("kk-k"));
4fbe94
+        assert_se(valid_user_group_name_or_id(".moo"));
4fbe94
+        assert_se(valid_user_group_name_or_id("eff.eff"));
4fbe94
 
4fbe94
         assert_se(valid_user_group_name_or_id("some5"));
4fbe94
         assert_se(!valid_user_group_name_or_id("5some"));