7679b773f4b13c544d63563ac036c240b9495085
[bbaumbach/samba-autobuild/.git] / source4 / scripting / swig / dcerpc.i
1 /* 
2    Unix SMB/CIFS implementation.
3
4    Swig interface to librpc functions.
5
6    Copyright (C) Tim Potter 2004
7    
8    This program is free software; you can redistribute it and/or modify
9    it under the terms of the GNU General Public License as published by
10    the Free Software Foundation; either version 2 of the License, or
11    (at your option) any later version.
12    
13    This program is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16    GNU General Public License for more details.
17    
18    You should have received a copy of the GNU General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */
22
23 %module dcerpc
24
25 %{
26
27 /* This symbol is used in both includes.h and Python.h which causes an
28    annoying compiler warning. */
29
30 #ifdef HAVE_FSTAT
31 #undef HAVE_FSTAT
32 #endif
33
34 #include "includes.h"
35
36 #undef strcpy
37
38 PyObject *ntstatus_exception;
39
40 /* Set up return of a dcerpc.NTSTATUS exception */
41
42 void set_ntstatus_exception(int status)
43 {
44         PyObject *obj = Py_BuildValue("(i,s)", status, 
45                                 nt_errstr(NT_STATUS(status)));
46
47         PyErr_SetObject(ntstatus_exception, obj);
48 }
49
50 uint8 uint8_from_python(PyObject *obj)
51 {
52         return (uint8)PyInt_AsLong(obj);
53 }
54
55 PyObject *uint8_to_python(uint8 obj)
56 {
57         return PyInt_FromLong(obj);
58 }
59
60 uint16 uint16_from_python(PyObject *obj)
61 {
62         return (uint16)PyInt_AsLong(obj);
63 }
64
65 PyObject *uint16_to_python(uint16 obj)
66 {
67         return PyInt_FromLong(obj);
68 }
69
70 uint32 uint32_from_python(PyObject *obj)
71 {
72         return (uint32)PyInt_AsLong(obj);
73 }
74
75 PyObject *uint32_to_python(uint32 obj)
76 {
77         return PyInt_FromLong(obj);
78 }
79
80 int64 int64_from_python(PyObject *obj)
81 {
82         return (int64)PyLong_AsLong(obj);
83 }
84
85 PyObject *int64_to_python(int64 obj)
86 {
87         return PyLong_FromLong(obj);
88 }
89
90 uint64 uint64_from_python(PyObject *obj)
91 {
92         return (uint64)PyLong_AsLong(obj);
93 }
94
95 PyObject *uint64_to_python(uint64 obj)
96 {
97         return PyLong_FromLong(obj);
98 }
99
100 NTTIME NTTIME_from_python(PyObject *obj)
101 {
102         return (NTTIME)PyLong_AsLong(obj);
103 }
104
105 PyObject *NTTIME_to_python(NTTIME obj)
106 {
107         return PyLong_FromLong(obj);
108 }
109
110 HYPER_T HYPER_T_from_python(PyObject *obj)
111 {
112         return (HYPER_T)PyLong_AsLong(obj);
113 }
114
115 PyObject *HYPER_T_to_python(HYPER_T obj)
116 {
117         return PyLong_FromLong(obj);
118 }
119
120 struct policy_handle *policy_handle_from_python(PyObject *obj)
121 {
122         return (struct policy_handle *)PyString_AsString(obj);
123 }
124
125 PyObject *policy_handle_to_python(struct policy_handle *handle)
126 {
127         return PyString_FromStringAndSize((char *)handle, sizeof(*handle));
128 }
129
130 struct security_descriptor *security_descriptor_ptr_from_python(TALLOC_CTX *mem_ctx, PyObject *obj)
131 {
132         return NULL;
133 }
134
135 PyObject *security_descriptor_to_python(struct security_descriptor *obj)
136 {
137         return Py_None;
138 }
139
140 struct dom_sid2 *dom_sid2_ptr_from_python(TALLOC_CTX *mem_ctx, PyObject *obj)
141 {
142         return NULL;
143 }
144
145 PyObject *dom_sid2_to_python(struct dom_sid2 *obj)
146 {
147         return Py_None;
148 }
149
150 char *string_from_python(PyObject *obj)
151 {
152         if (obj == Py_None)
153                 return NULL;
154
155         return PyString_AsString(obj);
156 }
157
158 PyObject *string_to_python(char *obj)
159 {
160         if (obj == NULL)
161                 return Py_None;
162
163         return PyString_FromString(obj);
164 }
165
166 struct samr_Password *samr_Password_ptr_from_python(TALLOC_CTX *mem_ctx, PyObject *obj)
167 {
168         return NULL;
169 }
170
171 PyObject *samr_Password_to_python(struct samr_Password *obj)
172 {
173         return NULL;
174 }
175
176 %}
177
178 %include "samba.i"
179
180 %init  %{
181 /* setup_logging("python", DEBUG_STDOUT);       */
182         lp_load(dyn_CONFIGFILE, True, False, False);
183         load_interfaces();
184         ntstatus_exception = PyErr_NewException("dcerpc.NTSTATUS", NULL, NULL);
185 %}
186
187 %typemap(in, numinputs=0) struct dcerpc_pipe **OUT (struct dcerpc_pipe *temp_dcerpc_pipe) {
188         $1 = &temp_dcerpc_pipe;
189 }
190
191 %typemap(in, numinputs=0) TALLOC_CTX * {
192         $1 = talloc_init("$symname");
193 }
194
195 %typemap(freearg) TALLOC_CTX * {
196         talloc_free($1);
197 }
198
199 %typemap(argout) struct dcerpc_pipe ** {
200         long status = PyLong_AsLong(resultobj);
201
202         /* Throw exception if result was not OK */
203
204         if (status != 0) {
205                 set_ntstatus_exception(status);
206                 return NULL;
207         }
208
209         /* Set REF_ALLOC flag so we don't have to do too much extra
210            mucking around with ref variables in ndr unmarshalling. */
211
212         (*$1)->flags |= DCERPC_NDR_REF_ALLOC;
213
214         /* Return swig handle on dcerpc_pipe */
215
216         resultobj = SWIG_NewPointerObj(*$1, SWIGTYPE_p_dcerpc_pipe, 0);
217 }
218
219 %types(struct dcerpc_pipe *);
220
221 %rename(pipe_connect) dcerpc_pipe_connect;
222
223 NTSTATUS dcerpc_pipe_connect(struct dcerpc_pipe **OUT,
224                              const char *binding,
225                              const char *pipe_uuid,
226                              uint32 pipe_version,
227                              const char *domain,
228                              const char *username,
229                              const char *password);
230
231 %include "librpc/gen_ndr/lsa.i"
232 %include "librpc/gen_ndr/samr.i"