Fix some uncleanness with testsmbc.c
[Samba/gebeck_regimport.git] / testsuite / smbd / sec_ctx_groups.c
blob61d77f6f4f0f0e35f386ab8997b29296b4a7e1a7
1 /*
2 Unix SMB/Netbios implementation.
3 Version 1.9.
4 Security context tests
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 2 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, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #include "includes.h"
23 #include "sec_ctx_utils.h"
25 int main (int argc, char **argv)
27 int ngroups, initial_ngroups, check_ngroups, final_ngroups;
28 gid_t *groups, *initial_groups, *check_groups, *final_groups;
29 int i;
31 init_sec_ctx();
33 /* Save current groups */
35 initial_ngroups = sys_getgroups(0, NULL);
36 initial_groups = malloc(sizeof(gid_t) * initial_ngroups);
37 sys_getgroups(initial_ngroups, initial_groups);
39 printf("Initial groups are: ");
40 for (i = 0; i < initial_ngroups; i++) {
41 printf("%d, ", initial_groups[i]);
43 printf("\n");
45 /* Push a context plus groups */
47 get_random_grouplist(&ngroups, &groups);
49 printf("Random groups are: ");
50 for (i = 0; i < ngroups; i++) {
51 printf("%d, ", groups[i]);
53 printf("\n");
55 if (!push_sec_ctx()) {
56 printf("FAIL: push_sec_ctx\n");
57 return 1;
60 set_sec_ctx(1, 2, ngroups, groups);
62 /* Check grouplist stuck */
64 check_ngroups = sys_getgroups(0, NULL);
65 check_groups = malloc(sizeof(gid_t) * check_ngroups);
66 sys_getgroups(check_ngroups, check_groups);
68 printf("Actual groups are: ");
69 for (i = 0; i < check_ngroups; i++) {
70 printf("%d, ", check_groups[i]);
72 printf("\n");
74 if (ngroups != check_ngroups) {
75 printf("FAIL: number of groups differs\n");
76 return 1;
79 for (i = 0; i < ngroups; i++) {
80 if (groups[i] != check_groups[i]) {
81 printf("FAIL: group %d differs\n", i);
82 return 1;
86 safe_free(groups);
87 safe_free(check_groups);
89 /* Pop and check initial groups are back */
91 if (!pop_sec_ctx()) {
92 printf("FAIL: pop_sec_ctx\n");
93 return 1;
96 final_ngroups = sys_getgroups(0, NULL);
97 final_groups = malloc(sizeof(gid_t) * final_ngroups);
98 sys_getgroups(final_ngroups, final_groups);
100 printf("Final groups are: ");
101 for (i = 0; i < final_ngroups; i++) {
102 printf("%d, ", final_groups[i]);
104 printf("\n");
106 if (initial_ngroups != final_ngroups) {
107 printf("FAIL: final number of groups differ\n");
108 return 1;
111 for (i = 0; i < initial_ngroups; i++) {
112 if (initial_groups[i] != final_groups[i]) {
113 printf("FAIL: final group %d differs\n", i);
114 return 1;
118 printf("Final groups are: ");
119 for (i = 0; i < final_ngroups; i++) {
120 printf("%d, ", final_groups[i]);
122 printf("\n");
124 safe_free(initial_groups);
125 safe_free(final_groups);
127 /* Everything's cool */
129 printf("PASS\n");
130 return 0;