The FreeRADIUS server  $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
Data Structures | Macros | Functions | Variables
rlm_exec.c File Reference

Execute commands and parse the results. More...

#include <stdint.h>
#include <freeradius-devel/server/log.h>
#include <freeradius-devel/server/module_rlm.h>
#include <freeradius-devel/server/tmpl.h>
#include <freeradius-devel/server/exec.h>
#include <freeradius-devel/server/main_config.h>
#include <freeradius-devel/unlang/interpret.h>
#include <freeradius-devel/unlang/call_env.h>
#include <freeradius-devel/util/debug.h>
#include <freeradius-devel/util/token.h>
#include <freeradius-devel/server/pairmove.h>
#include <freeradius-devel/unlang/xlat_func.h>
#include <freeradius-devel/unlang/xlat.h>
#include <freeradius-devel/unlang/module.h>
+ Include dependency graph for rlm_exec.c:

Go to the source code of this file.

Data Structures

struct  exec_call_env_t
 
struct  rlm_exec_ctx_t
 
struct  rlm_exec_t
 

Macros

#define LOG_PREFIX   mctx->mi->name
 

Functions

static xlat_action_t exec_xlat_oneshot (TALLOC_CTX *ctx, UNUSED fr_dcursor_t *out, xlat_ctx_t const *xctx, request_t *request, fr_value_box_list_t *in)
 Exec programs from an xlat. More...
 
static xlat_action_t exec_xlat_oneshot_wait_resume (TALLOC_CTX *ctx, fr_dcursor_t *out, xlat_ctx_t const *xctx, request_t *request, UNUSED fr_value_box_list_t *in)
 
static int mob_instantiate (module_inst_ctx_t const *mctx)
 
static int mod_bootstrap (module_inst_ctx_t const *mctx)
 
static unlang_action_t mod_exec_dispatch_oneshot (rlm_rcode_t *p_result, module_ctx_t const *mctx, request_t *request)
 Dispatch one request using a short lived process. More...
 
static unlang_action_t mod_exec_oneshot_nowait_resume (rlm_rcode_t *p_result, module_ctx_t const *mctx, request_t *request)
 Resume a request after xlat expansion. More...
 
static unlang_action_t mod_exec_oneshot_wait_resume (rlm_rcode_t *p_result, module_ctx_t const *mctx, request_t *request)
 Process the exit code and output of a short lived process. More...
 
static rlm_rcode_t rlm_exec_status2rcode (request_t *request, fr_value_box_t *box, int status)
 Process the exit code returned by one of the exec functions. More...
 

Variables

static const call_env_method_t exec_method_env
 
static xlat_arg_parser_t const exec_xlat_args []
 
static const conf_parser_t module_config []
 
static fr_sbuff_parse_rules_t const rhs_term
 
module_rlm_t rlm_exec
 
static const rlm_rcode_t status2rcode []
 

Detailed Description

Execute commands and parse the results.

Id
3c1ac23a4d58ee9062aece1f3ee762b0f1fd16f4

Definition in file rlm_exec.c.


Data Structure Documentation

◆ exec_call_env_t

struct exec_call_env_t

Definition at line 68 of file rlm_exec.c.

+ Collaboration diagram for exec_call_env_t:
Data Fields
tmpl_t * program

◆ rlm_exec_ctx_t

struct rlm_exec_ctx_t

Definition at line 176 of file rlm_exec.c.

Data Fields
fr_value_box_list_t box
int status

◆ rlm_exec_t

struct rlm_exec_t

Definition at line 48 of file rlm_exec.c.

+ Collaboration diagram for rlm_exec_t:
Data Fields
bool env_inherit
tmpl_t * input_list
tmpl_t * output_list
bool shell_escape
fr_time_delta_t timeout
bool timeout_is_set
bool wait

Macro Definition Documentation

◆ LOG_PREFIX

#define LOG_PREFIX   mctx->mi->name

Definition at line 27 of file rlm_exec.c.

Function Documentation

◆ exec_xlat_oneshot_wait_resume()

static xlat_action_t exec_xlat_oneshot_wait_resume ( TALLOC_CTX *  ctx,
fr_dcursor_t out,
xlat_ctx_t const *  xctx,
request_t request,
UNUSED fr_value_box_list_t *  in 
)
static

Definition at line 80 of file rlm_exec.c.

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

◆ mob_instantiate()

static int mob_instantiate ( module_inst_ctx_t const *  mctx)
static

Definition at line 445 of file rlm_exec.c.

+ Here is the call graph for this function:

◆ mod_bootstrap()

static int mod_bootstrap ( module_inst_ctx_t const *  mctx)
static

Definition at line 505 of file rlm_exec.c.

+ Here is the call graph for this function:

◆ mod_exec_dispatch_oneshot()

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

Dispatch one request using a short lived process.

Definition at line 385 of file rlm_exec.c.

+ Here is the call graph for this function:

◆ mod_exec_oneshot_nowait_resume()

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

Resume a request after xlat expansion.

Definition at line 240 of file rlm_exec.c.

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

◆ mod_exec_oneshot_wait_resume()

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

Process the exit code and output of a short lived process.

Definition at line 282 of file rlm_exec.c.

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

◆ rlm_exec_status2rcode()

static rlm_rcode_t rlm_exec_status2rcode ( request_t request,
fr_value_box_t box,
int  status 
)
static

Process the exit code returned by one of the exec functions.

Parameters
requestCurrent request.
boxOutput string from exec call.
statuscode returned by exec call.
Returns
One of the RLM_MODULE_* values.

Definition at line 202 of file rlm_exec.c.

+ Here is the caller graph for this function:

Variable Documentation

◆ exec_method_env

const call_env_method_t exec_method_env
static
Initial value:
= {
.env = (call_env_parser_t[]){
}
}
#define CALL_ENV_TERMINATOR
Definition: call_env.h:231
#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:235
@ CALL_ENV_FLAG_FORCE_QUOTE
Force quote method when parsing tmpl.
Definition: call_env.h:81
#define FR_CALL_ENV_PARSE_ONLY_OFFSET(_name, _cast_type, _flags, _struct, _parse_field)
Specify a call_env_parser_t which writes out the result of the parsing phase to the field specified.
Definition: call_env.h:384
Per method call config.
Definition: call_env.h:175
@ FR_TYPE_STRING
String of printable characters.
Definition: merged_model.c:83
@ T_BACK_QUOTED_STRING
Definition: token.h:123

Definition at line 72 of file rlm_exec.c.

◆ exec_xlat_args

xlat_arg_parser_t const exec_xlat_args[]
static
Initial value:
= {
{ .required = true, .type = FR_TYPE_STRING },
{ .variadic = XLAT_ARG_VARIADIC_EMPTY_KEEP, .type = FR_TYPE_VOID},
}
@ FR_TYPE_VOID
User data.
Definition: merged_model.c:127
@ XLAT_ARG_VARIADIC_EMPTY_KEEP
Empty argument groups are left alone, and either passed through as empty groups or null boxes.
Definition: xlat.h:137
#define XLAT_ARG_PARSER_TERMINATOR
Definition: xlat.h:166

Definition at line 119 of file rlm_exec.c.

◆ module_config

const conf_parser_t module_config[]
static
Initial value:
= {
{ FR_CONF_OFFSET("wait", rlm_exec_t, wait), .dflt = "yes" },
{ FR_CONF_OFFSET("input_pairs", rlm_exec_t, input_list) },
{ FR_CONF_OFFSET("output_pairs", rlm_exec_t, output_list) },
{ FR_CONF_OFFSET("shell_escape", rlm_exec_t, shell_escape), .dflt = "yes" },
{ FR_CONF_OFFSET("env_inherit", rlm_exec_t, env_inherit), .dflt = "no" },
}
#define CONF_PARSER_TERMINATOR
Definition: cf_parse.h:627
#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:268
#define FR_CONF_OFFSET_IS_SET(_name, _type, _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:282
static fr_time_delta_t timeout
Definition: dhcpclient.c:54
@ FR_TYPE_TIME_DELTA
A period of time measured in nanoseconds.
Definition: merged_model.c:113

Definition at line 58 of file rlm_exec.c.

◆ rhs_term

fr_sbuff_parse_rules_t const rhs_term
static
Initial value:
= {
.chr = '\\',
.do_hex = true,
.do_oct = false
},
.terminals = &FR_SBUFF_TERMS(
L(""),
L("\t"),
L("\n"),
L(","),
)
}
#define L(_str)
Helper for initialising arrays of string literals.
Definition: build.h:207
#define FR_SBUFF_TERMS(...)
Initialise a terminal structure with a list of sorted strings.
Definition: sbuff.h:167
Set of parsing rules for *unescape_until functions.
Definition: merged_model.c:163

Definition at line 265 of file rlm_exec.c.

◆ rlm_exec

module_rlm_t rlm_exec
Initial value:
= {
.common = {
.name = "exec",
.inst_size = sizeof(rlm_exec_t),
.bootstrap = mod_bootstrap,
},
.method_group = {
.bindings = (module_method_binding_t[]){
}
}
}
#define CF_IDENT_ANY
Definition: cf_util.h:78
#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_bootstrap(module_inst_ctx_t const *mctx)
Definition: rlm_exec.c:505
static unlang_action_t mod_exec_dispatch_oneshot(rlm_rcode_t *p_result, module_ctx_t const *mctx, request_t *request)
Dispatch one request using a short lived process.
Definition: rlm_exec.c:385
static const call_env_method_t exec_method_env
Definition: rlm_exec.c:72
static int mob_instantiate(module_inst_ctx_t const *mctx)
Definition: rlm_exec.c:445
static const conf_parser_t module_config[]
Definition: rlm_exec.c:58
static int instantiate(module_inst_ctx_t const *mctx)
Definition: rlm_rest.c:1302
#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 525 of file rlm_exec.c.

◆ status2rcode

const rlm_rcode_t status2rcode[]
static
Initial value:
= {
}
@ RLM_MODULE_INVALID
The module considers the request invalid.
Definition: rcode.h:45
@ RLM_MODULE_OK
The module is OK, continue.
Definition: rcode.h:43
@ RLM_MODULE_FAIL
Module failed, don't reply.
Definition: rcode.h:42
@ RLM_MODULE_DISALLOW
Reject the request (user is locked out).
Definition: rcode.h:46
@ RLM_MODULE_REJECT
Immediately reject the request.
Definition: rcode.h:41
@ RLM_MODULE_NOTFOUND
User not found.
Definition: rcode.h:47
@ RLM_MODULE_UPDATED
OK (pairs modified).
Definition: rcode.h:49
@ RLM_MODULE_NOOP
Module succeeded without doing anything.
Definition: rcode.h:48
@ RLM_MODULE_HANDLED
The module handled the request, so stop.
Definition: rcode.h:44

Definition at line 181 of file rlm_exec.c.