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