![]() |
The FreeRADIUS server $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
|
Translates requests between the server an a python interpreter. More...
#include <freeradius-devel/server/base.h>
#include <freeradius-devel/server/module_rlm.h>
#include <freeradius-devel/server/pairmove.h>
#include <freeradius-devel/util/debug.h>
#include <freeradius-devel/util/lsan.h>
#include <Python.h>
#include <structmember.h>
#include <frameobject.h>
#include <libgen.h>
#include <dlfcn.h>
Go to the source code of this file.
Data Structures | |
struct | libpython_global_config_t |
Global config for python library. More... | |
struct | py_freeradius_pair_t |
Additional fields for pairs. More... | |
struct | py_freeradius_request_t |
struct | py_freeradius_state_t |
Wrapper around a python instance. More... | |
struct | python_call_env_t |
struct | python_func_def_t |
Specifies the module.function to load for processing a section. More... | |
struct | rlm_python_t |
An instance of the rlm_python module. More... | |
struct | rlm_python_thread_t |
Tracks a python module inst/thread state pair. More... | |
Macros | |
#define | _PyCFunction_CAST(func) (PyCFunction)((void(*)(void))(func)) |
#define | A(x) |
#define | A(x) { #x, x }, |
#define | LOAD_INFO(_fmt, ...) fr_log(LOG_DST, L_INFO, __FILE__, __LINE__, "rlm_python - " _fmt, ## __VA_ARGS__) |
#define | LOAD_WARN(_fmt, ...) |
#define | LOG_PREFIX inst->name |
#define | PYTHON_FUNC_DESTROY(_x) python_function_destroy(&inst->_x) |
#define | PYTHON_FUNC_LOAD(_x) if (python_function_load(mctx, &inst->_x) < 0) goto error |
Functions | |
static unlang_action_t | do_python_single (rlm_rcode_t *p_result, module_ctx_t const *mctx, request_t *request, PyObject *p_func, char const *funcname) |
static void | libpython_free (void) |
static int | libpython_init (void) |
static int | mod_detach (module_detach_ctx_t const *mctx) |
static int | mod_instantiate (module_inst_ctx_t const *mctx) |
static unlang_action_t | mod_python (rlm_rcode_t *p_result, module_ctx_t const *mctx, request_t *request) |
Thread safe call to a python function. | |
static int | mod_thread_detach (module_thread_inst_ctx_t const *mctx) |
static int | mod_thread_instantiate (module_thread_inst_ctx_t const *mctx) |
static PyObject * | pair_list_alloc (request_t *request, fr_dict_attr_t const *list) |
Create the Python object representing a pair list. | |
static PyObject * | py_freeradius_attribute_instance (PyObject *self, PyObject *attr) |
Returns a specific instance of freeradius.Pair. | |
static fr_pair_t * | py_freeradius_build_parents (PyObject *obj) |
Build out missing parent pairs when a leaf node is assigned a value. | |
static PyObject * | py_freeradius_log (UNUSED PyObject *self, PyObject *args, PyObject *kwds) |
Allow fr_log to be called from python. | |
static PyObject * | py_freeradius_pair_getvalue (PyObject *self, UNUSED void *closure) |
Return a native Python object of the appropriate type for leaf pair objects. | |
static PyObject * | py_freeradius_pair_getvalue (PyObject *self, void *closure) |
static int | py_freeradius_pair_map_set (PyObject *self, PyObject *attr, PyObject *value) |
Set the value of a pair. | |
static PyObject * | py_freeradius_pair_map_subscript (PyObject *self, PyObject *attr) |
Returns a freeradius.Pair. | |
static int | py_freeradius_pair_setvalue (PyObject *self, PyObject *value, UNUSED void *closure) |
Use a native Python object of the appropriate type to set a leaf pair. | |
static int | py_freeradius_pair_setvalue (PyObject *self, PyObject *value, void *closure) |
static PyObject * | py_freeradius_pair_str (PyObject *self) |
Return the string representation of a leaf pair node. | |
static int | py_freeradius_state_init (PyObject *self, UNUSED PyObject *args, UNUSED PyObject *kwds) |
static void | python_error_log (rlm_python_t const *inst, request_t *request) |
Print out the current error. | |
static int8_t | python_func_def_cmp (void const *one, void const *two) |
How to compare two Python calls. | |
static void | python_func_name_safe (char *name) |
static int | python_func_parse (TALLOC_CTX *ctx, call_env_parsed_head_t *out, UNUSED tmpl_rules_t const *t_rules, UNUSED CONF_ITEM *ci, call_env_ctx_t const *cec, UNUSED call_env_parser_t const *rule) |
static void | python_function_destroy (python_func_def_t *def) |
static int | python_function_load (module_inst_ctx_t const *mctx, python_func_def_t *def) |
Import a user module and load a function from it. | |
static void | python_interpreter_free (rlm_python_t *inst, PyThreadState *interp) |
static int | python_interpreter_init (module_inst_ctx_t const *mctx) |
static int | python_module_import_config (rlm_python_t *inst, CONF_SECTION *conf, PyObject *module) |
Make the current instance's config available within the module we're initialising. | |
static int | python_module_import_constants (rlm_python_t const *inst, PyObject *module) |
Import integer constants into the module we're initialising. | |
static PyObject * | python_module_init (void) |
static void | python_obj_destroy (PyObject **ob) |
static int | python_parse_config (rlm_python_t const *inst, CONF_SECTION *cs, int lvl, PyObject *dict) |
static rlm_python_t const * | rlm_python_get_inst (void) |
Return the rlm_python instance associated with the current interpreter. | |
static request_t * | rlm_python_get_request (void) |
Return the request associated with the current thread state. | |
static void | rlm_python_set_request (request_t *request) |
Set the request associated with the current thread state. | |
static py_freeradius_state_t * | rlm_python_state_obj (void) |
Return the module instance object associated with the thread state or interpreter state. | |
Variables | ||
static CONF_SECTION * | current_conf | |
Used for communication with inittab functions. | ||
static rlm_python_t const * | current_inst = NULL | |
Used for communication with inittab functions. | ||
static rlm_python_thread_t * | current_t | |
Used for communicating with object init function. | ||
struct { | ||
char const * | name | |
int | value | |
} | freeradius_constants [] | |
static PyThreadState * | global_interpreter | |
Our first interpreter. | ||
static libpython_global_config_t | libpython_global_config | |
static conf_parser_t | module_config [] | |
static PyModuleDef | py_freeradius_def | |
static PyTypeObject | py_freeradius_grouping_pair_def | |
Contains group attribute of a specific type. | ||
static PyMethodDef | py_freeradius_methods [] | |
static PyTypeObject | py_freeradius_pair_def | |
The class which all pair types inherit from. | ||
static PyGetSetDef | py_freeradius_pair_getset [] | |
How to access "value" attribute of a pair. | ||
static PyTypeObject | py_freeradius_pair_list_def | |
Each instance contains a top level list (i.e. | ||
static PyMemberDef | py_freeradius_request_attrs [] | |
static PyTypeObject | py_freeradius_request_def | |
static PyTypeObject | py_freeradius_state_def | |
static PyTypeObject | py_freeradius_value_pair_def | |
Contains a value pair of a specific type. | ||
static void * | python_dlhandle | |
static conf_parser_t const | python_global_config [] | |
static const call_env_method_t | python_method_env | |
module_rlm_t | rlm_python | |
static global_lib_autoinst_t | rlm_python_autoinst | |
global_lib_autoinst_t const *const | rlm_python_lib [] | |
Translates requests between the server an a python interpreter.
Definition in file rlm_python.c.
struct libpython_global_config_t |
Global config for python library.
Definition at line 79 of file rlm_python.c.
Data Fields | ||
---|---|---|
char const * | path | Path to search for python files in. |
bool | path_include_default |
Include the default python path in path |
bool | verbose | Enable libpython verbose logging. |
struct py_freeradius_pair_t |
Additional fields for pairs.
Definition at line 102 of file rlm_python.c.
Data Fields | ||
---|---|---|
PyObject_HEAD fr_dict_attr_t const * | da |
< Common fields needed for every python object. dictionary attribute for this pair. |
unsigned int | idx | Instance index. |
PyObject * | parent | Parent object of this pair. |
fr_pair_t * | vp | Real FreeRADIUS pair for this Python pair. |
struct py_freeradius_request_t |
Definition at line 110 of file rlm_python.c.
struct py_freeradius_state_t |
Wrapper around a python instance.
This is added to the FreeRADIUS module to allow us to get at the global and thread local instance data.
Definition at line 123 of file rlm_python.c.
Data Fields | ||
---|---|---|
PyObject_HEAD rlm_python_t const * | inst |
< Common fields needed for every python object. Module instance. |
request_t * | request | Current request. |
rlm_python_thread_t * | t | Thread-specific python instance. |
struct python_call_env_t |
Definition at line 85 of file rlm_python.c.
Data Fields | ||
---|---|---|
python_func_def_t * | func |
struct python_func_def_t |
Specifies the module.function to load for processing a section.
Definition at line 46 of file rlm_python.c.
Data Fields | ||
---|---|---|
PyObject *PyObject * | function |
< Python reference to module. Python reference to function in module. |
char const * | function_name | String name of function in module. |
char const * | module_name | String name of module. |
char * | name1 | Section name1 where this is called. |
char * | name2 | Section name2 where this is called. |
fr_rb_node_t | node | Entry in tree of Python functions. |
struct rlm_python_t |
An instance of the rlm_python module.
Definition at line 60 of file rlm_python.c.
Data Fields | ||
---|---|---|
PyObject *char const * | def_module_name |
< Local, interpreter specific module. Default module for Python functions |
python_func_def_t | detach | |
fr_rb_tree_t | funcs | Tree of function calls found by call_env parser. |
bool | funcs_init | Has the tree been initialised. |
python_func_def_t | instantiate | |
PyThreadState * | interpreter | The interpreter used for this instance of rlm_python. |
char const * | name | Name of the module instance. |
PyObject * | pythonconf_dict | Configuration parameters defined in the module made available to the python script. |
struct rlm_python_thread_t |
Tracks a python module inst/thread state pair.
Multiple instances of python create multiple interpreters and each thread must have a PyThreadState per interpreter, to track execution.
Definition at line 94 of file rlm_python.c.
Data Fields | ||
---|---|---|
rlm_python_t const * | inst | Current module instance data. |
PyThreadState * | state | Module instance/thread specific state. |
#define _PyCFunction_CAST | ( | func | ) | (PyCFunction)((void(*)(void))(func)) |
Definition at line 375 of file rlm_python.c.
#define A | ( | x | ) |
#define A | ( | x | ) | { #x, x }, |
#define LOAD_INFO | ( | _fmt, | |
... | |||
) | fr_log(LOG_DST, L_INFO, __FILE__, __LINE__, "rlm_python - " _fmt, ## __VA_ARGS__) |
#define LOAD_WARN | ( | _fmt, | |
... | |||
) |
Definition at line 29 of file rlm_python.c.
#define PYTHON_FUNC_DESTROY | ( | _x | ) | python_function_destroy(&inst->_x) |
#define PYTHON_FUNC_LOAD | ( | _x | ) | if (python_function_load(mctx, &inst->_x) < 0) goto error |
|
static |
Definition at line 1182 of file rlm_python.c.
|
static |
Definition at line 1958 of file rlm_python.c.
|
static |
|
static |
|
static |
|
static |
Thread safe call to a python function.
Will swap in thread state specific to module/thread.
Definition at line 1270 of file rlm_python.c.
|
static |
Definition at line 1859 of file rlm_python.c.
|
static |
Definition at line 1807 of file rlm_python.c.
|
inlinestatic |
Create the Python object representing a pair list.
Definition at line 1158 of file rlm_python.c.
|
static |
Returns a specific instance of freeradius.Pair.
Called when a numeric index is used on a PairGroup or PairValue as part of an object getter
Definition at line 522 of file rlm_python.c.
|
static |
Build out missing parent pairs when a leaf node is assigned a value.
Definition at line 618 of file rlm_python.c.
|
static |
Allow fr_log to be called from python.
Definition at line 487 of file rlm_python.c.
|
static |
Return a native Python object of the appropriate type for leaf pair objects.
Accessed as ‘request['attr’].value`
self
is the Python leaf pair object
Definition at line 800 of file rlm_python.c.
|
static |
|
static |
Set the value of a pair.
Called with two Python syntaxes
self
will be the parent object - either the list or parent structural object. attr
is the value in []. value
is what we want to set the pair to.self
will be the first instance of the attribute foo
attr
will be the instance number value
is what we want to set the pair to.We expect value
to be a UTF8 string object.
Due to Python "magic" this is also called when ‘del request['foo’]` happens - only with value as NULL.
Definition at line 662 of file rlm_python.c.
|
static |
Returns a freeradius.Pair.
Called when pair["attr"] or pair["attr"][n] is accessed. When pair["attr"] is accessed, self
is pair
- which is the list or a pair group object When pair["attr"][n] is accessed, self
is pair["attr"]
Either a group object or pair object will be returned.
Definition at line 561 of file rlm_python.c.
|
static |
Use a native Python object of the appropriate type to set a leaf pair.
Using Python syntax ‘request['attr’].value = objector
request['attr'][n].value`
self
is the Python object representing the leaf node pair
Definition at line 906 of file rlm_python.c.
|
static |
|
static |
Return the string representation of a leaf pair node.
Called when the attribute is accessed in print() or str() or selective other magical Python contexts.
Definition at line 1064 of file rlm_python.c.
|
static |
Definition at line 505 of file rlm_python.c.
|
static |
Print out the current error.
Must be called with a valid thread state set
Definition at line 1105 of file rlm_python.c.
|
static |
How to compare two Python calls.
Definition at line 412 of file rlm_python.c.
|
static |
|
static |
|
static |
Definition at line 1298 of file rlm_python.c.
|
static |
Import a user module and load a function from it.
Definition at line 1307 of file rlm_python.c.
|
static |
|
static |
Definition at line 1591 of file rlm_python.c.
|
static |
Make the current instance's config available within the module we're initialising.
Definition at line 1441 of file rlm_python.c.
|
static |
Import integer constants into the module we're initialising.
Definition at line 1476 of file rlm_python.c.
|
static |
Definition at line 1494 of file rlm_python.c.
|
static |
|
static |
Definition at line 1358 of file rlm_python.c.
|
static |
Return the rlm_python instance associated with the current interpreter.
Definition at line 449 of file rlm_python.c.
|
static |
Return the request associated with the current thread state.
Definition at line 461 of file rlm_python.c.
|
static |
Set the request associated with the current thread state.
Definition at line 474 of file rlm_python.c.
|
inlinestatic |
Return the module instance object associated with the thread state or interpreter state.
Definition at line 428 of file rlm_python.c.
|
static |
Used for communication with inittab functions.
Definition at line 134 of file rlm_python.c.
|
static |
Used for communication with inittab functions.
Definition at line 133 of file rlm_python.c.
|
static |
Used for communicating with object init function.
Definition at line 135 of file rlm_python.c.
struct { ... } freeradius_constants[] |
|
static |
Our first interpreter.
Definition at line 131 of file rlm_python.c.
|
static |
Definition at line 148 of file rlm_python.c.
|
static |
Definition at line 190 of file rlm_python.c.
|
static |
Definition at line 401 of file rlm_python.c.
|
static |
Contains group attribute of a specific type.
Children of this attribute may be accessed using the map protocol i.e. foo['child-of-foo'].
Definition at line 293 of file rlm_python.c.
|
static |
Definition at line 381 of file rlm_python.c.
|
static |
The class which all pair types inherit from.
Definition at line 246 of file rlm_python.c.
|
static |
How to access "value" attribute of a pair.
Definition at line 259 of file rlm_python.c.
|
static |
Each instance contains a top level list (i.e.
request, reply, control, session-state)
Definition at line 308 of file rlm_python.c.
|
static |
Definition at line 320 of file rlm_python.c.
|
static |
Definition at line 352 of file rlm_python.c.
|
static |
Definition at line 363 of file rlm_python.c.
|
static |
Contains a value pair of a specific type.
Definition at line 273 of file rlm_python.c.
|
static |
Definition at line 130 of file rlm_python.c.
|
static |
Definition at line 153 of file rlm_python.c.
|
static |
Definition at line 2037 of file rlm_python.c.
module_rlm_t rlm_python |
Definition at line 2055 of file rlm_python.c.
|
static |
Definition at line 163 of file rlm_python.c.
global_lib_autoinst_t const *const rlm_python_lib |
Definition at line 172 of file rlm_python.c.