|
@@ -66,7 +66,7 @@ Result<Account, String> Account::from_passwd(const passwd& pwd, const spwd& spwd
|
|
|
return account;
|
|
|
}
|
|
|
|
|
|
-Account Account::self()
|
|
|
+Account Account::self(Read options)
|
|
|
{
|
|
|
struct passwd fallback;
|
|
|
fallback.pw_name = const_cast<char*>("(unknown)");
|
|
@@ -95,17 +95,20 @@ Account Account::self()
|
|
|
spwd_dummy.sp_namp = pwd->pw_name;
|
|
|
spwd_dummy.sp_pwdp = const_cast<char*>("");
|
|
|
#ifndef AK_OS_BSD_GENERIC
|
|
|
- auto* spwd = getspnam(pwd->pw_name);
|
|
|
+ spwd* spwd = nullptr;
|
|
|
+ if (options != Read::PasswdOnly)
|
|
|
+ spwd = getspnam(pwd->pw_name);
|
|
|
if (!spwd)
|
|
|
spwd = &spwd_dummy;
|
|
|
#else
|
|
|
+ (void)options;
|
|
|
auto* spwd = &spwd_dummy;
|
|
|
#endif
|
|
|
|
|
|
return Account(*pwd, *spwd, extra_gids);
|
|
|
}
|
|
|
|
|
|
-Result<Account, String> Account::from_name(const char* username)
|
|
|
+Result<Account, String> Account::from_name(const char* username, Read options)
|
|
|
{
|
|
|
errno = 0;
|
|
|
auto* pwd = getpwnam(username);
|
|
@@ -119,16 +122,19 @@ Result<Account, String> Account::from_name(const char* username)
|
|
|
spwd_dummy.sp_namp = const_cast<char*>(username);
|
|
|
spwd_dummy.sp_pwdp = const_cast<char*>("");
|
|
|
#ifndef AK_OS_BSD_GENERIC
|
|
|
- auto* spwd = getspnam(username);
|
|
|
+ spwd* spwd = nullptr;
|
|
|
+ if (options != Read::PasswdOnly)
|
|
|
+ spwd = getspnam(pwd->pw_name);
|
|
|
if (!spwd)
|
|
|
spwd = &spwd_dummy;
|
|
|
#else
|
|
|
+ (void)options;
|
|
|
auto* spwd = &spwd_dummy;
|
|
|
#endif
|
|
|
return from_passwd(*pwd, *spwd);
|
|
|
}
|
|
|
|
|
|
-Result<Account, String> Account::from_uid(uid_t uid)
|
|
|
+Result<Account, String> Account::from_uid(uid_t uid, Read options)
|
|
|
{
|
|
|
errno = 0;
|
|
|
auto* pwd = getpwuid(uid);
|
|
@@ -142,10 +148,13 @@ Result<Account, String> Account::from_uid(uid_t uid)
|
|
|
spwd_dummy.sp_namp = pwd->pw_name;
|
|
|
spwd_dummy.sp_pwdp = const_cast<char*>("");
|
|
|
#ifndef AK_OS_BSD_GENERIC
|
|
|
- auto* spwd = getspnam(pwd->pw_name);
|
|
|
+ spwd* spwd = nullptr;
|
|
|
+ if (options != Read::PasswdOnly)
|
|
|
+ spwd = getspnam(pwd->pw_name);
|
|
|
if (!spwd)
|
|
|
spwd = &spwd_dummy;
|
|
|
#else
|
|
|
+ (void)options;
|
|
|
auto* spwd = &spwd_dummy;
|
|
|
#endif
|
|
|
return from_passwd(*pwd, *spwd);
|