LCOV - code coverage report
Current view: top level - source3/param - pyparam.c (source / functions) Hit Total Coverage
Test: coverage report for v4-17-test 1498b464 Lines: 20 30 66.7 %
Date: 2024-06-13 04:01:37 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 <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         803 : static PyObject *py_get_context(PyObject *self, PyObject *Py_UNUSED(ignored))
      32             : {
      33             :         PyObject *py_loadparm;
      34             :         const struct loadparm_s3_helpers *s3_context;
      35             :         const struct loadparm_context *s4_context;
      36             :         TALLOC_CTX *mem_ctx;
      37             : 
      38         803 :         mem_ctx = talloc_new(NULL);
      39         803 :         if (mem_ctx == NULL) {
      40           0 :                 PyErr_NoMemory();
      41           0 :                 return NULL;
      42             :         }
      43             : 
      44         803 :         s3_context = loadparm_s3_helpers();
      45             : 
      46         803 :         s4_context = loadparm_init_s3(mem_ctx, s3_context);
      47         803 :         if (s4_context == NULL) {
      48           0 :                 PyErr_NoMemory();
      49           0 :                 return NULL;
      50             :         }
      51             : 
      52         803 :         py_loadparm = pytalloc_steal(loadparm_Type, discard_const_p(struct loadparm_context, s4_context));
      53         803 :         if (py_loadparm == NULL) {
      54           0 :                 talloc_free(mem_ctx);
      55           0 :                 PyErr_NoMemory();
      56           0 :                 return NULL;
      57             :         }
      58             : 
      59         803 :         talloc_free(mem_ctx);
      60             : 
      61         803 :         return py_loadparm;
      62             : }
      63             : 
      64             : static PyMethodDef pyparam_methods[] = {
      65             :     { "get_context", (PyCFunction)py_get_context, METH_NOARGS,
      66             :         "Returns LoadParm context." },
      67             :     {0}
      68             : };
      69             : 
      70             : static struct PyModuleDef moduledef = {
      71             :     PyModuleDef_HEAD_INIT,
      72             :     .m_name = "param",
      73             :     .m_doc = "Parsing and writing Samba3 configuration files.",
      74             :     .m_size = -1,
      75             :     .m_methods = pyparam_methods,
      76             : };
      77             : 
      78        1202 : MODULE_INIT_FUNC(param)
      79             : {
      80        1202 :         PyObject *m = NULL, *mod = NULL;
      81             : 
      82        1202 :         m = PyModule_Create(&moduledef);
      83        1202 :         if (m == NULL)
      84           0 :                 return NULL;
      85             : 
      86        1202 :         mod = PyImport_ImportModule("samba.param");
      87        1202 :         if (mod == NULL) {
      88           0 :                 return NULL;
      89             :         }
      90             : 
      91        1202 :         loadparm_Type = (PyTypeObject *)PyObject_GetAttrString(mod, "LoadParm");
      92        1202 :         Py_DECREF(mod);
      93        1202 :         if (loadparm_Type == NULL) {
      94           0 :                 return NULL;
      95             :         }
      96        1202 :         return m;
      97             : }

Generated by: LCOV version 1.13