From: Stefan Metzmacher Date: Wed, 17 Jul 2024 16:11:49 +0000 (+0200) Subject: librpc:pyrpc: Allow new authenticated rpc connection on the same transport as the... X-Git-Tag: samba-4.21.7~8 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0a0d87f4093c88e6ba43951f7182d8bcac49fbc2;p=thirdparty%2Fsamba.git librpc:pyrpc: Allow new authenticated rpc connection on the same transport as the basis_connection BUG: https://bugzilla.samba.org/show_bug.cgi?id=15680 Signed-off-by: Stefan Metzmacher Reviewed-by: Andreas Schneider (cherry picked from commit 2c171fb1b8c88034a98c3aaf052e99ba5dbbafd9) (cherry picked from commit 82aa83142598f99d662fb9f16aa20c5e2f5fafa5) --- diff --git a/source4/librpc/rpc/pyrpc_util.c b/source4/librpc/rpc/pyrpc_util.c index e8de2f39eae..66f9562dae3 100644 --- a/source4/librpc/rpc/pyrpc_util.c +++ b/source4/librpc/rpc/pyrpc_util.c @@ -181,6 +181,8 @@ PyObject *py_dcerpc_interface_init_helper(PyTypeObject *type, PyObject *args, Py struct dcerpc_pipe *base_pipe; PyObject *py_base; PyTypeObject *ClientConnection_Type; + struct loadparm_context *lp_ctx = NULL; + struct cli_credentials *credentials = NULL; py_base = PyImport_ImportModule("samba.dcerpc.base"); if (py_base == NULL) { @@ -225,16 +227,76 @@ PyObject *py_dcerpc_interface_init_helper(PyTypeObject *type, PyObject *args, Py return NULL; } - status = dcerpc_secondary_context(base_pipe, &ret->pipe, table); - if (!NT_STATUS_IS_OK(status)) { - PyErr_SetNTSTATUS(status); - Py_DECREF(ret); - Py_DECREF(py_base); - Py_DECREF(ClientConnection_Type); - return NULL; + if (py_lp_ctx != Py_None) { + lp_ctx = lpcfg_from_py_object(ret->ev, py_lp_ctx); + if (lp_ctx == NULL) { + PyErr_SetString(PyExc_TypeError, "Expected loadparm context"); + Py_DECREF(ret); + return NULL; + } + } + + if (py_credentials != Py_None) { + credentials = cli_credentials_from_py_object(py_credentials); + if (credentials == NULL) { + PyErr_SetString(PyExc_TypeError, "Expected credentials"); + Py_DECREF(ret); + return NULL; + } + } + + if (credentials != NULL) { + struct dcerpc_binding *binding = NULL; + + if (lp_ctx == NULL) { + PyErr_SetString( + PyExc_TypeError, + "Expected a loadparm context together " + "with provided credentials"); + Py_DECREF(ret); + Py_DECREF(py_base); + Py_DECREF(ClientConnection_Type); + return NULL; + } + + status = dcerpc_parse_binding(ret->mem_ctx, + binding_string, + &binding); + if (!NT_STATUS_IS_OK(status)) { + PyErr_SetNTSTATUS(status); + Py_DECREF(ret); + Py_DECREF(py_base); + Py_DECREF(ClientConnection_Type); + return NULL; + } + + status = dcerpc_secondary_auth_connection(base_pipe, + binding, + table, + credentials, + lp_ctx, + ret->mem_ctx, + &ret->pipe); + TALLOC_FREE(binding); + if (!NT_STATUS_IS_OK(status)) { + PyErr_SetNTSTATUS(status); + Py_DECREF(ret); + Py_DECREF(py_base); + Py_DECREF(ClientConnection_Type); + return NULL; + } + } else { + status = dcerpc_secondary_context(base_pipe, &ret->pipe, table); + if (!NT_STATUS_IS_OK(status)) { + PyErr_SetNTSTATUS(status); + Py_DECREF(ret); + Py_DECREF(py_base); + Py_DECREF(ClientConnection_Type); + return NULL; + } + ret->pipe = talloc_steal(ret->mem_ctx, ret->pipe); } - ret->pipe = talloc_steal(ret->mem_ctx, ret->pipe); Py_XDECREF(ClientConnection_Type); Py_XDECREF(py_base); } else {