aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2022-11-22 09:03:30 +0100
committerEelco Dolstra <edolstra@gmail.com>2022-11-22 10:26:17 +0100
commit3d23b9d0324ff415af9e5f35568aca98c04a90cc (patch)
treeb0d2ef51637ce5957a5b850dc8c98b36b8c2e724 /src
parentb37c2d84b67635fc928ed174166f04d6f4d30c6b (diff)
SimpleUserLock::getSupplementaryGIDs(): Filter out main gid
This avoids having the user's gid in the supplementary group list as well.
Diffstat (limited to 'src')
-rw-r--r--src/libstore/lock.cc13
1 files changed, 8 insertions, 5 deletions
diff --git a/src/libstore/lock.cc b/src/libstore/lock.cc
index 3b93979a8..7459d837d 100644
--- a/src/libstore/lock.cc
+++ b/src/libstore/lock.cc
@@ -71,21 +71,22 @@ struct SimpleUserLock : UserLock
user. This is usually either empty or contains a
group such as "kvm". */
int ngroups = 32; // arbitrary initial guess
- lock->supplementaryGIDs.resize(ngroups);
+ std::vector<gid_t> gids;
+ gids.resize(ngroups);
int err = getgrouplist(
pw->pw_name, pw->pw_gid,
- lock->supplementaryGIDs.data(),
+ gids.data(),
&ngroups);
/* Our initial size of 32 wasn't sufficient, the
correct size has been stored in ngroups, so we try
again. */
if (err == -1) {
- lock->supplementaryGIDs.resize(ngroups);
+ gids.resize(ngroups);
err = getgrouplist(
pw->pw_name, pw->pw_gid,
- lock->supplementaryGIDs.data(),
+ gids.data(),
&ngroups);
}
@@ -94,7 +95,9 @@ struct SimpleUserLock : UserLock
throw Error("failed to get list of supplementary groups for '%s'", pw->pw_name);
// Finally, trim back the GID list to its real size.
- lock->supplementaryGIDs.resize(ngroups);
+ for (auto i = 0; i < ngroups; i++)
+ if (gids[i] != lock->gid)
+ lock->supplementaryGIDs.push_back(gids[i]);
#endif
return lock;