[SCM] Samba Shared Repository - branch v4-0-test updated - release-4-0-0alpha3-1796-ga875e07

Jelmer Vernooij jelmer at samba.org
Sun May 25 03:07:00 GMT 2008


The branch, v4-0-test has been updated
       via  a875e07a37568b7e51c290074d5e3834c2caa4d6 (commit)
       via  daed1432d22f5fa78907ee0fef9def8802538150 (commit)
       via  16d1ad050546ae6500153438db8d3c857e6f3ad5 (commit)
      from  4e5687e813e50d0bc8d6314e389d1d7a0be2f8c1 (commit)

http://gitweb.samba.org/?p=samba.git;a=shortlog;h=v4-0-test


- Log -----------------------------------------------------------------
commit a875e07a37568b7e51c290074d5e3834c2caa4d6
Author: Jelmer Vernooij <jelmer at samba.org>
Date:   Sun May 25 04:54:38 2008 +0200

    Expose transfer and abstract syntax.

commit daed1432d22f5fa78907ee0fef9def8802538150
Author: Jelmer Vernooij <jelmer at samba.org>
Date:   Sun May 25 04:38:57 2008 +0200

    Expose request timeout variable in Python.

commit 16d1ad050546ae6500153438db8d3c857e6f3ad5
Author: Jelmer Vernooij <jelmer at samba.org>
Date:   Sun May 25 04:23:03 2008 +0200

    Add support for secondary contexts from Python.

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

Summary of changes:
 source/librpc/rpc/pyrpc.c                          |  177 +++++++++++++++-----
 source/pidl/lib/Parse/Pidl/Samba4/Python.pm        |   26 +++-
 source/samba4-knownfail                            |    2 -
 source/scripting/python/samba/tests/dcerpc/bare.py |   16 ++
 .../scripting/python/samba/tests/dcerpc/rpcecho.py |    8 +
 5 files changed, 184 insertions(+), 45 deletions(-)


Changeset truncated at 500 lines:

diff --git a/source/librpc/rpc/pyrpc.c b/source/librpc/rpc/pyrpc.c
index 1fc6e4e..26242e8 100644
--- a/source/librpc/rpc/pyrpc.c
+++ b/source/librpc/rpc/pyrpc.c
@@ -19,6 +19,7 @@
 
 #include "includes.h"
 #include <Python.h>
+#include <structmember.h>
 #include "librpc/rpc/pyrpc.h"
 #include "librpc/rpc/dcerpc.h"
 #include "lib/events/events.h"
@@ -34,6 +35,39 @@ static bool PyString_AsGUID(PyObject *object, struct GUID *uuid)
 	return true;
 }
 
+static bool ndr_syntax_from_py_object(PyObject *object, struct ndr_syntax_id *syntax_id)
+{
+	ZERO_STRUCTP(syntax_id);
+
+	if (PyString_Check(object)) {
+		return PyString_AsGUID(object, &syntax_id->uuid);
+	} else if (PyTuple_Check(object)) {
+		if (PyTuple_Size(object) < 1 || PyTuple_Size(object) > 2) {
+			PyErr_SetString(PyExc_ValueError, "Syntax ID tuple has invalid size");
+			return false;
+		}
+
+		if (!PyString_Check(PyTuple_GetItem(object, 0))) {
+			PyErr_SetString(PyExc_ValueError, "Expected GUID as first element in tuple");
+			return false;
+		}
+
+		if (!PyString_AsGUID(PyTuple_GetItem(object, 0), &syntax_id->uuid)) 
+			return false;
+
+		if (!PyInt_Check(PyTuple_GetItem(object, 1))) {
+			PyErr_SetString(PyExc_ValueError, "Expected version as second element in tuple");
+			return false;
+		}
+
+		syntax_id->if_version = PyInt_AsLong(PyTuple_GetItem(object, 1));
+		return true;
+	}
+
+	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;
@@ -46,9 +80,50 @@ static PyObject *py_iface_server_name(PyObject *obj, void *closure)
 	return PyString_FromString(server_name);
 }
 
+static PyObject *py_ndr_syntax_id(struct ndr_syntax_id *syntax_id)
+{
+	PyObject *ret;
+	char *uuid_str;
+
+	uuid_str = GUID_string(NULL, &syntax_id->uuid);
+	if (uuid_str == NULL)
+		return NULL;
+
+	ret = Py_BuildValue("(s,i)", uuid_str, syntax_id->if_version);
+
+	talloc_free(uuid_str);
+
+	return ret;
+}
+
+static PyObject *py_iface_abstract_syntax(PyObject *obj, void *closure)
+{
+	dcerpc_InterfaceObject *iface = (dcerpc_InterfaceObject *)obj;
+
+	return py_ndr_syntax_id(&iface->pipe->syntax);
+}
+
+static PyObject *py_iface_transfer_syntax(PyObject *obj, void *closure)
+{
+	dcerpc_InterfaceObject *iface = (dcerpc_InterfaceObject *)obj;
+
+	return py_ndr_syntax_id(&iface->pipe->transfer_syntax);
+}
+
 static PyGetSetDef dcerpc_interface_getsetters[] = {
-	{ discard_const_p(char, "server_name"), py_iface_server_name,  
-	  "name of the server, if connected over SMB"},
+	{ discard_const_p(char, "server_name"), py_iface_server_name, NULL,
+	  discard_const_p(char, "name of the server, if connected over SMB") },
+	{ discard_const_p(char, "abstract_syntax"), py_iface_abstract_syntax, NULL, 
+ 	  discard_const_p(char, "syntax id of the abstract syntax") },
+	{ discard_const_p(char, "transfer_syntax"), py_iface_transfer_syntax, NULL, 
+ 	  discard_const_p(char, "syntax id of the transfersyntax") },
+	{ NULL }
+};
+
+static PyMemberDef dcerpc_interface_members[] = {
+	{ discard_const_p(char, "request_timeout"), T_INT, 
+	  offsetof(struct dcerpc_pipe, request_timeout), 0,
+	  discard_const_p(char, "request timeout, in seconds") },
 	{ NULL }
 };
 
@@ -107,8 +182,45 @@ static PyObject *py_iface_request(PyObject *self, PyObject *args, PyObject *kwar
 	return ret;
 }
 
+static PyObject *py_iface_later_context(PyObject *self, PyObject *args, PyObject *kwargs)
+{
+	dcerpc_InterfaceObject *iface = (dcerpc_InterfaceObject *)self;
+	NTSTATUS status;
+	const char *kwnames[] = { "abstract_syntax", "transfer_syntax", NULL };
+	PyObject *py_abstract_syntax = Py_None, *py_transfer_syntax = Py_None;
+	struct ndr_syntax_id abstract_syntax, transfer_syntax;
+
+	if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|O:alter_context", 
+		discard_const_p(char *, kwnames), &py_abstract_syntax,
+		&py_transfer_syntax)) {
+		return NULL;
+	}
+
+	if (!ndr_syntax_from_py_object(py_abstract_syntax, &abstract_syntax))
+		return NULL;
+
+	if (py_transfer_syntax == Py_None) {
+		transfer_syntax = ndr_transfer_syntax;
+	} else {
+		if (!ndr_syntax_from_py_object(py_transfer_syntax, 
+					       &transfer_syntax))
+			return NULL;
+	}
+
+	status = dcerpc_alter_context(iface->pipe, iface->pipe, &abstract_syntax, 
+				      &transfer_syntax);
+
+	if (NT_STATUS_IS_ERR(status)) {
+		PyErr_SetDCERPCStatus(iface->pipe, status);
+		return NULL;
+	}
+
+	return Py_None;
+}
+
 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_later_context, METH_VARARGS|METH_KEYWORDS, "S.alter_context(syntax)\nChange to a different interface" },
 	{ NULL, NULL, 0, NULL },
 };
 
@@ -120,39 +232,6 @@ static void dcerpc_interface_dealloc(PyObject* self)
 	PyObject_Del(self);
 }
 
-static bool ndr_syntax_from_py_object(PyObject *object, struct ndr_syntax_id *syntax_id)
-{
-	ZERO_STRUCTP(syntax_id);
-
-	if (PyString_Check(object)) {
-		return PyString_AsGUID(object, &syntax_id->uuid);
-	} else if (PyTuple_Check(object)) {
-		if (PyTuple_Size(object) < 1 || PyTuple_Size(object) > 2) {
-			PyErr_SetString(PyExc_ValueError, "Syntax ID tuple has invalid size");
-			return false;
-		}
-
-		if (!PyString_Check(PyTuple_GetItem(object, 0))) {
-			PyErr_SetString(PyExc_ValueError, "Expected GUID as first element in tuple");
-			return false;
-		}
-
-		if (!PyString_AsGUID(PyTuple_GetItem(object, 0), &syntax_id->uuid)) 
-			return false;
-
-		if (!PyInt_Check(PyTuple_GetItem(object, 1))) {
-			PyErr_SetString(PyExc_ValueError, "Expected version as second element in tuple");
-			return false;
-		}
-
-		syntax_id->if_version = PyInt_AsLong(PyTuple_GetItem(object, 1));
-		return true;
-	}
-
-	PyErr_SetString(PyExc_TypeError, "Expected UUID or syntax id tuple");
-	return false;
-}	
-
 static PyObject *dcerpc_interface_new(PyTypeObject *self, PyObject *args, PyObject *kwargs)
 {
 	dcerpc_InterfaceObject *ret;
@@ -164,15 +243,15 @@ static PyObject *dcerpc_interface_new(PyTypeObject *self, PyObject *args, PyObje
 	struct event_context *event_ctx;
 	NTSTATUS status;
 
-	PyObject *syntax;
+	PyObject *syntax, *py_basis = Py_None;
 	const char *kwnames[] = {
-		"binding", "syntax", "lp_ctx", "credentials", NULL
+		"binding", "syntax", "lp_ctx", "credentials", "basis_connection", NULL
 	};
 	extern struct loadparm_context *lp_from_py_object(PyObject *py_obj);
 	extern struct cli_credentials *cli_credentials_from_py_object(PyObject *py_obj);
 	struct ndr_interface_table *table;
 
-	if (!PyArg_ParseTupleAndKeywords(args, kwargs, "sO|OO:connect", discard_const_p(char *, kwnames), &binding_string, &syntax, &py_lp_ctx, &py_credentials)) {
+	if (!PyArg_ParseTupleAndKeywords(args, kwargs, "sO|OOO:connect", discard_const_p(char *, kwnames), &binding_string, &syntax, &py_lp_ctx, &py_credentials, &py_basis)) {
 		return NULL;
 	}
 
@@ -208,8 +287,25 @@ static PyObject *dcerpc_interface_new(PyTypeObject *self, PyObject *args, PyObje
 
 	ret->pipe = NULL;
 
-	status = dcerpc_pipe_connect(NULL, &ret->pipe, binding_string, 
-	             table, credentials, event_ctx, lp_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 = ((dcerpc_InterfaceObject *)py_basis)->pipe;
+
+		status = dcerpc_secondary_context(base_pipe, &ret->pipe, 
+				     table);
+		ret->pipe = talloc_steal(NULL, ret->pipe);
+	} else {
+		status = dcerpc_pipe_connect(NULL, &ret->pipe, binding_string, 
+			     table, credentials, event_ctx, lp_ctx);
+	}
+
 	if (NT_STATUS_IS_ERR(status)) {
 		PyErr_SetDCERPCStatus(ret->pipe, status);
 		talloc_free(mem_ctx);
@@ -226,6 +322,7 @@ PyTypeObject dcerpc_InterfaceType = {
 	.tp_basicsize = sizeof(dcerpc_InterfaceObject),
 	.tp_dealloc = dcerpc_interface_dealloc,
 	.tp_getset = dcerpc_interface_getsetters,
+	.tp_members = dcerpc_interface_members,
 	.tp_methods = dcerpc_interface_methods,
 	.tp_doc = "ClientConnection(binding, syntax, lp_ctx=None, credentials=None) -> connection\n"
 "\n"
diff --git a/source/pidl/lib/Parse/Pidl/Samba4/Python.pm b/source/pidl/lib/Parse/Pidl/Samba4/Python.pm
index 2795d98..dbbdb6b 100644
--- a/source/pidl/lib/Parse/Pidl/Samba4/Python.pm
+++ b/source/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;");
diff --git a/source/samba4-knownfail b/source/samba4-knownfail
index 1f780f1..d489dd3 100644
--- a/source/samba4-knownfail
+++ b/source/samba4-knownfail
@@ -40,5 +40,3 @@ samba4.winbind.struct.*.SHOW_SEQUENCE     # Not yet working in winbind
 samba4.winbind.struct.*.GETPWENT          # Not yet working in winbind
 samba4.winbind.struct.*.SETPWENT          # Not yet working in winbind
 samba4.winbind.struct.*.LOOKUP_NAME_SID   # Not yet working in winbind
-
-
diff --git a/source/scripting/python/samba/tests/dcerpc/bare.py b/source/scripting/python/samba/tests/dcerpc/bare.py
index dae1ded..d75ffc3 100644
--- a/source/scripting/python/samba/tests/dcerpc/bare.py
+++ b/source/scripting/python/samba/tests/dcerpc/bare.py
@@ -28,3 +28,19 @@ class BareTestCase(TestCase):
                 ("60a15ec5-4de8-11d7-a637-005056a20182", 1))
         self.assertEquals("\x01\x00\x00\x00", x.request(0, chr(0) * 4))
 
+    def test_alter_context(self):
+        x = ClientConnection("ncalrpc:localhost[DEFAULT]", 
+                ("12345778-1234-abcd-ef00-0123456789ac", 1))
+        y = ClientConnection("ncalrpc:localhost", 
+                ("60a15ec5-4de8-11d7-a637-005056a20182", 1),
+                basis_connection=x)
+        x.alter_context(("60a15ec5-4de8-11d7-a637-005056a20182", 1))
+        # FIXME: self.assertEquals("\x01\x00\x00\x00", x.request(0, chr(0) * 4))
+
+    def test_two_connections(self):
+        x = ClientConnection("ncalrpc:localhost[DEFAULT]", 
+                ("60a15ec5-4de8-11d7-a637-005056a20182", 1))
+        y = ClientConnection("ncalrpc:localhost", 
+                ("60a15ec5-4de8-11d7-a637-005056a20182", 1),
+                basis_connection=x)
+        self.assertEquals("\x01\x00\x00\x00", y.request(0, chr(0) * 4))
diff --git a/source/scripting/python/samba/tests/dcerpc/rpcecho.py b/source/scripting/python/samba/tests/dcerpc/rpcecho.py
index 83279a0..68b7a42 100644
--- a/source/scripting/python/samba/tests/dcerpc/rpcecho.py
+++ b/source/scripting/python/samba/tests/dcerpc/rpcecho.py
@@ -26,6 +26,14 @@ class RpcEchoTests(RpcInterfaceTestCase):
     def setUp(self):
         self.conn = echo.rpcecho("ncalrpc:", self.get_loadparm())
 
+    def test_two_contexts(self):
+        self.conn2 = echo.rpcecho("ncalrpc", basis_connection=self.conn)
+        self.assertEquals(3, self.conn2.AddOne(2))
+
+    def test_abstract_syntax(self):
+        self.assertEquals(("60a15ec5-4de8-11d7-a637-005056a20182", 1), 
+                          self.conn.abstract_syntax)
+
     def test_addone(self):
         self.assertEquals(2, self.conn.AddOne(1))
 


-- 
Samba Shared Repository


More information about the samba-cvs mailing list