From d224610ecffceb7ecb816f156a31aa828416ac3d Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Tue, 4 May 2021 15:11:44 +0100 Subject: [PATCH] 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. --- Userland/Libraries/LibCore/Account.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Userland/Libraries/LibCore/Account.cpp b/Userland/Libraries/LibCore/Account.cpp index 8f56e53193..af52c709af 100644 --- a/Userland/Libraries/LibCore/Account.cpp +++ b/Userland/Libraries/LibCore/Account.cpp @@ -39,10 +39,13 @@ static String get_salt() return builder.build(); } -static Vector get_gids(const StringView& username) +static Vector get_extra_gids(const passwd& pwd) { + StringView username { pwd.pw_name }; Vector extra_gids; 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) { if (username == group->gr_mem[i]) { extra_gids.append(group->gr_gid); @@ -56,7 +59,7 @@ static Vector get_gids(const StringView& username) Result 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(); #ifndef AK_OS_MACOS endspent();