summaryrefslogtreecommitdiff
path: root/source4
diff options
context:
space:
mode:
Diffstat (limited to 'source4')
-rw-r--r--source4/libcli/util/pyerrors.h8
-rw-r--r--source4/librpc/rpc/pyrpc.c1
-rw-r--r--source4/librpc/rpc/pyrpc.h2
-rw-r--r--source4/pidl/lib/Parse/Pidl/Samba4/Python.pm10
-rw-r--r--source4/scripting/python/samba/tests/dcerpc/rpcecho.py5
5 files changed, 18 insertions, 8 deletions
diff --git a/source4/libcli/util/pyerrors.h b/source4/libcli/util/pyerrors.h
index 49d9923130..aaa35b4d26 100644
--- a/source4/libcli/util/pyerrors.h
+++ b/source4/libcli/util/pyerrors.h
@@ -20,10 +20,14 @@
#ifndef __PYERRORS_H__
#define __PYERRORS_H__
+#define PyErr_FromWERROR(err) Py_BuildValue("(i,s)", W_ERROR_V(err), discard_const_p(char, win_errstr(err)))
+
+#define PyErr_FromNTSTATUS(status) Py_BuildValue("(i,s)", NT_STATUS_V(status), discard_const_p(char, nt_errstr(status)))
+
#define PyErr_SetWERROR(err) \
- PyErr_SetObject(PyExc_RuntimeError, Py_BuildValue((char *)"(i,s)", W_ERROR_V(err), discard_const_p(char, win_errstr(err))))
+ PyErr_SetObject(PyExc_RuntimeError, PyErr_FromWERROR(err))
#define PyErr_SetNTSTATUS(status) \
- PyErr_SetObject(PyExc_RuntimeError, Py_BuildValue((char *)"(i,s)", NT_STATUS_V(status), discard_const_p(char, nt_errstr(status))))
+ PyErr_SetObject(PyExc_RuntimeError, PyErr_FromNTSTATUS(status))
#endif /* __PYERRORS_H__ */
diff --git a/source4/librpc/rpc/pyrpc.c b/source4/librpc/rpc/pyrpc.c
index 8a0486c05e..33b3c63571 100644
--- a/source4/librpc/rpc/pyrpc.c
+++ b/source4/librpc/rpc/pyrpc.c
@@ -22,7 +22,6 @@
#include "librpc/rpc/pyrpc.h"
#include "librpc/rpc/dcerpc.h"
#include "lib/events/events.h"
-#include "libcli/util/pyerrors.h"
static PyObject *py_iface_server_name(PyObject *obj, void *closure)
{
diff --git a/source4/librpc/rpc/pyrpc.h b/source4/librpc/rpc/pyrpc.h
index 386b994494..3857f53634 100644
--- a/source4/librpc/rpc/pyrpc.h
+++ b/source4/librpc/rpc/pyrpc.h
@@ -20,6 +20,8 @@
#ifndef _PYRPC_H_
#define _PYRPC_H_
+#include "libcli/util/pyerrors.h"
+
#define PY_CHECK_TYPE(type, var, fail) \
if (!type ## _Check(var)) {\
PyErr_Format(PyExc_TypeError, "Expected type %s", type ## _Type.tp_name); \
diff --git a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm
index f252dd4f27..5e76ff027b 100644
--- a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm
+++ b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm
@@ -257,7 +257,7 @@ sub PythonStruct($$$$$$)
$self->pidl("$cname *object = py_talloc_get_ptr(py_obj);");
$self->pidl("DATA_BLOB blob;");
$self->pidl("enum ndr_err_code err;");
- $self->pidl("if (!PyArg_ParseTuple(args, \"(s#):__ndr_unpack__\", &blob.data, &blob.length))");
+ $self->pidl("if (!PyArg_ParseTuple(args, \"s#:__ndr_unpack__\", &blob.data, &blob.length))");
$self->pidl("\treturn NULL;");
$self->pidl("");
$self->pidl("err = ndr_pull_struct_blob_all(&blob, py_talloc_get_mem_ctx(py_obj), NULL, object, (ndr_pull_flags_fn_t)ndr_pull_$name);");
@@ -501,7 +501,7 @@ sub handle_werror($$$$)
$self->pidl("if (!W_ERROR_IS_OK($var)) {");
$self->indent;
- $self->pidl("PyErr_SetString(PyExc_RuntimeError, win_errstr($var));");
+ $self->pidl("PyErr_SetWERROR($var);");
$self->pidl("talloc_free($mem_ctx);") if ($mem_ctx);
$self->pidl("return $retval;");
$self->deindent;
@@ -515,7 +515,7 @@ sub handle_ntstatus($$$$)
$self->pidl("if (NT_STATUS_IS_ERR($var)) {");
$self->indent;
- $self->pidl("PyErr_SetString(PyExc_RuntimeError, nt_errstr($var));");
+ $self->pidl("PyErr_SetNTSTATUS($var);");
$self->pidl("talloc_free($mem_ctx);") if ($mem_ctx);
$self->pidl("return $retval;");
$self->deindent;
@@ -926,11 +926,11 @@ sub ConvertScalarToPython($$$)
}
if ($ctypename eq "NTSTATUS") {
- return "PyInt_FromLong(NT_STATUS_V($cvar))";
+ return "PyErr_FromNTSTATUS($cvar)";
}
if ($ctypename eq "WERROR") {
- return "PyInt_FromLong(W_ERROR_V($cvar))";
+ return "PyErr_FromWERROR($cvar)";
}
if (($ctypename eq "string" or $ctypename eq "nbt_string" or $ctypename eq "nbt_name" or $ctypename eq "wrepl_nbt_name")) {
diff --git a/source4/scripting/python/samba/tests/dcerpc/rpcecho.py b/source4/scripting/python/samba/tests/dcerpc/rpcecho.py
index 9157f83fc9..83279a0b30 100644
--- a/source4/scripting/python/samba/tests/dcerpc/rpcecho.py
+++ b/source4/scripting/python/samba/tests/dcerpc/rpcecho.py
@@ -42,6 +42,11 @@ class RpcEchoTests(RpcInterfaceTestCase):
y = self.conn.TestSurrounding(surrounding_struct)
self.assertEquals(8 * [0], y.surrounding)
+ def test_manual_request(self):
+ self.assertEquals("\x01\x00\x00\x00", self.conn.request(0, chr(0) * 4))
+
+ def test_server_name(self):
+ self.assertEquals(None, self.conn.server_name)
class NdrEchoTests(unittest.TestCase):
def test_info1_push(self):