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 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.
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;
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]);
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]);
55
if (!push_sec_ctx()) {
56
printf("FAIL: push_sec_ctx\n");
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]);
74
if (ngroups != check_ngroups) {
75
printf("FAIL: number of groups differs\n");
79
for (i = 0; i < ngroups; i++) {
80
if (groups[i] != check_groups[i]) {
81
printf("FAIL: group %d differs\n", i);
87
safe_free(check_groups);
89
/* Pop and check initial groups are back */
92
printf("FAIL: pop_sec_ctx\n");
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]);
106
if (initial_ngroups != final_ngroups) {
107
printf("FAIL: final number of groups differ\n");
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);
118
printf("Final groups are: ");
119
for (i = 0; i < final_ngroups; i++) {
120
printf("%d, ", final_groups[i]);
124
safe_free(initial_groups);
125
safe_free(final_groups);
127
/* Everything's cool */