2 Unix SMB/Netbios implementation.
5 Copyright (C) Tim Potter 2000
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #include "sec_ctx_utils.h"
24 int main (int argc
, char **argv
)
26 int ngroups
, initial_ngroups
, check_ngroups
, final_ngroups
;
27 gid_t
*groups
, *initial_groups
, *check_groups
, *final_groups
;
32 /* Save current groups */
34 initial_ngroups
= sys_getgroups(0, NULL
);
35 initial_groups
= malloc(sizeof(gid_t
) * initial_ngroups
);
36 sys_getgroups(initial_ngroups
, initial_groups
);
38 printf("Initial groups are: ");
39 for (i
= 0; i
< initial_ngroups
; i
++) {
40 printf("%d, ", initial_groups
[i
]);
44 /* Push a context plus groups */
46 get_random_grouplist(&ngroups
, &groups
);
48 printf("Random groups are: ");
49 for (i
= 0; i
< ngroups
; i
++) {
50 printf("%d, ", groups
[i
]);
54 if (!push_sec_ctx()) {
55 printf("FAIL: push_sec_ctx\n");
59 set_sec_ctx(1, 2, ngroups
, groups
);
61 /* Check grouplist stuck */
63 check_ngroups
= sys_getgroups(0, NULL
);
64 check_groups
= malloc(sizeof(gid_t
) * check_ngroups
);
65 sys_getgroups(check_ngroups
, check_groups
);
67 printf("Actual groups are: ");
68 for (i
= 0; i
< check_ngroups
; i
++) {
69 printf("%d, ", check_groups
[i
]);
73 if (ngroups
!= check_ngroups
) {
74 printf("FAIL: number of groups differs\n");
78 for (i
= 0; i
< ngroups
; i
++) {
79 if (groups
[i
] != check_groups
[i
]) {
80 printf("FAIL: group %d differs\n", i
);
86 safe_free(check_groups
);
88 /* Pop and check initial groups are back */
91 printf("FAIL: pop_sec_ctx\n");
95 final_ngroups
= sys_getgroups(0, NULL
);
96 final_groups
= malloc(sizeof(gid_t
) * final_ngroups
);
97 sys_getgroups(final_ngroups
, final_groups
);
99 printf("Final groups are: ");
100 for (i
= 0; i
< final_ngroups
; i
++) {
101 printf("%d, ", final_groups
[i
]);
105 if (initial_ngroups
!= final_ngroups
) {
106 printf("FAIL: final number of groups differ\n");
110 for (i
= 0; i
< initial_ngroups
; i
++) {
111 if (initial_groups
[i
] != final_groups
[i
]) {
112 printf("FAIL: final group %d differs\n", i
);
117 printf("Final groups are: ");
118 for (i
= 0; i
< final_ngroups
; i
++) {
119 printf("%d, ", final_groups
[i
]);
123 safe_free(initial_groups
);
124 safe_free(final_groups
);
126 /* Everything's cool */