2 Unix SMB/CIFS implementation.
4 Swig interface to librpc functions.
6 Copyright (C) Tim Potter 2004
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.
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.
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.
27 /* This symbol is used in both includes.h and Python.h which causes an
28 annoying compiler warning. */
38 PyObject *ntstatus_exception;
40 /* Set up return of a dcerpc.NTSTATUS exception */
42 void set_ntstatus_exception(int status)
44 PyObject *obj = Py_BuildValue("(i,s)", status,
45 nt_errstr(NT_STATUS(status)));
47 PyErr_SetObject(ntstatus_exception, obj);
50 /* Conversion functions for scalar types */
52 uint8 uint8_from_python(PyObject *obj, char *name)
54 if (!PyInt_Check(obj)) {
55 PyErr_Format(PyExc_TypeError, "Expecting int value for %s", name);
59 return (uint8)PyInt_AsLong(obj);
62 PyObject *uint8_to_python(uint8 obj)
64 return PyInt_FromLong(obj);
67 uint16 uint16_from_python(PyObject *obj, char *name)
69 if (!PyInt_Check(obj)) {
70 PyErr_Format(PyExc_TypeError, "Expecting int value for %s", name);
74 return (uint16)PyInt_AsLong(obj);
77 PyObject *uint16_to_python(uint16 obj)
79 return PyInt_FromLong(obj);
82 uint32 uint32_from_python(PyObject *obj, char *name)
84 if (!PyInt_Check(obj)) {
85 PyErr_Format(PyExc_TypeError, "Expecting int value for %s", name);
89 return (uint32)PyInt_AsLong(obj);
92 PyObject *uint32_to_python(uint32 obj)
94 return PyInt_FromLong(obj);
97 int64 int64_from_python(PyObject *obj, char *name)
99 if (!PyInt_Check(obj)) {
100 PyErr_Format(PyExc_TypeError, "Expecting int value for %s", name);
104 return (int64)PyLong_AsLong(obj);
107 PyObject *int64_to_python(int64 obj)
109 return PyLong_FromLong(obj);
112 uint64 uint64_from_python(PyObject *obj, char *name)
114 if (!PyInt_Check(obj)) {
115 PyErr_Format(PyExc_TypeError, "Expecting int value for %s", name);
119 return (uint64)PyLong_AsLong(obj);
122 PyObject *uint64_to_python(uint64 obj)
124 return PyLong_FromLong(obj);
127 NTTIME NTTIME_from_python(PyObject *obj, char *name)
129 if (!PyInt_Check(obj)) {
130 PyErr_Format(PyExc_TypeError, "Expecting integer value for %s", name);
134 return (NTTIME)PyLong_AsLong(obj);
137 PyObject *NTTIME_to_python(NTTIME obj)
139 return PyLong_FromLong(obj);
142 HYPER_T HYPER_T_from_python(PyObject *obj, char *name)
144 if (!PyInt_Check(obj)) {
145 PyErr_Format(PyExc_TypeError, "Expecting integer value for %s", name);
149 return (HYPER_T)PyLong_AsLong(obj);
152 PyObject *HYPER_T_to_python(HYPER_T obj)
154 return PyLong_FromLong(obj);
157 /* Conversion functions for types that we don't want generated automatically.
158 This is mostly security realted stuff in misc.idl */
160 char *string_ptr_from_python(TALLOC_CTX *mem_ctx, PyObject *obj, char *name)
165 if (!PyString_Check(obj)) {
166 PyErr_Format(PyExc_TypeError, "Expecting string value for %s", name);
170 return PyString_AsString(obj);
173 PyObject *string_ptr_to_python(TALLOC_CTX *mem_ctx, char *obj)
180 return PyString_FromString(obj);
183 #define dom_sid2_ptr_to_python dom_sid_ptr_to_python
184 #define dom_sid2_ptr_from_python dom_sid_ptr_from_python
191 setup_logging("python", DEBUG_STDOUT);
192 lp_load(dyn_CONFIGFILE, True, False, False);
194 ntstatus_exception = PyErr_NewException("dcerpc.NTSTATUS", NULL, NULL);
197 %typemap(in, numinputs=0) struct dcerpc_pipe **OUT (struct dcerpc_pipe *temp_dcerpc_pipe) {
198 $1 = &temp_dcerpc_pipe;
201 %typemap(in, numinputs=0) TALLOC_CTX * {
202 $1 = talloc_init("$symname");
205 %typemap(freearg) TALLOC_CTX * {
209 %typemap(argout) struct dcerpc_pipe ** {
210 long status = PyLong_AsLong(resultobj);
212 /* Throw exception if result was not OK */
215 set_ntstatus_exception(status);
219 /* Set REF_ALLOC flag so we don't have to do too much extra
220 mucking around with ref variables in ndr unmarshalling. */
222 (*$1)->flags |= DCERPC_NDR_REF_ALLOC;
224 /* Return swig handle on dcerpc_pipe */
226 resultobj = SWIG_NewPointerObj(*$1, SWIGTYPE_p_dcerpc_pipe, 0);
229 %types(struct dcerpc_pipe *);
231 %rename(pipe_connect) dcerpc_pipe_connect;
233 NTSTATUS dcerpc_pipe_connect(struct dcerpc_pipe **OUT,
235 const char *pipe_uuid,
238 const char *username,
239 const char *password);
241 %include "librpc/gen_ndr/misc.i"
242 %include "librpc/gen_ndr/lsa.i"
243 %include "librpc/gen_ndr/samr.i"