r23785: use the GPLv3 boilerplate as recommended by the FSF and the license text
[Samba/bb.git] / testsuite / nsswitch / getent_grent.c
blob4660b6a53d4ece864b53119b0d993b9b275f099c
1 /* Test out of order operations with {set,get,end}grent */
3 /*
4 Unix SMB/Netbios implementation.
5 Version 1.9.
6 Security context tests
7 Copyright (C) Tim Potter 2000
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #include <stdio.h>
24 #include <grp.h>
26 int main (int argc, char **argv)
28 struct group *gr;
29 int found = 0;
30 int num_users, i;
32 /* Test getgrent() without setgrent() */
34 for (i = 0; i < 100; i++) {
35 gr = getgrent();
37 /* This is supposed to work */
39 #if 0
40 if (gr != NULL) {
41 printf("FAIL: getgrent() with no setgrent()\n");
42 return 1;
44 #endif
47 /* Work out how many user till first domain group */
49 num_users = 0;
50 setgrent();
52 while (1) {
53 gr = getgrent();
54 num_users++;
56 if (gr == NULL) break;
58 if (strchr(gr->gr_name, '/')) {
59 found = 1;
60 break;
65 if (!found) {
66 printf("FAIL: could not find any domain groups\n");
67 return 1;
70 /* Test stopping getgrent in the middle of a set of users */
72 endgrent();
74 /* Test setgrent() without any getgrent() calls */
76 setgrent();
78 for (i = 0; i < (num_users - 1); i++) {
79 getgrent();
82 endgrent();
84 /* Test lots of setgrent() calls */
86 for (i = 0; i < 100; i++) {
87 setgrent();
90 /* Test lots of endgrent() calls */
92 for (i = 0; i < 100; i++) {
93 endgrent();
96 /* Everything's cool */
98 printf("PASS\n");
99 return 0;