mirror of
https://git.musl-libc.org/git/musl
synced 2025-01-27 08:29:27 +03:00
implement getgrouplist (for initgroups), formerly dummied-out
This commit is contained in:
parent
3f44f298e4
commit
91e836fda7
@ -1,11 +1,23 @@
|
|||||||
#include <grp.h>
|
#include <grp.h>
|
||||||
|
#include <string.h>
|
||||||
/* FIXME */
|
#include <limits.h>
|
||||||
|
|
||||||
int getgrouplist(const char *user, gid_t gid, gid_t *groups, int *ngroups)
|
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;
|
if (*ngroups<1) return -1;
|
||||||
*groups = gid;
|
n = *ngroups;
|
||||||
|
*groups++ = gid;
|
||||||
*ngroups = 1;
|
*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;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user