mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 00:47:45 +00:00
LibCore: Don't include user GID in Account::extra_gids()
The user's GID is already available via gid(), and it's not "extra", so don't include it in extra_gids() again. Also rename the internally used function from get_gids() to get_extra_gids() to make its purpose more clear.
This commit is contained in:
parent
3b759451c6
commit
d224610ecf
1 changed files with 5 additions and 2 deletions
|
@ -39,10 +39,13 @@ static String get_salt()
|
||||||
return builder.build();
|
return builder.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
static Vector<gid_t> get_gids(const StringView& username)
|
static Vector<gid_t> get_extra_gids(const passwd& pwd)
|
||||||
{
|
{
|
||||||
|
StringView username { pwd.pw_name };
|
||||||
Vector<gid_t> extra_gids;
|
Vector<gid_t> extra_gids;
|
||||||
for (auto* group = getgrent(); group; group = getgrent()) {
|
for (auto* group = getgrent(); group; group = getgrent()) {
|
||||||
|
if (group->gr_gid == pwd.pw_gid)
|
||||||
|
continue;
|
||||||
for (size_t i = 0; group->gr_mem[i]; ++i) {
|
for (size_t i = 0; group->gr_mem[i]; ++i) {
|
||||||
if (username == group->gr_mem[i]) {
|
if (username == group->gr_mem[i]) {
|
||||||
extra_gids.append(group->gr_gid);
|
extra_gids.append(group->gr_gid);
|
||||||
|
@ -56,7 +59,7 @@ static Vector<gid_t> get_gids(const StringView& username)
|
||||||
|
|
||||||
Result<Account, String> Account::from_passwd(const passwd& pwd, const spwd& spwd)
|
Result<Account, String> Account::from_passwd(const passwd& pwd, const spwd& spwd)
|
||||||
{
|
{
|
||||||
Account account(pwd, spwd, get_gids(pwd.pw_name));
|
Account account(pwd, spwd, get_extra_gids(pwd));
|
||||||
endpwent();
|
endpwent();
|
||||||
#ifndef AK_OS_MACOS
|
#ifndef AK_OS_MACOS
|
||||||
endspent();
|
endspent();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue