diff options
-rw-r--r-- | pidl/lib/Parse/Pidl/Samba4/Python.pm | 40 | ||||
-rw-r--r-- | source4/lib/messaging/pymessaging.c | 2 | ||||
-rw-r--r-- | source4/librpc/rpc/pyrpc.c | 177 | ||||
-rw-r--r-- | source4/librpc/rpc/pyrpc.h | 29 | ||||
-rw-r--r-- | source4/librpc/rpc/pyrpc_util.c | 183 | ||||
-rw-r--r-- | source4/librpc/rpc/pyrpc_util.h | 30 | ||||
-rwxr-xr-x | source4/librpc/wscript_build | 54 | ||||
-rw-r--r-- | source4/scripting/python/samba/tests/dcerpc/rpcecho.py | 2 |
8 files changed, 276 insertions, 241 deletions
diff --git a/pidl/lib/Parse/Pidl/Samba4/Python.pm b/pidl/lib/Parse/Pidl/Samba4/Python.pm index 64ddf4a925..715a400e79 100644 --- a/pidl/lib/Parse/Pidl/Samba4/Python.pm +++ b/pidl/lib/Parse/Pidl/Samba4/Python.pm @@ -25,7 +25,8 @@ sub new($) { my $self = { res => "", res_hdr => "", tabs => "", constants => {}, module_methods => [], module_objects => [], ready_types => [], module_imports => [], type_imports => {}, - patch_type_calls => [], readycode => [] }; + patch_type_calls => [], prereadycode => [], + postreadycode => []}; bless($self, $class); } @@ -728,7 +729,9 @@ sub Interface($$$) $self->pidl(""); $self->register_module_typeobject($interface->{NAME}, "&$if_typename"); - $self->register_module_readycode(["if (!PyInterface_AddNdrRpcMethods(&$if_typename, py_ndr_$interface->{NAME}\_methods))", "\treturn;", ""]); + my $dcerpc_typename = $self->import_type_variable("base", "ClientConnection"); + $self->register_module_prereadycode(["$if_typename.tp_base = $dcerpc_typename;", ""]); + $self->register_module_postreadycode(["if (!PyInterface_AddNdrRpcMethods(&$if_typename, py_ndr_$interface->{NAME}\_methods))", "\treturn;", ""]); } $self->pidl_hdr("\n"); @@ -765,6 +768,17 @@ sub register_module_import($$) push (@{$self->{module_imports}}, $basename) unless (grep(/^$basename$/,@{$self->{module_imports}})); } +sub import_type_variable($$$) +{ + my ($self, $module, $name) = @_; + + $self->register_module_import($module); + unless (defined($self->{type_imports}->{$name})) { + $self->{type_imports}->{$name} = $module; + } + return "$name\_Type"; +} + sub use_type_variable($$) { my ($self, $orig_ctype) = @_; @@ -779,11 +793,7 @@ sub use_type_variable($$) } # If this is an external type, make sure we do the right imports. if (($ctype->{BASEFILE} ne $self->{BASENAME})) { - $self->register_module_import($ctype->{BASEFILE}); - unless (defined($self->{type_imports}->{$ctype->{NAME}})) { - $self->{type_imports}->{$ctype->{NAME}} = $ctype->{BASEFILE}; - } - return "$ctype->{NAME}_Type"; + return $self->import_type_variable($ctype->{BASEFILE}, $ctype->{NAME}); } return "&$ctype->{NAME}_Type"; } @@ -796,11 +806,18 @@ sub register_patch_type_call($$$) } -sub register_module_readycode($$) +sub register_module_prereadycode($$) { my ($self, $code) = @_; - push (@{$self->{readycode}}, @$code); + push (@{$self->{prereadycode}}, @$code); +} + +sub register_module_postreadycode($$) +{ + my ($self, $code) = @_; + + push (@{$self->{postreadycode}}, @$code); } sub register_module_object($$$) @@ -1204,6 +1221,7 @@ sub Parse($$$$$) #include \"includes.h\" #include \"lib/talloc/pytalloc.h\" #include \"librpc/rpc/pyrpc.h\" +#include \"librpc/rpc/pyrpc_util.h\" #include \"$hdr\" #include \"$ndr_hdr\" @@ -1253,12 +1271,14 @@ sub Parse($$$$$) $self->pidl(""); } + $self->pidl($_) foreach (@{$self->{prereadycode}}); + foreach (@{$self->{ready_types}}) { $self->pidl("if (PyType_Ready($_) < 0)"); $self->pidl("\treturn;"); } - $self->pidl($_) foreach (@{$self->{readycode}}); + $self->pidl($_) foreach (@{$self->{postreadycode}}); foreach (@{$self->{patch_type_calls}}) { my ($typename, $cvar) = @$_; diff --git a/source4/lib/messaging/pymessaging.c b/source4/lib/messaging/pymessaging.c index 131f6c5f74..e8dcd7dd71 100644 --- a/source4/lib/messaging/pymessaging.c +++ b/source4/lib/messaging/pymessaging.c @@ -23,7 +23,7 @@ #include "includes.h" #include "scripting/python/modules.h" #include "libcli/util/pyerrors.h" -#include "librpc/rpc/pyrpc.h" +#include "librpc/rpc/pyrpc_util.h" #include "librpc/ndr/libndr.h" #include "lib/messaging/irpc.h" #include "lib/messaging/messaging.h" diff --git a/source4/librpc/rpc/pyrpc.c b/source4/librpc/rpc/pyrpc.c index bcfe8cf795..52b5d008b4 100644 --- a/source4/librpc/rpc/pyrpc.c +++ b/source4/librpc/rpc/pyrpc.c @@ -2,17 +2,17 @@ Unix SMB/CIFS implementation. Samba utility functions Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2008 - + This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. - + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - + You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ @@ -21,86 +21,13 @@ #include "includes.h" #include <structmember.h> #include "librpc/rpc/pyrpc.h" -#include "librpc/rpc/dcerpc.h" #include "lib/events/events.h" #include "param/pyparam.h" +#include "librpc/rpc/dcerpc.h" +#include "librpc/rpc/pyrpc_util.h" #include "auth/credentials/pycredentials.h" -static void PyErr_SetDCERPCStatus(struct dcerpc_pipe *p, NTSTATUS status); - -static PyObject *py_dcerpc_run_function(dcerpc_InterfaceObject *iface, - const struct PyNdrRpcMethodDef *md, - PyObject *args, PyObject *kwargs) -{ - TALLOC_CTX *mem_ctx; - NTSTATUS status; - void *r; - PyObject *result = Py_None; - - if (md->pack_in_data == NULL || md->unpack_out_data == NULL) { - PyErr_SetString(PyExc_NotImplementedError, "No marshalling code available yet"); - return NULL; - } - - mem_ctx = talloc_new(NULL); - if (mem_ctx == NULL) { - PyErr_NoMemory(); - return NULL; - } - - r = talloc_zero_size(mem_ctx, md->table->calls[md->opnum].struct_size); - if (r == NULL) { - PyErr_NoMemory(); - return NULL; - } - - if (!md->pack_in_data(args, kwargs, r)) { - talloc_free(mem_ctx); - return NULL; - } - - status = md->call(iface->binding_handle, mem_ctx, r); - if (!NT_STATUS_IS_OK(status)) { - PyErr_SetDCERPCStatus(iface->pipe, status); - talloc_free(mem_ctx); - return NULL; - } - - result = md->unpack_out_data(r); - - talloc_free(mem_ctx); - return result; -} - -static PyObject *py_dcerpc_call_wrapper(PyObject *self, PyObject *args, void *wrapped, PyObject *kwargs) -{ - dcerpc_InterfaceObject *iface = (dcerpc_InterfaceObject *)self; - const struct PyNdrRpcMethodDef *md = (const struct PyNdrRpcMethodDef *)wrapped; - - return py_dcerpc_run_function(iface, md, args, kwargs); -} - - -bool PyInterface_AddNdrRpcMethods(PyTypeObject *ifacetype, const struct PyNdrRpcMethodDef *mds) -{ - int i; - for (i = 0; mds[i].name; i++) { - PyObject *ret; - struct wrapperbase *wb = (struct wrapperbase *)calloc(sizeof(struct wrapperbase), 1); - - wb->name = discard_const_p(char, mds[i].name); - wb->flags = PyWrapperFlag_KEYWORDS; - wb->wrapper = (wrapperfunc)py_dcerpc_call_wrapper; - wb->doc = discard_const_p(char, mds[i].doc); - - ret = PyDescr_NewWrapper(ifacetype, wb, discard_const_p(void, &mds[i])); - - PyDict_SetItemString(ifacetype->tp_dict, mds[i].name, - (PyObject *)ret); - } - - return true; -} +staticforward PyTypeObject dcerpc_InterfaceType; static bool PyString_AsGUID(PyObject *object, struct GUID *uuid) { @@ -144,13 +71,13 @@ static bool ndr_syntax_from_py_object(PyObject *object, struct ndr_syntax_id *sy PyErr_SetString(PyExc_TypeError, "Expected UUID or syntax id tuple"); return false; -} +} static PyObject *py_iface_server_name(PyObject *obj, void *closure) { const char *server_name; dcerpc_InterfaceObject *iface = (dcerpc_InterfaceObject *)obj; - + server_name = dcerpc_server_name(iface->pipe); if (server_name == NULL) Py_RETURN_NONE; @@ -205,14 +132,6 @@ static PyMemberDef dcerpc_interface_members[] = { { NULL } }; -static void PyErr_SetDCERPCStatus(struct dcerpc_pipe *p, NTSTATUS status) -{ - if (p && NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) { - status = dcerpc_fault_to_nt_status(p->last_fault_code); - } - PyErr_SetNTSTATUS(status); -} - static PyObject *py_iface_request(PyObject *self, PyObject *args, PyObject *kwargs) { dcerpc_InterfaceObject *iface = (dcerpc_InterfaceObject *)self; @@ -292,84 +211,6 @@ static PyObject *py_iface_alter_context(PyObject *self, PyObject *args, PyObject Py_RETURN_NONE; } -PyObject *py_dcerpc_interface_init_helper(PyTypeObject *type, PyObject *args, PyObject *kwargs, const struct ndr_interface_table *table) -{ - dcerpc_InterfaceObject *ret; - const char *binding_string; - struct cli_credentials *credentials; - struct loadparm_context *lp_ctx = NULL; - PyObject *py_lp_ctx = Py_None, *py_credentials = Py_None, *py_basis = Py_None; - TALLOC_CTX *mem_ctx = NULL; - struct tevent_context *event_ctx; - NTSTATUS status; - - const char *kwnames[] = { - "binding", "lp_ctx", "credentials", "basis_connection", NULL - }; - - if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s|OOO:samr", discard_const_p(char *, kwnames), &binding_string, &py_lp_ctx, &py_credentials, &py_basis)) { - return NULL; - } - - mem_ctx = talloc_new(NULL); - if (mem_ctx == NULL) { - PyErr_NoMemory(); - return NULL; - } - - lp_ctx = lpcfg_from_py_object(mem_ctx, py_lp_ctx); - if (lp_ctx == NULL) { - PyErr_SetString(PyExc_TypeError, "Expected loadparm context"); - talloc_free(mem_ctx); - return NULL; - } - - status = dcerpc_init(lp_ctx); - if (!NT_STATUS_IS_OK(status)) { - PyErr_SetNTSTATUS(status); - talloc_free(mem_ctx); - return NULL; - } - credentials = cli_credentials_from_py_object(py_credentials); - if (credentials == NULL) { - PyErr_SetString(PyExc_TypeError, "Expected credentials"); - talloc_free(mem_ctx); - return NULL; - } - ret = PyObject_New(dcerpc_InterfaceObject, type); - ret->mem_ctx = mem_ctx; - - event_ctx = s4_event_context_init(ret->mem_ctx); - - if (py_basis != Py_None) { - struct dcerpc_pipe *base_pipe; - - if (!PyObject_TypeCheck(py_basis, &dcerpc_InterfaceType)) { - PyErr_SetString(PyExc_ValueError, "basis_connection must be a DCE/RPC connection"); - talloc_free(mem_ctx); - return NULL; - } - - base_pipe = talloc_reference(mem_ctx, ((dcerpc_InterfaceObject *)py_basis)->pipe); - - status = dcerpc_secondary_context(base_pipe, &ret->pipe, table); - - ret->pipe = talloc_steal(ret->mem_ctx, ret->pipe); - } else { - status = dcerpc_pipe_connect(event_ctx, &ret->pipe, binding_string, - table, credentials, event_ctx, lp_ctx); - } - if (NT_STATUS_IS_ERR(status)) { - PyErr_SetNTSTATUS(status); - talloc_free(mem_ctx); - return NULL; - } - - ret->pipe->conn->flags |= DCERPC_NDR_REF_ALLOC; - ret->binding_handle = ret->pipe->binding_handle; - return (PyObject *)ret; -} - static PyMethodDef dcerpc_interface_methods[] = { { "request", (PyCFunction)py_iface_request, METH_VARARGS|METH_KEYWORDS, "S.request(opnum, data, object=None) -> data\nMake a raw request" }, { "alter_context", (PyCFunction)py_iface_alter_context, METH_VARARGS|METH_KEYWORDS, "S.alter_context(syntax)\nChange to a different interface" }, @@ -479,7 +320,7 @@ static PyObject *dcerpc_interface_new(PyTypeObject *type, PyObject *args, PyObje return (PyObject *)ret; } -PyTypeObject dcerpc_InterfaceType = { +static PyTypeObject dcerpc_InterfaceType = { PyObject_HEAD_INIT(NULL) 0, .tp_name = "dcerpc.ClientConnection", .tp_basicsize = sizeof(dcerpc_InterfaceObject), diff --git a/source4/librpc/rpc/pyrpc.h b/source4/librpc/rpc/pyrpc.h index 4ba9bd3e1f..fb5f35fcf1 100644 --- a/source4/librpc/rpc/pyrpc.h +++ b/source4/librpc/rpc/pyrpc.h @@ -35,11 +35,6 @@ #define dom_sid2_Check dom_sid_Check #define dom_sid28_Check dom_sid_Check -/* This macro is only provided by Python >= 2.3 */ -#ifndef PyAPI_DATA -# define PyAPI_DATA(RTYPE) extern RTYPE -#endif - typedef struct { PyObject_HEAD TALLOC_CTX *mem_ctx; @@ -47,28 +42,4 @@ typedef struct { struct dcerpc_binding_handle *binding_handle; } dcerpc_InterfaceObject; -PyAPI_DATA(PyTypeObject) dcerpc_InterfaceType; - -#define PyErr_FromNdrError(err) Py_BuildValue("(is)", err, ndr_map_error2string(err)) - -#define PyErr_SetNdrError(err) \ - PyErr_SetObject(PyExc_RuntimeError, PyErr_FromNdrError(err)) - -typedef NTSTATUS (*py_dcerpc_call_fn) (struct dcerpc_binding_handle *, TALLOC_CTX *, void *); -typedef bool (*py_data_pack_fn) (PyObject *args, PyObject *kwargs, void *r); -typedef PyObject *(*py_data_unpack_fn) (void *r); - -struct PyNdrRpcMethodDef { - const char *name; - const char *doc; - py_dcerpc_call_fn call; - py_data_pack_fn pack_in_data; - py_data_unpack_fn unpack_out_data; - uint32_t opnum; - const struct ndr_interface_table *table; -}; - -bool PyInterface_AddNdrRpcMethods(PyTypeObject *object, const struct PyNdrRpcMethodDef *mds); -PyObject *py_dcerpc_interface_init_helper(PyTypeObject *type, PyObject *args, PyObject *kwargs, const struct ndr_interface_table *table); - #endif /* _PYRPC_H_ */ diff --git a/source4/librpc/rpc/pyrpc_util.c b/source4/librpc/rpc/pyrpc_util.c index e1d3450336..2af868c0c2 100644 --- a/source4/librpc/rpc/pyrpc_util.c +++ b/source4/librpc/rpc/pyrpc_util.c @@ -23,6 +23,11 @@ #include <Python.h> #include "includes.h" #include "librpc/rpc/pyrpc_util.h" +#include "librpc/rpc/dcerpc.h" +#include "librpc/rpc/pyrpc.h" +#include "param/pyparam.h" +#include "auth/credentials/pycredentials.h" +#include "lib/events/events.h" #ifndef Py_TYPE /* Py_TYPE is only available on Python > 2.6 */ #define Py_TYPE(ob) (((PyObject*)(ob))->ob_type) @@ -31,7 +36,7 @@ bool py_check_dcerpc_type(PyObject *obj, const char *module, const char *typename) { PyObject *mod; - PyTypeObject *type; + PyTypeObject *type; bool ret; mod = PyImport_ImportModule(module); @@ -59,3 +64,179 @@ bool py_check_dcerpc_type(PyObject *obj, const char *module, const char *typenam return ret; } + +PyObject *py_dcerpc_interface_init_helper(PyTypeObject *type, PyObject *args, PyObject *kwargs, const struct ndr_interface_table *table) +{ + dcerpc_InterfaceObject *ret; + const char *binding_string; + struct cli_credentials *credentials; + struct loadparm_context *lp_ctx = NULL; + PyObject *py_lp_ctx = Py_None, *py_credentials = Py_None, *py_basis = Py_None; + TALLOC_CTX *mem_ctx = NULL; + struct tevent_context *event_ctx; + NTSTATUS status; + + const char *kwnames[] = { + "binding", "lp_ctx", "credentials", "basis_connection", NULL + }; + + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s|OOO:samr", discard_const_p(char *, kwnames), &binding_string, &py_lp_ctx, &py_credentials, &py_basis)) { + return NULL; + } + + mem_ctx = talloc_new(NULL); + if (mem_ctx == NULL) { + PyErr_NoMemory(); + return NULL; + } + + lp_ctx = lpcfg_from_py_object(mem_ctx, py_lp_ctx); + if (lp_ctx == NULL) { + PyErr_SetString(PyExc_TypeError, "Expected loadparm context"); + talloc_free(mem_ctx); + return NULL; + } + + status = dcerpc_init(lp_ctx); + if (!NT_STATUS_IS_OK(status)) { + PyErr_SetNTSTATUS(status); + talloc_free(mem_ctx); + return NULL; + } + credentials = cli_credentials_from_py_object(py_credentials); + if (credentials == NULL) { + PyErr_SetString(PyExc_TypeError, "Expected credentials"); + talloc_free(mem_ctx); + return NULL; + } + ret = PyObject_New(dcerpc_InterfaceObject, type); + ret->mem_ctx = mem_ctx; + + event_ctx = s4_event_context_init(ret->mem_ctx); + + if (py_basis != Py_None) { + struct dcerpc_pipe *base_pipe; + PyObject *py_base; + PyTypeObject *ClientConnection_Type; + + py_base = PyImport_ImportModule("samba.dcerpc.base"); + if (py_base == NULL) { + talloc_free(mem_ctx); + return NULL; + } + + ClientConnection_Type = (PyTypeObject *)PyObject_GetAttrString(py_base, "ClientConnection"); + if (ClientConnection_Type == NULL) { + PyErr_SetNone(PyExc_TypeError); + talloc_free(mem_ctx); + return NULL; + } + + if (!PyObject_TypeCheck(py_basis, ClientConnection_Type)) { + PyErr_SetString(PyExc_TypeError, "basis_connection must be a DCE/RPC connection"); + talloc_free(mem_ctx); + return NULL; + } + + base_pipe = talloc_reference(mem_ctx, ((dcerpc_InterfaceObject *)py_basis)->pipe); + + status = dcerpc_secondary_context(base_pipe, &ret->pipe, table); + + ret->pipe = talloc_steal(ret->mem_ctx, ret->pipe); + } else { + status = dcerpc_pipe_connect(event_ctx, &ret->pipe, binding_string, + table, credentials, event_ctx, lp_ctx); + } + if (NT_STATUS_IS_ERR(status)) { + PyErr_SetNTSTATUS(status); + talloc_free(mem_ctx); + return NULL; + } + + ret->pipe->conn->flags |= DCERPC_NDR_REF_ALLOC; + ret->binding_handle = ret->pipe->binding_handle; + return (PyObject *)ret; +} + +static PyObject *py_dcerpc_run_function(dcerpc_InterfaceObject *iface, + const struct PyNdrRpcMethodDef *md, + PyObject *args, PyObject *kwargs) +{ + TALLOC_CTX *mem_ctx; + NTSTATUS status; + void *r; + PyObject *result = Py_None; + + if (md->pack_in_data == NULL || md->unpack_out_data == NULL) { + PyErr_SetString(PyExc_NotImplementedError, "No marshalling code available yet"); + return NULL; + } + + mem_ctx = talloc_new(NULL); + if (mem_ctx == NULL) { + PyErr_NoMemory(); + return NULL; + } + + r = talloc_zero_size(mem_ctx, md->table->calls[md->opnum].struct_size); + if (r == NULL) { + PyErr_NoMemory(); + return NULL; + } + + if (!md->pack_in_data(args, kwargs, r)) { + talloc_free(mem_ctx); + return NULL; + } + + status = md->call(iface->binding_handle, mem_ctx, r); + if (!NT_STATUS_IS_OK(status)) { + PyErr_SetDCERPCStatus(iface->pipe, status); + talloc_free(mem_ctx); + return NULL; + } + + result = md->unpack_out_data(r); + + talloc_free(mem_ctx); + return result; +} + +static PyObject *py_dcerpc_call_wrapper(PyObject *self, PyObject *args, void *wrapped, PyObject *kwargs) +{ + dcerpc_InterfaceObject *iface = (dcerpc_InterfaceObject *)self; + const struct PyNdrRpcMethodDef *md = (const struct PyNdrRpcMethodDef *)wrapped; + + return py_dcerpc_run_function(iface, md, args, kwargs); +} + +bool PyInterface_AddNdrRpcMethods(PyTypeObject *ifacetype, const struct PyNdrRpcMethodDef *mds) +{ + int i; + for (i = 0; mds[i].name; i++) { + PyObject *ret; + struct wrapperbase *wb = (struct wrapperbase *)calloc(sizeof(struct wrapperbase), 1); + + wb->name = discard_const_p(char, mds[i].name); + wb->flags = PyWrapperFlag_KEYWORDS; + wb->wrapper = (wrapperfunc)py_dcerpc_call_wrapper; + wb->doc = discard_const_p(char, mds[i].doc); + + ret = PyDescr_NewWrapper(ifacetype, wb, discard_const_p(void, &mds[i])); + + PyDict_SetItemString(ifacetype->tp_dict, mds[i].name, + (PyObject *)ret); + } + + return true; +} + +void PyErr_SetDCERPCStatus(struct dcerpc_pipe *p, NTSTATUS status) +{ + if (p && NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) { + status = dcerpc_fault_to_nt_status(p->last_fault_code); + } + PyErr_SetNTSTATUS(status); +} + + diff --git a/source4/librpc/rpc/pyrpc_util.h b/source4/librpc/rpc/pyrpc_util.h index 67fd4fcef1..abd7f6ba7b 100644 --- a/source4/librpc/rpc/pyrpc_util.h +++ b/source4/librpc/rpc/pyrpc_util.h @@ -23,6 +23,36 @@ #ifndef __PYRPC_UTIL_H__ #define __PYRPC_UTIL_H__ +#include "librpc/rpc/pyrpc.h" + +/* This macro is only provided by Python >= 2.3 */ +#ifndef PyAPI_DATA +# define PyAPI_DATA(RTYPE) extern RTYPE +#endif + +#define PyErr_FromNdrError(err) Py_BuildValue("(is)", err, ndr_map_error2string(err)) + +#define PyErr_SetNdrError(err) \ + PyErr_SetObject(PyExc_RuntimeError, PyErr_FromNdrError(err)) + +void PyErr_SetDCERPCStatus(struct dcerpc_pipe *p, NTSTATUS status); + +typedef NTSTATUS (*py_dcerpc_call_fn) (struct dcerpc_binding_handle *, TALLOC_CTX *, void *); +typedef bool (*py_data_pack_fn) (PyObject *args, PyObject *kwargs, void *r); +typedef PyObject *(*py_data_unpack_fn) (void *r); + +struct PyNdrRpcMethodDef { + const char *name; + const char *doc; + py_dcerpc_call_fn call; + py_data_pack_fn pack_in_data; + py_data_unpack_fn unpack_out_data; + uint32_t opnum; + const struct ndr_interface_table *table; +}; + bool py_check_dcerpc_type(PyObject *obj, const char *module, const char *typename); +bool PyInterface_AddNdrRpcMethods(PyTypeObject *object, const struct PyNdrRpcMethodDef *mds); +PyObject *py_dcerpc_interface_init_helper(PyTypeObject *type, PyObject *args, PyObject *kwargs, const struct ndr_interface_table *table); #endif /* __PYRPC_UTIL_H__ */ diff --git a/source4/librpc/wscript_build b/source4/librpc/wscript_build index 69f3850efb..a48c1ead01 100755 --- a/source4/librpc/wscript_build +++ b/source4/librpc/wscript_build @@ -639,159 +639,151 @@ bld.SAMBA_LIBRARY('dcerpc', bld.SAMBA_SUBSYSTEM('pyrpc_util', source='rpc/pyrpc_util.c', - public_deps='PYTALLOC', + public_deps='PYTALLOC pyparam_util pycredentials dcerpc', needs_python=True, ) bld.SAMBA_PYTHON('python_dcerpc', source='rpc/pyrpc.c', - public_deps='LIBCLI_SMB LIBSAMBA-UTIL LIBSAMBA-HOSTCONFIG dcerpc_samr RPC_NDR_LSA DYNCONFIG pycredentials pyparam_util', + public_deps='LIBCLI_SMB LIBSAMBA-UTIL LIBSAMBA-HOSTCONFIG dcerpc_samr RPC_NDR_LSA DYNCONFIG pyrpc_util', realname='samba/dcerpc/base.so' ) bld.SAMBA_PYTHON('python_echo', source='../../librpc/gen_ndr/py_echo.c', - deps='RPC_NDR_ECHO PYTALLOC pyparam_util pycredentials python_dcerpc', + deps='RPC_NDR_ECHO PYTALLOC pyrpc_util', realname='samba/dcerpc/echo.so' ) bld.SAMBA_PYTHON('python_winreg', source='../../librpc/gen_ndr/py_winreg.c', - deps='RPC_NDR_WINREG PYTALLOC pyparam_util pycredentials python_dcerpc', + deps='RPC_NDR_WINREG PYTALLOC pyrpc_util', realname='samba/dcerpc/winreg.so' ) bld.SAMBA_PYTHON('python_dcerpc_misc', source='../../librpc/gen_ndr/py_misc.c', - deps='PYTALLOC python_dcerpc NDR_MISC NDR_KRB5PAC', + deps='PYTALLOC pyrpc_util NDR_MISC NDR_KRB5PAC', realname='samba/dcerpc/misc.so' ) bld.SAMBA_PYTHON('python_initshutdown', source='../../librpc/gen_ndr/py_initshutdown.c', - deps='RPC_NDR_INITSHUTDOWN PYTALLOC pyparam_util pycredentials python_dcerpc', + deps='RPC_NDR_INITSHUTDOWN PYTALLOC pyrpc_util', realname='samba/dcerpc/initshutdown.so' ) bld.SAMBA_PYTHON('python_epmapper', source='../../librpc/gen_ndr/py_epmapper.c', - deps='dcerpc PYTALLOC pyparam_util pycredentials python_dcerpc', + deps='dcerpc PYTALLOC pyrpc_util', realname='samba/dcerpc/epmapper.so' ) bld.SAMBA_PYTHON('python_mgmt', source='../../librpc/gen_ndr/py_mgmt.c', - deps='PYTALLOC param pycredentials dcerpc python_dcerpc', + deps='PYTALLOC dcerpc pyrpc_util', realname='samba/dcerpc/mgmt.so' ) bld.SAMBA_PYTHON('python_atsvc', source='../../librpc/gen_ndr/py_atsvc.c', - deps='dcerpc_atsvc PYTALLOC pyparam_util pycredentials python_dcerpc', + deps='dcerpc_atsvc PYTALLOC pyrpc_util', realname='samba/dcerpc/atsvc.so' ) bld.SAMBA_PYTHON('python_dcerpc_nbt', source='../../librpc/gen_ndr/py_nbt.c', - deps='NDR_NBT PYTALLOC pyparam_util pycredentials python_dcerpc', + deps='NDR_NBT PYTALLOC pyrpc_util', realname='samba/dcerpc/nbt.so' ) bld.SAMBA_PYTHON('python_samr', source='../../librpc/gen_ndr/py_samr.c', - deps='dcerpc_samr PYTALLOC pycredentials pyparam_util python_dcerpc', + deps='dcerpc_samr PYTALLOC pyrpc_util', realname='samba/dcerpc/samr.so' ) bld.SAMBA_PYTHON('python_svcctl', source='../../librpc/gen_ndr/py_svcctl.c', - deps='RPC_NDR_SVCCTL PYTALLOC pyparam_util pycredentials python_dcerpc', + deps='RPC_NDR_SVCCTL PYTALLOC pyrpc_util', realname='samba/dcerpc/svcctl.so' ) bld.SAMBA_PYTHON('python_lsa', source='../../librpc/gen_ndr/py_lsa.c', - deps='RPC_NDR_LSA PYTALLOC pyparam_util pycredentials python_dcerpc', + deps='RPC_NDR_LSA PYTALLOC pyrpc_util', realname='samba/dcerpc/lsa.so' ) bld.SAMBA_PYTHON('python_wkssvc', source='../../librpc/gen_ndr/py_wkssvc.c', - deps='RPC_NDR_WKSSVC PYTALLOC pyparam_util pycredentials python_dcerpc', + deps='RPC_NDR_WKSSVC PYTALLOC pyrpc_util', realname='samba/dcerpc/wkssvc.so' ) bld.SAMBA_PYTHON('python_dfs', source='../../librpc/gen_ndr/py_dfs.c', - deps='RPC_NDR_DFS PYTALLOC pyparam_util pycredentials python_dcerpc', + deps='RPC_NDR_DFS PYTALLOC pyrpc_util', realname='samba/dcerpc/dfs.so' ) bld.SAMBA_PYTHON('python_unixinfo', source='../../librpc/gen_ndr/py_unixinfo.c', - deps='RPC_NDR_UNIXINFO PYTALLOC pyparam_util pycredentials python_dcerpc', + deps='RPC_NDR_UNIXINFO PYTALLOC pyrpc_util', realname='samba/dcerpc/unixinfo.so' ) bld.SAMBA_PYTHON('python_irpc', source='gen_ndr/py_irpc.c', - deps='RPC_NDR_IRPC PYTALLOC pyparam_util pycredentials python_dcerpc', + deps='RPC_NDR_IRPC PYTALLOC pyrpc_util', realname='samba/dcerpc/irpc.so' ) bld.SAMBA_PYTHON('python_drsuapi', source='../../librpc/gen_ndr/py_drsuapi.c', - deps='RPC_NDR_DRSUAPI PYTALLOC pyparam_util pycredentials python_dcerpc', + deps='RPC_NDR_DRSUAPI PYTALLOC pyrpc_util', realname='samba/dcerpc/drsuapi.so' ) - -bld.SAMBA_PYTHON('python_drsblobs', - source='../../librpc/gen_ndr/py_drsblobs.c', - deps='RPC_NDR_DRSBLOBS PYTALLOC pyparam_util pycredentials python_dcerpc', - realname='samba/dcerpc/drsblobs.so' - ) - - bld.SAMBA_PYTHON('python_dcerpc_security', source='../../librpc/gen_ndr/py_security.c', - deps='PYTALLOC python_dcerpc_misc python_dcerpc NDR_SECURITY', + deps='PYTALLOC pyrpc_util NDR_SECURITY', realname='samba/dcerpc/security.so' ) bld.SAMBA_PYTHON('python_dcerpc_drsblobs', - source='../../librpc/gen_ndr/py_drsblobs.c ../../librpc/gen_ndr/ndr_drsblobs_c.c', - deps='PYTALLOC python_dcerpc_misc python_dcerpc NDR_SECURITY', + source='../../librpc/gen_ndr/py_drsblobs.c', + deps='PYTALLOC pyrpc_util NDR_SECURITY RPC_NDR_DRSBLOBS', realname='samba/dcerpc/drsblobs.so' ) bld.SAMBA_PYTHON('python_dcerpc_xattr', source='../../librpc/gen_ndr/py_xattr.c', - deps='PYTALLOC python_dcerpc_misc python_dcerpc python_dcerpc_security NDR_XATTR RPC_NDR_XATTR', + deps='PYTALLOC pyrpc_util RPC_NDR_XATTR', realname='samba/dcerpc/xattr.so' ) bld.SAMBA_PYTHON('python_netlogon', source='../../librpc/gen_ndr/py_netlogon.c', - deps='RPC_NDR_NETLOGON PYTALLOC pyparam_util pycredentials python_dcerpc', + deps='RPC_NDR_NETLOGON PYTALLOC pyrpc_util', realname='samba/dcerpc/netlogon.so' ) diff --git a/source4/scripting/python/samba/tests/dcerpc/rpcecho.py b/source4/scripting/python/samba/tests/dcerpc/rpcecho.py index 726ba849c3..b7dd065b8c 100644 --- a/source4/scripting/python/samba/tests/dcerpc/rpcecho.py +++ b/source4/scripting/python/samba/tests/dcerpc/rpcecho.py @@ -33,7 +33,7 @@ class RpcEchoTests(RpcInterfaceTestCase): self.assertEquals(3, self.conn2.AddOne(2)) def test_abstract_syntax(self): - self.assertEquals(("60a15ec5-4de8-11d7-a637-005056a20182", 1), + self.assertEquals(("60a15ec5-4de8-11d7-a637-005056a20182", 1), self.conn.abstract_syntax) def test_addone(self): |