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/>.
20 #include "param/param.h"
22 #include "auth/system_session_proto.h"
24 /* FIXME: These should be in a header file somewhere, once we finish moving
25 * away from SWIG .. */
26 extern struct loadparm_context *lp_from_py_object(PyObject *py_obj);
28 PyTypeObject PyAuthSession = {
29 .tp_name = "AuthSession",
30 .tp_basicsize = sizeof(py_talloc_Object),
31 .tp_dealloc = py_talloc_dealloc,
32 .tp_flags = Py_TPFLAGS_DEFAULT,
33 .tp_repr = py_talloc_default_repr,
36 PyObject *PyAuthSession_FromSession(struct auth_session_info *session)
38 return py_talloc_import(&PyAuthSession, session);
41 static PyObject *py_system_session(PyObject *module, PyObject *args)
43 PyObject *py_lp_ctx = Py_None;
44 struct loadparm_context *lp_ctx = NULL;
45 struct auth_session_info *session;
46 if (!PyArg_ParseTuple(args, "|O", &py_lp_ctx))
49 lp_ctx = lp_from_py_object(py_lp_ctx);
53 session = system_session(NULL, lp_ctx);
55 return PyAuthSession_FromSession(session);
59 static PyObject *py_system_session_anon(PyObject *module, PyObject *args)
61 PyObject *py_lp_ctx = Py_None;
62 struct loadparm_context *lp_ctx;
63 struct auth_session_info *session;
64 if (!PyArg_ParseTuple(args, "|O", &py_lp_ctx))
67 lp_ctx = lp_from_py_object(py_lp_ctx);
71 session = system_session_anon(NULL, lp_ctx);
73 return PyAuthSession_FromSession(session);
76 static PyMethodDef py_auth_methods[] = {
77 { "system_session", (PyCFunction)py_system_session, METH_VARARGS, NULL },
78 { "system_session_anonymous", (PyCFunction)py_system_session_anon, METH_VARARGS, NULL },
86 if (PyType_Ready(&PyAuthSession) < 0)
89 m = Py_InitModule3("auth", py_auth_methods, "Authentication and authorization support.");
93 Py_INCREF(&PyAuthSession);
94 PyModule_AddObject(m, "AuthSession", (PyObject *)&PyAuthSession);