summaryrefslogtreecommitdiff
path: root/source4/auth
diff options
context:
space:
mode:
authorAndrew Bartlett <abartlet@samba.org>2011-01-17 16:22:31 +1100
committerAndrew Bartlett <abartlet@samba.org>2011-01-18 10:55:05 +0100
commit969c1b58eb325d4741097c1f7b9a81c67b23270d (patch)
tree1ca95e033135a017d8b4b2cdfe0ecc5bfe88bd03 /source4/auth
parent017fbcdd101b3e8503ce643202fdbaa6d076a995 (diff)
downloadsamba-969c1b58eb325d4741097c1f7b9a81c67b23270d.tar.gz
samba-969c1b58eb325d4741097c1f7b9a81c67b23270d.tar.bz2
samba-969c1b58eb325d4741097c1f7b9a81c67b23270d.zip
s4-pyauth Add bindings for auth_context_create() as AuthContext()
Diffstat (limited to 'source4/auth')
-rw-r--r--source4/auth/pyauth.c80
-rw-r--r--source4/auth/wscript_build2
2 files changed, 81 insertions, 1 deletions
diff --git a/source4/auth/pyauth.c b/source4/auth/pyauth.c
index 65f86fb7f7..486d30f3d8 100644
--- a/source4/auth/pyauth.c
+++ b/source4/auth/pyauth.c
@@ -28,8 +28,11 @@
#include "param/pyparam.h"
#include "libcli/security/security.h"
#include "auth/credentials/pycredentials.h"
+#include <tevent.h>
#include "librpc/rpc/pyrpc_util.h"
+staticforward PyTypeObject PyAuthContext;
+
static PyObject *py_auth_session_get_security_token(PyObject *self, void *closure)
{
struct auth_session_info *session = py_talloc_get_type(self, struct auth_session_info);
@@ -223,6 +226,83 @@ static PyObject *py_user_session(PyObject *module, PyObject *args, PyObject *kwa
return PyAuthSession_FromSession(session);
}
+static PyObject *PyAuthContext_FromContext(struct auth_context *auth_context)
+{
+ return py_talloc_reference(&PyAuthContext, auth_context);
+}
+
+static PyObject *py_auth_context_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
+{
+ PyObject *py_lp_ctx;
+ PyObject *py_messaging_ctx;
+ PyObject *py_auth_context;
+ TALLOC_CTX *mem_ctx;
+ struct auth_context *auth_context;
+ struct messaging_context *messaging_context;
+ struct loadparm_context *lp_ctx;
+ struct tevent_context *ev;
+ NTSTATUS nt_status;
+
+ const char * const kwnames[] = { "lp_ctx", "messaging_ctx", NULL };
+
+ if (!PyArg_ParseTupleAndKeywords(args, kwargs, "OO",
+ discard_const_p(char *, kwnames),
+ &py_lp_ctx, &py_messaging_ctx))
+ return 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) {
+ return NULL;
+ }
+
+ ev = tevent_context_init(mem_ctx);
+ if (ev == NULL) {
+ PyErr_NoMemory();
+ return NULL;
+ }
+
+ messaging_context = py_talloc_get_type(py_messaging_ctx, struct messaging_context);
+
+ nt_status = auth_context_create(mem_ctx, ev, messaging_context, lp_ctx, &auth_context);
+
+ if (!NT_STATUS_IS_OK(nt_status)) {
+ talloc_free(mem_ctx);
+ PyErr_NTSTATUS_IS_ERR_RAISE(nt_status);
+ }
+
+ if (!talloc_reference(auth_context, lp_ctx)) {
+ talloc_free(mem_ctx);
+ PyErr_NoMemory();
+ return NULL;
+ }
+
+ if (!talloc_reference(auth_context, ev)) {
+ talloc_free(mem_ctx);
+ PyErr_NoMemory();
+ return NULL;
+ }
+
+ py_auth_context = PyAuthContext_FromContext(auth_context);
+
+ talloc_free(mem_ctx);
+
+ return py_auth_context;
+}
+
+static PyTypeObject PyAuthContext = {
+ .tp_name = "AuthContext",
+ .tp_basicsize = sizeof(py_talloc_Object),
+ .tp_flags = Py_TPFLAGS_DEFAULT,
+ .tp_new = py_auth_context_new,
+ .tp_basicsize = sizeof(py_talloc_Object),
+};
+
static PyMethodDef py_auth_methods[] = {
{ "system_session", (PyCFunction)py_system_session, METH_VARARGS, NULL },
{ "admin_session", (PyCFunction)py_admin_session, METH_VARARGS, NULL },
diff --git a/source4/auth/wscript_build b/source4/auth/wscript_build
index 71b3c9d086..c0701bf9f5 100644
--- a/source4/auth/wscript_build
+++ b/source4/auth/wscript_build
@@ -48,7 +48,7 @@ bld.SAMBA_SUBSYSTEM('auth_sam_reply',
bld.SAMBA_PYTHON('pyauth',
source='pyauth.c',
public_deps='auth_system_session',
- deps='samdb pytalloc-util pyparam_util pyldb-util pycredentials',
+ deps='samdb pytalloc-util pyparam_util pyldb-util pycredentials auth',
realname='samba/auth.so'
)