diff --git a/Userland/Libraries/LibCore/Account.cpp b/Userland/Libraries/LibCore/Account.cpp index 9109343643..4958f5bb2d 100644 --- a/Userland/Libraries/LibCore/Account.cpp +++ b/Userland/Libraries/LibCore/Account.cpp @@ -157,18 +157,13 @@ ErrorOr Account::create_user_temporary_directory_if_needed() const return {}; } -bool Account::login() const +ErrorOr Account::login() const { - if (setgroups(m_extra_gids.size(), m_extra_gids.data()) < 0) - return false; + TRY(Core::System::setgroups(m_extra_gids)); + TRY(Core::System::setgid(m_gid)); + TRY(Core::System::setuid(m_uid)); - if (setgid(m_gid) < 0) - return false; - - if (setuid(m_uid) < 0) - return false; - - return true; + return {}; } void Account::set_password(SecretString const& password) diff --git a/Userland/Libraries/LibCore/Account.h b/Userland/Libraries/LibCore/Account.h index f34a698ba0..54b432e4d5 100644 --- a/Userland/Libraries/LibCore/Account.h +++ b/Userland/Libraries/LibCore/Account.h @@ -38,7 +38,7 @@ public: static ErrorOr from_uid(uid_t uid, Read options = Read::All); bool authenticate(SecretString const& password) const; - bool login() const; + ErrorOr login() const; ErrorOr create_user_temporary_directory_if_needed() const; diff --git a/Userland/Services/LoginServer/main.cpp b/Userland/Services/LoginServer/main.cpp index 0efd279042..192e1d0610 100644 --- a/Userland/Services/LoginServer/main.cpp +++ b/Userland/Services/LoginServer/main.cpp @@ -23,8 +23,8 @@ static void child_process(Core::Account const& account) exit(1); } - if (!account.login()) { - dbgln("failed to switch users: {}", strerror(errno)); + if (auto const result = account.login(); result.is_error()) { + dbgln("failed to switch users: {}", result.error()); exit(1); } diff --git a/Userland/Utilities/su.cpp b/Userland/Utilities/su.cpp index ba1ffadb0e..d101f45f76 100644 --- a/Userland/Utilities/su.cpp +++ b/Userland/Utilities/su.cpp @@ -51,10 +51,7 @@ ErrorOr serenity_main(Main::Arguments arguments) TRY(Core::System::pledge("stdio rpath exec id")); - if (!account.login()) { - perror("Core::Account::login"); - return 1; - } + TRY(account.login()); if (simulate_login) TRY(Core::System::chdir(account.home_directory()));