auth: Move auth_session_info into IDL
[sfrench/samba-autobuild/.git] / source4 / librpc / ndr / py_auth.c
1 /* 
2    Unix SMB/CIFS implementation.
3    Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2007-2008
4    Copyright (C) Andrew Bartlett <abartlet@samba.org> 2011
5
6    This program is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 3 of the License, or
9    (at your option) any later version.
10    
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15    
16    You should have received a copy of the GNU General Public License
17    along with this program.  If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #include <Python.h>
21 #include "includes.h"
22 #include "libcli/util/pyerrors.h"
23 #include "pyauth.h"
24 #include "auth/auth.h"
25 #include "auth/credentials/pycredentials.h"
26 #include "librpc/rpc/pyrpc_util.h"
27
28 #ifndef Py_RETURN_NONE
29 #define Py_RETURN_NONE return Py_INCREF(Py_None), Py_None
30 #endif
31
32 static void PyType_AddGetSet(PyTypeObject *type, PyGetSetDef *getset)
33 {
34         PyObject *dict;
35         int i;
36         if (type->tp_dict == NULL)
37                 type->tp_dict = PyDict_New();
38         dict = type->tp_dict;
39         for (i = 0; getset[i].name; i++) {
40                 PyObject *descr;
41                 descr = PyDescr_NewGetSet(type, &getset[i]);
42                 PyDict_SetItemString(dict, getset[i].name, 
43                                      descr);
44         }
45 }
46
47 static PyObject *py_auth_session_get_credentials(PyObject *self, void *closure)
48 {
49         struct auth_session_info *session = py_talloc_get_type(self, struct auth_session_info);
50         PyObject *py_credentials;
51         /* This is evil, as the credentials are not IDL structures */
52         py_credentials = py_return_ndr_struct("samba.credentials", "Credentials", session->credentials, session->credentials);
53         return py_credentials;
54 }
55
56 static int py_auth_session_set_credentials(PyObject *self, PyObject *value, void *closure)
57 {
58         struct auth_session_info *session = py_talloc_get_type(self, struct auth_session_info);
59         session->credentials = talloc_reference(session, PyCredentials_AsCliCredentials(value));
60         return 0;
61 }
62
63 static PyGetSetDef py_auth_session_extra_getset[] = {
64         { discard_const_p(char, "credentials"), (getter)py_auth_session_get_credentials, (setter)py_auth_session_set_credentials, NULL },
65         { NULL }
66 };
67
68 static void py_auth_session_info_patch(PyTypeObject *type)
69 {
70         PyType_AddGetSet(type, py_auth_session_extra_getset);
71 }
72
73 #define PY_SESSION_INFO_PATCH py_auth_session_info_patch
74