]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
librpc:pyrpc: Allow new authenticated rpc connection on the same transport as the...
authorStefan Metzmacher <metze@samba.org>
Wed, 17 Jul 2024 16:11:49 +0000 (18:11 +0200)
committerJule Anger <janger@samba.org>
Thu, 12 Jun 2025 11:27:15 +0000 (11:27 +0000)
BUG: https://bugzilla.samba.org/show_bug.cgi?id=15680

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
(cherry picked from commit 2c171fb1b8c88034a98c3aaf052e99ba5dbbafd9)
(cherry picked from commit 82aa83142598f99d662fb9f16aa20c5e2f5fafa5)

source4/librpc/rpc/pyrpc_util.c

index e8de2f39eaeb76841d87b119382bb99136f14ae3..66f9562dae3cfc5d9532492b32ed1f88e68409ad 100644 (file)
@@ -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 {