account_pol: use dbwrap_trans_store_uint32()
[Samba/bb.git] / testsuite / smbd / sec_ctx_groups.c
blob63109634278351f7368cdaf5159d61bf90b856c9
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 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/>.
21 #include "includes.h"
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;
28 int i;
30 init_sec_ctx();
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]);
42 printf("\n");
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]);
52 printf("\n");
54 if (!push_sec_ctx()) {
55 printf("FAIL: push_sec_ctx\n");
56 return 1;
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]);
71 printf("\n");
73 if (ngroups != check_ngroups) {
74 printf("FAIL: number of groups differs\n");
75 return 1;
78 for (i = 0; i < ngroups; i++) {
79 if (groups[i] != check_groups[i]) {
80 printf("FAIL: group %d differs\n", i);
81 return 1;
85 safe_free(groups);
86 safe_free(check_groups);
88 /* Pop and check initial groups are back */
90 if (!pop_sec_ctx()) {
91 printf("FAIL: pop_sec_ctx\n");
92 return 1;
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]);
103 printf("\n");
105 if (initial_ngroups != final_ngroups) {
106 printf("FAIL: final number of groups differ\n");
107 return 1;
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);
113 return 1;
117 printf("Final groups are: ");
118 for (i = 0; i < final_ngroups; i++) {
119 printf("%d, ", final_groups[i]);
121 printf("\n");
123 safe_free(initial_groups);
124 safe_free(final_groups);
126 /* Everything's cool */
128 printf("PASS\n");
129 return 0;