sysusers: validate shell credentials

Validate passwd.shell.<user> credentials with the same login-shell
rules used for sysusers.d shell fields before writing passwd entries.

Reproducer: CREDENTIALS_DIRECTORY=... systemd-sysusers --root=...
with --inline 'u creduser 999 "Cred User" / -'

Before: relative-shell was written as the login shell and the command
exited successfully.

Follow-up: 99e9f896fb
This commit is contained in:
dongshengyuan
2026-07-18 15:48:34 +08:00
parent 8729fa0e4b
commit 05b49871a2
2 changed files with 48 additions and 9 deletions
+9
View File
@@ -30,6 +30,15 @@ at_exit() {
trap at_exit EXIT
root="$(mktemp -d)"
cred="$(mktemp -d)"
mkdir -p "$root/etc"
printf 'relative-shell' >"$cred/passwd.shell.creduser"
(! env CREDENTIALS_DIRECTORY="$cred" systemd-sysusers --dry-run --root="$root" --inline 'u creduser 999 "Cred User" / -')
(! env CREDENTIALS_DIRECTORY="$cred" systemd-sysusers --root="$root" --inline 'u creduser 999 "Cred User" / -')
(! grep -F creduser "$root/etc/passwd" >/dev/null 2>&1)
rm -rf "$root" "$cred"
# Ensure that a non-responsive NSS socket doesn't make sysusers fail
mount -t tmpfs tmpfs /run/systemd/userdb/
touch /run/systemd/userdb/io.systemd.DynamicUser