2011-08-12 09:48:03 +04:00
/*
Unix SMB / CIFS implementation .
Samba utility functions
Copyright ( C ) Amitay Isaacs < amitay @ gmail . com > 2011
This program is free software ; you can redistribute it and / or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation ; either version 3 of the License , or
( at your option ) any later version .
This program is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU General Public License for more details .
You should have received a copy of the GNU General Public License
along with this program . If not , see < http : //www.gnu.org/licenses/>.
*/
2023-11-09 13:35:56 +03:00
# include "lib/replace/system/python.h"
2011-08-12 09:48:03 +04:00
# include "includes.h"
2018-02-05 14:39:58 +03:00
# include "python/py3compat.h"
2011-08-12 09:48:03 +04:00
# include "param/param.h"
# include "param/loadparm.h"
# include "lib/talloc/pytalloc.h"
static PyTypeObject * loadparm_Type = NULL ;
void initparam ( void ) ;
2019-05-02 21:40:23 +03:00
static PyObject * py_get_context ( PyObject * self , PyObject * Py_UNUSED ( ignored ) )
2011-08-12 09:48:03 +04:00
{
PyObject * py_loadparm ;
2012-06-27 17:24:39 +04:00
const struct loadparm_s3_helpers * s3_context ;
2011-08-12 09:48:03 +04:00
const struct loadparm_context * s4_context ;
2023-10-25 13:26:44 +03:00
TALLOC_CTX * frame = talloc_stackframe ( ) ;
2011-08-12 09:48:03 +04:00
2012-06-27 17:24:39 +04:00
s3_context = loadparm_s3_helpers ( ) ;
2011-08-12 09:48:03 +04:00
2023-10-25 13:26:44 +03:00
s4_context = loadparm_init_s3 ( frame , s3_context ) ;
2011-08-12 09:48:03 +04:00
if ( s4_context = = NULL ) {
2023-10-25 13:26:44 +03:00
talloc_free ( frame ) ;
2011-08-12 09:48:03 +04:00
PyErr_NoMemory ( ) ;
return NULL ;
}
py_loadparm = pytalloc_steal ( loadparm_Type , discard_const_p ( struct loadparm_context , s4_context ) ) ;
if ( py_loadparm = = NULL ) {
2023-10-25 13:26:44 +03:00
talloc_free ( frame ) ;
2011-08-12 09:48:03 +04:00
PyErr_NoMemory ( ) ;
return NULL ;
}
2023-10-25 13:26:44 +03:00
talloc_free ( frame ) ;
2011-08-12 09:48:03 +04:00
return py_loadparm ;
}
static PyMethodDef pyparam_methods [ ] = {
{ " get_context " , ( PyCFunction ) py_get_context , METH_NOARGS ,
" Returns LoadParm context. " } ,
2020-05-05 04:47:39 +03:00
{ 0 }
2011-08-12 09:48:03 +04:00
} ;
2018-02-05 14:39:58 +03:00
static struct PyModuleDef moduledef = {
PyModuleDef_HEAD_INIT ,
. m_name = " param " ,
. m_doc = " Parsing and writing Samba3 configuration files. " ,
. m_size = - 1 ,
. m_methods = pyparam_methods ,
} ;
MODULE_INIT_FUNC ( param )
2011-08-12 09:48:03 +04:00
{
2018-02-05 14:39:58 +03:00
PyObject * m = NULL , * mod = NULL ;
2011-08-12 09:48:03 +04:00
2018-02-05 14:39:58 +03:00
m = PyModule_Create ( & moduledef ) ;
2011-08-12 09:48:03 +04:00
if ( m = = NULL )
2018-02-05 14:39:58 +03:00
return NULL ;
2011-08-12 09:48:03 +04:00
mod = PyImport_ImportModule ( " samba.param " ) ;
if ( mod = = NULL ) {
2018-02-05 14:39:58 +03:00
return NULL ;
2011-08-12 09:48:03 +04:00
}
loadparm_Type = ( PyTypeObject * ) PyObject_GetAttrString ( mod , " LoadParm " ) ;
Py_DECREF ( mod ) ;
if ( loadparm_Type = = NULL ) {
2018-02-05 14:39:58 +03:00
return NULL ;
2011-08-12 09:48:03 +04:00
}
2018-02-05 14:39:58 +03:00
return m ;
2011-08-12 09:48:03 +04:00
}