summaryrefslogtreecommitdiff
path: root/source4/auth/pyauth.c
diff options
context:
space:
mode:
Diffstat (limited to 'source4/auth/pyauth.c')
-rw-r--r--source4/auth/pyauth.c40
1 files changed, 32 insertions, 8 deletions
diff --git a/source4/auth/pyauth.c b/source4/auth/pyauth.c
index a66411bb4a..c2a5e408c7 100644
--- a/source4/auth/pyauth.c
+++ b/source4/auth/pyauth.c
@@ -43,16 +43,25 @@ static PyObject *py_system_session(PyObject *module, PyObject *args)
PyObject *py_lp_ctx = Py_None;
struct loadparm_context *lp_ctx = NULL;
struct auth_session_info *session;
+ TALLOC_CTX *mem_ctx;
if (!PyArg_ParseTuple(args, "|O", &py_lp_ctx))
return NULL;
- lp_ctx = lpcfg_from_py_object(NULL, py_lp_ctx);
- if (lp_ctx == NULL)
+ mem_ctx = talloc_new(NULL);
+ if (mem_ctx == NULL) {
+ PyErr_NoMemory();
return NULL;
+ }
+
+ lp_ctx = lpcfg_from_py_object(mem_ctx, py_lp_ctx);
+ if (lp_ctx == NULL) {
+ talloc_free(mem_ctx);
+ return NULL;
+ }
session = system_session(lp_ctx);
- talloc_free(lp_ctx);
+ talloc_free(mem_ctx);
return PyAuthSession_FromSession(session);
}
@@ -65,17 +74,32 @@ static PyObject *py_admin_session(PyObject *module, PyObject *args)
struct loadparm_context *lp_ctx = NULL;
struct auth_session_info *session;
struct dom_sid *domain_sid = NULL;
+ TALLOC_CTX *mem_ctx;
+
if (!PyArg_ParseTuple(args, "OO", &py_lp_ctx, &py_sid))
return NULL;
- lp_ctx = lpcfg_from_py_object(NULL, py_lp_ctx);
- if (lp_ctx == NULL)
+ mem_ctx = talloc_new(NULL);
+ if (mem_ctx == NULL) {
+ PyErr_NoMemory();
return NULL;
+ }
- domain_sid = dom_sid_parse_talloc(NULL, PyString_AsString(py_sid));
- session = admin_session(NULL, lp_ctx, domain_sid);
+ lp_ctx = lpcfg_from_py_object(mem_ctx, py_lp_ctx);
+ if (lp_ctx == NULL) {
+ talloc_free(mem_ctx);
+ return NULL;
+ }
- talloc_free(lp_ctx);
+ domain_sid = dom_sid_parse_talloc(mem_ctx, PyString_AsString(py_sid));
+ if (domain_sid == NULL) {
+ PyErr_Format(PyExc_RuntimeError, "Unable to parse sid %s",
+ PyString_AsString(py_sid));
+ talloc_free(mem_ctx);
+ return NULL;
+ }
+ session = admin_session(NULL, lp_ctx, domain_sid);
+ talloc_free(mem_ctx);
return PyAuthSession_FromSession(session);
}