r208: merge the version schema changes from 4_0
[Samba/gebeck_regimport.git] / testsuite / smbd / sec_ctx_current_user.c
blob5b7da0ef464d0993081e19913318f004cf8e2751
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 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.
22 #include "includes.h"
23 #include "sec_ctx_utils.h"
25 int main(int argc, char **argv)
27 extern struct current_user current_user;
28 uid_t initial_uid = current_user.uid;
29 gid_t initial_gid = current_user.gid;
30 int ngroups;
31 gid_t *groups;
33 init_sec_ctx();
35 /* Check initial id */
37 if (initial_uid != 0 || initial_gid != 0) {
38 printf("FAIL: current_user not initialised to root\n");
39 return 1;
42 /* Push a context and check current user is updated */
44 if (!push_sec_ctx()) {
45 printf("FAIL: push_sec_ctx\n");
46 return 1;
49 set_sec_ctx(1, 2, 0, NULL);
51 if (current_user.uid != 1 || current_user.gid != 2) {
52 printf("FAIL: current_user id not updated after push\n");
53 return 1;
56 if (current_user.ngroups != 0 || current_user.groups) {
57 printf("FAIL: current_user groups not updated after push\n");
58 return 1;
61 /* Push another */
63 get_random_grouplist(&ngroups, &groups);
65 if (!push_sec_ctx()) {
66 printf("FAIL: push_sec_ctx\n");
67 return 1;
70 set_sec_ctx(2, 3, ngroups, groups);
72 if (current_user.uid != 2 || current_user.gid != 3) {
73 printf("FAIL: current_user id not updated after second "
74 "push\n");
75 return 1;
78 if (current_user.ngroups != ngroups ||
79 (memcmp(current_user.groups, groups,
80 sizeof(gid_t) * ngroups) != 0)) {
81 printf("FAIL: current_user groups not updated\n");
82 return 1;
85 /* Pop them both off */
87 if (!pop_sec_ctx()) {
88 printf("FAIL: pop_sec_ctx\n");
89 return 1;
92 if (current_user.uid != 1 || current_user.gid != 2) {
93 printf("FAIL: current_user not updaded pop\n");
94 return 1;
97 if (!pop_sec_ctx()) {
98 printf("FAIL: pop_sec_ctx\n");
99 return 1;
102 /* Check initial state was returned */
104 if (current_user.uid != initial_uid ||
105 current_user.gid != initial_gid) {
106 printf("FAIL: current_user not updaded pop\n");
107 return 1;
110 /* Everything's cool */
112 printf("PASS\n");
113 return 0;