]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
firstboot: validate root shell credentials
authordongshengyuan <545258830@qq.com>
Thu, 16 Jul 2026 06:23:35 +0000 (14:23 +0800)
committerdongshengyuan <545258830@qq.com>
Sat, 18 Jul 2026 07:48:34 +0000 (15:48 +0800)
Validate passwd.shell.root after reading the credential so it uses
the same target-root shell checks as --root-shell= and prompted input.

Reproducer: CREDENTIALS_DIRECTORY=... systemd-firstboot --root=...
with passwd.shell.root=/bin/nonexistentshell

Before: /etc/passwd was written with the nonexistent root shell and
the command exited successfully.

Follow-up: 416f7b3a11e00d1a43da950fb4a00bc6c2707013

src/firstboot/firstboot.c
test/units/TEST-74-AUX-UTILS.firstboot.sh

index f3ea57ec929e962dc7ff5f6700a3f57d0eeee6d5..5ebaf89764bd116860548c5ff57f0d356be4bcff 100644 (file)
@@ -998,6 +998,10 @@ static int prompt_root_shell(int rfd, sd_varlink **mute_console_link) {
         if (r < 0)
                 log_debug_errno(r, "Failed to read credential passwd.shell.root, ignoring: %m");
         else {
+                r = find_shell(rfd, arg_root_shell);
+                if (r < 0)
+                        return r;
+
                 log_debug("Acquired root shell from credential.");
                 return 0;
         }
index 8c3c222c884d727cc1dc49f8e07415d1ee1a032f..4fbbb18efa18d63e7527461a655e08e1ae4d6df7 100755 (executable)
@@ -352,6 +352,11 @@ grep -q "^root::" "$ROOT/etc/shadow"
 rm -fv "$ROOT/etc/passwd" "$ROOT/etc/shadow"
 
 (! systemd-firstboot --root="$ROOT" --root-shell=/bin/nonexistentshell)
+WCREDS="$(mktemp -d)"
+printf '/bin/nonexistentshell' >"$WCREDS/passwd.shell.root"
+(! CREDENTIALS_DIRECTORY="$WCREDS" systemd-firstboot --root="$ROOT")
+[[ ! -e "$ROOT/etc/passwd" ]]
+rm -rf "$WCREDS"
 (! systemd-firstboot --root="$ROOT" --machine-id=invalidmachineid)
 (! systemd-firstboot --root="$ROOT" --timezone=Foo/Bar)