blob: d644cced89d5c3ac23f57bb63402bb10a758fc43 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
#include <grp.h>
#include "pw_defs.h"
int nv_getgrouplist(const char*user, gid_t group, gid_t*groups, int*ngroups) /*EXTRACT_INCL*/ {
long n=0,size=*ngroups;
struct group*g;
int ret=0;
if (0<size) { groups[n++]=group; }
else { *ngroups=0; return (-1); }
nv_setgrent();
while ((g=nv_getgrent())) {
char **duh;
if (g->gr_gid==group) continue;
duh=g->gr_mem;
while (*duh) {
if (!str_diff(*duh,user)) {
if (n>=size) {
ret=~ret;
goto err_out;
}
groups[n++]=g->gr_gid;
break;
}
duh++;
}
}
err_out:
nv_endgrent();
*ngroups=n;
return ret;
}
|