daandemeyer / rpms / systemd

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