LCOV - code coverage report
Current view: top level - source3/param - pyparam.c (source / functions) Hit Total Coverage
Test: coverage report for vadcx-master-patch-75612 fe003de8 Lines: 22 31 71.0 %
Date: 2024-02-29 22:57:05 Functions: 2 2 100.0 %

          Line data    Source code
       1             : /*
       2             :    Unix SMB/CIFS implementation.
       3             :    Samba utility functions
       4             :    Copyright (C) Amitay Isaacs <amitay@gmail.com> 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 "lib/replace/system/python.h"
      21             : #include "includes.h"
      22             : #include "python/py3compat.h"
      23             : #include "param/param.h"
      24             : #include "param/loadparm.h"
      25             : #include "lib/talloc/pytalloc.h"
      26             : 
      27             : static PyTypeObject *loadparm_Type = NULL;
      28             : 
      29             : void initparam(void);
      30             : 
      31        2420 : static PyObject *py_get_context(PyObject *self, PyObject *Py_UNUSED(ignored))
      32             : {
      33          51 :         PyObject *py_loadparm;
      34          51 :         const struct loadparm_s3_helpers *s3_context;
      35          51 :         const struct loadparm_context *s4_context;
      36        2420 :         TALLOC_CTX *frame = talloc_stackframe();
      37             : 
      38        2420 :         s3_context = loadparm_s3_helpers();
      39             : 
      40        2420 :         s4_context = loadparm_init_s3(frame, s3_context);
      41        2420 :         if (s4_context == NULL) {
      42           0 :                 talloc_free(frame);
      43           0 :                 PyErr_NoMemory();
      44           0 :                 return NULL;
      45             :         }
      46             : 
      47        2420 :         py_loadparm = pytalloc_steal(loadparm_Type, discard_const_p(struct loadparm_context, s4_context));
      48        2420 :         if (py_loadparm == NULL) {
      49           0 :                 talloc_free(frame);
      50           0 :                 PyErr_NoMemory();
      51           0 :                 return NULL;
      52             :         }
      53             : 
      54        2420 :         talloc_free(frame);
      55             : 
      56        2420 :         return py_loadparm;
      57             : }
      58             : 
      59             : static PyMethodDef pyparam_methods[] = {
      60             :     { "get_context", (PyCFunction)py_get_context, METH_NOARGS,
      61             :         "Returns LoadParm context." },
      62             :     {0}
      63             : };
      64             : 
      65             : static struct PyModuleDef moduledef = {
      66             :     PyModuleDef_HEAD_INIT,
      67             :     .m_name = "param",
      68             :     .m_doc = "Parsing and writing Samba3 configuration files.",
      69             :     .m_size = -1,
      70             :     .m_methods = pyparam_methods,
      71             : };
      72             : 
      73        2972 : MODULE_INIT_FUNC(param)
      74             : {
      75        2972 :         PyObject *m = NULL, *mod = NULL;
      76             : 
      77        2972 :         m = PyModule_Create(&moduledef);
      78        2972 :         if (m == NULL)
      79           0 :                 return NULL;
      80             : 
      81        2972 :         mod = PyImport_ImportModule("samba.param");
      82        2972 :         if (mod == NULL) {
      83           0 :                 return NULL;
      84             :         }
      85             : 
      86        2972 :         loadparm_Type = (PyTypeObject *)PyObject_GetAttrString(mod, "LoadParm");
      87        2316 :         Py_DECREF(mod);
      88        2972 :         if (loadparm_Type == NULL) {
      89           0 :                 return NULL;
      90             :         }
      91        2888 :         return m;
      92             : }

Generated by: LCOV version 1.14