The branch, master has been updated via bdab6c3 s4-pynet: pynet depends on pyrpc_util via 64552e1 pyrpc: Add py_check_dcerpc_type(). from 5115f78 Fix bug #7651 - mknod and mkfifo fails with "No such file or directory"
http://gitweb.samba.org/?p=samba.git;a=shortlog;h=master - Log ----------------------------------------------------------------- commit bdab6c36e84178b361b77ad0ee70757df6aca26a Author: Andrew Tridgell <tri...@samba.org> Date: Fri Aug 27 03:38:46 2010 +0200 s4-pynet: pynet depends on pyrpc_util commit 64552e11dd4435ebd85a0c291987457a99d7fe50 Author: Jelmer Vernooij <jel...@samba.org> Date: Fri Aug 27 02:17:26 2010 +0200 pyrpc: Add py_check_dcerpc_type(). This function checks whether the type of a PyObject matches a DCE/RPC Python type. Pair-Programmed-With: Andrew Tridgell <tri...@samba.org> ----------------------------------------------------------------------- Summary of changes: source4/libnet/py_net.c | 11 +--- source4/libnet/wscript_build | 2 +- source4/librpc/rpc/pyrpc_util.c | 61 ++++++++++++++++++++ .../librpc/rpc/pyrpc_util.h | 14 ++-- source4/librpc/wscript_build | 6 ++ 5 files changed, 78 insertions(+), 16 deletions(-) create mode 100644 source4/librpc/rpc/pyrpc_util.c copy libcli/smb/smb_common.h => source4/librpc/rpc/pyrpc_util.h (67%) Changeset truncated at 500 lines: diff --git a/source4/libnet/py_net.c b/source4/libnet/py_net.c index 79abcd2..4f3e5db 100644 --- a/source4/libnet/py_net.c +++ b/source4/libnet/py_net.c @@ -29,6 +29,7 @@ #include "lib/ldb/pyldb.h" #include "auth/gensec/gensec.h" #include "librpc/rpc/pyrpc.h" +#include "librpc/rpc/pyrpc_util.h" typedef struct { PyObject_HEAD @@ -407,12 +408,9 @@ static PyObject *py_net_replicate_chunk(py_net_Object *self, PyObject *args, PyO switch (level) { case 1: -#ifdef Py_TYPE - if (strcmp("drsuapi.DsGetNCChangesCtr1", Py_TYPE(py_ctr)->tp_name) != 0) { - PyErr_SetString(PyExc_TypeError, "Expected DsGetNCChangesCtr1 type for ctr"); + if (!py_check_dcerpc_type(py_ctr, "samba.dcerpc.drsuapi", "DsGetNCChangesCtr1")) { return NULL; } -#endif s->chunk.ctr1 = py_talloc_get_ptr(py_ctr); s->partition.nc = *s->chunk.ctr1->naming_context; s->partition.more_data = s->chunk.ctr1->more_data; @@ -421,12 +419,9 @@ static PyObject *py_net_replicate_chunk(py_net_Object *self, PyObject *args, PyO s->partition.highwatermark = s->chunk.ctr1->new_highwatermark; break; case 6: -#ifdef Py_TYPE - if (strcmp("drsuapi.DsGetNCChangesCtr6", Py_TYPE(py_ctr)->tp_name) != 0) { - PyErr_SetString(PyExc_TypeError, "Expected DsGetNCChangesCtr6 type for ctr"); + if (!py_check_dcerpc_type(py_ctr, "samba.dcerpc.drsuapi", "DsGetNCChangesCtr6")) { return NULL; } -#endif s->chunk.ctr6 = py_talloc_get_ptr(py_ctr); s->partition.nc = *s->chunk.ctr6->naming_context; s->partition.more_data = s->chunk.ctr6->more_data; diff --git a/source4/libnet/wscript_build b/source4/libnet/wscript_build index 5bf926b..0296bef 100644 --- a/source4/libnet/wscript_build +++ b/source4/libnet/wscript_build @@ -9,7 +9,7 @@ bld.SAMBA_SUBSYSTEM('LIBSAMBA-NET', bld.SAMBA_PYTHON('python_net', source='py_net.c', - deps='LIBSAMBA-NET', + deps='LIBSAMBA-NET pyrpc_util', realname='samba/net.so' ) diff --git a/source4/librpc/rpc/pyrpc_util.c b/source4/librpc/rpc/pyrpc_util.c new file mode 100644 index 0000000..e1d3450 --- /dev/null +++ b/source4/librpc/rpc/pyrpc_util.c @@ -0,0 +1,61 @@ +/* + Unix SMB/CIFS implementation. + + Python interface to DCE/RPC library - utility functions. + + Copyright (C) 2010 Jelmer Vernooij <jel...@samba.org> + Copyright (C) 2010 Andrew Tridgell <tri...@samba.org> + + 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/>. +*/ + +#include <Python.h> +#include "includes.h" +#include "librpc/rpc/pyrpc_util.h" + +#ifndef Py_TYPE /* Py_TYPE is only available on Python > 2.6 */ +#define Py_TYPE(ob) (((PyObject*)(ob))->ob_type) +#endif + +bool py_check_dcerpc_type(PyObject *obj, const char *module, const char *typename) +{ + PyObject *mod; + PyTypeObject *type; + bool ret; + + mod = PyImport_ImportModule(module); + + if (mod == NULL) { + PyErr_Format(PyExc_RuntimeError, "Unable to import %s to check type %s", + module, typename); + return NULL; + } + + type = (PyTypeObject *)PyObject_GetAttrString(mod, typename); + Py_DECREF(mod); + if (type == NULL) { + PyErr_Format(PyExc_RuntimeError, "Unable to find type %s in module %s", + module, typename); + return NULL; + } + + ret = PyObject_TypeCheck(obj, type); + Py_DECREF(type); + + if (!ret) + PyErr_Format(PyExc_TypeError, "Expected type %s.%s, got %s", + module, typename, Py_TYPE(obj)->tp_name); + + return ret; +} diff --git a/libcli/smb/smb_common.h b/source4/librpc/rpc/pyrpc_util.h similarity index 67% copy from libcli/smb/smb_common.h copy to source4/librpc/rpc/pyrpc_util.h index d6186ab..67fd4fc 100644 --- a/libcli/smb/smb_common.h +++ b/source4/librpc/rpc/pyrpc_util.h @@ -1,9 +1,10 @@ /* Unix SMB/CIFS implementation. - SMB and SMB2 common header + Python interface to DCE/RPC library - utility functions. - Copyright (C) Stefan Metzmacher 2009 + Copyright (C) 2010 Jelmer Vernooij <jel...@samba.org> + Copyright (C) 2010 Andrew Tridgell <tri...@samba.org> 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 @@ -19,10 +20,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef __LIBCLI_SMB_SMB_COMMON_H__ -#define __LIBCLI_SMB_SMB_COMMON_H__ +#ifndef __PYRPC_UTIL_H__ +#define __PYRPC_UTIL_H__ -#include "../libcli/smb/smb2_constants.h" -#include "../libcli/smb/smb2_create_blob.h" +bool py_check_dcerpc_type(PyObject *obj, const char *module, const char *typename); -#endif +#endif /* __PYRPC_UTIL_H__ */ diff --git a/source4/librpc/wscript_build b/source4/librpc/wscript_build index 62cb229..69f3850 100755 --- a/source4/librpc/wscript_build +++ b/source4/librpc/wscript_build @@ -637,6 +637,12 @@ bld.SAMBA_LIBRARY('dcerpc', vnum='0.0.1' ) +bld.SAMBA_SUBSYSTEM('pyrpc_util', + source='rpc/pyrpc_util.c', + public_deps='PYTALLOC', + needs_python=True, + ) + bld.SAMBA_PYTHON('python_dcerpc', source='rpc/pyrpc.c', -- Samba Shared Repository