1 /* Tastes like -*- C -*- */
4 Unix SMB/CIFS implementation.
6 Swig interface to librpc functions.
8 Copyright (C) Tim Potter 2004
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.
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.
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.
29 /* This symbol is used in both includes.h and Python.h which causes an
30 annoying compiler warning. */
37 #include "dynconfig.h"
41 PyObject *ntstatus_exception, *werror_exception;
43 /* Set up return of a dcerpc.NTSTATUS exception */
45 void set_ntstatus_exception(int status)
47 PyObject *obj = Py_BuildValue("(i,s)", status,
48 nt_errstr(NT_STATUS(status)));
50 PyErr_SetObject(ntstatus_exception, obj);
53 void set_werror_exception(int status)
55 PyObject *obj = Py_BuildValue("(i,s)", status,
56 win_errstr(W_ERROR(status)));
58 PyErr_SetObject(werror_exception, obj);
61 /* Conversion functions for scalar types */
63 uint8 uint8_from_python(PyObject *obj, char *name)
66 PyErr_Format(PyExc_ValueError, "Expecting key %s", name);
70 if (!PyInt_Check(obj) && !PyLong_Check(obj)) {
71 PyErr_Format(PyExc_TypeError, "Expecting int or long value for %s", name);
75 if (PyLong_Check(obj))
76 return (uint8)PyLong_AsLong(obj);
78 return (uint8)PyInt_AsLong(obj);
81 PyObject *uint8_to_python(uint8 obj)
83 return PyInt_FromLong(obj);
86 uint16 uint16_from_python(PyObject *obj, char *name)
89 PyErr_Format(PyExc_ValueError, "Expecting key %s", name);
93 if (!PyInt_Check(obj) && !PyLong_Check(obj)) {
94 PyErr_Format(PyExc_TypeError, "Expecting int or long value for %s", name);
98 if (PyLong_Check(obj))
99 return (uint16)PyLong_AsLong(obj);
101 return (uint16)PyInt_AsLong(obj);
104 PyObject *uint16_to_python(uint16 obj)
106 return PyInt_FromLong(obj);
109 uint32 uint32_from_python(PyObject *obj, char *name)
112 PyErr_Format(PyExc_ValueError, "Expecting key %s", name);
116 if (!PyLong_Check(obj) && !PyInt_Check(obj)) {
117 PyErr_Format(PyExc_TypeError, "Expecting int or long value for %s", name);
121 if (PyLong_Check(obj))
122 return (uint32)PyLong_AsLong(obj);
124 return (uint32)PyInt_AsLong(obj);
127 PyObject *uint32_to_python(uint32 obj)
129 return PyLong_FromLong(obj);
132 int64 int64_from_python(PyObject *obj, char *name)
135 PyErr_Format(PyExc_ValueError, "Expecting key %s", name);
139 if (!PyLong_Check(obj) && !PyInt_Check(obj)) {
140 PyErr_Format(PyExc_TypeError, "Expecting int or long value for %s", name);
144 if (PyLong_Check(obj))
145 return (int64)PyLong_AsLongLong(obj);
147 return (int64)PyInt_AsLong(obj);
150 PyObject *int64_to_python(int64 obj)
152 return PyLong_FromLongLong(obj);
155 uint64 uint64_from_python(PyObject *obj, char *name)
158 PyErr_Format(PyExc_ValueError, "Expecting key %s", name);
162 if (!PyLong_Check(obj) && !PyInt_Check(obj)) {
163 PyErr_Format(PyExc_TypeError, "Expecting int or long value for %s", name);
167 if (PyLong_Check(obj))
168 return (uint64)PyLong_AsUnsignedLongLong(obj);
170 return (uint64)PyInt_AsLong(obj);
173 PyObject *uint64_to_python(uint64 obj)
175 return PyLong_FromUnsignedLongLong(obj);
178 NTTIME NTTIME_from_python(PyObject *obj, char *name)
181 PyErr_Format(PyExc_ValueError, "Expecting key %s", name);
185 if (!PyLong_Check(obj) && !PyInt_Check(obj)) {
186 PyErr_Format(PyExc_TypeError, "Expecting int or long value for %s", name);
190 if (PyLong_Check(obj))
191 return (NTTIME)PyLong_AsUnsignedLongLong(obj);
193 return (NTTIME)PyInt_AsUnsignedLongMask(obj);
196 PyObject *NTTIME_to_python(NTTIME obj)
198 return PyLong_FromUnsignedLongLong(obj);
201 time_t time_t_from_python(PyObject *obj, char *name)
204 PyErr_Format(PyExc_ValueError, "Expecting key %s", name);
208 if (!PyLong_Check(obj) && !PyInt_Check(obj)) {
209 PyErr_Format(PyExc_TypeError, "Expecting int or long value for %s", name);
213 if (PyLong_Check(obj))
214 return (time_t)PyLong_AsUnsignedLongLong(obj);
216 return (time_t)PyInt_AsUnsignedLongMask(obj);
219 PyObject *time_t_to_python(time_t obj)
221 return PyLong_FromUnsignedLongLong(obj);
224 HYPER_T HYPER_T_from_python(PyObject *obj, char *name)
227 PyErr_Format(PyExc_ValueError, "Expecting key %s", name);
231 if (!PyLong_Check(obj) && !PyInt_Check(obj)) {
232 PyErr_Format(PyExc_TypeError, "Expecting int or long value for %s", name);
236 if (PyLong_Check(obj))
237 return (HYPER_T)PyLong_AsUnsignedLongLong(obj);
239 return (HYPER_T)PyInt_AsUnsignedLongMask(obj);
242 PyObject *HYPER_T_to_python(HYPER_T obj)
244 return PyLong_FromUnsignedLongLong(obj);
247 /* Conversion functions for types that we don't want generated automatically.
248 This is mostly security realted stuff in misc.idl */
250 char *string_ptr_from_python(TALLOC_CTX *mem_ctx, PyObject *obj, char *name)
253 PyErr_Format(PyExc_ValueError, "Expecting key %s", name);
260 if (!PyString_Check(obj)) {
261 PyErr_Format(PyExc_TypeError, "Expecting string value for %s", name);
265 return PyString_AsString(obj);
268 PyObject *string_ptr_to_python(TALLOC_CTX *mem_ctx, char *obj)
275 return PyString_FromString(obj);
278 #define dom_sid2_ptr_to_python dom_sid_ptr_to_python
279 #define dom_sid2_ptr_from_python dom_sid_ptr_from_python
281 void DATA_BLOB_from_python(TALLOC_CTX *mem_ctx, DATA_BLOB *s,
282 PyObject *obj, char name)
285 PyErr_Format(PyExc_ValueError, "Expecting key %s", name);
289 if (!PyString_Check(obj)) {
290 PyErr_Format(PyExc_TypeError, "Expecting string value for key '%s'", name);
294 s->length = PyString_Size(obj);
295 s->data = PyString_AsString(obj);
298 void DATA_BLOB_ptr_from_python(TALLOC_CTX *mem_ctx, DATA_BLOB **s,
299 PyObject *obj, char *name)
302 PyErr_Format(PyExc_ValueError, "Expecting key %s", name);
306 if (obj == Py_None) {
311 if (!PyString_Check(obj)) {
312 PyErr_Format(PyExc_TypeError, "Expecting string value for key '%s'", name);
316 *s = talloc(mem_ctx, sizeof(DATA_BLOB));
318 (*s)->length = PyString_Size(obj);
319 (*s)->data = PyString_AsString(obj);
322 PyObject *DATA_BLOB_to_python(DATA_BLOB obj)
324 return PyString_FromStringAndSize(obj.data, obj.length);
332 NTSTATUS = _dcerpc.NTSTATUS
333 WERROR = _dcerpc.WERROR
337 setup_logging("python", DEBUG_STDOUT);
338 lp_load(dyn_CONFIGFILE, True, False, False);
340 ntstatus_exception = PyErr_NewException("_dcerpc.NTSTATUS", NULL, NULL);
341 werror_exception = PyErr_NewException("_dcerpc.WERROR", NULL, NULL);
342 PyDict_SetItemString(d, "NTSTATUS", ntstatus_exception);
343 PyDict_SetItemString(d, "WERROR", werror_exception);
346 %typemap(in, numinputs=0) struct dcerpc_pipe **OUT (struct dcerpc_pipe *temp_dcerpc_pipe) {
347 $1 = &temp_dcerpc_pipe;
350 %typemap(in, numinputs=0) TALLOC_CTX * {
351 $1 = talloc_init("$symname");
354 %typemap(freearg) TALLOC_CTX * {
358 %typemap(argout) struct dcerpc_pipe ** {
359 long status = PyLong_AsLong(resultobj);
361 /* Throw exception if result was not OK */
364 set_ntstatus_exception(status);
368 /* Set REF_ALLOC flag so we don't have to do too much extra
369 mucking around with ref variables in ndr unmarshalling. */
371 (*$1)->flags |= DCERPC_NDR_REF_ALLOC;
373 /* Return swig handle on dcerpc_pipe */
375 resultobj = SWIG_NewPointerObj(*$1, SWIGTYPE_p_dcerpc_pipe, 0);
378 %types(struct dcerpc_pipe *);
380 %rename(pipe_connect) dcerpc_pipe_connect;
382 NTSTATUS dcerpc_pipe_connect(struct dcerpc_pipe **OUT,
384 const char *pipe_uuid,
387 const char *username,
388 const char *password);
390 %typemap(in) DATA_BLOB * (DATA_BLOB temp_data_blob) {
391 temp_data_blob.data = PyString_AsString($input);
392 temp_data_blob.length = PyString_Size($input);
393 $1 = &temp_data_blob;
396 const char *dcerpc_server_name(struct dcerpc_pipe *p);
399 #include "librpc/gen_ndr/ndr_misc.h"
400 #include "librpc/gen_ndr/ndr_lsa.h"
401 #include "librpc/gen_ndr/ndr_samr.h"
402 #include "librpc/gen_ndr/ndr_winreg.h"
403 #include "librpc/gen_ndr/ndr_spoolss.h"
406 %include "librpc/gen_ndr/misc.i"
407 %include "librpc/gen_ndr/lsa.i"
408 %include "librpc/gen_ndr/samr.i"
409 %include "librpc/gen_ndr/winreg.i"
410 %include "librpc/gen_ndr/spoolss.i"
412 /* The status codes must be included last otherwise the automatically
413 generated .i files get confused. This is kind of yucky. */
415 %include "status_codes.i"