LCOV - code coverage report
Current view: top level - source4/librpc/ndr - py_auth.c (source / functions) Hit Total Coverage
Test: coverage report for master 2f515e9b Lines: 18 24 75.0 %
Date: 2024-04-21 15:09:00 Functions: 3 4 75.0 %

          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 "lib/replace/system/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        3610 : static void PyType_AddGetSet(PyTypeObject *type, PyGetSetDef *getset)
      30             : {
      31         123 :         PyObject *dict;
      32         123 :         int i;
      33        3610 :         if (type->tp_dict == NULL)
      34           0 :                 type->tp_dict = PyDict_New();
      35        3610 :         dict = type->tp_dict;
      36        7220 :         for (i = 0; getset[i].name; i++) {
      37         123 :                 PyObject *descr;
      38        3610 :                 descr = PyDescr_NewGetSet(type, &getset[i]);
      39        3610 :                 PyDict_SetItemString(dict, getset[i].name, 
      40             :                                      descr);
      41        3610 :                 Py_CLEAR(descr);
      42             :         }
      43        3610 : }
      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           0 :         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        3610 : static void py_auth_session_info_patch(PyTypeObject *type)
      71             : {
      72        3610 :         PyType_AddGetSet(type, py_auth_session_extra_getset);
      73        3487 : }
      74             : 
      75             : #define PY_SESSION_INFO_PATCH py_auth_session_info_patch
      76             : 

Generated by: LCOV version 1.14