summaryrefslogtreecommitdiff
path: root/source4/librpc
diff options
context:
space:
mode:
authorStefan Metzmacher <metze@samba.org>2014-02-15 10:19:29 +0100
committerAndreas Schneider <asn@cryptomilk.org>2014-02-17 21:39:30 +0100
commitbf1e65ceb83b8bceea79c6522f867e0c3644f70f (patch)
tree28352f40724c0f2a60b26467868d717b8a14d2c6 /source4/librpc
parent4f31b3db3594f71cb86bf4c1cf4ae62886068962 (diff)
downloadsamba-bf1e65ceb83b8bceea79c6522f867e0c3644f70f.tar.gz
s4:pyrpc: let dcerpc_interface_new() use py_dcerpc_interface_init_helper()
Signed-off-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Andreas Schneider <asn@samba.org> Autobuild-User(master): Andreas Schneider <asn@cryptomilk.org> Autobuild-Date(master): Mon Feb 17 21:39:30 CET 2014 on sn-devel-104
Diffstat (limited to 'source4/librpc')
-rw-r--r--source4/librpc/rpc/pyrpc.c100
1 files changed, 26 insertions, 74 deletions
diff --git a/source4/librpc/rpc/pyrpc.c b/source4/librpc/rpc/pyrpc.c
index 0de36810b5c..140d86cfeef 100644
--- a/source4/librpc/rpc/pyrpc.c
+++ b/source4/librpc/rpc/pyrpc.c
@@ -296,7 +296,7 @@ static void dcerpc_interface_dealloc(PyObject* self)
static PyObject *dcerpc_interface_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
{
- dcerpc_InterfaceObject *ret;
+ PyObject *ret;
const char *binding_string = NULL;
PyObject *py_lp_ctx = Py_None;
PyObject *py_credentials = Py_None;
@@ -305,97 +305,49 @@ static PyObject *dcerpc_interface_new(PyTypeObject *type, PyObject *args, PyObje
const char *kwnames[] = {
"binding", "syntax", "lp_ctx", "credentials", "basis_connection", NULL
};
- struct ndr_interface_table *table;
- NTSTATUS status;
+ static struct ndr_interface_table dummy_table;
+ PyObject *args2 = Py_None;
+ PyObject *kwargs2 = Py_None;
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;
}
- ret = PyObject_New(dcerpc_InterfaceObject, type);
- ret->pipe = NULL;
- ret->binding_handle = NULL;
- ret->mem_ctx = talloc_new(NULL);
- if (ret->mem_ctx == NULL) {
- PyErr_NoMemory();
+ if (strncmp(binding_string, "irpc:", 5) == 0) {
+ PyErr_SetString(PyExc_ValueError, "irpc: transport not supported");
return NULL;
}
- /* Create a dummy interface table struct. TODO: In the future, we should
+ /*
+ * Fill a dummy interface table struct. TODO: In the future, we should
* rather just allow connecting without requiring an interface table.
+ *
+ * We just fill the syntax during the connect, but keep the memory valid
+ * the whole time.
*/
-
- table = talloc_zero(ret->mem_ctx, struct ndr_interface_table);
-
- if (table == NULL) {
- PyErr_SetString(PyExc_MemoryError, "Allocating interface table");
- TALLOC_FREE(ret->mem_ctx);
+ if (!ndr_syntax_from_py_object(syntax, &dummy_table.syntax_id)) {
return NULL;
}
- if (!ndr_syntax_from_py_object(syntax, &table->syntax_id)) {
- TALLOC_FREE(ret->mem_ctx);
+ args2 = Py_BuildValue("(s)", binding_string);
+ if (args2 == NULL) {
return NULL;
}
- 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(ret->mem_ctx);
- return NULL;
- }
-
- base_pipe = talloc_reference(ret->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 {
- struct tevent_context *event_ctx;
- struct loadparm_context *lp_ctx;
- struct cli_credentials *credentials;
-
- event_ctx = s4_event_context_init(ret->mem_ctx);
- if (event_ctx == NULL) {
- PyErr_SetString(PyExc_TypeError, "Expected loadparm context");
- TALLOC_FREE(ret->mem_ctx);
- return NULL;
- }
-
- lp_ctx = lpcfg_from_py_object(event_ctx, py_lp_ctx);
- if (lp_ctx == NULL) {
- PyErr_SetString(PyExc_TypeError, "Expected loadparm context");
- TALLOC_FREE(ret->mem_ctx);
- return NULL;
- }
-
- credentials = cli_credentials_from_py_object(py_credentials);
- if (credentials == NULL) {
- PyErr_SetString(PyExc_TypeError, "Expected credentials");
- TALLOC_FREE(ret->mem_ctx);
- return NULL;
- }
- status = dcerpc_pipe_connect(ret->mem_ctx, &ret->pipe, binding_string,
- table, credentials, event_ctx, lp_ctx);
-
- /*
- * the event context is cached under the connection,
- * so let it be a child of it.
- */
- talloc_steal(ret->pipe->conn, event_ctx);
- }
-
- if (!NT_STATUS_IS_OK(status)) {
- PyErr_SetDCERPCStatus(ret->pipe, status);
- TALLOC_FREE(ret->mem_ctx);
+ kwargs2 = Py_BuildValue("{s:O,s:O,s:O}",
+ "lp_ctx", py_lp_ctx,
+ "credentials", py_credentials,
+ "basis_connection", py_basis);
+ if (kwargs2 == NULL) {
+ Py_DECREF(args2);
return NULL;
}
- ret->pipe->conn->flags |= DCERPC_NDR_REF_ALLOC;
- ret->binding_handle = ret->pipe->binding_handle;
- return (PyObject *)ret;
+
+ ret = py_dcerpc_interface_init_helper(type, args2, kwargs2, &dummy_table);
+ ZERO_STRUCT(dummy_table.syntax_id);
+ Py_DECREF(args2);
+ Py_DECREF(kwargs2);
+ return ret;
}
static PyTypeObject dcerpc_InterfaceType = {