1
0
mirror of https://github.com/systemd/systemd.git synced 2025-03-09 12:58:26 +03:00

firstboot: create locked and empty root passwords consistently

Although locked and empty passwords in /etc/passwd are treated the same, in all
other cases the entry is configured to read the password from /etc/shadow.
This commit is contained in:
Dan Nicholson 2024-07-30 11:11:11 -06:00
parent 38688bbc8f
commit 5088de9daa
2 changed files with 9 additions and 6 deletions

View File

@ -1142,10 +1142,13 @@ static int process_root_account(int rfd) {
password = PASSWORD_SEE_SHADOW;
hashed_password = _hashed_password;
} else if (arg_delete_root_password)
password = hashed_password = PASSWORD_NONE;
else
password = hashed_password = PASSWORD_LOCKED_AND_INVALID;
} else if (arg_delete_root_password) {
password = PASSWORD_SEE_SHADOW;
hashed_password = PASSWORD_NONE;
} else {
password = PASSWORD_SEE_SHADOW;
hashed_password = PASSWORD_LOCKED_AND_INVALID;
}
r = write_root_passwd(rfd, pfd, password, arg_root_shell);
if (r < 0)

View File

@ -211,7 +211,7 @@ echo -ne "\nfoobar\n" | systemd-firstboot --root="$ROOT" --prompt-hostname
grep -q "foobar" "$ROOT/etc/hostname"
# With no root password provided, a locked account should be created.
systemd-firstboot --root="$ROOT" --prompt-root-password </dev/null
grep -q "^root:!\*:0:0:" "$ROOT/etc/passwd"
grep -q "^root:x:0:0:" "$ROOT/etc/passwd"
grep -q "^root:!\*:" "$ROOT/etc/shadow"
rm -fv "$ROOT/etc/passwd" "$ROOT/etc/shadow"
echo -ne "\n/bin/fooshell\n" | systemd-firstboot --root="$ROOT" --prompt-root-shell
@ -262,7 +262,7 @@ grep -E "[a-z0-9]{32}" "$ROOT/etc/machine-id"
rm -fv "$ROOT/etc/machine-id"
systemd-firstboot --root="$ROOT" --delete-root-password
grep -q "^root::0:0:" "$ROOT/etc/passwd"
grep -q "^root:x:0:0:" "$ROOT/etc/passwd"
grep -q "^root::" "$ROOT/etc/shadow"
rm -fv "$ROOT/etc/passwd" "$ROOT/etc/shadow"