[SCM] Samba Shared Repository - branch master updated

Stefan Metzmacher metze at samba.org
Mon Jan 9 02:29:05 MST 2012


The branch, master has been updated
       via  507e75e s4:python/samba/ndr.py: add an optional 'allow_remaining' to ndr_unpack()
       via  1be5e58 pidl:Samba4/Python: add an optional 'allow_remaining' argument to __ndr_unpack__() hooks
      from  12cb6cd s3-build: Remove unused hooks to set smbtorture4 and test args

http://gitweb.samba.org/?p=samba.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit 507e75ebb9bcacc1e75cb13af77a9fc08c49015f
Author: Stefan Metzmacher <metze at samba.org>
Date:   Thu Jan 5 16:34:02 2012 +0100

    s4:python/samba/ndr.py: add an optional 'allow_remaining' to ndr_unpack()
    
    metze
    
    Autobuild-User: Stefan Metzmacher <metze at samba.org>
    Autobuild-Date: Mon Jan  9 10:28:30 CET 2012 on sn-devel-104

commit 1be5e5895865996425d39abf79f0e42b23d9e64c
Author: Stefan Metzmacher <metze at samba.org>
Date:   Thu Jan 5 16:33:13 2012 +0100

    pidl:Samba4/Python: add an optional 'allow_remaining' argument to __ndr_unpack__() hooks
    
    Thanks to Amitay Isaacs <amitay at gmail.com> for the help with this.
    
    metze

-----------------------------------------------------------------------

Summary of changes:
 pidl/lib/Parse/Pidl/Samba4/Python.pm  |   29 ++++++++++++++++++++++++++---
 source4/scripting/python/samba/ndr.py |    5 +++--
 2 files changed, 29 insertions(+), 5 deletions(-)


Changeset truncated at 500 lines:

diff --git a/pidl/lib/Parse/Pidl/Samba4/Python.pm b/pidl/lib/Parse/Pidl/Samba4/Python.pm
index 63f4b2b..63f41a1 100644
--- a/pidl/lib/Parse/Pidl/Samba4/Python.pm
+++ b/pidl/lib/Parse/Pidl/Samba4/Python.pm
@@ -271,21 +271,44 @@ sub PythonStruct($$$$$$)
 		$self->pidl("}");
 		$self->pidl("");
 
-		$self->pidl("static PyObject *py_$name\_ndr_unpack(PyObject *py_obj, PyObject *args)");
+		$self->pidl("static PyObject *py_$name\_ndr_unpack(PyObject *py_obj, PyObject *args, PyObject *kwargs)");
 		$self->pidl("{");
 		$self->indent;
 		$self->pidl("$cname *object = ($cname *)pytalloc_get_ptr(py_obj);");
 		$self->pidl("DATA_BLOB blob;");
 		$self->pidl("int blob_length = 0;");
 		$self->pidl("enum ndr_err_code err;");
-		$self->pidl("if (!PyArg_ParseTuple(args, \"s#:__ndr_unpack__\", &blob.data, &blob_length)) {");
+		$self->pidl("const char * const kwnames[] = { \"data_blob\", \"allow_remaining\", NULL };");
+		$self->pidl("PyObject *allow_remaining_obj = NULL;");
+		$self->pidl("bool allow_remaining = false;");
+		$self->pidl("");
+		$self->pidl("if (!PyArg_ParseTupleAndKeywords(args, kwargs, \"s#|O:__ndr_unpack__\",");
+		$self->indent;
+		$self->pidl("discard_const_p(char *, kwnames),");
+		$self->pidl("&blob.data, &blob_length,");
+		$self->pidl("&allow_remaining_obj)) {");
+		$self->deindent;
 		$self->indent;
 		$self->pidl("return NULL;");
 		$self->deindent;
 		$self->pidl("}");
 		$self->pidl("blob.length = blob_length;");
 		$self->pidl("");
+		$self->pidl("if (allow_remaining_obj && PyObject_IsTrue(allow_remaining_obj)) {");
+		$self->indent;
+		$self->pidl("allow_remaining = true;");
+		$self->deindent;
+		$self->pidl("}");
+		$self->pidl("");
+		$self->pidl("if (allow_remaining) {");
+		$self->indent;
+		$self->pidl("err = ndr_pull_struct_blob(&blob, pytalloc_get_mem_ctx(py_obj), object, (ndr_pull_flags_fn_t)ndr_pull_$name);");
+		$self->deindent;
+		$self->pidl("} else {");
+		$self->indent;
 		$self->pidl("err = ndr_pull_struct_blob_all(&blob, pytalloc_get_mem_ctx(py_obj), object, (ndr_pull_flags_fn_t)ndr_pull_$name);");
+		$self->deindent;
+		$self->pidl("}");
 		$self->pidl("if (err != NDR_ERR_SUCCESS) {");
 		$self->indent;
 		$self->pidl("PyErr_SetNdrError(err);");
@@ -318,7 +341,7 @@ sub PythonStruct($$$$$$)
 		$self->pidl("static PyMethodDef $py_methods\[] = {");
 		$self->indent;
 		$self->pidl("{ \"__ndr_pack__\", (PyCFunction)py_$name\_ndr_pack, METH_NOARGS, \"S.ndr_pack(object) -> blob\\nNDR pack\" },");
-		$self->pidl("{ \"__ndr_unpack__\", (PyCFunction)py_$name\_ndr_unpack, METH_VARARGS, \"S.ndr_unpack(class, blob) -> None\\nNDR unpack\" },");
+		$self->pidl("{ \"__ndr_unpack__\", (PyCFunction)py_$name\_ndr_unpack, METH_VARARGS|METH_KEYWORDS, \"S.ndr_unpack(class, blob, allow_remaining=False) -> None\\nNDR unpack\" },");
 		$self->pidl("{ \"__ndr_print__\", (PyCFunction)py_$name\_ndr_print, METH_VARARGS, \"S.ndr_print(object) -> None\\nNDR print\" },");
 		$self->pidl("{ NULL, NULL, 0, NULL }");
 		$self->deindent;
diff --git a/source4/scripting/python/samba/ndr.py b/source4/scripting/python/samba/ndr.py
index ccab112..39e4a48 100644
--- a/source4/scripting/python/samba/ndr.py
+++ b/source4/scripting/python/samba/ndr.py
@@ -33,15 +33,16 @@ def ndr_pack(object):
     return ndr_pack()
 
 
-def ndr_unpack(cls, data):
+def ndr_unpack(cls, data, allow_remaining=False):
     """NDR unpack an object.
 
     :param cls: Class of the object to unpack
     :param data: Buffer to unpack
+    :param allow_remaining: allows remaining data at the end (default=False)
     :return: Unpacked object
     """
     object = cls()
-    object.__ndr_unpack__(data)
+    object.__ndr_unpack__(data, allow_remaining=allow_remaining)
     return object
 
 


-- 
Samba Shared Repository


More information about the samba-cvs mailing list