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