Skip to content

Commit f2c2b65

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)
1 parent bc25576 commit f2c2b65

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
@@ -1377,9 +1377,15 @@ static int process_item(Item *i) {
13771377
case ADD_USER: {
13781378
Item *j = NULL;
13791379

1380-
if (!i->gid_set)
1380+
if (!i->gid_set) {
13811381
j = ordered_hashmap_get(groups, i->group_name ?: i->name);
13821382

1383+
/* If that's not a match, also check if the group name
1384+
* matches a user name in the queue. */
1385+
if (!j && i->group_name)
1386+
j = ordered_hashmap_get(users, i->group_name);
1387+
}
1388+
13831389
if (j && j->todo_group) {
13841390
/* When a group with the target name is already in queue,
13851391
* 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)