mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 18:17:44 +00:00
LibCore: Add ability to not read shadow data for Account
This stops spamming the kernel logs with unveil violations if the program didn't unveil /etc/shadow.
This commit is contained in:
parent
fdf638dde0
commit
16983dbe8e
2 changed files with 23 additions and 9 deletions
|
@ -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);
|
||||
|
|
|
@ -27,9 +27,14 @@ struct spwd {
|
|||
|
||||
class Account {
|
||||
public:
|
||||
static Account self();
|
||||
static Result<Account, String> from_name(const char* username);
|
||||
static Result<Account, String> from_uid(uid_t uid);
|
||||
enum class Read {
|
||||
All,
|
||||
PasswdOnly
|
||||
};
|
||||
|
||||
static Account self(Read options = Read::All);
|
||||
static Result<Account, String> from_name(const char* username, Read options = Read::All);
|
||||
static Result<Account, String> from_uid(uid_t uid, Read options = Read::All);
|
||||
|
||||
bool authenticate(const char* password) const;
|
||||
bool login() const;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue