Merge branch 'master' of ssh://git.samba.org/data/git/samba into noejs
[tprouty/samba.git] / source4 / libcli / security / security.i
1 /* 
2    Unix SMB/CIFS implementation.
3    Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2007
4    
5    This program is free software; you can redistribute it and/or modify
6    it under the terms of the GNU General Public License as published by
7    the Free Software Foundation; either version 3 of the License, or
8    (at your option) any later version.
9    
10    This program is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13    GNU General Public License for more details.
14    
15    You should have received a copy of the GNU General Public License
16    along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 %module(docstring="Security-related classes.",package="samba.security") security
20
21 %{
22 #include "includes.h"
23 #include "libcli/security/security.h"
24
25 typedef struct dom_sid dom_sid;
26 typedef struct security_token security_token;
27 typedef struct security_descriptor security_descriptor;
28 %}
29
30 %import "../lib/talloc/talloc.i"
31 %include "../util/errors.i"
32 %import "stdint.i"
33
34 enum sec_privilege {
35         SEC_PRIV_SECURITY=1,
36         SEC_PRIV_BACKUP=2,
37         SEC_PRIV_RESTORE=3,
38         SEC_PRIV_SYSTEMTIME=4,
39         SEC_PRIV_SHUTDOWN=5,
40         SEC_PRIV_REMOTE_SHUTDOWN=6,
41         SEC_PRIV_TAKE_OWNERSHIP=7,
42         SEC_PRIV_DEBUG=8,
43         SEC_PRIV_SYSTEM_ENVIRONMENT=9,
44         SEC_PRIV_SYSTEM_PROFILE=10,
45         SEC_PRIV_PROFILE_SINGLE_PROCESS=11,
46         SEC_PRIV_INCREASE_BASE_PRIORITY=12,
47         SEC_PRIV_LOAD_DRIVER=13,
48         SEC_PRIV_CREATE_PAGEFILE=14,
49         SEC_PRIV_INCREASE_QUOTA=15,
50         SEC_PRIV_CHANGE_NOTIFY=16,
51         SEC_PRIV_UNDOCK=17,
52         SEC_PRIV_MANAGE_VOLUME=18,
53         SEC_PRIV_IMPERSONATE=19,
54         SEC_PRIV_CREATE_GLOBAL=20,
55         SEC_PRIV_ENABLE_DELEGATION=21,
56         SEC_PRIV_INTERACTIVE_LOGON=22,
57         SEC_PRIV_NETWORK_LOGON=23,
58         SEC_PRIV_REMOTE_INTERACTIVE_LOGON=24
59 };
60
61 %rename(SecurityToken) security_token;
62
63 %talloctype(security_token);
64
65 typedef struct security_token { 
66     %extend {
67         security_token(TALLOC_CTX *mem_ctx) { return security_token_initialise(mem_ctx); }
68         %feature("docstring") is_sid "S.is_sid(sid) -> bool\n" \
69             "Check whether this token is of the specified SID.";
70         bool is_sid(const struct dom_sid *sid);
71         %feature("docstring") is_system "S.is_system() -> bool\n" \
72                           "Check whether this is a system token.";
73         bool is_system();
74         %feature("docstring") is_anonymous "S.is_anonymus() -> bool\n" \
75                           "Check whether this is an anonymous token.";
76         bool is_anonymous();
77         bool has_sid(const struct dom_sid *sid);
78         bool has_builtin_administrators();
79         bool has_nt_authenticated_users();
80         bool has_privilege(enum sec_privilege privilege);
81         void set_privilege(enum sec_privilege privilege);
82     }
83 } security_token;
84
85 %talloctype(security_descriptor);
86
87 typedef struct security_descriptor {
88     %extend {
89         security_descriptor(TALLOC_CTX *mem_ctx) { return security_descriptor_initialise(mem_ctx); }
90         %feature("docstring") sacl_add "S.sacl_add(ace) -> None\n" \
91                               "Add a security ace to this security descriptor";
92         NTSTATUS sacl_add(const struct security_ace *ace);
93         NTSTATUS dacl_add(const struct security_ace *ace);
94         NTSTATUS dacl_del(const struct dom_sid *trustee);
95         NTSTATUS sacl_del(const struct dom_sid *trustee);
96 #ifdef SWIGPYTHON
97         %rename(__eq__) equal;
98 #endif
99         bool equal(const struct security_descriptor *other);
100     }
101 } security_descriptor;
102
103 %rename(Sid) dom_sid;
104
105 %talloctype(dom_sid);
106
107 typedef struct dom_sid {
108     %extend {
109         dom_sid(TALLOC_CTX *mem_ctx, const char *text) {
110             return dom_sid_parse_talloc(mem_ctx, text);
111         }
112 #ifdef SWIGPYTHON
113         const char *__str__(TALLOC_CTX *mem_ctx) {
114             return dom_sid_string(mem_ctx, $self);
115         }
116         %rename(__eq__) equal;
117 #endif
118         bool equal(const struct dom_sid *other);
119     }
120 %pythoncode {
121     def __repr__(self):
122         return "Sid(%r)" % str(self)
123 }
124 } dom_sid;
125
126 %feature("docstring") random_sid "random_sid() -> sid\n" \
127          "Generate a random SID";
128
129 %inline %{
130 static struct dom_sid *random_sid(TALLOC_CTX *mem_ctx)
131 {
132     char *str = talloc_asprintf(mem_ctx, "S-1-5-21-%u-%u-%u", 
133                                 (unsigned)generate_random(), 
134                                 (unsigned)generate_random(), 
135                                 (unsigned)generate_random());
136
137         return dom_sid_parse_talloc(mem_ctx, str);
138 }
139 %}
140
141 %rename(privilege_name) sec_privilege_name;
142 const char *sec_privilege_name(enum sec_privilege privilege);
143 %rename(privilege_id) sec_privilege_id;
144 enum sec_privilege sec_privilege_id(const char *name);