1 | /* Test out of order operations with {set,get,end}pwent */
|
---|
2 |
|
---|
3 | /*
|
---|
4 | Unix SMB/Netbios implementation.
|
---|
5 | Version 1.9.
|
---|
6 | Security context tests
|
---|
7 | Copyright (C) Tim Potter 2000
|
---|
8 |
|
---|
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.
|
---|
13 |
|
---|
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.
|
---|
18 |
|
---|
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/>.
|
---|
21 | */
|
---|
22 |
|
---|
23 | #include <stdio.h>
|
---|
24 | #include <pwd.h>
|
---|
25 |
|
---|
26 | int main (int argc, char **argv)
|
---|
27 | {
|
---|
28 | struct passwd *pw;
|
---|
29 | int found = 0;
|
---|
30 | int num_users, i;
|
---|
31 |
|
---|
32 | /* Test getpwent() without setpwent() */
|
---|
33 |
|
---|
34 | for (i = 0; i < 100; i++) {
|
---|
35 | pw = getpwent();
|
---|
36 |
|
---|
37 | /* This is supposed to work */
|
---|
38 |
|
---|
39 | #if 0
|
---|
40 | if (pw != NULL) {
|
---|
41 | printf("FAIL: getpwent() with no setpwent()\n");
|
---|
42 | return 1;
|
---|
43 | }
|
---|
44 | #endif
|
---|
45 | }
|
---|
46 |
|
---|
47 | /* Work out how many user till first domain user */
|
---|
48 |
|
---|
49 | num_users = 0;
|
---|
50 | setpwent();
|
---|
51 |
|
---|
52 | while (1) {
|
---|
53 | pw = getpwent();
|
---|
54 | num_users++;
|
---|
55 |
|
---|
56 | if (pw == NULL) break;
|
---|
57 |
|
---|
58 | if (strchr(pw->pw_name, '/')) {
|
---|
59 | found = 1;
|
---|
60 | break;
|
---|
61 | }
|
---|
62 |
|
---|
63 | }
|
---|
64 |
|
---|
65 | if (!found) {
|
---|
66 | printf("FAIL: could not find any domain users\n");
|
---|
67 | return 1;
|
---|
68 | }
|
---|
69 |
|
---|
70 | /* Test stopping getpwent in the middle of a set of users */
|
---|
71 |
|
---|
72 | endpwent();
|
---|
73 |
|
---|
74 | /* Test setpwent() without any getpwent() calls */
|
---|
75 |
|
---|
76 | setpwent();
|
---|
77 |
|
---|
78 | for (i = 0; i < (num_users - 1); i++) {
|
---|
79 | getpwent();
|
---|
80 | }
|
---|
81 |
|
---|
82 | endpwent();
|
---|
83 |
|
---|
84 | /* Test lots of setpwent() calls */
|
---|
85 |
|
---|
86 | setpwent();
|
---|
87 |
|
---|
88 | for (i = 0; i < (num_users - 1); i++) {
|
---|
89 | getpwent();
|
---|
90 | }
|
---|
91 |
|
---|
92 | for (i = 0; i < 100; i++) {
|
---|
93 | setpwent();
|
---|
94 | }
|
---|
95 |
|
---|
96 | /* Test lots of endpwent() calls */
|
---|
97 |
|
---|
98 | setpwent();
|
---|
99 |
|
---|
100 | for (i = 0; i < (num_users - 1); i++) {
|
---|
101 | getpwent();
|
---|
102 | }
|
---|
103 |
|
---|
104 | for (i = 0; i < 100; i++) {
|
---|
105 | endpwent();
|
---|
106 | }
|
---|
107 |
|
---|
108 | /* Everything's cool */
|
---|
109 |
|
---|
110 | printf("PASS\n");
|
---|
111 | return 0;
|
---|
112 | }
|
---|