r6540: Implement a bunch more SAMR functions.
[samba.git] / source4 / scripting / swig / dcerpc.i
1 /* Tastes like -*- C -*- */
2
3 /* 
4    Unix SMB/CIFS implementation.
5
6    Swig interface to librpc functions.
7
8    Copyright (C) Tim Potter 2004
9    
10    This program is free software; you can redistribute it and/or modify
11    it under the terms of the GNU General Public License as published by
12    the Free Software Foundation; either version 2 of the License, or
13    (at your option) any later version.
14    
15    This program is distributed in the hope that it will be useful,
16    but WITHOUT ANY WARRANTY; without even the implied warranty of
17    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18    GNU General Public License for more details.
19    
20    You should have received a copy of the GNU General Public License
21    along with this program; if not, write to the Free Software
22    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 */
24
25 %module dcerpc
26
27 %{
28
29 /* This symbol is used in both includes.h and Python.h which causes an
30    annoying compiler warning. */
31
32 #ifdef HAVE_FSTAT
33 #undef HAVE_FSTAT
34 #endif
35
36 #include "includes.h"
37 #include "dynconfig.h"
38
39 #undef strcpy
40
41 PyObject *ntstatus_exception, *werror_exception;
42
43 /* Set up return of a dcerpc.NTSTATUS exception */
44
45 void set_ntstatus_exception(int status)
46 {
47         PyObject *obj = Py_BuildValue("(i,s)", status, 
48                                 nt_errstr(NT_STATUS(status)));
49
50         PyErr_SetObject(ntstatus_exception, obj);
51 }
52
53 void set_werror_exception(int status)
54 {
55         PyObject *obj = Py_BuildValue("(i,s)", status, 
56                                 win_errstr(W_ERROR(status)));
57
58         PyErr_SetObject(werror_exception, obj);
59 }
60
61 %}
62
63 %include "samba.i"
64
65 %pythoncode %{
66         NTSTATUS = _dcerpc.NTSTATUS
67         WERROR = _dcerpc.WERROR
68 %}
69
70 %init  %{
71         setup_logging("python", DEBUG_STDOUT);  
72         lp_load(dyn_CONFIGFILE, True, False, False);
73         load_interfaces();
74         ntstatus_exception = PyErr_NewException("_dcerpc.NTSTATUS", NULL, NULL);
75         werror_exception = PyErr_NewException("_dcerpc.WERROR", NULL, NULL);
76         PyDict_SetItemString(d, "NTSTATUS", ntstatus_exception);
77         PyDict_SetItemString(d, "WERROR", werror_exception);
78
79 /* BINARY swig_dcerpc INIT */
80
81                 extern NTSTATUS dcerpc_misc_init(void);
82                 extern NTSTATUS dcerpc_krb5pac_init(void);
83                 extern NTSTATUS dcerpc_samr_init(void);
84                 extern NTSTATUS dcerpc_dcerpc_init(void);
85                 extern NTSTATUS auth_sam_init(void);
86                 extern NTSTATUS dcerpc_lsa_init(void);
87                 extern NTSTATUS dcerpc_netlogon_init(void);
88                 extern NTSTATUS gensec_init(void);
89                 extern NTSTATUS auth_developer_init(void);
90                 extern NTSTATUS gensec_spnego_init(void);
91                 extern NTSTATUS auth_winbind_init(void);
92                 extern NTSTATUS gensec_gssapi_init(void);
93                 extern NTSTATUS gensec_ntlmssp_init(void);
94                 extern NTSTATUS dcerpc_nbt_init(void);
95                 extern NTSTATUS auth_anonymous_init(void);
96                 extern NTSTATUS gensec_krb5_init(void);
97                 extern NTSTATUS dcerpc_schannel_init(void);
98                 extern NTSTATUS dcerpc_epmapper_init(void);
99                 if (NT_STATUS_IS_ERR(dcerpc_misc_init())) exit(1);
100                 if (NT_STATUS_IS_ERR(dcerpc_krb5pac_init())) exit(1);
101                 if (NT_STATUS_IS_ERR(dcerpc_samr_init())) exit(1);
102                 if (NT_STATUS_IS_ERR(dcerpc_dcerpc_init())) exit(1);
103                 if (NT_STATUS_IS_ERR(auth_sam_init())) exit(1);
104                 if (NT_STATUS_IS_ERR(dcerpc_lsa_init())) exit(1);
105                 if (NT_STATUS_IS_ERR(dcerpc_netlogon_init())) exit(1);
106                 if (NT_STATUS_IS_ERR(gensec_init())) exit(1);
107                 if (NT_STATUS_IS_ERR(auth_developer_init())) exit(1);
108                 if (NT_STATUS_IS_ERR(gensec_spnego_init())) exit(1);
109                 if (NT_STATUS_IS_ERR(auth_winbind_init())) exit(1);
110                 if (NT_STATUS_IS_ERR(gensec_gssapi_init())) exit(1);
111                 if (NT_STATUS_IS_ERR(gensec_ntlmssp_init())) exit(1);
112                 if (NT_STATUS_IS_ERR(dcerpc_nbt_init())) exit(1);
113                 if (NT_STATUS_IS_ERR(auth_anonymous_init())) exit(1);
114                 if (NT_STATUS_IS_ERR(gensec_krb5_init())) exit(1);
115                 if (NT_STATUS_IS_ERR(dcerpc_schannel_init())) exit(1);
116                 if (NT_STATUS_IS_ERR(dcerpc_epmapper_init())) exit(1);
117
118 %}
119
120 %typemap(in, numinputs=0) struct dcerpc_pipe **OUT (struct dcerpc_pipe *temp_dcerpc_pipe) {
121         $1 = &temp_dcerpc_pipe;
122 }
123
124 %typemap(in, numinputs=0) TALLOC_CTX * {
125         $1 = talloc_init("$symname");
126 }
127
128 %typemap(freearg) TALLOC_CTX * {
129 //      talloc_free($1);
130 }
131
132 %typemap(argout) struct dcerpc_pipe ** {
133         long status = PyLong_AsLong(resultobj);
134
135         /* Throw exception if result was not OK */
136
137         if (status != 0) {
138                 set_ntstatus_exception(status);
139                 return NULL;
140         }
141
142         /* Set REF_ALLOC flag so we don't have to do too much extra
143            mucking around with ref variables in ndr unmarshalling. */
144
145         (*$1)->conn->flags |= DCERPC_NDR_REF_ALLOC;
146
147         /* Return swig handle on dcerpc_pipe */
148
149         resultobj = SWIG_NewPointerObj(*$1, SWIGTYPE_p_dcerpc_pipe, 0);
150 }
151
152 %types(struct dcerpc_pipe *);
153
154 %rename(pipe_connect) dcerpc_pipe_connect;
155
156 NTSTATUS dcerpc_pipe_connect(TALLOC_CTX *parent_ctx,
157                              struct dcerpc_pipe **OUT,
158                              const char *binding,
159                              const char *pipe_uuid,
160                              uint32_t pipe_version,
161                              struct cli_credentials *credentials);
162
163 %typemap(in) DATA_BLOB * (DATA_BLOB temp_data_blob) {
164         temp_data_blob.data = PyString_AsString($input);
165         temp_data_blob.length = PyString_Size($input);
166         $1 = &temp_data_blob;
167 }
168
169 const char *dcerpc_server_name(struct dcerpc_pipe *p);
170
171 char *nt_errstr(NTSTATUS nt_code);
172
173 /* Some typemaps for easier access to resume handles.  Really this can
174    also be done using the uint32 carray functions, but it's a bit of a
175    hassle.  TODO: Fix memory leak here. */
176
177 %typemap(in) uint32_t *resume_handle {
178         $1 = malloc(sizeof(*$1));
179         *$1 = PyLong_AsLong($input);
180 }
181
182 %typemap(out) uint32_t *resume_handle {
183         $result = PyLong_FromLong(*$1);
184 }
185
186 %typemap(in) struct policy_handle * {
187
188         if ((SWIG_ConvertPtr($input, (void **) &$1, $1_descriptor,
189                              SWIG_POINTER_EXCEPTION)) == -1) 
190                 return NULL;
191
192         if ($1 == NULL) {
193                 PyErr_SetString(PyExc_TypeError, "None is not a valid policy handle");
194                 return NULL;
195         }
196 }
197
198 /* When returning a policy handle to Python we need to make a copy of
199    as the talloc context it is created under is destroyed after the
200    wrapper function returns.  TODO: Fix memory leak created here. */
201
202 %typemap(out) struct policy_handle * {
203         if ($1) {
204                 struct policy_handle *temp = (struct policy_handle *)malloc(sizeof(struct policy_handle));
205                 memcpy(temp, $1, sizeof(struct policy_handle));
206                 $result = SWIG_NewPointerObj(temp, SWIGTYPE_p_policy_handle, 0);
207         } else {
208                 Py_INCREF(Py_None);
209                 $result = Py_None;
210         }
211 }
212
213 %{
214 #include "librpc/gen_ndr/ndr_misc.h"
215 #include "librpc/gen_ndr/ndr_security.h"
216 #include "librpc/gen_ndr/ndr_samr.h"
217 %}
218
219 %include "carrays.i"
220
221 /* Some functions for accessing arrays of fixed-width integers. */
222
223 %array_functions(uint8_t, uint8_array);
224 %array_functions(uint16_t, uint16_array);
225 %array_functions(uint32_t, uint32_array);
226
227 /* Functions for handling arrays of structures.  It would be nice for 
228    pidl to automatically generating these instead of having to find
229    them all by hand. */
230
231 %array_functions(struct samr_String, samr_String_array);
232 %array_functions(struct samr_SamEntry, samr_SamEntry_array);
233 %array_functions(union samr_ConnectInfo, samr_ConnectInfo_array);
234 %array_functions(struct samr_RidType, samr_RidType_array);
235
236 %array_functions(struct lsa_SidPtr, lsa_SidPtr_array);
237
238 %include "librpc/gen_ndr/misc.i"
239 %include "librpc/gen_ndr/security.i"
240 %include "librpc/gen_ndr/samr.i"
241 %include "librpc/gen_ndr/lsa.i"