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

Translates requests between the server an a perl interpreter. More...

#include <freeradius-devel/server/base.h>
#include <freeradius-devel/server/module_rlm.h>
#include <freeradius-devel/util/debug.h>
#include <freeradius-devel/unlang/xlat_func.h>
#include <freeradius-devel/unlang/xlat.h>
#include <freeradius-devel/radius/radius.h>
#include <EXTERN.h>
#include <perl.h>
#include <XSUB.h>
#include <dlfcn.h>
#include <semaphore.h>
+ Include dependency graph for rlm_perl.c:

Go to the source code of this file.

Data Structures

struct  perl_call_env_t
 
struct  perl_func_def_t
 
struct  rlm_perl_replace_t
 
struct  rlm_perl_t
 
struct  rlm_perl_thread_t
 

Macros

#define dl_librefs   "DynaLoader::dl_librefs"
 
#define dl_modules   "DynaLoader::dl_modules"
 
#define LOAD_INFO(_fmt, ...)   fr_log(LOG_DST, L_INFO, __FILE__, __LINE__, "rlm_perl - " _fmt, ## __VA_ARGS__)
 
#define LOAD_WARN(_fmt, ...)
 
#define LOG_PREFIX   "perl"
 

Functions

EXTERN_C void boot_DynaLoader (pTHX_ CV *cv)
 
static int get_hv_content (TALLOC_CTX *ctx, request_t *request, HV *my_hv, fr_pair_list_t *vps, const char *list_name, fr_dict_attr_t const *parent, bool dbg_print)
 
static int mod_bootstrap (module_inst_ctx_t const *mctx)
 
static int mod_detach (module_detach_ctx_t const *mctx)
 
static int mod_instantiate (module_inst_ctx_t const *mctx)
 
static int mod_load (void)
 
static unlang_action_t mod_perl (rlm_rcode_t *p_result, module_ctx_t const *mctx, request_t *request)
 
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 void mod_unload (void)
 
static int pairadd_sv (TALLOC_CTX *ctx, request_t *request, fr_pair_list_t *vps, char *key, SV *sv, const char *list_name, fr_dict_attr_t const *parent, bool dbg_print)
 
static int8_t perl_func_def_cmp (void const *one, void const *two)
 How to compare two Perl function calls.
 
static bool perl_func_exists (char const *func)
 Check if a given Perl subroutine exists.
 
static void perl_func_name_safe (char *name)
 
static int perl_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 perl_parse_config (CONF_SECTION *cs, int lvl, HV *rad_hv)
 
static void perl_store_vps (request_t *request, fr_pair_list_t *vps, HV *rad_hv, const char *hash_name, bool dbg_print)
 
static int perl_sv_to_vblist (TALLOC_CTX *ctx, fr_value_box_list_t *list, request_t *request, SV *sv)
 Parse a Perl SV and create value boxes, appending to a list.
 
static int perl_vblist_to_av (AV *av, fr_value_box_list_t *head)
 Convert a list of value boxes to a Perl array for passing to subroutines.
 
static void perl_vp_to_svpvn_element (request_t *request, AV *av, fr_pair_t *vp, int *i, const char *hash_name, bool dbg_print)
 
static xlat_action_t perl_xlat (TALLOC_CTX *ctx, fr_dcursor_t *out, xlat_ctx_t const *xctx, request_t *request, fr_value_box_list_t *in)
 Call perl code using an xlat.
 
static void rlm_perl_clear_handles (pTHX)
 
static void rlm_perl_close_handles (void **handles)
 
static void ** rlm_perl_get_handles (pTHX)
 
static void rlm_perl_interp_free (PerlInterpreter *perl)
 
static XS (XS_radiusd_log)
 
static XS (XS_radiusd_xlat)
 
static void xs_init (pTHX)
 

Variables

static const conf_parser_t module_config []
 
static void * perl_dlhandle
 To allow us to load perl's symbols into the global symbol table.
 
static const call_env_method_t perl_method_env
 
static xlat_arg_parser_t const perl_xlat_args []
 
static const conf_parser_t replace_config []
 
module_rlm_t rlm_perl
 
static _Thread_local request_trlm_perl_request
 

Detailed Description

Translates requests between the server an a perl interpreter.

Id
8d78fcca17dd0175a09908ad69825f6f9d7a72ed

Definition in file rlm_perl.c.


Data Structure Documentation

◆ perl_call_env_t

struct perl_call_env_t

Definition at line 71 of file rlm_perl.c.

+ Collaboration diagram for perl_call_env_t:
Data Fields
perl_func_def_t * func

◆ perl_func_def_t

struct perl_func_def_t

Definition at line 64 of file rlm_perl.c.

+ Collaboration diagram for perl_func_def_t:
Data Fields
char const * function_name Name of the function being called.
char * name1 Section name1 where this is called.
char * name2 Section name2 where this is called.
fr_rb_node_t node Node in tree of function calls.

◆ rlm_perl_replace_t

struct rlm_perl_replace_t

Definition at line 57 of file rlm_perl.c.

Data Fields
bool control Should the control list be replaced after module call.
bool reply Should the reply list be replaced after module call.
bool request Should the request list be replaced after module call.
bool session Should the session list be replaced after module call.

◆ rlm_perl_t

struct rlm_perl_t

Definition at line 82 of file rlm_perl.c.

+ Collaboration diagram for rlm_perl_t:
Data Fields
char const * func_detach Function to run when mod_detach is run.
char const *fr_rb_tree_t funcs Tree of function calls found by call_env parser.
bool funcs_init Has the tree been initialised.
PerlInterpreter * perl
char const * perl_flags
bool perl_parsed
HV * rad_perlconf_hv holds "config" items (perl RAD_PERLCONF hash).
rlm_perl_replace_t replace

◆ rlm_perl_thread_t

struct rlm_perl_thread_t

Definition at line 97 of file rlm_perl.c.

Data Fields
PerlInterpreter * perl Thread specific perl interpreter.

Macro Definition Documentation

◆ dl_librefs

#define dl_librefs   "DynaLoader::dl_librefs"

Definition at line 149 of file rlm_perl.c.

◆ dl_modules

#define dl_modules   "DynaLoader::dl_modules"

Definition at line 150 of file rlm_perl.c.

◆ LOAD_INFO

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

◆ LOAD_WARN

#define LOAD_WARN (   _fmt,
  ... 
)
Value:
fr_log_perror(LOG_DST, L_WARN, __FILE__, __LINE__, \
.first_prefix = "rlm_perl - ", \
.subsq_prefix = "rlm_perl - ", \
}, \
_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   "perl"

Definition at line 27 of file rlm_perl.c.

Function Documentation

◆ boot_DynaLoader()

EXTERN_C void boot_DynaLoader ( pTHX_ CV *  cv)
+ Here is the caller graph for this function:

◆ get_hv_content()

static int get_hv_content ( TALLOC_CTX *  ctx,
request_t request,
HV *  my_hv,
fr_pair_list_t vps,
const char *  list_name,
fr_dict_attr_t const *  parent,
bool  dbg_print 
)
static

Definition at line 845 of file rlm_perl.c.

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

◆ mod_bootstrap()

static int mod_bootstrap ( module_inst_ctx_t const *  mctx)
static

Definition at line 1255 of file rlm_perl.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 1219 of file rlm_perl.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 1088 of file rlm_perl.c.

+ Here is the call graph for this function:

◆ mod_load()

static int mod_load ( void  )
static

Definition at line 1265 of file rlm_perl.c.

+ Here is the call graph for this function:

◆ mod_perl()

static unlang_action_t mod_perl ( rlm_rcode_t p_result,
module_ctx_t const *  mctx,
request_t request 
)
static

Definition at line 880 of file rlm_perl.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 1047 of file rlm_perl.c.

+ Here is the call graph for this function:

◆ mod_thread_instantiate()

static int mod_thread_instantiate ( module_thread_inst_ctx_t const *  mctx)
static

Definition at line 1020 of file rlm_perl.c.

+ Here is the call graph for this function:

◆ mod_unload()

static void mod_unload ( void  )
static

Definition at line 1306 of file rlm_perl.c.

◆ pairadd_sv()

static int pairadd_sv ( TALLOC_CTX *  ctx,
request_t request,
fr_pair_list_t vps,
char *  key,
SV *  sv,
const char *  list_name,
fr_dict_attr_t const *  parent,
bool  dbg_print 
)
static

Definition at line 782 of file rlm_perl.c.

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

◆ perl_func_def_cmp()

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

How to compare two Perl function calls.

Definition at line 129 of file rlm_perl.c.

+ Here is the caller graph for this function:

◆ perl_func_exists()

static bool perl_func_exists ( char const *  func)
static

Check if a given Perl subroutine exists.

Definition at line 1059 of file rlm_perl.c.

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

◆ perl_func_name_safe()

static void perl_func_name_safe ( char *  name)
static

Definition at line 1316 of file rlm_perl.c.

+ Here is the caller graph for this function:

◆ perl_func_parse()

static int perl_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 1328 of file rlm_perl.c.

+ Here is the call graph for this function:

◆ perl_parse_config()

static void perl_parse_config ( CONF_SECTION cs,
int  lvl,
HV *  rad_hv 
)
static

Definition at line 587 of file rlm_perl.c.

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

◆ perl_store_vps()

static void perl_store_vps ( request_t request,
fr_pair_list_t vps,
HV *  rad_hv,
const char *  hash_name,
bool  dbg_print 
)
static

Definition at line 699 of file rlm_perl.c.

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

◆ perl_sv_to_vblist()

static int perl_sv_to_vblist ( TALLOC_CTX *  ctx,
fr_value_box_list_t *  list,
request_t request,
SV *  sv 
)
static

Parse a Perl SV and create value boxes, appending to a list.

For parsing values passed back from a Perl subroutine

When hashes are returned, first the key is added as a value box then the value

Parameters
[in]ctxto allocate boxes in.
[out]listto append value boxes to.
[in]requestbeing handled - only used for debug messages
[in]svto parse
Returns
  • 0 on success
  • -1 on failure

Definition at line 343 of file rlm_perl.c.

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

◆ perl_vblist_to_av()

static int perl_vblist_to_av ( AV *  av,
fr_value_box_list_t *  head 
)
static

Convert a list of value boxes to a Perl array for passing to subroutines.

The Perl array object should be created before calling this to populate it.

Parameters
[in,out]avPerl array object to append values to.
[in]headof VB list.
Returns
  • 0 on success
  • -1 on failure

Definition at line 289 of file rlm_perl.c.

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

◆ perl_vp_to_svpvn_element()

static void perl_vp_to_svpvn_element ( request_t request,
AV *  av,
fr_pair_t vp,
int *  i,
const char *  hash_name,
bool  dbg_print 
)
static

Definition at line 649 of file rlm_perl.c.

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

◆ rlm_perl_clear_handles()

static void rlm_perl_clear_handles ( pTHX  )
static

Definition at line 151 of file rlm_perl.c.

+ Here is the caller graph for this function:

◆ rlm_perl_close_handles()

static void rlm_perl_close_handles ( void **  handles)
static

Definition at line 193 of file rlm_perl.c.

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

◆ rlm_perl_get_handles()

static void ** rlm_perl_get_handles ( pTHX  )
static

Definition at line 159 of file rlm_perl.c.

+ Here is the caller graph for this function:

◆ rlm_perl_interp_free()

static void rlm_perl_interp_free ( PerlInterpreter *  perl)
static

Definition at line 992 of file rlm_perl.c.

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

◆ XS() [1/2]

static XS ( XS_radiusd_log  )
static

Definition at line 214 of file rlm_perl.c.

+ Here is the call graph for this function:

◆ XS() [2/2]

static XS ( XS_radiusd_xlat  )
static

Definition at line 242 of file rlm_perl.c.

+ Here is the call graph for this function:

◆ xs_init()

static void xs_init ( pTHX  )
static

Definition at line 267 of file rlm_perl.c.

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

Variable Documentation

◆ module_config

const conf_parser_t module_config[]
static
Initial value:
= {
{ FR_CONF_OFFSET("func_detach", rlm_perl_t, func_detach), .data = NULL, .dflt = "detach", .quote = T_INVALID },
{ FR_CONF_OFFSET("perl_flags", rlm_perl_t, perl_flags) },
{ FR_CONF_OFFSET_SUBSECTION("replace", 0, rlm_perl_t, replace, replace_config) },
}
#define CONF_PARSER_TERMINATOR
Definition cf_parse.h:658
#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
#define FR_CONF_OFFSET_FLAGS(_name, _flags, _struct, _field)
conf_parser_t which parses a single CONF_PAIR, writing the result to a field in a struct
Definition cf_parse.h:272
#define FR_CONF_OFFSET_SUBSECTION(_name, _flags, _struct, _field, _subcs)
conf_parser_t which populates a sub-struct using a CONF_SECTION
Definition cf_parse.h:313
@ CONF_FLAG_REQUIRED
Error out if no matching CONF_PAIR is found, and no dflt value is set.
Definition cf_parse.h:434
@ CONF_FLAG_FILE_INPUT
File matching value must exist, and must be readable.
Definition cf_parse.h:440
static const conf_parser_t replace_config[]
Definition rlm_perl.c:103
@ T_INVALID
Definition token.h:39

Definition at line 114 of file rlm_perl.c.

◆ perl_dlhandle

void* perl_dlhandle
static

To allow us to load perl's symbols into the global symbol table.

Definition at line 101 of file rlm_perl.c.

◆ perl_method_env

const call_env_method_t perl_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 perl_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 rlm_perl.c:1328

Definition at line 1377 of file rlm_perl.c.

◆ perl_xlat_args

xlat_arg_parser_t const perl_xlat_args[]
static
Initial value:
= {
{ .required = true, .single = true, .type = FR_TYPE_STRING },
{ .variadic = XLAT_ARG_VARIADIC_EMPTY_KEEP, .type = FR_TYPE_VOID },
}
@ FR_TYPE_STRING
String of printable characters.
@ FR_TYPE_VOID
User data.
@ XLAT_ARG_VARIADIC_EMPTY_KEEP
Empty argument groups are left alone, and either passed through as empty groups or null boxes.
Definition xlat.h:136
#define XLAT_ARG_PARSER_TERMINATOR
Definition xlat.h:166

Definition at line 450 of file rlm_perl.c.

◆ replace_config

const conf_parser_t replace_config[]
static
Initial value:
= {
{ FR_CONF_OFFSET("request", rlm_perl_replace_t, request) },
{ FR_CONF_OFFSET("reply", rlm_perl_replace_t, reply) },
{ FR_CONF_OFFSET("control", rlm_perl_replace_t, control) },
{ FR_CONF_OFFSET("session", rlm_perl_replace_t, session) },
}

Definition at line 103 of file rlm_perl.c.

◆ rlm_perl

module_rlm_t rlm_perl
Initial value:
= {
.common = {
.name = "perl",
.inst_size = sizeof(rlm_perl_t),
.onload = mod_load,
.unload = mod_unload,
.bootstrap = mod_bootstrap,
.detach = mod_detach,
.thread_inst_size = sizeof(rlm_perl_thread_t),
.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_perl, .method_env = &perl_method_env },
}
}
}
#define MODULE_MAGIC_INIT
Stop people using different module/library/server versions together.
Definition dl_module.h:63
static const conf_parser_t config[]
Definition base.c:183
static int mod_detach(module_detach_ctx_t const *mctx)
Definition rlm_perl.c:1219
static int mod_load(void)
Definition rlm_perl.c:1265
static int mod_bootstrap(module_inst_ctx_t const *mctx)
Definition rlm_perl.c:1255
static void mod_unload(void)
Definition rlm_perl.c:1306
static int mod_thread_instantiate(module_thread_inst_ctx_t const *mctx)
Definition rlm_perl.c:1020
static unlang_action_t mod_perl(rlm_rcode_t *p_result, module_ctx_t const *mctx, request_t *request)
Definition rlm_perl.c:880
static const conf_parser_t module_config[]
Definition rlm_perl.c:114
static const call_env_method_t perl_method_env
Definition rlm_perl.c:1377
static int mod_thread_detach(module_thread_inst_ctx_t const *mctx)
Definition rlm_perl.c:1047
static int mod_instantiate(module_inst_ctx_t const *mctx)
Definition rlm_perl.c:1088
static int instantiate(module_inst_ctx_t const *mctx)
Definition rlm_rest.c:1313
#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 1395 of file rlm_perl.c.

◆ rlm_perl_request

_Thread_local request_t* rlm_perl_request
static

Definition at line 147 of file rlm_perl.c.