diff options
author | Linus Groh <mail@linusgroh.de> | 2021-05-04 15:11:44 +0100 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2021-05-04 15:16:19 +0100 |
commit | d224610ecffceb7ecb816f156a31aa828416ac3d (patch) | |
tree | ae2235f3b861ab35904ac8e346a3d477d873c1db /Userland/Libraries/LibCore | |
parent | 3b759451c6b736cd2a2e796b51dc5c06a01d91cb (diff) | |
download | serenity-d224610ecffceb7ecb816f156a31aa828416ac3d.zip |
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.
Diffstat (limited to 'Userland/Libraries/LibCore')
-rw-r--r-- | Userland/Libraries/LibCore/Account.cpp | 7 |
1 files 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<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; 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<gid_t> get_gids(const StringView& username) 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(); #ifndef AK_OS_MACOS endspent(); |