logo

utils-std

Collection of commonly available Unix tools
commit: 0e443fbe5c17bc13110e2ef07f649c52d47ece02
parent 8fb74af81e0cb41388447a8ec5a3a34cb61c2702
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Wed, 10 Jul 2024 02:38:58 +0200

cmd/id: print basegid only once

As seen in FreeBSD where getgrouplist(3) always start with basegid *and* then
supplemental groups without deduplication.

Diffstat:

Mcmd/id.c22++++++++++++++++++++++
1 file changed, 22 insertions(+), 0 deletions(-)

diff --git a/cmd/id.c b/cmd/id.c @@ -16,8 +16,19 @@ bool name_flag = false; static int simple_list_groups(struct passwd *pw, int ngroups, gid_t *groups) { + // Don't print basegid twice when present in pw and grouplist + bool basegid_done = false; + for(int i = 0; i < ngroups; i++) { + if(groups[i] == pw->pw_gid) + { + if(basegid_done) + continue; + else + basegid_done = true; + } + if(name_flag) { struct group *lgr = getgrgid(groups[i]); @@ -45,12 +56,23 @@ simple_list_groups(struct passwd *pw, int ngroups, gid_t *groups) static int list_groups(struct passwd *pw, int ngroups, gid_t *groups) { + // Don't print basegid twice when present in pw and grouplist + bool basegid_done = false; + printf(" groups="); for(int i = 0; i < ngroups; i++) { struct group *lgr = getgrgid(groups[i]); + if(groups[i] == pw->pw_gid) + { + if(basegid_done) + continue; + else + basegid_done = true; + } + if(name_flag) { if(lgr == NULL) return 1;