The FreeRADIUS server $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
Loading...
Searching...
No Matches
Data Structures | Macros | Functions | Variables
rlm_python.c File Reference

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>
+ Include dependency graph for rlm_python.c:

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_tpy_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_trlm_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_trlm_python_state_obj (void)
 Return the module instance object associated with the thread state or interpreter state.
 

Variables

static CONF_SECTIONcurrent_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_tcurrent_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 []
 

Detailed Description

Translates requests between the server an a python interpreter.

Id
f08823aa4a80e0598dc9f0c4239f458e9f10c9e3
Note
Rewritten by Nick Porter for FreeRADIUS v4

Definition in file rlm_python.c.


Data Structure Documentation

◆ libpython_global_config_t

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.

◆ py_freeradius_pair_t

struct py_freeradius_pair_t

Additional fields for pairs.

Definition at line 102 of file rlm_python.c.

+ Collaboration diagram for py_freeradius_pair_t:
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.

◆ py_freeradius_request_t

struct py_freeradius_request_t

Definition at line 110 of file rlm_python.c.

Data Fields
PyObject * control Control list.
PyObject * reply Reply list.
PyObject_HEAD PyObject * request < Common fields needed for every python object.

Request list.

PyObject * state Session state list.

◆ py_freeradius_state_t

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.

+ Collaboration diagram for py_freeradius_state_t:
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.

◆ python_call_env_t

struct python_call_env_t

Definition at line 85 of file rlm_python.c.

+ Collaboration diagram for python_call_env_t:
Data Fields
python_func_def_t * func

◆ python_func_def_t

struct python_func_def_t

Specifies the module.function to load for processing a section.

Definition at line 46 of file rlm_python.c.

+ Collaboration diagram for python_func_def_t:
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.

◆ rlm_python_t

struct rlm_python_t

An instance of the rlm_python module.

Definition at line 60 of file rlm_python.c.

+ Collaboration diagram for rlm_python_t:
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.

◆ rlm_python_thread_t

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.

+ Collaboration diagram for rlm_python_thread_t:
Data Fields
rlm_python_t const * inst Current module instance data.
PyThreadState * state Module instance/thread specific state.

Macro Definition Documentation

◆ _PyCFunction_CAST

#define _PyCFunction_CAST (   func)    (PyCFunction)((void(*)(void))(func))

Definition at line 375 of file rlm_python.c.

◆ A [1/2]

#define A (   x)
Value:
{ FR_CONF_OFFSET("mod_" #x, rlm_python_t, x.module_name), .dflt = "${.module}" }, \
{ FR_CONF_OFFSET("func_" #x, rlm_python_t, x.function_name) },
#define FR_CONF_OFFSET(_name, _struct, _field)
conf_parser_t which parses a single CONF_PAIR, writing the result to a field in a struct
Definition cf_parse.h:284
An instance of the rlm_python module.
Definition rlm_python.c:60

◆ A [2/2]

#define A (   x)    { #x, x },

◆ LOAD_INFO

#define LOAD_INFO (   _fmt,
  ... 
)    fr_log(LOG_DST, L_INFO, __FILE__, __LINE__, "rlm_python - " _fmt, ## __VA_ARGS__)

◆ LOAD_WARN

#define LOAD_WARN (   _fmt,
  ... 
)
Value:
fr_log_perror(LOG_DST, L_WARN, __FILE__, __LINE__, \
.first_prefix = "rlm_python - ", \
.subsq_prefix = "rlm_python - ", \
}, \
_fmt, ## __VA_ARGS__)
#define LOG_DST
Definition network.c:29
void fr_log_perror(fr_log_t const *log, fr_log_type_t type, char const *file, int line, fr_log_perror_format_t const *rules, char const *fmt,...)
Drain any outstanding messages from the fr_strerror buffers.
Definition log.c:706
@ L_WARN
Warning.
Definition log.h:57

◆ LOG_PREFIX

#define LOG_PREFIX   inst->name

Definition at line 29 of file rlm_python.c.

◆ PYTHON_FUNC_DESTROY

#define PYTHON_FUNC_DESTROY (   _x)    python_function_destroy(&inst->_x)

◆ PYTHON_FUNC_LOAD

#define PYTHON_FUNC_LOAD (   _x)    if (python_function_load(mctx, &inst->_x) < 0) goto error

Function Documentation

◆ do_python_single()

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

Definition at line 1182 of file rlm_python.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ libpython_free()

static void libpython_free ( void  )
static

Definition at line 1958 of file rlm_python.c.

◆ libpython_init()

static int libpython_init ( void  )
static

Definition at line 1872 of file rlm_python.c.

+ Here is the call graph for this function:

◆ mod_detach()

static int mod_detach ( module_detach_ctx_t const *  mctx)
static

Definition at line 1759 of file rlm_python.c.

+ Here is the call graph for this function:

◆ mod_instantiate()

static int mod_instantiate ( module_inst_ctx_t const *  mctx)
static

Definition at line 1665 of file rlm_python.c.

+ Here is the call graph for this function:

◆ mod_python()

static unlang_action_t mod_python ( rlm_rcode_t p_result,
module_ctx_t const *  mctx,
request_t request 
)
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.

+ Here is the call graph for this function:

◆ mod_thread_detach()

static int mod_thread_detach ( module_thread_inst_ctx_t const *  mctx)
static

Definition at line 1859 of file rlm_python.c.

◆ mod_thread_instantiate()

static int mod_thread_instantiate ( module_thread_inst_ctx_t const *  mctx)
static

Definition at line 1807 of file rlm_python.c.

◆ pair_list_alloc()

static PyObject * pair_list_alloc ( request_t request,
fr_dict_attr_t const *  list 
)
inlinestatic

Create the Python object representing a pair list.

Definition at line 1158 of file rlm_python.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ py_freeradius_attribute_instance()

static PyObject * py_freeradius_attribute_instance ( PyObject *  self,
PyObject *  attr 
)
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.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ py_freeradius_build_parents()

static fr_pair_t * py_freeradius_build_parents ( PyObject *  obj)
static

Build out missing parent pairs when a leaf node is assigned a value.

Definition at line 618 of file rlm_python.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ py_freeradius_log()

static PyObject * py_freeradius_log ( UNUSED PyObject *  self,
PyObject *  args,
PyObject *  kwds 
)
static

Allow fr_log to be called from python.

Definition at line 487 of file rlm_python.c.

+ Here is the call graph for this function:

◆ py_freeradius_pair_getvalue() [1/2]

static PyObject * py_freeradius_pair_getvalue ( PyObject *  self,
UNUSED void *  closure 
)
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.

+ Here is the call graph for this function:

◆ py_freeradius_pair_getvalue() [2/2]

static PyObject * py_freeradius_pair_getvalue ( PyObject *  self,
void *  closure 
)
static

◆ py_freeradius_pair_map_set()

static int py_freeradius_pair_map_set ( PyObject *  self,
PyObject *  attr,
PyObject *  value 
)
static

Set the value of a pair.

Called with two Python syntaxes

  • request['foo'] = 'baa' 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.
    • request['foo'][n] = 'baa' 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.

+ Here is the call graph for this function:

◆ py_freeradius_pair_map_subscript()

static PyObject * py_freeradius_pair_map_subscript ( PyObject *  self,
PyObject *  attr 
)
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.

+ Here is the call graph for this function:

◆ py_freeradius_pair_setvalue() [1/2]

static int py_freeradius_pair_setvalue ( PyObject *  self,
PyObject *  value,
UNUSED void *  closure 
)
static

Use a native Python object of the appropriate type to set a leaf pair.

Using Python syntax ‘request['attr’].value = objectorrequest['attr'][n].value`

self is the Python object representing the leaf node pair

Definition at line 906 of file rlm_python.c.

+ Here is the call graph for this function:

◆ py_freeradius_pair_setvalue() [2/2]

static int py_freeradius_pair_setvalue ( PyObject *  self,
PyObject *  value,
void *  closure 
)
static

◆ py_freeradius_pair_str()

static PyObject * py_freeradius_pair_str ( PyObject *  self)
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.

+ Here is the call graph for this function:

◆ py_freeradius_state_init()

static int py_freeradius_state_init ( PyObject *  self,
UNUSED PyObject *  args,
UNUSED PyObject *  kwds 
)
static

Definition at line 505 of file rlm_python.c.

◆ python_error_log()

static void python_error_log ( rlm_python_t const *  inst,
request_t request 
)
static

Print out the current error.

Must be called with a valid thread state set

Definition at line 1105 of file rlm_python.c.

+ Here is the caller graph for this function:

◆ python_func_def_cmp()

static int8_t python_func_def_cmp ( void const *  one,
void const *  two 
)
static

How to compare two Python calls.

Definition at line 412 of file rlm_python.c.

+ Here is the caller graph for this function:

◆ python_func_name_safe()

static void python_func_name_safe ( char *  name)
static

Definition at line 1975 of file rlm_python.c.

+ Here is the caller graph for this function:

◆ python_func_parse()

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

Definition at line 1987 of file rlm_python.c.

+ Here is the call graph for this function:

◆ python_function_destroy()

static void python_function_destroy ( python_func_def_t def)
static

Definition at line 1298 of file rlm_python.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ python_function_load()

static int python_function_load ( module_inst_ctx_t const *  mctx,
python_func_def_t def 
)
static

Import a user module and load a function from it.

Definition at line 1307 of file rlm_python.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ python_interpreter_free()

static void python_interpreter_free ( rlm_python_t inst,
PyThreadState *  interp 
)
static

Definition at line 1639 of file rlm_python.c.

+ Here is the caller graph for this function:

◆ python_interpreter_init()

static int python_interpreter_init ( module_inst_ctx_t const *  mctx)
static

Definition at line 1591 of file rlm_python.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ python_module_import_config()

static int python_module_import_config ( rlm_python_t inst,
CONF_SECTION conf,
PyObject *  module 
)
static

Make the current instance's config available within the module we're initialising.

Definition at line 1441 of file rlm_python.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ python_module_import_constants()

static int python_module_import_constants ( rlm_python_t const *  inst,
PyObject *  module 
)
static

Import integer constants into the module we're initialising.

Definition at line 1476 of file rlm_python.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ python_module_init()

static PyObject * python_module_init ( void  )
static

Definition at line 1494 of file rlm_python.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ python_obj_destroy()

static void python_obj_destroy ( PyObject **  ob)
static

Definition at line 1290 of file rlm_python.c.

+ Here is the caller graph for this function:

◆ python_parse_config()

static int python_parse_config ( rlm_python_t const *  inst,
CONF_SECTION cs,
int  lvl,
PyObject *  dict 
)
static

Definition at line 1358 of file rlm_python.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ rlm_python_get_inst()

static rlm_python_t const * rlm_python_get_inst ( void  )
static

Return the rlm_python instance associated with the current interpreter.

Definition at line 449 of file rlm_python.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ rlm_python_get_request()

static request_t * rlm_python_get_request ( void  )
static

Return the request associated with the current thread state.

Definition at line 461 of file rlm_python.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ rlm_python_set_request()

static void rlm_python_set_request ( request_t request)
static

Set the request associated with the current thread state.

Definition at line 474 of file rlm_python.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ rlm_python_state_obj()

static py_freeradius_state_t * rlm_python_state_obj ( void  )
inlinestatic

Return the module instance object associated with the thread state or interpreter state.

Definition at line 428 of file rlm_python.c.

+ Here is the caller graph for this function:

Variable Documentation

◆ current_conf

CONF_SECTION* current_conf
static

Used for communication with inittab functions.

Definition at line 134 of file rlm_python.c.

◆ current_inst

rlm_python_t const* current_inst = NULL
static

Used for communication with inittab functions.

Definition at line 133 of file rlm_python.c.

◆ current_t

rlm_python_thread_t* current_t
static

Used for communicating with object init function.

Definition at line 135 of file rlm_python.c.

◆ [struct]

struct { ... } freeradius_constants[]

◆ global_interpreter

PyThreadState* global_interpreter
static

Our first interpreter.

Definition at line 131 of file rlm_python.c.

◆ libpython_global_config

libpython_global_config_t libpython_global_config
static
Initial value:
= {
.path = NULL,
.path_include_default = true
}

Definition at line 148 of file rlm_python.c.

◆ module_config

conf_parser_t module_config[]
static
Initial value:
= {
#define A(x)
A(detach)
{ FR_CONF_OFFSET("module", rlm_python_t, def_module_name) },
}
#define CONF_PARSER_TERMINATOR
Definition cf_parse.h:658
#define A(x)
static int instantiate(module_inst_ctx_t const *mctx)
Definition rlm_rest.c:1313

Definition at line 190 of file rlm_python.c.

◆ py_freeradius_def

PyModuleDef py_freeradius_def
static
Initial value:
= {
PyModuleDef_HEAD_INIT,
.m_name = "freeradius",
.m_doc = "FreeRADIUS python module",
.m_size = 0,
.m_methods = py_freeradius_methods
}
static PyMethodDef py_freeradius_methods[]
Definition rlm_python.c:381

Definition at line 401 of file rlm_python.c.

◆ py_freeradius_grouping_pair_def

PyTypeObject py_freeradius_grouping_pair_def
static
Initial value:
= {
PyVarObject_HEAD_INIT(NULL, 0)
.tp_name = "freeradius.GroupingPair",
.tp_doc = "A grouping pair, i.e. one of the type group, tlv, vsa or vendor. "
"Children are accessible via the mapping protocol i.e. foo['child-of-foo]",
.tp_flags = Py_TPFLAGS_DEFAULT,
.tp_as_mapping = &(PyMappingMethods){
.mp_ass_subscript = py_freeradius_pair_map_set,
}
}
static int py_freeradius_pair_map_set(PyObject *self, PyObject *attr, PyObject *value)
Set the value of a pair.
Definition rlm_python.c:662
static PyObject * py_freeradius_pair_map_subscript(PyObject *self, PyObject *attr)
Returns a freeradius.Pair.
Definition rlm_python.c:561
static PyTypeObject py_freeradius_pair_def
The class which all pair types inherit from.
Definition rlm_python.c:246

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.

◆ py_freeradius_methods

PyMethodDef py_freeradius_methods[]
static
Initial value:
= {
{ "log", _PyCFunction_CAST(py_freeradius_log), METH_VARARGS | METH_KEYWORDS,
"freeradius.log(msg[, type, lvl])\n\n"
"Print a message using the freeradius daemon's logging system.\n"
"type should be one of the following constants:\n"
" freeradius.L_DBG\n"
" freeradius.L_INFO\n"
" freeradius.L_WARN\n"
" freeradius.L_ERR\n"
"lvl should be one of the following constants:\n"
" freeradius.L_DBG_LVL_OFF\n"
" freeradius.L_DBG_LVL_1\n"
" freeradius.L_DBG_LVL_2\n"
" freeradius.L_DBG_LVL_3\n"
" freeradius.L_DBG_LVL_4\n"
" freeradius.L_DBG_LVL_MAX\n"
},
{ NULL, NULL, 0, NULL },
}
static PyObject * py_freeradius_log(UNUSED PyObject *self, PyObject *args, PyObject *kwds)
Allow fr_log to be called from python.
Definition rlm_python.c:487
#define _PyCFunction_CAST(func)
Definition rlm_python.c:375

Definition at line 381 of file rlm_python.c.

◆ py_freeradius_pair_def

PyTypeObject py_freeradius_pair_def
static
Initial value:
= {
PyVarObject_HEAD_INIT(NULL, 0)
.tp_name = "freeradius.Pair",
.tp_doc = "An attribute value pair",
.tp_basicsize = sizeof(py_freeradius_pair_t),
.tp_itemsize = 0,
.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
.tp_new = PyType_GenericNew,
}
Additional fields for pairs.
Definition rlm_python.c:102

The class which all pair types inherit from.

Definition at line 246 of file rlm_python.c.

◆ py_freeradius_pair_getset

PyGetSetDef py_freeradius_pair_getset[]
static
Initial value:
= {
{
.name = "value",
.doc = "Pair value",
.closure = NULL
},
{ NULL }
}
static int py_freeradius_pair_setvalue(PyObject *self, PyObject *value, void *closure)
static PyObject * py_freeradius_pair_getvalue(PyObject *self, void *closure)

How to access "value" attribute of a pair.

Definition at line 259 of file rlm_python.c.

◆ py_freeradius_pair_list_def

PyTypeObject py_freeradius_pair_list_def
static
Initial value:
= {
PyVarObject_HEAD_INIT(NULL, 0)
.tp_name = "freeradius.PairList",
.tp_doc = "A list of objects of freeradius.GroupingPairList and freeradius.ValuePair",
.tp_flags = Py_TPFLAGS_DEFAULT,
.tp_as_mapping = &(PyMappingMethods){
.mp_ass_subscript = py_freeradius_pair_map_set,
}
}

Each instance contains a top level list (i.e.

request, reply, control, session-state)

Definition at line 308 of file rlm_python.c.

◆ py_freeradius_request_attrs

PyMemberDef py_freeradius_request_attrs[]
static

Definition at line 320 of file rlm_python.c.

◆ py_freeradius_request_def

PyTypeObject py_freeradius_request_def
static
Initial value:
= {
PyVarObject_HEAD_INIT(NULL, 0)
.tp_name = "freeradius.Request",
.tp_doc = "freeradius request handle",
.tp_basicsize = sizeof(py_freeradius_request_t),
.tp_itemsize = 0,
.tp_flags = Py_TPFLAGS_DEFAULT,
.tp_new = PyType_GenericNew,
}
static PyMemberDef py_freeradius_request_attrs[]
Definition rlm_python.c:320

Definition at line 352 of file rlm_python.c.

◆ py_freeradius_state_def

PyTypeObject py_freeradius_state_def
static
Initial value:
= {
PyVarObject_HEAD_INIT(NULL, 0)
.tp_name = "freeradius.State",
.tp_doc = "Private state data",
.tp_basicsize = sizeof(py_freeradius_state_t),
.tp_itemsize = 0,
.tp_flags = Py_TPFLAGS_DEFAULT,
.tp_new = PyType_GenericNew,
}
static int py_freeradius_state_init(PyObject *self, UNUSED PyObject *args, UNUSED PyObject *kwds)
Definition rlm_python.c:505
Wrapper around a python instance.
Definition rlm_python.c:123

Definition at line 363 of file rlm_python.c.

◆ py_freeradius_value_pair_def

PyTypeObject py_freeradius_value_pair_def
static
Initial value:
= {
PyVarObject_HEAD_INIT(NULL, 0)
.tp_name = "freeradius.ValuePair",
.tp_doc = "A value pair, i.e. one of the type string, integer, ipaddr etc...)",
.tp_flags = Py_TPFLAGS_DEFAULT,
.tp_as_mapping = &(PyMappingMethods) {
.mp_ass_subscript = py_freeradius_pair_map_set,
}
}
static PyGetSetDef py_freeradius_pair_getset[]
How to access "value" attribute of a pair.
Definition rlm_python.c:259
static PyObject * py_freeradius_pair_str(PyObject *self)
Return the string representation of a leaf pair node.
static PyObject * py_freeradius_attribute_instance(PyObject *self, PyObject *attr)
Returns a specific instance of freeradius.Pair.
Definition rlm_python.c:522

Contains a value pair of a specific type.

Definition at line 273 of file rlm_python.c.

◆ python_dlhandle

void* python_dlhandle
static

Definition at line 130 of file rlm_python.c.

◆ python_global_config

conf_parser_t const python_global_config[]
static
Initial value:
= {
{ FR_CONF_OFFSET("path_include_default", libpython_global_config_t, path_include_default) },
{ FR_CONF_OFFSET("verbose", libpython_global_config_t, verbose) },
}
Global config for python library.
Definition rlm_python.c:79

Definition at line 153 of file rlm_python.c.

◆ python_method_env

const call_env_method_t python_method_env
static
Initial value:
= {
.env = (call_env_parser_t[]) {
}
}
#define CALL_ENV_TERMINATOR
Definition call_env.h:236
#define FR_CALL_ENV_METHOD_OUT(_inst)
Helper macro for populating the size/type fields of a call_env_method_t from the output structure typ...
Definition call_env.h:240
@ CALL_ENV_FLAG_PARSE_MISSING
If this subsection is missing, still parse it.
Definition call_env.h:88
#define FR_CALL_ENV_SUBSECTION_FUNC(_name, _name2, _flags, _func)
Specify a call_env_parser_t which parses a subsection using a callback function.
Definition call_env.h:412
Per method call config.
Definition call_env.h:180
#define CF_IDENT_ANY
Definition cf_util.h:78
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)

Definition at line 2037 of file rlm_python.c.

◆ rlm_python

module_rlm_t rlm_python
Initial value:
= {
.common = {
.name = "python",
.inst_size = sizeof(rlm_python_t),
.thread_inst_size = sizeof(rlm_python_thread_t),
.config = module_config,
.instantiate = mod_instantiate,
.detach = mod_detach,
.thread_instantiate = mod_thread_instantiate,
.thread_detach = mod_thread_detach
},
.method_group = {
.bindings = (module_method_binding_t[]){
{ .section = SECTION_NAME(CF_IDENT_ANY, CF_IDENT_ANY), .method = mod_python, .method_env = &python_method_env },
}
}
}
#define MODULE_MAGIC_INIT
Stop people using different module/library/server versions together.
Definition dl_module.h:63
static int mod_detach(module_detach_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_instantiate(module_thread_inst_ctx_t const *mctx)
static const call_env_method_t python_method_env
static int mod_thread_detach(module_thread_inst_ctx_t const *mctx)
static int mod_instantiate(module_inst_ctx_t const *mctx)
static conf_parser_t module_config[]
Definition rlm_python.c:190
Tracks a python module inst/thread state pair.
Definition rlm_python.c:94
#define SECTION_NAME(_name1, _name2)
Define a section name consisting of a verb and a noun.
Definition section.h:40
#define MODULE_BINDING_TERMINATOR
Terminate a module binding list.
Definition module.h:151
Named methods exported by a module.
Definition module.h:173

Definition at line 2055 of file rlm_python.c.

◆ rlm_python_autoinst

global_lib_autoinst_t rlm_python_autoinst
static
Initial value:
= {
.name = "python",
.init = libpython_init,
.free = libpython_free,
}
static int libpython_init(void)
static void libpython_free(void)
static conf_parser_t const python_global_config[]
Definition rlm_python.c:153
static libpython_global_config_t libpython_global_config
Definition rlm_python.c:148

Definition at line 163 of file rlm_python.c.

◆ rlm_python_lib

global_lib_autoinst_t const *const rlm_python_lib
Initial value:
= {
}
#define GLOBAL_LIB_TERMINATOR
Definition global_lib.h:51
static global_lib_autoinst_t rlm_python_autoinst
Definition rlm_python.c:163

Definition at line 172 of file rlm_python.c.