Skip to content

Commit 4bc72f7

Browse files
enr0nbluca
authored andcommitted
sysusers: check if requested group name matches user name in queue
When creating a user, check if the requested group name matches a user name in the queue. If that matched user name is also going to be a group name, then use it for the new user too. In other words, allow the following: u foo - u bar -:foo when both foo and bar are new users. Fixes #33547 (cherry picked from commit 18a8f03) (cherry picked from commit edf5238) (cherry picked from commit 25003a6) (cherry picked from commit ed2da03) (cherry picked from commit f2c2b65)
1 parent 1970b83 commit 4bc72f7

File tree

4 files changed

+17
-1
lines changed

4 files changed

+17
-1
lines changed

src/sysusers/sysusers.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1356,9 +1356,15 @@ static int process_item(Item *i) {
13561356
case ADD_USER: {
13571357
Item *j = NULL;
13581358

1359-
if (!i->gid_set)
1359+
if (!i->gid_set) {
13601360
j = ordered_hashmap_get(groups, i->group_name ?: i->name);
13611361

1362+
/* If that's not a match, also check if the group name
1363+
* matches a user name in the queue. */
1364+
if (!j && i->group_name)
1365+
j = ordered_hashmap_get(users, i->group_name);
1366+
}
1367+
13621368
if (j && j->todo_group) {
13631369
/* When a group with the target name is already in queue,
13641370
* use the information about the group and do not create
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
foo:x:SYSTEM_UGID_MAX:
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
foo:x:SYSTEM_UGID_MAX:SYSTEM_UGID_MAX::/:NOLOGIN
2+
bar:x:300:SYSTEM_UGID_MAX::/:NOLOGIN

test/test-sysusers/test-16.input

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# SPDX-License-Identifier: LGPL-2.1-or-later
2+
#
3+
# Test fix for https://github.com/systemd/systemd/issues/33547.
4+
#
5+
#Type Name ID
6+
u foo -
7+
u bar 300:foo

0 commit comments

Comments
 (0)