Fjernet gruppebegrensning (allokerer GID-listen dynamisk).
This commit is contained in:
parent
33c3ba82e2
commit
63d34a6e15
16
common.c
16
common.c
@ -204,20 +204,28 @@ member(char *gr) {
|
||||
char **get_group_names(int *numgroups)
|
||||
{
|
||||
char **grouplist;
|
||||
gid_t gids[33];
|
||||
gid_t *gids = NULL;
|
||||
int real_nr_groups, nr_groups, i;
|
||||
struct group *g;
|
||||
|
||||
nr_groups = 0;
|
||||
|
||||
nr_groups = getgroups(32, &gids[0]); /* Allow a max of 32 groups */
|
||||
/* Find number and allocate */
|
||||
nr_groups = getgroups(0, NULL);
|
||||
if (nr_groups == -1) {
|
||||
dberror(NULL, "Error while trying to find group count");
|
||||
return NULL;
|
||||
}
|
||||
gids = malloc(nr_groups*sizeof(gid_t));
|
||||
|
||||
/* Fetch group IDs */
|
||||
nr_groups = getgroups(nr_groups, gids);
|
||||
if (nr_groups == -1) {
|
||||
dberror(NULL, "Error while trying to fetch group info");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
grouplist = malloc(33 * sizeof(char *));
|
||||
grouplist = malloc((nr_groups + 1)*sizeof(char *));
|
||||
real_nr_groups = 0;
|
||||
|
||||
for (i = 0; i < nr_groups; i++) {
|
||||
@ -232,6 +240,8 @@ char **get_group_names(int *numgroups)
|
||||
}
|
||||
grouplist[real_nr_groups] = NULL;
|
||||
|
||||
free(gids);
|
||||
|
||||
*numgroups = real_nr_groups;
|
||||
|
||||
return grouplist;
|
||||
|
Loading…
Reference in New Issue
Block a user