From 63c2a19e6e9d0e5e9b662fafe9fd531c2c073174 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 24 May 2008 23:39:38 +0200 Subject: Add helper function to return DCE/RPC fault codes. (This used to be commit 4716cdfb5d5abad85cba18be89d72fe8ee18f359) --- source4/librpc/rpc/pyrpc.c | 17 +++++++++++++++-- source4/librpc/rpc/pyrpc.h | 1 + 2 files changed, 16 insertions(+), 2 deletions(-) (limited to 'source4/librpc') diff --git a/source4/librpc/rpc/pyrpc.c b/source4/librpc/rpc/pyrpc.c index 1662140bbc..70875168c5 100644 --- a/source4/librpc/rpc/pyrpc.c +++ b/source4/librpc/rpc/pyrpc.c @@ -47,10 +47,23 @@ static PyObject *py_iface_server_name(PyObject *obj, void *closure) } static PyGetSetDef dcerpc_interface_getsetters[] = { - { discard_const_p(char, "server_name"), py_iface_server_name, NULL }, + { discard_const_p(char, "server_name"), py_iface_server_name, + "name of the server, if connected over SMB"}, { NULL } }; +void PyErr_SetDCERPCStatus(struct dcerpc_pipe *p, NTSTATUS status) +{ + if (NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) { + const char *errstr = dcerpc_errstr(NULL, p->last_fault_code); + PyErr_SetObject(PyExc_RuntimeError, + Py_BuildValue("(i,s)", p->last_fault_code, + errstr)); + } else { + PyErr_SetNTSTATUS(status); + } +} + static PyObject *py_iface_request(PyObject *self, PyObject *args, PyObject *kwargs) { dcerpc_InterfaceObject *iface = (dcerpc_InterfaceObject *)self; @@ -83,7 +96,7 @@ static PyObject *py_iface_request(PyObject *self, PyObject *args, PyObject *kwar opnum, false, mem_ctx, &data_in, &data_out); if (NT_STATUS_IS_ERR(status)) { - PyErr_SetNTSTATUS(status); + PyErr_SetDCERPCStatus(iface->pipe, status); talloc_free(mem_ctx); return NULL; } diff --git a/source4/librpc/rpc/pyrpc.h b/source4/librpc/rpc/pyrpc.h index 65501b6b83..209d7d3f1f 100644 --- a/source4/librpc/rpc/pyrpc.h +++ b/source4/librpc/rpc/pyrpc.h @@ -50,5 +50,6 @@ PyAPI_DATA(PyTypeObject) dcerpc_InterfaceType; #define PyErr_SetNdrError(err) \ PyErr_SetObject(PyExc_RuntimeError, PyErr_FromNdrError(err)) +void PyErr_SetDCERPCStatus(struct dcerpc_pipe *pipe, NTSTATUS status); #endif /* _PYRPC_H_ */ -- cgit