From: Rich Felker Date: Wed, 13 Apr 2011 13:39:47 +0000 (-0400) Subject: implement getgrouplist (for initgroups), formerly dummied-out X-Git-Tag: v0.7.8 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=91e836fda7d4e2a4ba38d5faec6e3876b1b5e179;p=oweals%2Fmusl.git implement getgrouplist (for initgroups), formerly dummied-out --- diff --git a/src/misc/getgrouplist.c b/src/misc/getgrouplist.c index 88f273d7..63557afe 100644 --- a/src/misc/getgrouplist.c +++ b/src/misc/getgrouplist.c @@ -1,11 +1,23 @@ #include - -/* FIXME */ +#include +#include int getgrouplist(const char *user, gid_t gid, gid_t *groups, int *ngroups) { + size_t n, i; + struct group *gr; if (*ngroups<1) return -1; - *groups = gid; + n = *ngroups; + *groups++ = gid; *ngroups = 1; - return 0; + + setgrent(); + while ((gr = getgrent()) && *ngroups < INT_MAX) { + for (i=0; gr->gr_mem[i] && strcmp(user, gr->gr_mem[i]); i++); + if (!gr->gr_mem[i]) continue; + if (++*ngroups <= n) *groups++ = gr->gr_gid; + } + endgrent(); + + return *ngroups > n ? -1 : *ngroups; }