s3:modules: s/struct timed_event/struct tevent_timer
[Samba/gebeck_regimport.git] / testsuite / nsswitch / getgrgid.c
blob947dd0ac4c78fe8e074078e23de88c9e4b0774ac
1 /*
2 * Lookup a group by gid.
3 */
5 #include <stdio.h>
6 #include <grp.h>
7 #include <sys/types.h>
9 int main(int argc, char **argv)
11 struct group *gr;
12 gid_t gid;
14 /* Check args */
16 if (argc != 2) {
17 printf("ERROR: no arg specified\n");
18 exit(1);
21 if ((gid = atoi(argv[1])) == 0) {
22 printf("ERROR: invalid gid specified\n");
23 exit(1);
26 /* Do getgrgid() */
28 if ((gr = getgrgid(gid)) == NULL) {
29 printf("FAIL: gid %d does not exist\n", gid);
30 exit(1);
33 /* Print group info */
35 printf("PASS: gid %d exists\n", gid);
36 printf("gr_name = %s\n", gr->gr_name);
37 printf("gr_passwd = %s\n", gr->gr_passwd);
38 printf("gr_gid = %d\n", gr->gr_gid);
40 /* Group membership */
42 if (gr->gr_mem != NULL) {
43 int i = 0;
45 printf("gr_mem = ");
46 while(gr->gr_mem[i] != NULL) {
47 printf("%s", gr->gr_mem[i]);
48 i++;
49 if (gr->gr_mem != NULL) {
50 printf(",");
53 printf("\n");
56 exit(0);