1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 09:27:35 +00:00

LibCore: Propagate errors from LibCore::Account::login()

This commit is contained in:
Lucas CHOLLET 2022-07-09 14:53:04 +02:00 committed by Sam Atkins
parent 08dcc40aa5
commit 8fabe9a3ad
4 changed files with 9 additions and 17 deletions

View file

@ -157,18 +157,13 @@ ErrorOr<void> Account::create_user_temporary_directory_if_needed() const
return {};
}
bool Account::login() const
ErrorOr<void> 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)

View file

@ -38,7 +38,7 @@ public:
static ErrorOr<Account> from_uid(uid_t uid, Read options = Read::All);
bool authenticate(SecretString const& password) const;
bool login() const;
ErrorOr<void> login() const;
ErrorOr<void> create_user_temporary_directory_if_needed() const;

View file

@ -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);
}

View file

@ -51,10 +51,7 @@ ErrorOr<int> 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()));