27RCSID(
"$Id: f08823aa4a80e0598dc9f0c4239f458e9f10c9e3 $")
29#define LOG_PREFIX inst->name
31#include <freeradius-devel/server/base.h>
32#include <freeradius-devel/server/module_rlm.h>
33#include <freeradius-devel/server/pairmove.h>
34#include <freeradius-devel/util/debug.h>
35#include <freeradius-devel/util/lsan.h>
38#include <structmember.h>
39#include <frameobject.h>
150 .path_include_default =
true
192#define A(x) { FR_CONF_OFFSET("mod_" #x, rlm_python_t, x.module_name), .dflt = "${.module}" }, \
193 { FR_CONF_OFFSET("func_" #x, rlm_python_t, x.function_name) },
210#define A(x) { #x, x },
247 PyVarObject_HEAD_INIT(NULL, 0)
248 .tp_name =
"freeradius.Pair",
249 .tp_doc =
"An attribute value pair",
252 .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
253 .tp_new = PyType_GenericNew,
274 PyVarObject_HEAD_INIT(NULL, 0)
275 .tp_name =
"freeradius.ValuePair",
276 .tp_doc =
"A value pair, i.e. one of the type string, integer, ipaddr etc...)",
277 .tp_flags = Py_TPFLAGS_DEFAULT,
281 .tp_as_mapping = &(PyMappingMethods) {
294 PyVarObject_HEAD_INIT(NULL, 0)
295 .tp_name =
"freeradius.GroupingPair",
296 .tp_doc =
"A grouping pair, i.e. one of the type group, tlv, vsa or vendor. "
297 "Children are accessible via the mapping protocol i.e. foo['child-of-foo]",
298 .tp_flags = Py_TPFLAGS_DEFAULT,
300 .tp_as_mapping = &(PyMappingMethods){
309 PyVarObject_HEAD_INIT(NULL, 0)
310 .tp_name =
"freeradius.PairList",
311 .tp_doc =
"A list of objects of freeradius.GroupingPairList and freeradius.ValuePair",
312 .tp_flags = Py_TPFLAGS_DEFAULT,
314 .tp_as_mapping = &(PyMappingMethods){
326 .doc =
"Pairs in the request list - received from the network"
333 .doc =
"Pairs in the reply list - sent to the network"
340 .doc =
"Pairs in the control list - control the behaviour of subsequently called modules"
343 .name =
"session-state",
347 .doc =
"Pairs in the session-state list - persists for the length of the session"
353 PyVarObject_HEAD_INIT(NULL, 0)
354 .tp_name =
"freeradius.Request",
355 .tp_doc =
"freeradius request handle",
358 .tp_flags = Py_TPFLAGS_DEFAULT,
359 .tp_new = PyType_GenericNew,
364 PyVarObject_HEAD_INIT(NULL, 0)
365 .tp_name =
"freeradius.State",
366 .tp_doc =
"Private state data",
369 .tp_flags = Py_TPFLAGS_DEFAULT,
370 .tp_new = PyType_GenericNew,
374#ifndef _PyCFunction_CAST
375#define _PyCFunction_CAST(func) (PyCFunction)((void(*)(void))(func))
383 "freeradius.log(msg[, type, lvl])\n\n"
384 "Print a message using the freeradius daemon's logging system.\n"
385 "type should be one of the following constants:\n"
386 " freeradius.L_DBG\n"
387 " freeradius.L_INFO\n"
388 " freeradius.L_WARN\n"
389 " freeradius.L_ERR\n"
390 "lvl should be one of the following constants:\n"
391 " freeradius.L_DBG_LVL_OFF\n"
392 " freeradius.L_DBG_LVL_1\n"
393 " freeradius.L_DBG_LVL_2\n"
394 " freeradius.L_DBG_LVL_3\n"
395 " freeradius.L_DBG_LVL_4\n"
396 " freeradius.L_DBG_LVL_MAX\n"
398 { NULL, NULL, 0, NULL },
402 PyModuleDef_HEAD_INIT,
403 .m_name =
"freeradius",
404 .m_doc =
"FreeRADIUS python module",
417 ret = strcmp(a->
name1, b->name1);
418 if (ret != 0)
return CMP(ret, 0);
419 if (!a->
name2 && !b->name2)
return 0;
420 if (!a->
name2 || !b->name2)
return a->
name2 ? 1 : -1;
421 ret = strcmp(a->
name2, b->name2);
432 dict = PyThreadState_GetDict();
436 module = PyState_FindModule(&py_freeradius_def);
439 dict = PyModule_GetDict(module);
454 if (
unlikely(!p_state))
return NULL;
455 return p_state->
inst;
466 if (
unlikely(!p_state))
return NULL;
489 static char const *kwlist[] = {
"msg",
"type",
"lvl", NULL };
497 if (!PyArg_ParseTupleAndKeywords(
args, kwds,
"s|ii", (
char **)((uintptr_t)kwlist),
498 &
msg, &
type, &lvl)) Py_RETURN_NONE;
513 DEBUG3(
"Populating __State data with %p/%p", our_self->
inst, our_self->
t);
527 if (!PyLong_CheckExact(attr)) Py_RETURN_NONE;
528 index = PyLong_AsLong(attr);
531 PyErr_SetString(PyExc_AttributeError,
"Cannot use negative attribute instance values");
534 if (index == 0)
return self;
542 PyErr_SetString(PyExc_MemoryError,
"Failed to allocate PyObject");
546 Py_INCREF(init_pair->
parent);
547 pair->
da = init_pair->
da;
550 return (PyObject *)pair;
564 char const *attr_name;
576 if (!PyUnicode_CheckExact(attr)) {
577 PyErr_Format(PyExc_AttributeError,
"Invalid type '%s' for map attribute",
578 ((PyTypeObject *)PyObject_Type(attr))->tp_name);
581 attr_name = PyUnicode_AsUTF8AndSize(attr, &len);
589 if (our_self->
vp) list = &our_self->
vp->vp_group;
592 PyErr_Format(PyExc_AttributeError,
"Invalid attribute name '%.*s'", (
int)len, attr_name);
602 PyErr_SetString(PyExc_MemoryError,
"Failed to allocate PyObject");
612 return (PyObject *)pair;
631 if (obj_pair->
idx > 0) {
633 if (count < obj_pair->idx) {
634 PyErr_Format(PyExc_AttributeError,
"Attempt to set instance %d when only %d exist", index,
count);
670 bool del = (
value ? false :
true);
673 PyErr_Format(PyExc_AttributeError,
"Invalid value type '%s'", ((PyTypeObject *)PyObject_Type(
value))->tp_name);
681 if (PyUnicode_CheckExact(attr)) {
682 char const *attr_name;
686 attr_name = PyUnicode_AsUTF8AndSize(attr, &len);
696 PyErr_Format(PyExc_AttributeError,
"Invalid attribute name %.*s", (
int)len, attr_name);
705 if (!our_self->
vp)
return -1;
707 list = &our_self->
vp->vp_group;
714 PyErr_Format(PyExc_MemoryError,
"Failed to add attribute %s", da->name);
725 }
else if (PyLong_CheckExact(attr)) {
726 long index = PyLong_AsLong(attr);
730 PyErr_SetString(PyExc_AttributeError,
"Cannot use negative attribute instance values");
738 if (!
parent->vp)
return -1;
740 list = &
parent->vp->vp_group;
745 PyErr_Format(PyExc_MemoryError,
"Failed to add attribute %s", our_self->
da->name);
759 PyErr_Format(PyExc_AttributeError,
"Attempt to set instance %ld when only %d exist", index,
count);
763 PyErr_Format(PyExc_MemoryError,
"Failed to add attribute %s", our_self->
da->name);
769 PyErr_Format(PyExc_AttributeError,
"Invalid object type '%s'", ((PyTypeObject *)PyObject_Type(attr))->tp_name);
775 vstr = PyUnicode_AsUTF8AndSize(
value, &vlen);
778 PyErr_Format(PyExc_AttributeError,
"Failed setting '%s' = '%.*s",
vp->
da->name, (
int)vlen, vstr);
803 PyObject *
value = NULL;
806 if (!
vp) Py_RETURN_NONE;
808 switch(
vp->vp_type) {
810 value = PyUnicode_FromStringAndSize(
vp->vp_strvalue,
vp->vp_length);
814 value = PyBytes_FromStringAndSize((
char const *)
vp->vp_octets,
vp->vp_length);
818 value = PyBool_FromLong(
vp->vp_bool);
822 value = PyLong_FromUnsignedLong(
vp->vp_uint8);
826 value = PyLong_FromUnsignedLong(
vp->vp_uint16);
830 value = PyLong_FromUnsignedLong(
vp->vp_uint32);
834 value = PyLong_FromUnsignedLongLong(
vp->vp_uint64);
838 value = PyLong_FromLong(
vp->vp_int8);
842 value = PyLong_FromLong(
vp->vp_int16);
846 value = PyLong_FromLong(
vp->vp_int32);
850 value = PyLong_FromLongLong(
vp->vp_int64);
854 value = PyFloat_FromDouble((
double)
vp->vp_float32);
858 value = PyFloat_FromDouble(
vp->vp_float64);
862 value = PyLong_FromSize_t(
vp->vp_size);
882 PyErr_Format(PyExc_MemoryError,
"Failed marshalling %s to Python value",
vp->
da->name);
885 value = PyUnicode_FromStringAndSize(
buffer, (
size_t)slen);
894 if (
value == NULL)
goto error;
920 if (!
parent->vp)
return -1;
922 list = &
parent->vp->vp_group;
924 if (count < own_self->idx) {
925 PyErr_Format(PyExc_AttributeError,
"Attempt to set instance %d when only %d exist", own_self->
idx,
count);
932 switch (
vp->
da->type) {
937 if (!PyUnicode_CheckExact(
value)){
939 PyErr_Format(PyExc_AttributeError,
"Incorrect Python type '%s' for attribute type '%s'",
943 val = PyUnicode_AsUTF8AndSize(
value, &len);
953 if (!PyObject_IsInstance(
value, (PyObject *)&PyBytes_Type))
goto wrong_type;
954 PyBytes_AsStringAndSize(
value, (
char **)&val, &len);
972 if (!PyLong_CheckExact(
value))
goto wrong_type;
973 val = PyLong_AsLongLong(
value);
975 switch (
vp->
da->type) {
989 vp->vp_uint64 = (uint64_t)val;
992 vp->vp_int8 = (int8_t)val;
995 vp->vp_int16 = (int16_t)val;
998 vp->vp_int32 = (int32_t)val;
1001 vp->vp_int64 = (int64_t)val;
1016 if (!PyFloat_CheckExact(
value))
goto wrong_type;
1017 val = PyFloat_AsDouble(
value);
1020 vp->vp_float32 = (float)val;
1022 vp->vp_float64 = val;
1041 if (!PyUnicode_CheckExact(
value))
goto wrong_type;
1043 val = PyUnicode_AsUTF8AndSize(
value, &len);
1045 PyErr_Format(PyExc_AttributeError,
"Failed parsing %.*s as %s", (
int)len, val,
fr_type_to_str(
vp->
da->type));
1066 PyObject *
value = NULL;
1069 if (!
vp)
return PyObject_Str(Py_None);
1071 switch(
vp->vp_type) {
1073 value = PyUnicode_FromStringAndSize(
vp->vp_strvalue,
vp->vp_length);
1088 PyErr_Format(PyExc_MemoryError,
"Failed casting %s to Python string",
vp->
da->name);
1091 value = PyUnicode_FromStringAndSize(
buffer, (
size_t)slen);
1096 if (
value == NULL)
goto error;
1107 PyObject *p_type = NULL, *p_value = NULL, *p_traceback = NULL, *p_str_1 = NULL, *p_str_2 = NULL;
1109 PyErr_Fetch(&p_type, &p_value, &p_traceback);
1110 PyErr_NormalizeException(&p_type, &p_value, &p_traceback);
1111 if (!p_type || !p_value)
goto failed;
1113 if (((p_str_1 = PyObject_Str(p_type)) == NULL) || ((p_str_2 = PyObject_Str(p_value)) == NULL))
goto failed;
1117 if (p_traceback != Py_None) {
1118 PyTracebackObject *ptb = (PyTracebackObject*)p_traceback;
1121 while (ptb != NULL) {
1122 PyFrameObject *cur_frame = ptb->tb_frame;
1123#if PY_VERSION_HEX >= 0x030A0000
1124 PyCodeObject *code = PyFrame_GetCode(cur_frame);
1128 PyUnicode_AsUTF8(code->co_filename),
1129 PyFrame_GetLineNumber(cur_frame),
1130 PyUnicode_AsUTF8(code->co_name)
1136 PyUnicode_AsUTF8(cur_frame->f_code->co_filename),
1137 PyFrame_GetLineNumber(cur_frame),
1138 PyUnicode_AsUTF8(cur_frame->f_code->co_name)
1148 Py_XDECREF(p_str_1);
1149 Py_XDECREF(p_str_2);
1151 Py_XDECREF(p_value);
1152 Py_XDECREF(p_traceback);
1172 if (
unlikely(!py_list))
return NULL;
1175 our_list->
da = list;
1183 request_t *request, PyObject *p_func,
char const *funcname)
1188 PyObject *p_ret = NULL;
1189 PyObject *py_request;
1210 Py_DECREF(py_request);
1225 p_ret = PyObject_CallFunctionObjArgs(p_func, py_request, NULL);
1227 RERROR(
"Python function returned no value");
1234 if (PyNumber_Check(p_ret)) rcode = PyLong_AsLong(p_ret);
1242 if (PyNumber_Check(p_ret)) {
1244 rcode = PyLong_AsLong(p_ret);
1246 }
else if (p_ret == Py_None) {
1251 ERROR(
"%s - Function did not return a tuple or None", funcname);
1261 Py_XDECREF(py_request);
1283 PyEval_RestoreThread(t->
state);
1310 char const *funcname =
"python_function_load";
1321 Py_XDECREF(def->module);
1345 if (!PyCallable_Check(def->
function)) {
1360 int indent_section = (lvl * 4);
1361 int indent_item = (lvl + 1) * 4;
1365 if (!cs || !dict)
return -1;
1378 PyObject *sub_dict, *p_key;
1380 p_key = PyUnicode_FromString(key);
1382 ERROR(
"Failed converting config key \"%s\" to python string", key);
1386 if (PyDict_Contains(dict, p_key)) {
1387 WARN(
"Ignoring duplicate config section '%s'", key);
1391 MEM(sub_dict = PyDict_New());
1392 (void)PyDict_SetItem(dict, p_key, sub_dict);
1400 PyObject *p_key, *p_value;
1403 WARN(
"Skipping \"%s\" as it has no value", key);
1407 p_key = PyUnicode_FromString(key);
1408 p_value = PyUnicode_FromString(
value);
1410 ERROR(
"Failed converting config key \"%s\" to python string", key);
1414 ERROR(
"Failed converting config value \"%s\" to python string",
value);
1422 if (PyDict_Contains(dict, p_key)) {
1423 WARN(
"Ignoring duplicate config item '%s'", key);
1427 (void)PyDict_SetItem(dict, p_key, p_value);
1429 DEBUG(
"%*s%s = \"%s\"", indent_item,
" ", key,
value);
1433 DEBUG(
"%*s}", indent_section,
" ");
1449 inst->pythonconf_dict = PyDict_New();
1450 if (!
inst->pythonconf_dict) {
1451 ERROR(
"Unable to create python dict for config");
1453 Py_XDECREF(
inst->pythonconf_dict);
1454 inst->pythonconf_dict = NULL;
1461 DEBUG(
"Inserting \"config\" section into python environment as radiusd.config");
1468 if (PyModule_AddObject(module,
"config",
inst->pythonconf_dict) < 0)
goto error;
1482 ERROR(
"Failed adding constant to module");
1499 static bool type_ready =
false;
1508 pthread_mutex_lock(&init_lock);
1524 pthread_mutex_unlock(&init_lock);
1545 module = PyModule_Create(&py_freeradius_def);
1569 if (PyModule_AddObject(module,
"__State", p_state) < 0) {
1586 pthread_mutex_unlock(&init_lock);
1608 if (!
inst->interpreter) {
1609 ERROR(
"Failed creating new interpreter");
1612 DEBUG3(
"Created new interpreter %p",
inst->interpreter);
1613 PyEval_SaveThread();
1615 PyEval_RestoreThread(
inst->interpreter);
1623 module = PyImport_ImportModule("freeradius");
1625 ERROR(
"Failed importing \"freeradius\" module into interpreter %p",
inst->interpreter);
1633 inst->module =
module;
1634 PyEval_SaveThread();
1641 PyEval_RestoreThread(interp);
1647 Py_XDECREF(
inst->module);
1649 Py_EndInterpreter(interp);
1651 PyEval_SaveThread();
1673 if (
inst->interpreter)
return 0;
1680 PyEval_RestoreThread(
inst->interpreter);
1685#define PYTHON_FUNC_LOAD(_x) if (python_function_load(mctx, &inst->_x) < 0) goto error
1699 pair_name = talloc_asprintf(func,
"mod_%s_%s", func->
name1, func->
name2);
1702 if (cp)
goto found_mod;
1704 pair_name = talloc_asprintf(func,
"mod_%s", func->
name1);
1716 pair_name = talloc_asprintf(func,
"func_%s_%s", func->
name1, func->
name2);
1719 if (cp)
goto found_func;
1721 pair_name = talloc_asprintf(func,
"func_%s", func->
name1);
1734 if (
inst->instantiate.function) {
1771 if (!
inst->interpreter)
return 0;
1776 PyEval_RestoreThread(
inst->interpreter);
1781 if (
inst->detach.function) {
1787#define PYTHON_FUNC_DESTROY(_x) python_function_destroy(&inst->_x)
1797 PyEval_SaveThread();
1812 PyThreadState *t_state;
1819 t_state = PyThreadState_New(
inst->interpreter->interp);
1821 ERROR(
"Failed initialising local PyThreadState");
1825 PyEval_RestoreThread(t_state);
1826 t_dict = PyThreadState_GetDict();
1828 ERROR(
"Failed getting PyThreadState dictionary");
1830 PyEval_SaveThread();
1831 PyThreadState_Delete(t_state);
1843 ERROR(
"Failed instantiating module instance information object");
1847 if (
unlikely(PyDict_SetItemString(t_dict,
"__State", p_state) < 0)) {
1848 ERROR(
"Failed setting module instance information in thread dict");
1852 DEBUG3(
"Initialised PyThreadState %p", t_state);
1854 PyEval_SaveThread();
1863 PyEval_RestoreThread(t->
state);
1864 PyThreadState_Clear(t->
state);
1865 PyEval_SaveThread();
1867 PyThreadState_Delete(t->
state);
1874#define LOAD_INFO(_fmt, ...) fr_log(LOG_DST, L_INFO, __FILE__, __LINE__, "rlm_python - " _fmt, ## __VA_ARGS__)
1875#define LOAD_WARN(_fmt, ...) fr_log_perror(LOG_DST, L_WARN, __FILE__, __LINE__, \
1876 &(fr_log_perror_format_t){ \
1877 .first_prefix = "rlm_python - ", \
1878 .subsq_prefix = "rlm_python - ", \
1880 _fmt, ## __VA_ARGS__)
1887 LOAD_INFO(
"Python version: %s", Py_GetVersion());
1898 PyConfig_InitPythonConfig(&
config);
1905 status = PyConfig_SetString(&
config, &
config.program_name, wide_name);
1906 PyMem_RawFree(wide_name);
1908 if (PyStatus_Exception(status)) {
1931 status = PyConfig_SetString(&
config, &
config.pythonpath_env, wide_path);
1937 config.module_search_paths_set = 1;
1938 status = PyWideStringList_Append(&
config.module_search_paths, wide_path);
1940 PyMem_RawFree(wide_path);
1941 if (PyStatus_Exception(status))
goto fail;
1944 config.install_signal_handlers = 0;
1949 if (PyStatus_Exception(status))
goto fail;
1980 for (i = 0; i < talloc_array_length(
name); i++) {
1982 if (!strchr(
"abcdefghijklmnopqrstuvwxyz1234567890", *p)) *p =
'_';
1995 if (!
inst->funcs_init) {
1997 inst->funcs_init =
true;
2006 .offset = rule->pair.offset,
unlang_action_t
Returned by unlang_op_t calls, determine the next action of the interpreter.
static int const char char buffer[256]
#define CMP(_a, _b)
Same as CMP_PREFER_SMALLER use when you don't really care about ordering, you just want an ordering.
call_env_parsed_t * call_env_parsed_add(TALLOC_CTX *ctx, call_env_parsed_head_t *head, call_env_parser_t const *rule)
Allocate a new call_env_parsed_t structure and add it to the list of parsed call envs.
void call_env_parsed_set_data(call_env_parsed_t *parsed, void const *data)
Assign data to a call_env_parsed_t.
#define CALL_ENV_TERMINATOR
#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...
call_env_parser_t const * env
Parsing rules for call method env.
section_name_t const * asked
The actual name1/name2 that resolved to a module_method_binding_t.
@ CALL_ENV_FLAG_PARSE_ONLY
The result of parsing will not be evaluated at runtime.
@ CALL_ENV_FLAG_PARSE_MISSING
If this subsection is missing, still parse it.
@ CALL_ENV_PARSE_TYPE_VOID
Output of the parsing phase is undefined (a custom structure).
module_instance_t const * mi
Module instance that the callenv is registered to.
#define FR_CALL_ENV_SUBSECTION_FUNC(_name, _name2, _flags, _func)
Specify a call_env_parser_t which parses a subsection using a callback function.
#define CONF_PARSER_TERMINATOR
#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
Defines a CONF_PAIR to C data type mapping.
Common header for all CONF_* types.
Configuration AVP similar to a fr_pair_t.
A section grouping multiple CONF_PAIR.
bool cf_item_is_pair(CONF_ITEM const *ci)
Determine if CONF_ITEM is a CONF_PAIR.
char const * cf_section_name1(CONF_SECTION const *cs)
Return the second identifier of a CONF_SECTION.
CONF_SECTION * cf_section_find(CONF_SECTION const *cs, char const *name1, char const *name2)
Find a CONF_SECTION with name1 and optionally name2.
CONF_SECTION * cf_item_to_section(CONF_ITEM const *ci)
Cast a CONF_ITEM to a CONF_SECTION.
CONF_PAIR * cf_pair_find(CONF_SECTION const *cs, char const *attr)
Search for a CONF_PAIR with a specific name.
bool cf_item_is_section(CONF_ITEM const *ci)
Determine if CONF_ITEM is a CONF_SECTION.
CONF_PAIR * cf_item_to_pair(CONF_ITEM const *ci)
Cast a CONF_ITEM to a CONF_PAIR.
char const * cf_pair_value(CONF_PAIR const *pair)
Return the value of a CONF_PAIR.
char const * cf_pair_attr(CONF_PAIR const *pair)
Return the attr of a CONF_PAIR.
#define cf_item_next(_parent, _curr)
#define fr_cond_assert(_x)
Calls panic_action ifndef NDEBUG, else logs error and evaluates to value of _x.
int dependency_version_number_add(CONF_SECTION *cs, char const *name, char const *version)
Add a library/server version pair to the main configuration.
fr_slen_t fr_dict_attr_by_name_substr(fr_dict_attr_err_t *err, fr_dict_attr_t const **out, fr_dict_attr_t const *parent, fr_sbuff_t *name, fr_sbuff_term_t const *tt))
fr_slen_t fr_dict_attr_search_by_name_substr(fr_dict_attr_err_t *err, fr_dict_attr_t const **out, fr_dict_t const *dict_def, fr_sbuff_t *name, fr_sbuff_term_t const *tt, bool internal, bool foreign))
Locate a fr_dict_attr_t by its name in the top level namespace of a dictionary.
void * dl_open_by_sym(char const *sym_name, int flags)
Utility function to dlopen the library containing a particular symbol.
#define MODULE_MAGIC_INIT
Stop people using different module/library/server versions together.
char const * name
Name of library and section within global config.
#define GLOBAL_LIB_TERMINATOR
Structure to define how to initialise libraries with global configuration.
#define ROPTIONAL(_l_request, _l_global, _fmt,...)
Use different logging functions depending on whether request is NULL or not.
void fr_log(fr_log_t const *log, fr_log_type_t type, char const *file, int line, char const *fmt,...)
Send a server log message to its destination.
@ L_DBG_LVL_3
3rd highest priority debug messages (-xxx | -Xx).
@ L_DBG_LVL_1
Highest priority debug messages (-x).
@ L_DBG_LVL_2
2nd highest priority debug messages (-xx | -X).
@ L_DBG_LVL_OFF
No debug messages.
@ L_DBG_LVL_4
4th highest priority debug messages (-xxxx | -Xxx).
@ L_DBG_LVL_MAX
Lowest priority debug messages (-xxxxx | -Xxxx).
@ L_DBG_WARN_REQ
Less severe warning only displayed when debugging is enabled.
@ L_DBG_ERR
Error only displayed when debugging is enabled.
@ L_DBG_ERR_REQ
Less severe error only displayed when debugging is enabled.
@ L_DBG_WARN
Warning only displayed when debugging is enabled.
@ L_INFO
Informational message.
@ L_DBG
Only displayed when debugging is enabled.
main_config_t const * main_config
Main server configuration.
char const * name
Name of the daemon, usually 'radiusd'.
@ FR_TYPE_TIME_DELTA
A period of time measured in nanoseconds.
@ FR_TYPE_FLOAT32
Single precision floating point.
@ FR_TYPE_IPV4_ADDR
32 Bit IPv4 Address.
@ FR_TYPE_INT8
8 Bit signed integer.
@ FR_TYPE_ETHERNET
48 Bit Mac-Address.
@ FR_TYPE_IPV6_PREFIX
IPv6 Prefix.
@ FR_TYPE_STRING
String of printable characters.
@ FR_TYPE_UINT16
16 Bit unsigned integer.
@ FR_TYPE_INT64
64 Bit signed integer.
@ FR_TYPE_INT16
16 Bit signed integer.
@ FR_TYPE_DATE
Unix time stamp, always has value >2^31.
@ FR_TYPE_COMBO_IP_PREFIX
IPv4 or IPv6 address prefix depending on length.
@ FR_TYPE_UINT8
8 Bit unsigned integer.
@ FR_TYPE_UINT32
32 Bit unsigned integer.
@ FR_TYPE_INT32
32 Bit signed integer.
@ FR_TYPE_UINT64
64 Bit unsigned integer.
@ FR_TYPE_IPV6_ADDR
128 Bit IPv6 Address.
@ FR_TYPE_IPV4_PREFIX
IPv4 Prefix.
@ FR_TYPE_BOOL
A truth value.
@ FR_TYPE_SIZE
Unsigned integer capable of representing any memory address on the local system.
@ FR_TYPE_COMBO_IP_ADDR
IPv4 or IPv6 address depending on length.
@ FR_TYPE_IFID
Interface ID.
@ FR_TYPE_OCTETS
Raw octets.
@ FR_TYPE_FLOAT64
Double precision floating point.
void * env_data
Per call environment data.
module_instance_t const * mi
Instance of the module being instantiated.
void * thread
Thread specific instance data.
module_instance_t * mi
Module instance to detach.
void * thread
Thread instance data.
#define MODULE_CTX_FROM_INST(_mctx)
Wrapper to create a module_ctx_t as a compound literal from a module_inst_ctx_t.
module_instance_t const * mi
Instance of the module being instantiated.
module_instance_t * mi
Instance of the module being instantiated.
Temporary structure to hold arguments for module calls.
Temporary structure to hold arguments for detach calls.
Temporary structure to hold arguments for instantiation calls.
Temporary structure to hold arguments for thread_instantiation calls.
module_t common
Common fields presented by all modules.
fr_pair_t * fr_pair_list_parent(fr_pair_list_t const *list)
Return a pointer to the parent pair which contains this list.
unsigned int fr_pair_count_by_da(fr_pair_list_t const *list, fr_dict_attr_t const *da)
Return the number of instances of a given da in the specified list.
int fr_pair_append_by_da(TALLOC_CTX *ctx, fr_pair_t **out, fr_pair_list_t *list, fr_dict_attr_t const *da)
Alloc a new fr_pair_t (and append)
int fr_pair_value_from_str(fr_pair_t *vp, char const *value, size_t inlen, fr_sbuff_unescape_rules_t const *uerules, UNUSED bool tainted)
Convert string value to native attribute value.
fr_pair_list_t * fr_pair_parent_list(fr_pair_t const *vp)
Return a pointer to the parent pair list.
fr_pair_t * fr_pair_find_by_da(fr_pair_list_t const *list, fr_pair_t const *prev, fr_dict_attr_t const *da)
Find the first pair with a matching da.
fr_pair_t * fr_pair_find_by_da_idx(fr_pair_list_t const *list, fr_dict_attr_t const *da, unsigned int idx)
Find a pair with a matching da at a given index.
int fr_pair_delete(fr_pair_list_t *list, fr_pair_t *vp)
Remove fr_pair_t from a list and free.
static const conf_parser_t config[]
void * fr_rb_iter_init_inorder(fr_rb_iter_inorder_t *iter, fr_rb_tree_t *tree)
Initialise an in-order iterator.
int fr_rb_find_or_insert(void **found, fr_rb_tree_t *tree, void const *data)
Attempt to find current data in the tree, if it does not exist insert it.
void * fr_rb_iter_next_inorder(fr_rb_iter_inorder_t *iter)
Return the next node.
#define fr_rb_inline_init(_tree, _type, _field, _data_cmp, _data_free)
Initialises a red black tree.
Iterator structure for in-order traversal of an rbtree.
The main red black tree structure.
#define RETURN_MODULE_NOOP
#define RETURN_MODULE_RCODE(_rcode)
#define RETURN_MODULE_FAIL
rlm_rcode_t
Return codes indicating the result of the module call.
@ RLM_MODULE_INVALID
The module considers the request invalid.
@ RLM_MODULE_OK
The module is OK, continue.
@ RLM_MODULE_FAIL
Module failed, don't reply.
@ RLM_MODULE_DISALLOW
Reject the request (user is locked out).
@ RLM_MODULE_REJECT
Immediately reject the request.
@ RLM_MODULE_NOTFOUND
User not found.
@ RLM_MODULE_UPDATED
OK (pairs modified).
@ RLM_MODULE_NOOP
Module succeeded without doing anything.
@ RLM_MODULE_NUMCODES
How many valid return codes there are.
@ RLM_MODULE_HANDLED
The module handled the request, so stop.
fr_dict_attr_t const * request_attr_request
fr_dict_attr_t const * request_attr_control
fr_dict_attr_t const * request_attr_state
fr_dict_attr_t const * request_attr_reply
static py_freeradius_state_t * rlm_python_state_obj(void)
Return the module instance object associated with the thread state or interpreter state.
static int libpython_init(void)
static PyMethodDef py_freeradius_methods[]
PyObject * pythonconf_dict
Configuration parameters defined in the module made available to the python script.
static int python_parse_config(rlm_python_t const *inst, CONF_SECTION *cs, int lvl, PyObject *dict)
static int mod_detach(module_detach_ctx_t const *mctx)
static void python_function_destroy(python_func_def_t *def)
PyObject * reply
Reply list.
static int python_module_import_constants(rlm_python_t const *inst, PyObject *module)
Import integer constants into the module we're initialising.
PyObject_HEAD PyObject * request
< Common fields needed for every python object.
static PyTypeObject py_freeradius_value_pair_def
Contains a value pair of a specific type.
char * name2
Section name2 where this is called.
fr_rb_node_t node
Entry in tree of Python functions.
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)
request_t * request
Current request.
rlm_python_thread_t * t
Thread-specific python instance.
PyObject_HEAD rlm_python_t const * inst
< Common fields needed for every python object.
static rlm_python_thread_t * current_t
Used for communicating with object init function.
static int py_freeradius_pair_map_set(PyObject *self, PyObject *attr, PyObject *value)
Set the value of a pair.
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 PyGetSetDef py_freeradius_pair_getset[]
How to access "value" attribute of a pair.
PyObject *char const * def_module_name
< Local, interpreter specific module.
static PyObject * pair_list_alloc(request_t *request, fr_dict_attr_t const *list)
Create the Python object representing a pair list.
static global_lib_autoinst_t rlm_python_autoinst
static void rlm_python_set_request(request_t *request)
Set the request associated with the current thread state.
static rlm_python_t const * rlm_python_get_inst(void)
Return the rlm_python instance associated with the current interpreter.
static rlm_python_t const * current_inst
Used for communication with inittab functions.
static void libpython_free(void)
PyThreadState * interpreter
The interpreter used for this instance of rlm_python.
static PyObject * py_freeradius_pair_str(PyObject *self)
Return the string representation of a leaf pair node.
PyObject * control
Control list.
static int py_freeradius_state_init(PyObject *self, UNUSED PyObject *args, UNUSED PyObject *kwds)
static void python_obj_destroy(PyObject **ob)
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 request_t * rlm_python_get_request(void)
Return the request associated with the current thread state.
static void python_func_name_safe(char *name)
rlm_python_t const * inst
Current module instance data.
char const * module_name
String name of module.
PyThreadState * state
Module instance/thread specific state.
PyObject * parent
Parent object of this pair.
char const * name
Name of the module instance.
static PyTypeObject py_freeradius_request_def
static PyThreadState * global_interpreter
Our first interpreter.
static PyObject * py_freeradius_pair_map_subscript(PyObject *self, PyObject *attr)
Returns a freeradius.Pair.
bool path_include_default
Include the default python path in path
static int py_freeradius_pair_setvalue(PyObject *self, PyObject *value, void *closure)
#define LOAD_WARN(_fmt,...)
static int8_t python_func_def_cmp(void const *one, void const *two)
How to compare two Python calls.
static PyObject * python_module_init(void)
PyObject *PyObject * function
< Python reference to module.
char * name1
Section name1 where this is called.
static PyObject * py_freeradius_attribute_instance(PyObject *self, PyObject *attr)
Returns a specific instance of freeradius.Pair.
static conf_parser_t const python_global_config[]
static int mod_thread_instantiate(module_thread_inst_ctx_t const *mctx)
static void python_interpreter_free(rlm_python_t *inst, PyThreadState *interp)
fr_pair_t * vp
Real FreeRADIUS pair for this Python pair.
static PyTypeObject py_freeradius_grouping_pair_def
Contains group attribute of a specific type.
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 PyObject * py_freeradius_log(UNUSED PyObject *self, PyObject *args, PyObject *kwds)
Allow fr_log to be called from python.
#define _PyCFunction_CAST(func)
static libpython_global_config_t libpython_global_config
char const * function_name
String name of function in module.
bool verbose
Enable libpython verbose logging.
static fr_pair_t * py_freeradius_build_parents(PyObject *obj)
Build out missing parent pairs when a leaf node is assigned a value.
bool funcs_init
Has the tree been initialised.
static CONF_SECTION * current_conf
Used for communication with inittab functions.
static PyObject * py_freeradius_pair_getvalue(PyObject *self, void *closure)
static PyMemberDef py_freeradius_request_attrs[]
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)
unsigned int idx
Instance index.
PyObject * state
Session state list.
#define LOAD_INFO(_fmt,...)
#define PYTHON_FUNC_LOAD(_x)
static PyModuleDef py_freeradius_def
static void * python_dlhandle
static struct @175 freeradius_constants[]
static PyTypeObject py_freeradius_pair_def
The class which all pair types inherit from.
static int python_interpreter_init(module_inst_ctx_t const *mctx)
static const call_env_method_t python_method_env
char const * path
Path to search for python files in.
#define PYTHON_FUNC_DESTROY(_x)
static PyTypeObject py_freeradius_state_def
static int mod_thread_detach(module_thread_inst_ctx_t const *mctx)
static int mod_instantiate(module_inst_ctx_t const *mctx)
global_lib_autoinst_t const *const rlm_python_lib[]
static conf_parser_t module_config[]
fr_rb_tree_t funcs
Tree of function calls found by call_env parser.
static void python_error_log(rlm_python_t const *inst, request_t *request)
Print out the current error.
python_func_def_t instantiate
static PyTypeObject py_freeradius_pair_list_def
Each instance contains a top level list (i.e.
PyObject_HEAD fr_dict_attr_t const * da
< Common fields needed for every python object.
Global config for python library.
Additional fields for pairs.
Wrapper around a python instance.
Specifies the module.function to load for processing a section.
An instance of the rlm_python module.
Tracks a python module inst/thread state pair.
static int instantiate(module_inst_ctx_t const *mctx)
#define FR_SBUFF_IN(_start, _len_or_end)
#define FR_SBUFF_OUT(_start, _len_or_end)
#define SECTION_NAME(_name1, _name2)
Define a section name consisting of a verb and a noun.
char const * name2
Second section name. Usually a packet type like 'access-request', 'access-accept',...
char const * name1
First section name. Usually a verb like 'recv', 'send', etc...
char const * name
Instance name e.g. user_database.
CONF_SECTION * conf
Module's instance configuration.
size_t inst_size
Size of the module's instance data.
void * data
Module's instance data.
#define MODULE_BINDING_TERMINATOR
Terminate a module binding list.
Named methods exported by a module.
fr_pair_list_t * tmpl_list_head(request_t *request, fr_dict_attr_t const *list)
Resolve attribute fr_pair_list_t value to an attribute list.
Optional arguments passed to vp_tmpl functions.
eap_aka_sim_process_conf_t * inst
fr_aka_sim_id_type_t type
Stores an attribute, a value and various bits of other data.
fr_dict_attr_t const *_CONST da
Dictionary attribute defines the attribute number, vendor and type of the pair.
static int talloc_const_free(void const *ptr)
Free const'd memory.
#define fr_type_is_leaf(_x)
static char const * fr_type_to_str(fr_type_t type)
Return a static string containing the type name.
ssize_t fr_value_box_print(fr_sbuff_t *out, fr_value_box_t const *data, fr_sbuff_escape_rules_t const *e_rules)
Print one boxed value to a string.
void fr_value_box_clear_value(fr_value_box_t *data)
Clear/free any existing value.
void fr_value_box_clear(fr_value_box_t *data)
Clear/free any existing value and metadata.
int fr_value_box_bstrndup(TALLOC_CTX *ctx, fr_value_box_t *dst, fr_dict_attr_t const *enumv, char const *src, size_t len, bool tainted)
Copy a string to to a fr_value_box_t.
int fr_value_box_memdup(TALLOC_CTX *ctx, fr_value_box_t *dst, fr_dict_attr_t const *enumv, uint8_t const *src, size_t len, bool tainted)
Copy a buffer to a fr_value_box_t.
static size_t char ** out