mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 01:07:36 +00:00
LibCore: Let Account::from_* succeed if /etc/shadow is unreadable
This previously worked and was broken by 302f9798e
.
This commit is contained in:
parent
19bef3877a
commit
3cab91e8d7
1 changed files with 10 additions and 18 deletions
|
@ -74,18 +74,14 @@ Result<Account, String> Account::from_name(const char* username)
|
|||
|
||||
return String(strerror(errno));
|
||||
}
|
||||
#ifndef AK_OS_MACOS
|
||||
auto* spwd = getspnam(username);
|
||||
if (!spwd) {
|
||||
if (errno == 0)
|
||||
return String("No such user");
|
||||
|
||||
return String(strerror(errno));
|
||||
}
|
||||
#else
|
||||
spwd spwd_dummy = {};
|
||||
spwd_dummy.sp_namp = const_cast<char*>(username);
|
||||
spwd_dummy.sp_pwdp = const_cast<char*>("");
|
||||
#ifndef AK_OS_MACOS
|
||||
auto* spwd = getspnam(username);
|
||||
if (!spwd)
|
||||
spwd = &spwd_dummy;
|
||||
#else
|
||||
auto* spwd = &spwd_dummy;
|
||||
#endif
|
||||
return from_passwd(*pwd, *spwd);
|
||||
|
@ -101,18 +97,14 @@ Result<Account, String> Account::from_uid(uid_t uid)
|
|||
|
||||
return String(strerror(errno));
|
||||
}
|
||||
#ifndef AK_OS_MACOS
|
||||
auto* spwd = getspnam(pwd->pw_name);
|
||||
if (!spwd) {
|
||||
if (errno == 0)
|
||||
return String("No such user");
|
||||
|
||||
return String(strerror(errno));
|
||||
}
|
||||
#else
|
||||
spwd spwd_dummy = {};
|
||||
spwd_dummy.sp_namp = pwd->pw_name;
|
||||
spwd_dummy.sp_pwdp = const_cast<char*>("");
|
||||
#ifndef AK_OS_MACOS
|
||||
auto* spwd = getspnam(pwd->pw_name);
|
||||
if (!spwd)
|
||||
spwd = &spwd_dummy;
|
||||
#else
|
||||
auto* spwd = &spwd_dummy;
|
||||
#endif
|
||||
return from_passwd(*pwd, *spwd);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue