~vcs-imports/samba/main

« back to all changes in this revision

Viewing changes to testsuite/smbd/sec_ctx_current_user.c

  • Committer: jerry
  • Date: 2006-07-14 21:48:39 UTC
  • Revision ID: vcs-imports@canonical.com-20060714214839-586d8c489a8fcead
gutting trunk to move to svn:externals

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
 
        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;
32
 
 
33
 
        init_sec_ctx();
34
 
 
35
 
        /* Check initial id */
36
 
 
37
 
        if (initial_uid != 0 || initial_gid != 0) {
38
 
                printf("FAIL: current_user not initialised to root\n");
39
 
                return 1;
40
 
        }
41
 
 
42
 
        /* Push a context and check current user is updated */
43
 
 
44
 
        if (!push_sec_ctx()) {
45
 
                printf("FAIL: push_sec_ctx\n");
46
 
                return 1;
47
 
        }
48
 
 
49
 
        set_sec_ctx(1, 2, 0, NULL);
50
 
 
51
 
        if (current_user.uid != 1 || current_user.gid != 2) {
52
 
                printf("FAIL: current_user id not updated after push\n");
53
 
                return 1;
54
 
        }
55
 
 
56
 
        if (current_user.ngroups != 0 || current_user.groups) {
57
 
                printf("FAIL: current_user groups not updated after push\n");
58
 
                return 1;
59
 
        }
60
 
 
61
 
        /* Push another */
62
 
 
63
 
        get_random_grouplist(&ngroups, &groups);
64
 
 
65
 
        if (!push_sec_ctx()) {
66
 
                printf("FAIL: push_sec_ctx\n");
67
 
                return 1;
68
 
        }
69
 
 
70
 
        set_sec_ctx(2, 3, ngroups, groups);
71
 
 
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;
76
 
        }
77
 
 
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;
83
 
        }
84
 
 
85
 
        /* Pop them both off */
86
 
 
87
 
        if (!pop_sec_ctx()) {
88
 
                printf("FAIL: pop_sec_ctx\n");
89
 
                return 1;
90
 
        }
91
 
 
92
 
        if (current_user.uid != 1 || current_user.gid != 2) {
93
 
                printf("FAIL: current_user not updaded pop\n");
94
 
                return 1;
95
 
        }
96
 
 
97
 
        if (!pop_sec_ctx()) {
98
 
                printf("FAIL: pop_sec_ctx\n");
99
 
                return 1;
100
 
        }
101
 
 
102
 
        /* Check initial state was returned */
103
 
 
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;
108
 
        }
109
 
 
110
 
        /* Everything's cool */
111
 
 
112
 
        printf("PASS\n");
113
 
        return 0;
114
 
}