systemd/SOURCES/0470-shared-user-util-emit-a-warning-on-names-with-dots.patch
2021-09-10 05:03:39 +00:00

51 lines
1.8 KiB
Diff

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