On Thu, Jan 23, 2020 at 11:42:59AM +0000, Daniel P. Berrangé wrote: > The mgetgroups function is a GNULIB custom wrapper around > getgrouplist(). This implements a simplified version of > that code directly. > > Signed-off-by: Daniel P. Berrangé <berra...@redhat.com> > --- > src/internal.h | 4 ++++ > src/util/virutil.c | 34 ++++++++++++++++++++++++++++------ > 2 files changed, 32 insertions(+), 6 deletions(-) > > diff --git a/src/util/virutil.c b/src/util/virutil.c > index 87ca16c088..4bc0aef35f 100644 > --- a/src/util/virutil.c > +++ b/src/util/virutil.c > @@ -1000,11 +1004,27 @@ virGetGroupList(uid_t uid, gid_t gid, gid_t **list) > /* invalid users have no supplementary groups */ > if (uid != (uid_t)-1 && > virGetUserEnt(uid, &user, &primary, NULL, NULL, true) >= 0) { > - if ((ret = mgetgroups(user, primary, list)) < 0) { > - virReportSystemError(errno, > - _("cannot get group list for '%s'"), user); > - ret = -1; > - goto cleanup; > + int nallocgrps = 10; > + gid_t *grps = g_new(gid_t, nallocgrps);
This is never used anywhere except in the while loop. > + while (1) { > + int nprevallocgrps = nallocgrps; > + int rv; > + > + rv = getgrouplist(user, primary, grps, &nallocgrps); > + > + /* Some systems (like Darwin) have a bug where they > + never increase max_n_groups. */ > + if (rv < 0 && nprevallocgrps == nallocgrps) > + nallocgrps *= 2; > + > + /* either shrinks to actual size, or enlarges tonew size */ s/tonew/to new/ > + grps = g_renew(gid_t, grps, nallocgrps); > + > + if (rv >= 0) { > + ret = rv; > + break; Based on the GNULIB implementation here we should set *list = grps. With that fixed: Reviewed-by: Pavel Hrdina <phrd...@redhat.com>
signature.asc
Description: PGP signature