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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user