1 | /*
|
---|
2 | Unix SMB/Netbios implementation.
|
---|
3 | Version 1.9.
|
---|
4 | Security context tests
|
---|
5 | Copyright (C) Tim Potter 2000
|
---|
6 |
|
---|
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.
|
---|
11 |
|
---|
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.
|
---|
16 |
|
---|
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/>.
|
---|
19 | */
|
---|
20 |
|
---|
21 | #include "includes.h"
|
---|
22 | #include "sec_ctx_utils.h"
|
---|
23 |
|
---|
24 | int main (int argc, char **argv)
|
---|
25 | {
|
---|
26 | int ngroups, initial_ngroups, check_ngroups, final_ngroups;
|
---|
27 | gid_t *groups, *initial_groups, *check_groups, *final_groups;
|
---|
28 | int i;
|
---|
29 |
|
---|
30 | init_sec_ctx();
|
---|
31 |
|
---|
32 | /* Save current groups */
|
---|
33 |
|
---|
34 | initial_ngroups = sys_getgroups(0, NULL);
|
---|
35 | initial_groups = malloc(sizeof(gid_t) * initial_ngroups);
|
---|
36 | sys_getgroups(initial_ngroups, initial_groups);
|
---|
37 |
|
---|
38 | printf("Initial groups are: ");
|
---|
39 | for (i = 0; i < initial_ngroups; i++) {
|
---|
40 | printf("%d, ", initial_groups[i]);
|
---|
41 | }
|
---|
42 | printf("\n");
|
---|
43 |
|
---|
44 | /* Push a context plus groups */
|
---|
45 |
|
---|
46 | get_random_grouplist(&ngroups, &groups);
|
---|
47 |
|
---|
48 | printf("Random groups are: ");
|
---|
49 | for (i = 0; i < ngroups; i++) {
|
---|
50 | printf("%d, ", groups[i]);
|
---|
51 | }
|
---|
52 | printf("\n");
|
---|
53 |
|
---|
54 | if (!push_sec_ctx()) {
|
---|
55 | printf("FAIL: push_sec_ctx\n");
|
---|
56 | return 1;
|
---|
57 | }
|
---|
58 |
|
---|
59 | set_sec_ctx(1, 2, ngroups, groups);
|
---|
60 |
|
---|
61 | /* Check grouplist stuck */
|
---|
62 |
|
---|
63 | check_ngroups = sys_getgroups(0, NULL);
|
---|
64 | check_groups = malloc(sizeof(gid_t) * check_ngroups);
|
---|
65 | sys_getgroups(check_ngroups, check_groups);
|
---|
66 |
|
---|
67 | printf("Actual groups are: ");
|
---|
68 | for (i = 0; i < check_ngroups; i++) {
|
---|
69 | printf("%d, ", check_groups[i]);
|
---|
70 | }
|
---|
71 | printf("\n");
|
---|
72 |
|
---|
73 | if (ngroups != check_ngroups) {
|
---|
74 | printf("FAIL: number of groups differs\n");
|
---|
75 | return 1;
|
---|
76 | }
|
---|
77 |
|
---|
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;
|
---|
82 | }
|
---|
83 | }
|
---|
84 |
|
---|
85 | safe_free(groups);
|
---|
86 | safe_free(check_groups);
|
---|
87 |
|
---|
88 | /* Pop and check initial groups are back */
|
---|
89 |
|
---|
90 | if (!pop_sec_ctx()) {
|
---|
91 | printf("FAIL: pop_sec_ctx\n");
|
---|
92 | return 1;
|
---|
93 | }
|
---|
94 |
|
---|
95 | final_ngroups = sys_getgroups(0, NULL);
|
---|
96 | final_groups = malloc(sizeof(gid_t) * final_ngroups);
|
---|
97 | sys_getgroups(final_ngroups, final_groups);
|
---|
98 |
|
---|
99 | printf("Final groups are: ");
|
---|
100 | for (i = 0; i < final_ngroups; i++) {
|
---|
101 | printf("%d, ", final_groups[i]);
|
---|
102 | }
|
---|
103 | printf("\n");
|
---|
104 |
|
---|
105 | if (initial_ngroups != final_ngroups) {
|
---|
106 | printf("FAIL: final number of groups differ\n");
|
---|
107 | return 1;
|
---|
108 | }
|
---|
109 |
|
---|
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;
|
---|
114 | }
|
---|
115 | }
|
---|
116 |
|
---|
117 | printf("Final groups are: ");
|
---|
118 | for (i = 0; i < final_ngroups; i++) {
|
---|
119 | printf("%d, ", final_groups[i]);
|
---|
120 | }
|
---|
121 | printf("\n");
|
---|
122 |
|
---|
123 | safe_free(initial_groups);
|
---|
124 | safe_free(final_groups);
|
---|
125 |
|
---|
126 | /* Everything's cool */
|
---|
127 |
|
---|
128 | printf("PASS\n");
|
---|
129 | return 0;
|
---|
130 | }
|
---|