From 57905603e066e2d1ca60268b1b1e8166868d60e5 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Sat, 14 Sep 2024 14:20:46 +0200 Subject: [PATCH] xss4:pyrpc: make use of dcerpc_binding_handle_transport_session_key() Signed-off-by: Stefan Metzmacher Reviewed-by: Ralph Boehme --- source4/librpc/rpc/pyrpc.c | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/source4/librpc/rpc/pyrpc.c b/source4/librpc/rpc/pyrpc.c index 28ffdc71d65..b8e1ac0c35e 100644 --- a/source4/librpc/rpc/pyrpc.c +++ b/source4/librpc/rpc/pyrpc.c @@ -130,12 +130,30 @@ static PyObject *py_iface_transfer_syntax(PyObject *obj, void *closure) static PyObject *py_iface_session_key(PyObject *obj, void *closure) { dcerpc_InterfaceObject *iface = (dcerpc_InterfaceObject *)obj; - DATA_BLOB session_key; + TALLOC_CTX *frame = talloc_stackframe(); + DATA_BLOB session_key = { .length = 0, }; + static PyObject *session_key_obj = NULL; + NTSTATUS status; - NTSTATUS status = dcerpc_fetch_session_key(iface->pipe, &session_key); - PyErr_NTSTATUS_IS_ERR_RAISE(status); + if (iface->binding_handle == NULL) { + PyErr_SetNTSTATUS(NT_STATUS_NO_USER_SESSION_KEY); + TALLOC_FREE(frame); + return NULL; + } - return PyBytes_FromStringAndSize((const char *)session_key.data, session_key.length); + status = dcerpc_binding_handle_transport_session_key(iface->binding_handle, + frame, + &session_key); + if (!NT_STATUS_IS_OK(status)) { + PyErr_SetNTSTATUS(status); + TALLOC_FREE(frame); + return NULL; + } + + session_key_obj = PyBytes_FromStringAndSize((const char *)session_key.data, + session_key.length); + TALLOC_FREE(frame); + return session_key_obj; } static PyObject *py_iface_user_session_key(PyObject *obj, void *closure)