diff options
author | Björn Baumbach <bb@sernet.de> | 2018-09-04 14:37:41 +0200 |
---|---|---|
committer | Björn Baumbach <bb@sernet.de> | 2018-10-11 10:28:17 +0200 |
commit | ea38be487e64dcdac65f7080ac86f9e0699432b9 (patch) | |
tree | e3a4e2c5d6c4f8c2512895affedbfa0d15c1708b /source4/auth | |
parent | 96b5bf1370fc7975e766dccb1ad70aa57f1d9c6a (diff) | |
download | samba-ea38be487e64dcdac65f7080ac86f9e0699432b9.tar.gz |
python: Add samba.auth.copy_session_info()
Signed-off-by: Björn Baumbach <bb@sernet.de>
Reviewed-by: Volker Lendecke <vl@samba.org>
Diffstat (limited to 'source4/auth')
-rw-r--r-- | source4/auth/pyauth.c | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/source4/auth/pyauth.c b/source4/auth/pyauth.c index b8d7a4c8d96..26d8277887e 100644 --- a/source4/auth/pyauth.c +++ b/source4/auth/pyauth.c @@ -26,6 +26,7 @@ #include "pyldb.h" #include "auth/system_session_proto.h" #include "auth/auth.h" +#include "auth/auth_util.h" #include "param/pyparam.h" #include "libcli/security/security.h" #include "auth/credentials/pycredentials.h" @@ -40,6 +41,60 @@ static PyObject *PyAuthSession_FromSession(struct auth_session_info *session) return py_return_ndr_struct("samba.dcerpc.auth", "session_info", session, session); } +static PyObject *py_copy_session_info(PyObject *module, + PyObject *args, + PyObject *kwargs) +{ + PyObject *py_session = Py_None; + PyObject *result = Py_None; + struct auth_session_info *session = NULL; + struct auth_session_info *session_duplicate = NULL; + TALLOC_CTX *frame; + int ret = 1; + + const char * const kwnames[] = { "session_info", NULL }; + + ret = PyArg_ParseTupleAndKeywords(args, + kwargs, + "O", + discard_const_p(char *, kwnames), + &py_session); + if (!ret) { + return NULL; + } + + ret = py_check_dcerpc_type(py_session, + "samba.dcerpc.auth", + "session_info"); + if (!ret) { + return NULL; + } + session = pytalloc_get_type(py_session, + struct auth_session_info); + if (!session) { + PyErr_Format(PyExc_TypeError, + "Expected auth_session_info for session_info " + "argument got %s", + talloc_get_name(pytalloc_get_ptr(py_session))); + return NULL; + } + + frame = talloc_stackframe(); + if (frame == NULL) { + return PyErr_NoMemory(); + } + + session_duplicate = copy_session_info(frame, session); + if (session_duplicate == NULL) { + TALLOC_FREE(frame); + return PyErr_NoMemory(); + } + + result = PyAuthSession_FromSession(session_duplicate); + TALLOC_FREE(frame); + return result; +} + static PyObject *py_system_session(PyObject *module, PyObject *args) { PyObject *py_lp_ctx = Py_None; @@ -363,6 +418,10 @@ static PyMethodDef py_auth_methods[] = { (PyCFunction)py_session_info_fill_unix, METH_VARARGS|METH_KEYWORDS, NULL }, + { "copy_session_info", + (PyCFunction)py_copy_session_info, + METH_VARARGS|METH_KEYWORDS, + NULL }, { NULL }, }; |