registry: Fix CID 240989 Buffer not null terminated
[Samba.git] / source4 / librpc / ndr / py_auth.c
blob95c9a30321fa82eb143ffbde6a43323b746765a0
1 /*
2 Unix SMB/CIFS implementation.
4 Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2007-2011
5 Copyright (C) Andrew Bartlett <abartlet@samba.org> 2011
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.
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.
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/>.
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"
29 static void PyType_AddGetSet(PyTypeObject *type, PyGetSetDef *getset)
31 PyObject *dict;
32 int i;
33 if (type->tp_dict == NULL)
34 type->tp_dict = PyDict_New();
35 dict = type->tp_dict;
36 for (i = 0; getset[i].name; i++) {
37 PyObject *descr;
38 descr = PyDescr_NewGetSet(type, &getset[i]);
39 PyDict_SetItemString(dict, getset[i].name,
40 descr);
44 static PyObject *py_auth_session_get_credentials(PyObject *self, void *closure)
46 struct auth_session_info *session = pytalloc_get_type(self, struct auth_session_info);
47 PyObject *py_credentials;
48 /* This is evil, as the credentials are not IDL structures */
49 py_credentials = py_return_ndr_struct("samba.credentials", "Credentials", session->credentials, session->credentials);
50 return py_credentials;
53 static int py_auth_session_set_credentials(PyObject *self, PyObject *value, void *closure)
55 struct auth_session_info *session = pytalloc_get_type(self, struct auth_session_info);
56 session->credentials = talloc_reference(session, PyCredentials_AsCliCredentials(value));
57 return 0;
60 static PyGetSetDef py_auth_session_extra_getset[] = {
61 { discard_const_p(char, "credentials"), (getter)py_auth_session_get_credentials, (setter)py_auth_session_set_credentials, NULL },
62 { NULL }
65 static void py_auth_session_info_patch(PyTypeObject *type)
67 PyType_AddGetSet(type, py_auth_session_extra_getset);
70 #define PY_SESSION_INFO_PATCH py_auth_session_info_patch