]> git.ipfire.org Git - thirdparty/systemd.git/commit
sysusers: gracefully handle existing group in /etc/gshadow main
authorFrantisek Sumsal <frantisek@sumsal.cz>
Mon, 3 Aug 2026 13:34:15 +0000 (15:34 +0200)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Mon, 3 Aug 2026 23:17:04 +0000 (08:17 +0900)
commit36a9875c1dd20c65806e1ac5d81bedf8c38e48f0
tree73bac6e23ed164e2acc8b9c090473ebca267549c
parentf4cb4596a371028da9e83d0be0d5e506e164650c
sysusers: gracefully handle existing group in /etc/gshadow

systemd-sysusers currently skips entries for groups that already exists.
However, if a group exists only in /etc/gshadow and not in /etc/group,
systemd-sysusers panics:

~# groupdel sgx
~# systemd-sysusers; echo $?
Creating group 'sgx' with GID 106.
0
~# systemd-sysusers; echo $?
0
~# sed -i '/sgx/d' /etc/group
~# systemd-sysusers; echo $?
Creating group 'sgx' with GID 106.
/etc/gshadow: Group "sgx" already exists.
1

To fix this, let's mirror the logic from the user path
(write_temporary_shadow()) where we simply drop the user from the "todo"
queue if it already exists in /etc/shadow instead of throwing an error.
12 files changed:
src/sysusers/sysusers.c
test/test-sysusers.sh.in
test/test-sysusers/test-17.expected-group [new file with mode: 0644]
test/test-sysusers/test-17.expected-passwd [new file with mode: 0644]
test/test-sysusers/test-17.initial-group [new file with mode: 0644]
test/test-sysusers/test-17.initial-gshadow [new file with mode: 0644]
test/test-sysusers/test-17.initial-passwd [new file with mode: 0644]
test/test-sysusers/test-17.input [new file with mode: 0644]
test/test-sysusers/test-18.expected-group [new file with mode: 0644]
test/test-sysusers/test-18.expected-passwd [new file with mode: 0644]
test/test-sysusers/test-18.initial-shadow [new file with mode: 0644]
test/test-sysusers/test-18.input [new file with mode: 0644]