]> granicus.if.org Git - sudo/commitdiff
Check the user's primary gid from the passwd file too.
authorTodd C. Miller <Todd.Miller@sudo.ws>
Fri, 26 Oct 2018 16:24:38 +0000 (10:24 -0600)
committerTodd C. Miller <Todd.Miller@sudo.ws>
Fri, 26 Oct 2018 16:24:38 +0000 (10:24 -0600)
lib/util/regress/getgrouplist/getgrouplist_test.c

index 02edabdfa060be25826dfe45c70e9b7b70f2047c..a88d80b13e11ad51455e36b6962ad976879243c4 100644 (file)
@@ -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) {