user_in_group: the user's group vector already includes the primary group.

There's no need to look up the name of user's primary group (pw_gid),
we always include the primary group ID in the group vector.
This commit is contained in:
Todd C. Miller
2023-08-30 13:36:41 -06:00
parent 05f823df22
commit f5b3f99098

View File

@@ -1177,21 +1177,13 @@ user_in_group(const struct passwd *pw, const char *group)
else else
compare = strcmp; compare = strcmp;
/* Check the supplementary group vector. */ /* Check the user's group vector, which includes the primary group. */
for (i = 0; i < grlist->ngroups; i++) { for (i = 0; i < grlist->ngroups; i++) {
if (compare(group, grlist->groups[i]) == 0) { if (compare(group, grlist->groups[i]) == 0) {
matched = true; matched = true;
goto done; goto done;
} }
} }
/* Check against user's primary (passwd file) group. */
if ((grp = sudo_getgrgid(pw->pw_gid)) != NULL) {
if (compare(group, grp->gr_name) == 0) {
matched = true;
goto done;
}
}
} }
done: done: