Instead of keeping separate groups and gids arrays, create struct
group_info and use it to store both, along with a count for each. Cache group info on a per-user basis using getgrouplist() to get the groups. We no longer need special to special case the user or list user for user_in_group() and thus no longer need to reset the groups list when listing another user.
This commit is contained in:
@@ -343,7 +343,6 @@ static char *
|
||||
get_user_groups(struct user_details *ud)
|
||||
{
|
||||
char *gid_list = NULL;
|
||||
#ifdef HAVE_GETGROUPS
|
||||
size_t glsize;
|
||||
char *cp;
|
||||
int i, len;
|
||||
@@ -364,7 +363,6 @@ get_user_groups(struct user_details *ud)
|
||||
i ? "," : "", (unsigned int)ud->groups[i]);
|
||||
cp += len;
|
||||
}
|
||||
#endif
|
||||
return gid_list;
|
||||
}
|
||||
|
||||
@@ -929,19 +927,12 @@ exec_setup(struct command_details *details, const char *ptyname, int ptyfd)
|
||||
}
|
||||
|
||||
if (!ISSET(details->flags, CD_PRESERVE_GROUPS)) {
|
||||
#ifdef HAVE_GETGROUPS
|
||||
if (details->ngroups >= 0) {
|
||||
if (setgroups(details->ngroups, details->groups) < 0) {
|
||||
warning(_("unable to set supplementary group IDs"));
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
#else
|
||||
if (pw && initgroups(pw->pw_name, pw->pw_gid) < 0) {
|
||||
warning(_("unable to set supplementary group IDs"));
|
||||
goto done;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
if (ISSET(details->flags, CD_SET_PRIORITY)) {
|
||||
|
Reference in New Issue
Block a user