diff options
author | Tim Potter <tpot@samba.org> | 2004-09-05 02:39:47 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 12:58:33 -0500 |
commit | 86bf5cefa9798378ffb881a9a668c852fe56b2e2 (patch) | |
tree | c3b46aece62d0c6105d37bf8fe7f42c510182099 | |
parent | 779b89cfc8e65b8e6a4ad2d868ab04f014a4bc20 (diff) | |
download | samba-86bf5cefa9798378ffb881a9a668c852fe56b2e2.tar.gz samba-86bf5cefa9798378ffb881a9a668c852fe56b2e2.tar.bz2 samba-86bf5cefa9798378ffb881a9a668c852fe56b2e2.zip |
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)
-rw-r--r-- | source4/scripting/swig/dcerpc.i | 26 |
1 files changed, 22 insertions, 4 deletions
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 *); |