mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 12:47:35 +00:00
LibCore: Replace Result<T, E> use with ErrorOr<T> in Core::Account
This commit is contained in:
parent
01a6a4f7c4
commit
4eeab4cfc8
2 changed files with 10 additions and 13 deletions
|
@ -55,7 +55,7 @@ static Vector<gid_t> get_extra_gids(const passwd& pwd)
|
||||||
return extra_gids;
|
return extra_gids;
|
||||||
}
|
}
|
||||||
|
|
||||||
Result<Account, String> Account::from_passwd(const passwd& pwd, const spwd& spwd)
|
ErrorOr<Account> Account::from_passwd(const passwd& pwd, const spwd& spwd)
|
||||||
{
|
{
|
||||||
Account account(pwd, spwd, get_extra_gids(pwd));
|
Account account(pwd, spwd, get_extra_gids(pwd));
|
||||||
endpwent();
|
endpwent();
|
||||||
|
@ -107,15 +107,14 @@ Account Account::self(Read options)
|
||||||
return Account(*pwd, *spwd, extra_gids);
|
return Account(*pwd, *spwd, extra_gids);
|
||||||
}
|
}
|
||||||
|
|
||||||
Result<Account, String> Account::from_name(const char* username, Read options)
|
ErrorOr<Account> Account::from_name(const char* username, Read options)
|
||||||
{
|
{
|
||||||
errno = 0;
|
errno = 0;
|
||||||
auto* pwd = getpwnam(username);
|
auto* pwd = getpwnam(username);
|
||||||
if (!pwd) {
|
if (!pwd) {
|
||||||
if (errno == 0)
|
if (errno == 0)
|
||||||
return String("No such user");
|
return Error::from_string_literal("No such user"sv);
|
||||||
|
return Error::from_errno(errno);
|
||||||
return String(strerror(errno));
|
|
||||||
}
|
}
|
||||||
spwd spwd_dummy = {};
|
spwd spwd_dummy = {};
|
||||||
spwd_dummy.sp_namp = const_cast<char*>(username);
|
spwd_dummy.sp_namp = const_cast<char*>(username);
|
||||||
|
@ -133,15 +132,14 @@ Result<Account, String> Account::from_name(const char* username, Read options)
|
||||||
return from_passwd(*pwd, *spwd);
|
return from_passwd(*pwd, *spwd);
|
||||||
}
|
}
|
||||||
|
|
||||||
Result<Account, String> Account::from_uid(uid_t uid, Read options)
|
ErrorOr<Account> Account::from_uid(uid_t uid, Read options)
|
||||||
{
|
{
|
||||||
errno = 0;
|
errno = 0;
|
||||||
auto* pwd = getpwuid(uid);
|
auto* pwd = getpwuid(uid);
|
||||||
if (!pwd) {
|
if (!pwd) {
|
||||||
if (errno == 0)
|
if (errno == 0)
|
||||||
return String("No such user");
|
return Error::from_string_literal("No such user"sv);
|
||||||
|
return Error::from_errno(errno);
|
||||||
return String(strerror(errno));
|
|
||||||
}
|
}
|
||||||
spwd spwd_dummy = {};
|
spwd spwd_dummy = {};
|
||||||
spwd_dummy.sp_namp = pwd->pw_name;
|
spwd_dummy.sp_namp = pwd->pw_name;
|
||||||
|
|
|
@ -6,7 +6,6 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <AK/Result.h>
|
|
||||||
#include <AK/String.h>
|
#include <AK/String.h>
|
||||||
#include <AK/Types.h>
|
#include <AK/Types.h>
|
||||||
#include <AK/Vector.h>
|
#include <AK/Vector.h>
|
||||||
|
@ -34,8 +33,8 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
static Account self(Read options = Read::All);
|
static Account self(Read options = Read::All);
|
||||||
static Result<Account, String> from_name(const char* username, Read options = Read::All);
|
static ErrorOr<Account> from_name(char const* username, Read options = Read::All);
|
||||||
static Result<Account, String> from_uid(uid_t uid, Read options = Read::All);
|
static ErrorOr<Account> from_uid(uid_t uid, Read options = Read::All);
|
||||||
|
|
||||||
bool authenticate(SecretString const& password) const;
|
bool authenticate(SecretString const& password) const;
|
||||||
bool login() const;
|
bool login() const;
|
||||||
|
@ -68,7 +67,7 @@ public:
|
||||||
bool sync();
|
bool sync();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static Result<Account, String> from_passwd(const passwd&, const spwd&);
|
static ErrorOr<Account> from_passwd(passwd const&, spwd const&);
|
||||||
|
|
||||||
Account(const passwd& pwd, const spwd& spwd, Vector<gid_t> extra_gids);
|
Account(const passwd& pwd, const spwd& spwd, Vector<gid_t> extra_gids);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue