From 1b45f2aed86dda9fda6e6bcf1c9c7cbdc471c18d Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Fri, 16 Dec 2011 10:55:46 +0100 Subject: s4:pyrpc: add 'user_session_key' getter to the connection object This gets the session key from gensec for usage in DRSUAPI. metze Autobuild-User: Stefan Metzmacher Autobuild-Date: Wed Jan 4 22:31:52 CET 2012 on sn-devel-104 --- source4/librpc/rpc/pyrpc.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ source4/librpc/wscript_build | 2 +- 2 files changed, 45 insertions(+), 1 deletion(-) (limited to 'source4') diff --git a/source4/librpc/rpc/pyrpc.c b/source4/librpc/rpc/pyrpc.c index 7aa5ff5868..23961e7a07 100644 --- a/source4/librpc/rpc/pyrpc.c +++ b/source4/librpc/rpc/pyrpc.c @@ -26,6 +26,7 @@ #include "librpc/rpc/dcerpc.h" #include "librpc/rpc/pyrpc_util.h" #include "auth/credentials/pycredentials.h" +#include "auth/gensec/gensec.h" void initbase(void); @@ -128,6 +129,47 @@ static PyObject *py_iface_session_key(PyObject *obj, void *closure) return PyString_FromStringAndSize((const char *)session_key.data, session_key.length); } +static PyObject *py_iface_user_session_key(PyObject *obj, void *closure) +{ + dcerpc_InterfaceObject *iface = (dcerpc_InterfaceObject *)obj; + TALLOC_CTX *mem_ctx; + NTSTATUS status; + struct gensec_security *security = NULL; + DATA_BLOB session_key = data_blob_null; + static PyObject *session_key_obj = NULL; + + if (iface->pipe == NULL) { + PyErr_SetNTSTATUS(NT_STATUS_NO_USER_SESSION_KEY); + return NULL; + } + + if (iface->pipe->conn == NULL) { + PyErr_SetNTSTATUS(NT_STATUS_NO_USER_SESSION_KEY); + return NULL; + } + + if (iface->pipe->conn->security_state.generic_state == NULL) { + PyErr_SetNTSTATUS(NT_STATUS_NO_USER_SESSION_KEY); + return NULL; + } + + security = iface->pipe->conn->security_state.generic_state; + + mem_ctx = talloc_new(NULL); + + status = gensec_session_key(security, mem_ctx, &session_key); + if (!NT_STATUS_IS_OK(status)) { + talloc_free(mem_ctx); + PyErr_SetNTSTATUS(status); + return NULL; + } + + session_key_obj = PyString_FromStringAndSize((const char *)session_key.data, + session_key.length); + talloc_free(mem_ctx); + return session_key_obj; +} + static PyGetSetDef dcerpc_interface_getsetters[] = { { discard_const_p(char, "server_name"), py_iface_server_name, NULL, discard_const_p(char, "name of the server, if connected over SMB") }, @@ -137,6 +179,8 @@ static PyGetSetDef dcerpc_interface_getsetters[] = { discard_const_p(char, "syntax id of the transfersyntax") }, { discard_const_p(char, "session_key"), py_iface_session_key, NULL, discard_const_p(char, "session key (as used for blob encryption on LSA and SAMR)") }, + { discard_const_p(char, "user_session_key"), py_iface_user_session_key, NULL, + discard_const_p(char, "user_session key (as used for blob encryption on DRSUAPI)") }, { NULL } }; diff --git a/source4/librpc/wscript_build b/source4/librpc/wscript_build index cb4c5307a6..bf36d1d18a 100755 --- a/source4/librpc/wscript_build +++ b/source4/librpc/wscript_build @@ -165,7 +165,7 @@ bld.SAMBA_SUBSYSTEM('pyrpc_util', bld.SAMBA_PYTHON('python_dcerpc', source='rpc/pyrpc.c', - public_deps='LIBCLI_SMB samba-util samba-hostconfig dcerpc-samr RPC_NDR_LSA DYNCONFIG pyrpc_util', + public_deps='LIBCLI_SMB samba-util samba-hostconfig dcerpc-samr RPC_NDR_LSA DYNCONFIG pyrpc_util gensec', realname='samba/dcerpc/base.so' ) -- cgit