1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 03:37:45 +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:
Gunnar Beutner 2021-05-04 14:32:00 +02:00 committed by Linus Groh
parent 19bef3877a
commit 3cab91e8d7

View file

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