From 1cd3a2be3199b7e1a3aa2ef29234255b8c1675ba Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 24 May 2008 18:46:32 +0200 Subject: Add __ndr_pack__ method to all DCE/RPC structures. (This used to be commit 06d272b42f59d0a785697d207e6d7dbbcf355175) --- source4/pidl/lib/Parse/Pidl/Samba4/Python.pm | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'source4/pidl/lib/Parse/Pidl') diff --git a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm index 440b1bff97..ad3cab6ffb 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm @@ -225,7 +225,33 @@ sub PythonStruct($$$$$$) $self->pidl("return py_talloc_import(&$name\_Type, ret);"); $self->deindent; $self->pidl("}"); + $self->pidl(""); + + $self->pidl("static PyObject *py_$name\_ndr_pack(PyObject *py_obj)"); + $self->pidl("{"); + $self->indent; + $self->pidl("$cname *object = py_talloc_get_ptr(py_obj);"); + $self->pidl("DATA_BLOB blob;"); + $self->pidl("enum ndr_err_code err;"); + $self->pidl("err = ndr_push_struct_blob(&blob, py_talloc_get_mem_ctx(py_obj), NULL, object, ndr_push_$name);"); + $self->pidl("if (err != NDR_ERR_SUCCESS) {"); + $self->indent; + $self->pidl("PyErr_SetString(PyExc_RuntimeError, \"Unable to ndr pack\");"); + $self->pidl("return NULL;"); + $self->deindent; + $self->pidl("}"); + $self->pidl(""); + $self->pidl("return PyString_FromStringAndSize((char *)blob.data, blob.length);"); + $self->deindent; + $self->pidl("}"); + $self->pidl(""); + $self->pidl("static PyMethodDef py_$name\_methods[] = {"); + $self->indent; + $self->pidl("{ \"__ndr_pack__\", (PyCFunction)py_$name\_ndr_pack, METH_O|METH_NOARGS, \"NDR pack\" },"); + $self->pidl("{ NULL, NULL, 0, NULL }"); + $self->deindent; + $self->pidl("};"); $self->pidl(""); $self->pidl_hdr("PyAPI_DATA(PyTypeObject) $name\_Type;\n"); @@ -243,6 +269,7 @@ sub PythonStruct($$$$$$) $self->pidl(".tp_getset = $getsetters,"); $self->pidl(".tp_repr = py_talloc_default_repr,"); $self->pidl(".tp_doc = $docstring,"); + $self->pidl(".tp_methods = py_$name\_methods,"); $self->pidl(".tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,"); $self->pidl(".tp_new = py_$name\_new,"); $self->deindent; -- cgit From 14c4028f261cbbdba03cc8b3f0ec6e32a390c79e Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 24 May 2008 18:55:46 +0200 Subject: Support __ndr_unpack__ on DCE/RPC structures in Python. (This used to be commit 3b2bd4d849946aaff2b0adfbacdc15284670b916) --- source4/pidl/lib/Parse/Pidl/Samba4/Python.pm | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'source4/pidl/lib/Parse/Pidl') diff --git a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm index ad3cab6ffb..56d54d3d36 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm @@ -244,11 +244,33 @@ sub PythonStruct($$$$$$) $self->pidl("return PyString_FromStringAndSize((char *)blob.data, blob.length);"); $self->deindent; $self->pidl("}"); + $self->pidl(""); + $self->pidl("static PyObject *py_$name\_ndr_unpack(PyObject *py_obj, PyObject *args)"); + $self->pidl("{"); + $self->indent; + $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#\", &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_$name);"); + $self->pidl("if (err != NDR_ERR_SUCCESS) {"); + $self->indent; + $self->pidl("PyErr_SetString(PyExc_RuntimeError, \"Unable to ndr unpack\");"); + $self->pidl("return NULL;"); + $self->deindent; + $self->pidl("}"); + $self->pidl(""); + $self->pidl("return Py_None;"); + $self->deindent; + $self->pidl("}"); $self->pidl(""); $self->pidl("static PyMethodDef py_$name\_methods[] = {"); $self->indent; - $self->pidl("{ \"__ndr_pack__\", (PyCFunction)py_$name\_ndr_pack, METH_O|METH_NOARGS, \"NDR pack\" },"); + $self->pidl("{ \"__ndr_pack__\", (PyCFunction)py_$name\_ndr_pack, METH_O|METH_NOARGS, \"S.pack() -> blob\\nNDR pack\" },"); + $self->pidl("{ \"__ndr_unpack__\", (PyCFunction)py_$name\_ndr_pack, METH_O|METH_VARARGS, \"S.unpack(blob) -> None\\nNDR unpack\" },"); $self->pidl("{ NULL, NULL, 0, NULL }"); $self->deindent; $self->pidl("};"); -- cgit From e3bbe61d8162ebb5bf4ef2d3702587b39b0c4284 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 24 May 2008 19:49:54 +0200 Subject: Only provide __ndr_pack__ / __ndr_unpack__ if the push/pull functions are public. (This used to be commit dd43bdcb880d08013a600f81d40e5280db74c534) --- source4/pidl/lib/Parse/Pidl/Samba4/Python.pm | 103 ++++++++++++++------------- 1 file changed, 55 insertions(+), 48 deletions(-) (limited to 'source4/pidl/lib/Parse/Pidl') diff --git a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm index 56d54d3d36..b83f9a5360 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm @@ -227,54 +227,61 @@ sub PythonStruct($$$$$$) $self->pidl("}"); $self->pidl(""); - $self->pidl("static PyObject *py_$name\_ndr_pack(PyObject *py_obj)"); - $self->pidl("{"); - $self->indent; - $self->pidl("$cname *object = py_talloc_get_ptr(py_obj);"); - $self->pidl("DATA_BLOB blob;"); - $self->pidl("enum ndr_err_code err;"); - $self->pidl("err = ndr_push_struct_blob(&blob, py_talloc_get_mem_ctx(py_obj), NULL, object, ndr_push_$name);"); - $self->pidl("if (err != NDR_ERR_SUCCESS) {"); - $self->indent; - $self->pidl("PyErr_SetString(PyExc_RuntimeError, \"Unable to ndr pack\");"); - $self->pidl("return NULL;"); - $self->deindent; - $self->pidl("}"); - $self->pidl(""); - $self->pidl("return PyString_FromStringAndSize((char *)blob.data, blob.length);"); - $self->deindent; - $self->pidl("}"); - $self->pidl(""); + my $py_methods = "NULL"; - $self->pidl("static PyObject *py_$name\_ndr_unpack(PyObject *py_obj, PyObject *args)"); - $self->pidl("{"); - $self->indent; - $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#\", &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_$name);"); - $self->pidl("if (err != NDR_ERR_SUCCESS) {"); - $self->indent; - $self->pidl("PyErr_SetString(PyExc_RuntimeError, \"Unable to ndr unpack\");"); - $self->pidl("return NULL;"); - $self->deindent; - $self->pidl("}"); - $self->pidl(""); - $self->pidl("return Py_None;"); - $self->deindent; - $self->pidl("}"); - $self->pidl(""); - $self->pidl("static PyMethodDef py_$name\_methods[] = {"); - $self->indent; - $self->pidl("{ \"__ndr_pack__\", (PyCFunction)py_$name\_ndr_pack, METH_O|METH_NOARGS, \"S.pack() -> blob\\nNDR pack\" },"); - $self->pidl("{ \"__ndr_unpack__\", (PyCFunction)py_$name\_ndr_pack, METH_O|METH_VARARGS, \"S.unpack(blob) -> None\\nNDR unpack\" },"); - $self->pidl("{ NULL, NULL, 0, NULL }"); - $self->deindent; - $self->pidl("};"); - $self->pidl(""); + # If the struct is not public there ndr_pull/ndr_push functions will + # be static so not callable from here + if (has_property($d, "public")) { + $self->pidl("static PyObject *py_$name\_ndr_pack(PyObject *py_obj)"); + $self->pidl("{"); + $self->indent; + $self->pidl("$cname *object = py_talloc_get_ptr(py_obj);"); + $self->pidl("DATA_BLOB blob;"); + $self->pidl("enum ndr_err_code err;"); + $self->pidl("err = ndr_push_struct_blob(&blob, py_talloc_get_mem_ctx(py_obj), NULL, object, (ndr_push_flags_fn_t)ndr_push_$name);"); + $self->pidl("if (err != NDR_ERR_SUCCESS) {"); + $self->indent; + $self->pidl("PyErr_SetString(PyExc_RuntimeError, \"Unable to ndr pack\");"); + $self->pidl("return NULL;"); + $self->deindent; + $self->pidl("}"); + $self->pidl(""); + $self->pidl("return PyString_FromStringAndSize((char *)blob.data, blob.length);"); + $self->deindent; + $self->pidl("}"); + $self->pidl(""); + + $self->pidl("static PyObject *py_$name\_ndr_unpack(PyObject *py_obj, PyObject *args)"); + $self->pidl("{"); + $self->indent; + $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("\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);"); + $self->pidl("if (err != NDR_ERR_SUCCESS) {"); + $self->indent; + $self->pidl("PyErr_SetString(PyExc_RuntimeError, \"Unable to ndr unpack\");"); + $self->pidl("return NULL;"); + $self->deindent; + $self->pidl("}"); + $self->pidl(""); + $self->pidl("return Py_None;"); + $self->deindent; + $self->pidl("}"); + $self->pidl(""); + $py_methods = "py_$name\_methods"; + $self->pidl("static PyMethodDef $py_methods\[] = {"); + $self->indent; + $self->pidl("{ \"__ndr_pack__\", (PyCFunction)py_$name\_ndr_pack, METH_NOARGS, \"S.pack() -> blob\\nNDR pack\" },"); + $self->pidl("{ \"__ndr_unpack__\", (PyCFunction)py_$name\_ndr_unpack, METH_VARARGS, \"S.unpack(blob) -> None\\nNDR unpack\" },"); + $self->pidl("{ NULL, NULL, 0, NULL }"); + $self->deindent; + $self->pidl("};"); + $self->pidl(""); + } $self->pidl_hdr("PyAPI_DATA(PyTypeObject) $name\_Type;\n"); $self->pidl_hdr("#define $name\_Check(op) PyObject_TypeCheck(op, &$name\_Type)\n"); @@ -291,7 +298,7 @@ sub PythonStruct($$$$$$) $self->pidl(".tp_getset = $getsetters,"); $self->pidl(".tp_repr = py_talloc_default_repr,"); $self->pidl(".tp_doc = $docstring,"); - $self->pidl(".tp_methods = py_$name\_methods,"); + $self->pidl(".tp_methods = $py_methods,"); $self->pidl(".tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,"); $self->pidl(".tp_new = py_$name\_new,"); $self->deindent; -- cgit From 515b6ed5867bba8180bd0eeadbeab1c52bffc0ab Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 24 May 2008 20:00:37 +0200 Subject: Share struct used for interfaces in Python code. (This used to be commit 8501a3fc31e688dba696667a187821480e8cb714) --- source4/pidl/lib/Parse/Pidl/Samba4/Python.pm | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) (limited to 'source4/pidl/lib/Parse/Pidl') diff --git a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm index b83f9a5360..dea8f2c648 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm @@ -327,7 +327,7 @@ sub PythonFunctionBody($$$) { my ($self, $fn, $iface, $prettyname) = @_; - $self->pidl("$iface\_InterfaceObject *iface = ($iface\_InterfaceObject *)self;"); + $self->pidl("dcerpc_InterfaceObject *iface = (dcerpc_InterfaceObject *)self;"); $self->pidl("NTSTATUS status;"); $self->pidl("TALLOC_CTX *mem_ctx = talloc_new(NULL);"); $self->pidl("struct $fn->{NAME} *r = talloc_zero(mem_ctx, struct $fn->{NAME});"); @@ -607,13 +607,6 @@ sub Interface($$$) if (defined $interface->{PROPERTIES}->{uuid}) { $self->pidl_hdr("PyAPI_DATA(PyTypeObject) $interface->{NAME}_InterfaceType;\n"); - $self->pidl("typedef struct {"); - $self->indent; - $self->pidl("PyObject_HEAD"); - $self->pidl("struct dcerpc_pipe *pipe;"); - $self->deindent; - $self->pidl("} $interface->{NAME}_InterfaceObject;"); - $self->pidl(""); my @fns = (); @@ -646,7 +639,7 @@ sub Interface($$$) $self->pidl("static void interface_$interface->{NAME}_dealloc(PyObject* self)"); $self->pidl("{"); $self->indent; - $self->pidl("$interface->{NAME}_InterfaceObject *interface = ($interface->{NAME}_InterfaceObject *)self;"); + $self->pidl("dcerpc_InterfaceObject *interface = (dcerpc_InterfaceObject *)self;"); $self->pidl("talloc_free(interface->pipe);"); $self->pidl("PyObject_Del(self);"); $self->deindent; @@ -656,7 +649,7 @@ sub Interface($$$) $self->pidl("static PyObject *interface_$interface->{NAME}_new(PyTypeObject *self, PyObject *args, PyObject *kwargs)"); $self->pidl("{"); $self->indent; - $self->pidl("$interface->{NAME}_InterfaceObject *ret;"); + $self->pidl("dcerpc_InterfaceObject *ret;"); $self->pidl("const char *binding_string;"); $self->pidl("struct cli_credentials *credentials;"); $self->pidl("struct loadparm_context *lp_ctx = NULL;"); @@ -696,7 +689,7 @@ sub Interface($$$) $self->deindent; $self->pidl("}"); - $self->pidl("ret = PyObject_New($interface->{NAME}_InterfaceObject, &$interface->{NAME}_InterfaceType);"); + $self->pidl("ret = PyObject_New(dcerpc_InterfaceObject, &$interface->{NAME}_InterfaceType);"); $self->pidl(""); $self->pidl("event_ctx = event_context_init(mem_ctx);"); $self->pidl(""); @@ -732,7 +725,7 @@ sub Interface($$$) $self->indent; $self->pidl("PyObject_HEAD_INIT(NULL) 0,"); $self->pidl(".tp_name = \"$basename.$interface->{NAME}\","); - $self->pidl(".tp_basicsize = sizeof($interface->{NAME}_InterfaceObject),"); + $self->pidl(".tp_basicsize = sizeof(dcerpc_InterfaceObject),"); $self->pidl(".tp_dealloc = interface_$interface->{NAME}_dealloc,"); $self->pidl(".tp_methods = interface_$interface->{NAME}_methods,"); $self->pidl(".tp_doc = $docstring,"); @@ -1085,7 +1078,7 @@ sub Parse($$$$$) #include #include \"librpc/rpc/dcerpc.h\" #include \"scripting/python/pytalloc.h\" -#include \"scripting/python/pyrpc.h\" +#include \"librpc/rpc/pyrpc.h\" #include \"lib/events/events.h\" #include \"$hdr\" #include \"$ndr_hdr\" -- cgit From 654be49c010949a0420412450971effdbd4ce585 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 24 May 2008 21:02:56 +0200 Subject: Use manually written Python bindings for DCE/RPC rather than SWIG based. Use base class for pidl-generated DCE/RPC interface Python bindings. (This used to be commit 25e7fc8a2c7a5914c4db4bfe428fd0a8efbf0784) --- source4/pidl/lib/Parse/Pidl/Samba4/Python.pm | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) (limited to 'source4/pidl/lib/Parse/Pidl') diff --git a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm index dea8f2c648..f252dd4f27 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm @@ -636,16 +636,6 @@ sub Interface($$$) $self->pidl("};"); $self->pidl(""); - $self->pidl("static void interface_$interface->{NAME}_dealloc(PyObject* self)"); - $self->pidl("{"); - $self->indent; - $self->pidl("dcerpc_InterfaceObject *interface = (dcerpc_InterfaceObject *)self;"); - $self->pidl("talloc_free(interface->pipe);"); - $self->pidl("PyObject_Del(self);"); - $self->deindent; - $self->pidl("}"); - $self->pidl(""); - $self->pidl("static PyObject *interface_$interface->{NAME}_new(PyTypeObject *self, PyObject *args, PyObject *kwargs)"); $self->pidl("{"); $self->indent; @@ -726,7 +716,7 @@ sub Interface($$$) $self->pidl("PyObject_HEAD_INIT(NULL) 0,"); $self->pidl(".tp_name = \"$basename.$interface->{NAME}\","); $self->pidl(".tp_basicsize = sizeof(dcerpc_InterfaceObject),"); - $self->pidl(".tp_dealloc = interface_$interface->{NAME}_dealloc,"); + $self->pidl(".tp_base = &dcerpc_InterfaceType,"); $self->pidl(".tp_methods = interface_$interface->{NAME}_methods,"); $self->pidl(".tp_doc = $docstring,"); $self->pidl(".tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,"); -- cgit From 75e7962d2efb1aa6e45ca999b1a93829406de540 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 24 May 2008 22:13:32 +0200 Subject: Add convenience functions for setting Python objects from errors. (This used to be commit f1de723b89251cbc8140b838941f304a34871bf3) --- source4/pidl/lib/Parse/Pidl/Samba4/Python.pm | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'source4/pidl/lib/Parse/Pidl') 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")) { -- cgit From 21b6e9ec9ea08cc5e19a068d68331c178091caa6 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 24 May 2008 23:22:49 +0200 Subject: Add convenience function for creating objects with NDR error codes. (This used to be commit 991541a78c2428db89509081cc28072c9b542ffa) --- source4/pidl/lib/Parse/Pidl/Samba4/Python.pm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source4/pidl/lib/Parse/Pidl') diff --git a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm index 5e76ff027b..26197365ee 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm @@ -241,7 +241,7 @@ sub PythonStruct($$$$$$) $self->pidl("err = ndr_push_struct_blob(&blob, py_talloc_get_mem_ctx(py_obj), NULL, object, (ndr_push_flags_fn_t)ndr_push_$name);"); $self->pidl("if (err != NDR_ERR_SUCCESS) {"); $self->indent; - $self->pidl("PyErr_SetString(PyExc_RuntimeError, \"Unable to ndr pack\");"); + $self->pidl("PyErr_SetNdrError(err);"); $self->pidl("return NULL;"); $self->deindent; $self->pidl("}"); @@ -263,7 +263,7 @@ sub PythonStruct($$$$$$) $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);"); $self->pidl("if (err != NDR_ERR_SUCCESS) {"); $self->indent; - $self->pidl("PyErr_SetString(PyExc_RuntimeError, \"Unable to ndr unpack\");"); + $self->pidl("PyErr_SetNdrError(err);"); $self->pidl("return NULL;"); $self->deindent; $self->pidl("}"); -- cgit 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/pidl/lib/Parse/Pidl/Samba4/Python.pm | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'source4/pidl/lib/Parse/Pidl') diff --git a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm index 26197365ee..2795d987f7 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm @@ -409,7 +409,14 @@ sub PythonFunctionBody($$$) } } $self->pidl("status = dcerpc_$fn->{NAME}(iface->pipe, mem_ctx, r);"); - $self->handle_ntstatus("status", "NULL", "mem_ctx"); + $self->pidl("if (NT_STATUS_IS_ERR(status)) {"); + $self->indent; + $self->pidl("PyErr_SetDCERPCStatus(iface->pipe, status);"); + $self->pidl("talloc_free(mem_ctx);"); + $self->pidl("return NULL;"); + $self->deindent; + $self->pidl("}"); + $self->pidl(""); $env = GenerateFunctionOutEnv($fn, "r->"); my $i = 0; -- cgit From 928ecbaebbde00515d08fd530db7c99169c905ef Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sun, 25 May 2008 04:23:03 +0200 Subject: Add support for secondary contexts from Python. (This used to be commit 16d1ad050546ae6500153438db8d3c857e6f3ad5) --- source4/pidl/lib/Parse/Pidl/Samba4/Python.pm | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) (limited to 'source4/pidl/lib/Parse/Pidl') diff --git a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm index 2795d987f7..dbbdb6bca1 100644 --- a/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm +++ b/source4/pidl/lib/Parse/Pidl/Samba4/Python.pm @@ -650,20 +650,20 @@ sub Interface($$$) $self->pidl("const char *binding_string;"); $self->pidl("struct cli_credentials *credentials;"); $self->pidl("struct loadparm_context *lp_ctx = NULL;"); - $self->pidl("PyObject *py_lp_ctx = Py_None, *py_credentials = Py_None;"); + $self->pidl("PyObject *py_lp_ctx = Py_None, *py_credentials = Py_None, *py_basis = Py_None;"); $self->pidl("TALLOC_CTX *mem_ctx = NULL;"); $self->pidl("struct event_context *event_ctx;"); $self->pidl("NTSTATUS status;"); $self->pidl(""); $self->pidl("const char *kwnames[] = {"); $self->indent; - $self->pidl("\"binding\", \"lp_ctx\", \"credentials\", NULL"); + $self->pidl("\"binding\", \"lp_ctx\", \"credentials\", \"basis_connection\", NULL"); $self->deindent; $self->pidl("};"); $self->pidl("extern struct loadparm_context *lp_from_py_object(PyObject *py_obj);"); $self->pidl("extern struct cli_credentials *cli_credentials_from_py_object(PyObject *py_obj);"); $self->pidl(""); - $self->pidl("if (!PyArg_ParseTupleAndKeywords(args, kwargs, \"s|OO:$interface->{NAME}\", discard_const_p(char *, kwnames), &binding_string, &py_lp_ctx, &py_credentials)) {"); + $self->pidl("if (!PyArg_ParseTupleAndKeywords(args, kwargs, \"s|OOO:$interface->{NAME}\", discard_const_p(char *, kwnames), &binding_string, &py_lp_ctx, &py_credentials, &py_basis)) {"); $self->indent; $self->pidl("return NULL;"); $self->deindent; @@ -691,8 +691,28 @@ sub Interface($$$) $self->pidl("event_ctx = event_context_init(mem_ctx);"); $self->pidl(""); + $self->pidl("if (py_basis != Py_None) {"); + $self->indent; + $self->pidl("struct dcerpc_pipe *base_pipe;"); + $self->pidl(""); + $self->pidl("if (!PyObject_TypeCheck(py_basis, &dcerpc_InterfaceType)) {"); + $self->indent; + $self->pidl("PyErr_SetString(PyExc_ValueError, \"basis_connection must be a DCE/RPC connection\");"); + $self->pidl("talloc_free(mem_ctx);"); + $self->pidl("return NULL;"); + $self->deindent; + $self->pidl("}"); + $self->pidl(""); + $self->pidl("base_pipe = ((dcerpc_InterfaceObject *)py_basis)->pipe;"); + $self->pidl(""); + $self->pidl("status = dcerpc_secondary_context(base_pipe, &ret->pipe, &ndr_table_$interface->{NAME});"); + $self->deindent; + $self->pidl("} else {"); + $self->indent; $self->pidl("status = dcerpc_pipe_connect(NULL, &ret->pipe, binding_string, "); $self->pidl(" &ndr_table_$interface->{NAME}, credentials, event_ctx, lp_ctx);"); + $self->deindent; + $self->pidl("}"); $self->handle_ntstatus("status", "NULL", "mem_ctx"); $self->pidl("ret->pipe->conn->flags |= DCERPC_NDR_REF_ALLOC;"); -- cgit