From a3cb22b4674b000a2833d29da730933824b1539e Mon Sep 17 00:00:00 2001 From: "Todd C. Miller" Date: Fri, 26 Oct 2018 10:24:38 -0600 Subject: [PATCH] Check the user's primary gid from the passwd file too. --- lib/util/regress/getgrouplist/getgrouplist_test.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/util/regress/getgrouplist/getgrouplist_test.c b/lib/util/regress/getgrouplist/getgrouplist_test.c index 02edabdfa..a88d80b13 100644 --- a/lib/util/regress/getgrouplist/getgrouplist_test.c +++ b/lib/util/regress/getgrouplist/getgrouplist_test.c @@ -52,14 +52,16 @@ main(int argc, char *argv[]) char *username; int i, j, errors = 0, ntests = 0; int ngroups; + gid_t basegid; initprogname(argc > 0 ? argv[0] : "getgrouplist_test"); if ((pw = getpwuid(0)) == NULL) sudo_fatal_nodebug("getpwuid(0)"); + basegid = pw->pw_gid; if ((username = strdup(pw->pw_name)) == NULL) sudo_fatal_nodebug(NULL); - if (sudo_getgrouplist2(pw->pw_name, pw->pw_gid, &groups, &ngroups) == -1) + if (sudo_getgrouplist2(username, basegid, &groups, &ngroups) == -1) sudo_fatal_nodebug("sudo_getgroulist2"); for (i = 0; i < ngroups; i++) { @@ -73,6 +75,10 @@ main(int argc, char *argv[]) continue; } + /* Check user's primary gid from the passwd file. */ + if (grp->gr_gid == basegid) + continue; + /* Verify group membership. */ for (j = 0; grp->gr_mem[j] != NULL; j++) { if (strcmp(username, grp->gr_mem[j]) == 0) { -- 2.50.1