From: Nick Porter Date: Tue, 23 May 2023 15:10:57 +0000 (+0100) Subject: Add a global config for libpython X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6a04e2b7d8921910b5b6b50c5d3226812e79b607;p=thirdparty%2Ffreeradius-server.git Add a global config for libpython --- diff --git a/raddb/global.d/python b/raddb/global.d/python new file mode 100644 index 00000000000..5bc6df7953e --- /dev/null +++ b/raddb/global.d/python @@ -0,0 +1,17 @@ +python { + # + # path:: + # + # The search path for Python modules. It must include the path to your + # Python module. + # +# path = ${modconfdir}/${.:name} + + # + # path_include_default:: + # + # If "yes", retain the default search path. Any additional search + # path components will be prepended to the the default search path. + # +# path_include_default = "yes" +} diff --git a/src/modules/rlm_python/rlm_python.c b/src/modules/rlm_python/rlm_python.c index 7dd657601a0..792e1bf5ff1 100644 --- a/src/modules/rlm_python/rlm_python.c +++ b/src/modules/rlm_python/rlm_python.c @@ -77,6 +77,14 @@ typedef struct { //!< made available to the python script. } rlm_python_t; +/** Global config for python library + * + */ +typedef struct { + char const *path; //!< Path to search for python files in. + bool path_include_default; //!< Include the default python path in `path` +} libpython_global_config_t; + /** Tracks a python module inst/thread state pair * * Multiple instances of python create multiple interpreters and each @@ -93,6 +101,29 @@ static module_ctx_t const *current_mctx; //!< Used for communication with initt static CONF_SECTION *current_conf; //!< Used for communication with inittab functions. static char *default_path; //!< The default python path. +static libpython_global_config_t libpython_global_config = { + .path = NULL, + .path_include_default = true +}; + +static CONF_PARSER const python_global_config[] = { + { FR_CONF_OFFSET("path", FR_TYPE_STRING, libpython_global_config_t, path) }, + { FR_CONF_OFFSET("path_include_default", FR_TYPE_BOOL, libpython_global_config_t, path_include_default) }, + CONF_PARSER_TERMINATOR +}; + +global_lib_autoinst_t rlm_python_autoinst = { + .name = "python", + .config = python_global_config, + .inst = &libpython_global_config +}; + +extern global_lib_autoinst_t const * const rlm_python_lib[]; +global_lib_autoinst_t const * const rlm_python_lib[] = { + &rlm_python_autoinst, + GLOBAL_LIB_TERMINATOR +}; + /* * As of Python 3.8 the GIL will be per-interpreter * If there are still issues with CEXTs,