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