From 3c04d22e387337fa2ab329644acf950e033e1ab0 Mon Sep 17 00:00:00 2001 From: Karol Baraniecki Date: Mon, 6 Feb 2023 18:55:43 +0100 Subject: [PATCH] su: Only check for an interactive tty if a password is actually needed --- Userland/Utilities/su.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Userland/Utilities/su.cpp b/Userland/Utilities/su.cpp index 6a4a97deea0..1f93c56501d 100644 --- a/Userland/Utilities/su.cpp +++ b/Userland/Utilities/su.cpp @@ -16,9 +16,6 @@ ErrorOr serenity_main(Main::Arguments arguments) { TRY(Core::System::pledge("stdio rpath tty exec id")); - if (!TRY(Core::System::isatty(STDIN_FILENO))) - return Error::from_string_literal("Standard input is not a terminal"); - StringView first_positional; StringView second_positional; DeprecatedString command; @@ -46,6 +43,9 @@ ErrorOr serenity_main(Main::Arguments arguments) TRY(Core::System::pledge("stdio rpath tty exec id")); if (getuid() != 0 && account.has_password()) { + if (!TRY(Core::System::isatty(STDIN_FILENO))) + return Error::from_string_literal("Standard input is not a terminal"); + auto password = TRY(Core::get_password()); if (!account.authenticate(password)) return Error::from_string_literal("Incorrect or disabled password.");