source: branches/samba-3.3.x/testsuite/nsswitch/getgrnam.c@ 206

Last change on this file since 206 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: 972 bytes
Line 
1/*
2 * Lookup a group by name
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
13 /* Check args */
14
15 if (argc != 2) {
16 printf("ERROR: no arg specified\n");
17 exit(1);
18 }
19
20 /* Do getgrnam() */
21
22 if ((gr = getgrnam(argv[1])) == NULL) {
23 printf("FAIL: group %s does not exist\n", argv[1]);
24 exit(1);
25 }
26
27 /* Print group info */
28
29 printf("PASS: group %s exists\n", argv[1]);
30 printf("gr_name = %s\n", gr->gr_name);
31 printf("gr_passwd = %s\n", gr->gr_passwd);
32 printf("gr_gid = %d\n", gr->gr_gid);
33
34 /* Group membership */
35
36 if (gr->gr_mem != NULL) {
37 int i = 0;
38
39 printf("gr_mem = ");
40 while(gr->gr_mem[i] != NULL) {
41 printf("%s", gr->gr_mem[i]);
42 i++;
43 if (gr->gr_mem != NULL) {
44 printf(",");
45 }
46 }
47 printf("\n");
48 }
49
50 exit(0);
51}
Note: See TracBrowser for help on using the repository browser.