s3:modules: s/struct timed_event/struct tevent_timer
[Samba/gebeck_regimport.git] / testsuite / smbd / sec_ctx_current_user.c
blob6361b16da92fa28c2c1597de8e3f9985fbc10568
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 extern struct current_user current_user;
27 uid_t initial_uid = current_user.uid;
28 gid_t initial_gid = current_user.gid;
29 int ngroups;
30 gid_t *groups;
32 init_sec_ctx();
34 /* Check initial id */
36 if (initial_uid != 0 || initial_gid != 0) {
37 printf("FAIL: current_user not initialised to root\n");
38 return 1;
41 /* Push a context and check current user is updated */
43 if (!push_sec_ctx()) {
44 printf("FAIL: push_sec_ctx\n");
45 return 1;
48 set_sec_ctx(1, 2, 0, NULL);
50 if (current_user.uid != 1 || current_user.gid != 2) {
51 printf("FAIL: current_user id not updated after push\n");
52 return 1;
55 if (current_user.ngroups != 0 || current_user.groups) {
56 printf("FAIL: current_user groups not updated after push\n");
57 return 1;
60 /* Push another */
62 get_random_grouplist(&ngroups, &groups);
64 if (!push_sec_ctx()) {
65 printf("FAIL: push_sec_ctx\n");
66 return 1;
69 set_sec_ctx(2, 3, ngroups, groups);
71 if (current_user.uid != 2 || current_user.gid != 3) {
72 printf("FAIL: current_user id not updated after second "
73 "push\n");
74 return 1;
77 if (current_user.ngroups != ngroups ||
78 (memcmp(current_user.groups, groups,
79 sizeof(gid_t) * ngroups) != 0)) {
80 printf("FAIL: current_user groups not updated\n");
81 return 1;
84 /* Pop them both off */
86 if (!pop_sec_ctx()) {
87 printf("FAIL: pop_sec_ctx\n");
88 return 1;
91 if (current_user.uid != 1 || current_user.gid != 2) {
92 printf("FAIL: current_user not updaded pop\n");
93 return 1;
96 if (!pop_sec_ctx()) {
97 printf("FAIL: pop_sec_ctx\n");
98 return 1;
101 /* Check initial state was returned */
103 if (current_user.uid != initial_uid ||
104 current_user.gid != initial_gid) {
105 printf("FAIL: current_user not updaded pop\n");
106 return 1;
109 /* Everything's cool */
111 printf("PASS\n");
112 return 0;