]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Add a global config for libpython
authorNick Porter <nick@portercomputing.co.uk>
Tue, 23 May 2023 15:10:57 +0000 (16:10 +0100)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Thu, 25 May 2023 13:43:52 +0000 (09:43 -0400)
raddb/global.d/python [new file with mode: 0644]
src/modules/rlm_python/rlm_python.c

diff --git a/raddb/global.d/python b/raddb/global.d/python
new file mode 100644 (file)
index 0000000..5bc6df7
--- /dev/null
@@ -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"
+}
index 7dd657601a0b8823b80ee973ce8a197e6f9e726c..792e1bf5ff1b560ea609ec17ff3b32b31c7afb82 100644 (file)
@@ -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,