1 /*
2 * test_grp.c - This file is part of the libc-8086/grp package for ELKS,
3 * Copyright (C) 1995, 1996 Nat Friedman <ndf@linux.mit.edu>.
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
14 *
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library; if not, write to the Free
17 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 *
19 */
20
21 #include <unistd.h>
22 #include <stdio.h>
23 #include <fcntl.h>
24 #include <grp.h>
25
26 int
main(int argc,char ** argv)27 main(int argc, char ** argv)
28 {
29 struct group * group;
30 char ** tmp_mem;
31 int test_gid;
32
33 fprintf(stderr, "Beginning test of libc/grp...\n");
34
35 fprintf(stderr, "=> Testing setgrent(), getgrent(), endgrent()...\n");
36 fprintf(stderr, "-> setgrent()...\n");
37 setgrent();
38 fprintf(stderr, "-> getgrent()...\n");
39 printf("********************************************************************************\n");
40 while ((group=getgrent())!=NULL)
41 {
42 printf("gr_name\t\t: %s\n", group->gr_name);
43 printf("gr_passwd\t: %s\n", group->gr_passwd);
44 printf("gr_gid\t\t: %d\n", (int) group->gr_gid);
45 printf("gr_mem\t\t: ");
46 fflush(stdout);
47 tmp_mem=group->gr_mem;
48 while(*tmp_mem!=NULL)
49 {
50 printf("%s, ", *tmp_mem);
51 tmp_mem++;
52 }
53 printf("\n********************************************************************************\n");
54 }
55 fprintf(stderr, "-> endgrent()...\n");
56 endgrent();
57 fprintf(stderr, "=> Test of setgrent(), getgrent(), endgrent() complete.\n");
58 fprintf(stderr, "=> Testing getgrid(), getgrnam()...\n");
59 fprintf(stderr, "-> getgrgid()...\n");
60 printf("********************************************************************************\n");
61 for(test_gid=0;test_gid<100;test_gid++)
62 {
63 fprintf(stderr, "-> getgrgid(%d)...\n", test_gid);
64 group=getgrgid((gid_t) test_gid);
65 if (group!=NULL)
66 {
67 printf("gr_name\t: %s\n", group->gr_name);
68 printf("gr_passwd\t: %s\n", group->gr_passwd);
69 printf("gr_gid\t: %d\n", (int) group->gr_gid);
70 printf("gr_mem\t\t: ");
71 fflush(stdout);
72 tmp_mem=group->gr_mem;
73 while(*tmp_mem!=NULL)
74 {
75 printf("%s, ", *tmp_mem);
76 tmp_mem++;
77 }
78 }
79 printf("\n********************************************************************************\n");
80 }
81 fprintf(stderr, "-> getgrnam()...\n");
82 group=getgrnam("root");
83 if (group==NULL)
84 {
85 printf(">NULL<\n");
86 }
87 else
88 {
89 printf("gr_name\t: %s\n", group->gr_name);
90 printf("gr_passwd\t: %s\n", group->gr_passwd);
91 printf("gr_gid\t: %d\n", (int) group->gr_gid);
92 printf("gr_mem\t\t: ");
93 fflush(stdout);
94 tmp_mem=group->gr_mem;
95 while(*tmp_mem!=NULL)
96 {
97 printf("%s, ", *tmp_mem);
98 tmp_mem++;
99 }
100 printf("\n");
101 }
102
103
104 return 0;
105 }
106
107
108