~zulcss/samba/server-dailies-3.4

« back to all changes in this revision

Viewing changes to testsuite/nsswitch/getgrnam.c

  • Committer: Chuck Short
  • Date: 2010-09-28 20:38:39 UTC
  • Revision ID: zulcss@ubuntu.com-20100928203839-pgjulytsi9ue63x1
Initial version

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Lookup a group by name
 
3
 */
 
4
 
 
5
#include <stdio.h>
 
6
#include <grp.h>
 
7
#include <sys/types.h>
 
8
 
 
9
int 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
}