preparing for release of 2.2.1
[Samba.git] / testsuite / nsswitch / getent_grent.c
blob782cc0c86b79392d672a8e9a9350b5cbd05bb2dd
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 2 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, write to the Free Software
21 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 #include <stdio.h>
25 #include <grp.h>
27 int main (int argc, char **argv)
29 struct group *gr;
30 int found = 0;
31 int num_users, i;
33 /* Test getgrent() without setgrent() */
35 for (i = 0; i < 100; i++) {
36 gr = getgrent();
38 /* This is supposed to work */
40 #if 0
41 if (gr != NULL) {
42 printf("FAIL: getgrent() with no setgrent()\n");
43 return 1;
45 #endif
48 /* Work out how many user till first domain group */
50 num_users = 0;
51 setgrent();
53 while (1) {
54 gr = getgrent();
55 num_users++;
57 if (gr == NULL) break;
59 if (strchr(gr->gr_name, '/')) {
60 found = 1;
61 break;
66 if (!found) {
67 printf("FAIL: could not find any domain groups\n");
68 return 1;
71 /* Test stopping getgrent in the middle of a set of users */
73 endgrent();
75 /* Test setgrent() without any getgrent() calls */
77 setgrent();
79 for (i = 0; i < (num_users - 1); i++) {
80 getgrent();
83 endgrent();
85 /* Test lots of setgrent() calls */
87 for (i = 0; i < 100; i++) {
88 setgrent();
91 /* Test lots of endgrent() calls */
93 for (i = 0; i < 100; i++) {
94 endgrent();
97 /* Everything's cool */
99 printf("PASS\n");
100 return 0;