]> granicus.if.org Git - sudo/commitdiff
Only do string comparisons on the group members if there is no
authorTodd C. Miller <Todd.Miller@courtesan.com>
Tue, 16 Nov 2004 23:40:58 +0000 (23:40 +0000)
committerTodd C. Miller <Todd.Miller@courtesan.com>
Tue, 16 Nov 2004 23:40:58 +0000 (23:40 +0000)
supplemental group list.

match.c

diff --git a/match.c b/match.c
index 4550b5fd80ac2a540c3c6440cc53513b0c7ff452..59dbd82c97f4c4f7a1c60d84a8a34428df09fb9a 100644 (file)
--- a/match.c
+++ b/match.c
@@ -539,17 +539,18 @@ usergr_matches(group, user, pw)
     if (grp->gr_gid == pw_gid)
        return(TRUE);
 
-    /* check the user's group vector */
-    n = user_ngroups;
-    while (n--)
-       if (grp->gr_gid == user_groups[n])
-           return(TRUE);
-
-    /* check to see if user is explicitly listed in the group */
-    /* XXX - skip if group vector is set? */
-    for (cur = grp->gr_mem; *cur; cur++) {
-       if (strcmp(*cur, user) == 0)
-           return(TRUE);
+    /*
+     * If the user has a supplementary group vector, check it.
+     * Otherwise, check the member list in struct group for the user name.
+     */
+    if ((n = user_ngroups) > 0) {
+       while (n--)
+           if (grp->gr_gid == user_groups[n])
+               return(TRUE);
+    } else {
+       for (cur = grp->gr_mem; *cur; cur++)
+           if (strcmp(*cur, user) == 0)
+               return(TRUE);
     }
 
     return(FALSE);