[SCM] Samba Shared Repository - branch v4-0-test updated -
release-4-0-0alpha3-1781-g468d358
Jelmer Vernooij
jelmer at samba.org
Sat May 24 17:51:03 GMT 2008
The branch, v4-0-test has been updated
via 468d35827fd055c82c6d43d6ce6d3d561abed54d (commit)
via dd43bdcb880d08013a600f81d40e5280db74c534 (commit)
via c5d7d48b32bcebf8a0495cbd4556e30587fa589f (commit)
via 3b2bd4d849946aaff2b0adfbacdc15284670b916 (commit)
via 06d272b42f59d0a785697d207e6d7dbbcf355175 (commit)
from b4560c90e5e8d3a35367d3a21d361dc4c9c0de23 (commit)
http://gitweb.samba.org/?p=samba.git;a=shortlog;h=v4-0-test
- Log -----------------------------------------------------------------
commit 468d35827fd055c82c6d43d6ce6d3d561abed54d
Author: Jelmer Vernooij <jelmer at samba.org>
Date: Sat May 24 19:50:09 2008 +0200
Add tests for new NDR pack/unpack functionality in Python DCE/RPC bindings.
commit dd43bdcb880d08013a600f81d40e5280db74c534
Author: Jelmer Vernooij <jelmer at samba.org>
Date: Sat May 24 19:49:54 2008 +0200
Only provide __ndr_pack__ / __ndr_unpack__ if the push/pull functions are public.
commit c5d7d48b32bcebf8a0495cbd4556e30587fa589f
Author: Jelmer Vernooij <jelmer at samba.org>
Date: Sat May 24 18:57:15 2008 +0200
Add convenience functions for packing/unpacking structs in python.
commit 3b2bd4d849946aaff2b0adfbacdc15284670b916
Author: Jelmer Vernooij <jelmer at samba.org>
Date: Sat May 24 18:55:46 2008 +0200
Support __ndr_unpack__ on DCE/RPC structures in Python.
commit 06d272b42f59d0a785697d207e6d7dbbcf355175
Author: Jelmer Vernooij <jelmer at samba.org>
Date: Sat May 24 18:46:32 2008 +0200
Add __ndr_pack__ method to all DCE/RPC structures.
-----------------------------------------------------------------------
Summary of changes:
source/librpc/idl/echo.idl | 2 +-
source/pidl/lib/Parse/Pidl/Samba4/Python.pm | 58 +++++++++++++++++++-
.../{bin/epdump.py => python/samba/ndr.py} | 14 +++--
.../scripting/python/samba/tests/dcerpc/rpcecho.py | 12 ++++
4 files changed, 79 insertions(+), 7 deletions(-)
copy source/scripting/{bin/epdump.py => python/samba/ndr.py} (75%)
Changeset truncated at 500 lines:
diff --git a/source/librpc/idl/echo.idl b/source/librpc/idl/echo.idl
index 5ea37f1..bf1e318 100644
--- a/source/librpc/idl/echo.idl
+++ b/source/librpc/idl/echo.idl
@@ -38,7 +38,7 @@ interface rpcecho
/* test some alignment issues */
- typedef struct {
+ typedef [public] struct {
uint8 v;
} echo_info1;
diff --git a/source/pidl/lib/Parse/Pidl/Samba4/Python.pm b/source/pidl/lib/Parse/Pidl/Samba4/Python.pm
index 440b1bf..b83f9a5 100644
--- a/source/pidl/lib/Parse/Pidl/Samba4/Python.pm
+++ b/source/pidl/lib/Parse/Pidl/Samba4/Python.pm
@@ -225,9 +225,64 @@ sub PythonStruct($$$$$$)
$self->pidl("return py_talloc_import(&$name\_Type, ret);");
$self->deindent;
$self->pidl("}");
-
$self->pidl("");
+ my $py_methods = "NULL";
+
+ # 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");
$self->pidl_hdr("#define $name\_CheckExact(op) ((op)->ob_type == &$name\_Type)\n");
@@ -243,6 +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_methods,");
$self->pidl(".tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,");
$self->pidl(".tp_new = py_$name\_new,");
$self->deindent;
diff --git a/source/scripting/bin/epdump.py b/source/scripting/python/samba/ndr.py
similarity index 75%
copy from source/scripting/bin/epdump.py
copy to source/scripting/python/samba/ndr.py
index 15dee33..e718ff3 100644
--- a/source/scripting/bin/epdump.py
+++ b/source/scripting/python/samba/ndr.py
@@ -1,7 +1,8 @@
#!/usr/bin/python
+# -*- coding: utf-8 -*-
# Unix SMB/CIFS implementation.
-# Copyright (C) Jelmer Vernooij <jelmer at samba.org> 2008
+# Copyright © Jelmer Vernooij <jelmer at 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
@@ -17,8 +18,11 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
-import sys
+def ndr_pack(object):
+ return object.__ndr_pack__()
-if len(sys.argv) < 2:
- print "Usage: %s <binding-string>" % sys.argv[0]
- sys.exit(1)
+
+def ndr_unpack(cls, data):
+ object = cls()
+ object.__ndr_unpack__(data)
+ return object
diff --git a/source/scripting/python/samba/tests/dcerpc/rpcecho.py b/source/scripting/python/samba/tests/dcerpc/rpcecho.py
index 3b37f8a..9157f83 100644
--- a/source/scripting/python/samba/tests/dcerpc/rpcecho.py
+++ b/source/scripting/python/samba/tests/dcerpc/rpcecho.py
@@ -18,6 +18,7 @@
#
from samba.dcerpc import echo
+from samba.ndr import ndr_pack, ndr_unpack
import unittest
from samba.tests import RpcInterfaceTestCase
@@ -40,3 +41,14 @@ class RpcEchoTests(RpcInterfaceTestCase):
surrounding_struct.surrounding = [1,2,3,4]
y = self.conn.TestSurrounding(surrounding_struct)
self.assertEquals(8 * [0], y.surrounding)
+
+
+class NdrEchoTests(unittest.TestCase):
+ def test_info1_push(self):
+ x = echo.info1()
+ x.v = 42
+ self.assertEquals("\x2a", ndr_pack(x))
+
+ def test_info1_pull(self):
+ x = ndr_unpack(echo.info1, "\x42")
+ self.assertEquals(x.v, 66)
--
Samba Shared Repository
More information about the samba-cvs
mailing list