source: branches/samba-3.3.x/testsuite/nsswitch/getgrgid.c

Last change on this file was 206, checked in by Herwig Bauernfeind, 16 years ago

Import Samba 3.3 branch at 3.0.0 level (psmedley's port)

File size: 1.1 KB
Line 
1/*
2 * Lookup a group by gid.
3 */
4
5#include <stdio.h>
6#include <grp.h>
7#include <sys/types.h>
8
9int main(int argc, char **argv)
10{
11 struct group *gr;
12 gid_t gid;
13
14 /* Check args */
15
16 if (argc != 2) {
17 printf("ERROR: no arg specified\n");
18 exit(1);
19 }
20
21 if ((gid = atoi(argv[1])) == 0) {
22 printf("ERROR: invalid gid specified\n");
23 exit(1);
24 }
25
26 /* Do getgrgid() */
27
28 if ((gr = getgrgid(gid)) == NULL) {
29 printf("FAIL: gid %d does not exist\n", gid);
30 exit(1);
31 }
32
33 /* Print group info */
34
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);
39
40 /* Group membership */
41
42 if (gr->gr_mem != NULL) {
43 int i = 0;
44
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(",");
51 }
52 }
53 printf("\n");
54 }
55
56 exit(0);
57}
Note: See TracBrowser for help on using the repository browser.