mirror of
https://github.com/PowerShell/openssh-portable.git
synced 2025-09-22 09:28:01 +02:00
Handle ngroups>_SC_NGROUPS_MAX.
Based on github pull request #99 from Darren Maffat at Oracle: Solaris' getgrouplist considers _SC_NGROUPS_MAX more of a guideline and can return a larger number of groups. In this case, retry getgrouplist with a larger array and defer allocating groups_byname. ok djm@
This commit is contained in:
parent
039bf2a817
commit
2678833013
@ -50,7 +50,7 @@ int
|
|||||||
ga_init(const char *user, gid_t base)
|
ga_init(const char *user, gid_t base)
|
||||||
{
|
{
|
||||||
gid_t *groups_bygid;
|
gid_t *groups_bygid;
|
||||||
int i, j;
|
int i, j, retry = 0;
|
||||||
struct group *gr;
|
struct group *gr;
|
||||||
|
|
||||||
if (ngroups > 0)
|
if (ngroups > 0)
|
||||||
@ -62,10 +62,14 @@ ga_init(const char *user, gid_t base)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
groups_bygid = xcalloc(ngroups, sizeof(*groups_bygid));
|
groups_bygid = xcalloc(ngroups, sizeof(*groups_bygid));
|
||||||
|
while (getgrouplist(user, base, groups_bygid, &ngroups) == -1) {
|
||||||
|
if (retry++ > 0)
|
||||||
|
fatal("getgrouplist: groups list too small");
|
||||||
|
groups_bygid = xreallocarray(groups_bygid, ngroups,
|
||||||
|
sizeof(*groups_bygid));
|
||||||
|
}
|
||||||
groups_byname = xcalloc(ngroups, sizeof(*groups_byname));
|
groups_byname = xcalloc(ngroups, sizeof(*groups_byname));
|
||||||
|
|
||||||
if (getgrouplist(user, base, groups_bygid, &ngroups) == -1)
|
|
||||||
logit("getgrouplist: groups list too small");
|
|
||||||
for (i = 0, j = 0; i < ngroups; i++)
|
for (i = 0, j = 0; i < ngroups; i++)
|
||||||
if ((gr = getgrgid(groups_bygid[i])) != NULL)
|
if ((gr = getgrgid(groups_bygid[i])) != NULL)
|
||||||
groups_byname[j++] = xstrdup(gr->gr_name);
|
groups_byname[j++] = xstrdup(gr->gr_name);
|
||||||
@ -124,5 +128,6 @@ ga_free(void)
|
|||||||
free(groups_byname[i]);
|
free(groups_byname[i]);
|
||||||
ngroups = 0;
|
ngroups = 0;
|
||||||
free(groups_byname);
|
free(groups_byname);
|
||||||
|
groups_byname = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user