7 int main(int argc
, char **argv
)
9 int result
, ngroups
, i
;
13 if (!(pw
= getpwnam(argv
[1]))) {
14 printf("FAIL: no passwd entry for %s\n", argv
[1]);
18 result
= initgroups(argv
[1], pw
->pw_gid
);
25 ngroups
= getgroups(0, NULL
);
27 groups
= (gid_t
*)malloc(sizeof(gid_t
) * ngroups
);
28 ngroups
= getgroups(ngroups
, groups
);
30 printf("%s is a member of groups:\n", argv
[1]);
32 for (i
= 0; i
< ngroups
; i
++) {
35 grp
= getgrgid(groups
[i
]);
37 printf("%d (%s)\n", groups
[i
], grp
? grp
->gr_name
: "?");