Fix unqualified "net join"
[Samba.git] / source4 / auth / pyauth.c
blob04880b71c93961172f16e53aae8ef706d5de01a8
1 /*
2 Unix SMB/CIFS implementation.
3 Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2007-2008
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
19 #include "includes.h"
20 #include "param/param.h"
21 #include "pyauth.h"
22 #include "auth/system_session_proto.h"
23 #include "param/pyparam.h"
25 PyTypeObject PyAuthSession = {
26 .tp_name = "AuthSession",
27 .tp_basicsize = sizeof(py_talloc_Object),
28 .tp_dealloc = py_talloc_dealloc,
29 .tp_flags = Py_TPFLAGS_DEFAULT,
30 .tp_repr = py_talloc_default_repr,
33 PyObject *PyAuthSession_FromSession(struct auth_session_info *session)
35 return py_talloc_reference(&PyAuthSession, session);
38 static PyObject *py_system_session(PyObject *module, PyObject *args)
40 PyObject *py_lp_ctx = Py_None;
41 struct loadparm_context *lp_ctx = NULL;
42 struct auth_session_info *session;
43 if (!PyArg_ParseTuple(args, "|O", &py_lp_ctx))
44 return NULL;
46 lp_ctx = lp_from_py_object(py_lp_ctx);
47 if (lp_ctx == NULL)
48 return NULL;
50 session = system_session(NULL, lp_ctx);
52 return PyAuthSession_FromSession(session);
56 static PyObject *py_system_session_anon(PyObject *module, PyObject *args)
58 PyObject *py_lp_ctx = Py_None;
59 struct loadparm_context *lp_ctx;
60 struct auth_session_info *session;
61 if (!PyArg_ParseTuple(args, "|O", &py_lp_ctx))
62 return NULL;
64 lp_ctx = lp_from_py_object(py_lp_ctx);
65 if (lp_ctx == NULL)
66 return NULL;
68 session = system_session_anon(NULL, lp_ctx);
70 return PyAuthSession_FromSession(session);
73 static PyMethodDef py_auth_methods[] = {
74 { "system_session", (PyCFunction)py_system_session, METH_VARARGS, NULL },
75 { "system_session_anonymous", (PyCFunction)py_system_session_anon, METH_VARARGS, NULL },
76 { NULL },
79 void initauth(void)
81 PyObject *m;
83 if (PyType_Ready(&PyAuthSession) < 0)
84 return;
86 m = Py_InitModule3("auth", py_auth_methods, "Authentication and authorization support.");
87 if (m == NULL)
88 return;
90 Py_INCREF(&PyAuthSession);
91 PyModule_AddObject(m, "AuthSession", (PyObject *)&PyAuthSession);