s3:modules: s/event_add_timed/tevent_add_timer
[Samba/gebeck_regimport.git] / testsuite / nsswitch / initgroups.c
blobb7d9c50eaa33b1bdca56548abde1377e29f51f4f
1 #include <stdio.h>
2 #include <unistd.h>
3 #include <grp.h>
4 #include <pwd.h>
5 #include <sys/types.h>
7 int main(int argc, char **argv)
9 int result, ngroups, i;
10 gid_t *groups;
11 struct passwd *pw;
13 if (!(pw = getpwnam(argv[1]))) {
14 printf("FAIL: no passwd entry for %s\n", argv[1]);
15 return 1;
18 result = initgroups(argv[1], pw->pw_gid);
20 if (result == -1) {
21 printf("FAIL");
22 return 1;
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++) {
33 struct group *grp;
35 grp = getgrgid(groups[i]);
37 printf("%d (%s)\n", groups[i], grp ? grp->gr_name : "?");
40 printf("PASS\n");
41 return 0;