From 86bf5cefa9798378ffb881a9a668c852fe56b2e2 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Sun, 5 Sep 2004 02:39:47 +0000 Subject: r2229: Have dcerpc_pipe_connect() throw an exception if non-zero NTSTATUS is returned from the C function. This way we can return the struct dcerpc_pipe object instead of a tuple of (NTSTATUS, dcerpc_pipe) which is a bad interface. (This used to be commit a3a85bd419e38f0dce138e67174517e23a361010) --- source4/scripting/swig/dcerpc.i | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) (limited to 'source4/scripting') diff --git a/source4/scripting/swig/dcerpc.i b/source4/scripting/swig/dcerpc.i index 9ecc2702bb..6130f85a60 100644 --- a/source4/scripting/swig/dcerpc.i +++ b/source4/scripting/swig/dcerpc.i @@ -35,6 +35,21 @@ #undef strcpy +PyObject *ntstatus_exception; + +/* Set up return of a dcerpc.NTSTATUS exception */ + +void set_ntstatus_exception(int status) +{ + PyObject *obj = PyTuple_New(2); + + PyTuple_SetItem(obj, 0, PyInt_FromLong(status)); + PyTuple_SetItem(obj, 1, + PyString_FromString(nt_errstr(NT_STATUS(status)))); + + PyErr_SetObject(ntstatus_exception, obj); +} + %} %include "samba.i" @@ -43,6 +58,7 @@ /* setup_logging("python", DEBUG_STDOUT); */ lp_load(dyn_CONFIGFILE, True, False, False); load_interfaces(); + ntstatus_exception = PyErr_NewException("dcerpc.NTSTATUS", NULL, NULL); %} %typemap(in, numinputs=0) struct dcerpc_pipe **OUT (struct dcerpc_pipe *temp) { @@ -50,10 +66,12 @@ } %typemap(argout) struct dcerpc_pipe ** { - PyObject *o = PyTuple_New(2); - PyTuple_SetItem(o, 0, resultobj); - PyTuple_SetItem(o, 1, SWIG_NewPointerObj(*$1, SWIGTYPE_p_dcerpc_pipe, 0)); - resultobj = o; + long status = PyLong_AsLong(resultobj); + if (status != 0) { + set_ntstatus_exception(status); + return NULL; + } + resultobj = SWIG_NewPointerObj(*$1, SWIGTYPE_p_dcerpc_pipe, 0); } %types(struct dcerpc_pipe *); -- cgit