From: Arran Cudbard-Bell Date: Sun, 2 Apr 2023 18:19:33 +0000 (-0600) Subject: exec: Use conf parser to deal with input and output tmpl parsing X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d9e292214cdad3b2f100e472e692dd031535c2d5;p=thirdparty%2Ffreeradius-server.git exec: Use conf parser to deal with input and output tmpl parsing --- diff --git a/raddb/mods-available/exec b/raddb/mods-available/exec index 27c7bce036..0fe751ca56 100644 --- a/raddb/mods-available/exec +++ b/raddb/mods-available/exec @@ -84,14 +84,14 @@ exec { # # [options="header,autowidth"] # |=== - # | Pairs | Description - # | request | attributes from the request - # | config | attributes from the configuration items list - # | reply | attributes from the reply - # | session-state | attributes that persist over multiple request/response rounds. + # | Pairs | Description + # | &request | attributes from the request + # | &config | attributes from the configuration items list + # | &reply | attributes from the reply + # | &session-state | attributes that persist over multiple request/response rounds. # |=== # - input_pairs = request + input_pairs = &request # # output_pairs::: Where to place the output attributes (if any) from @@ -103,7 +103,7 @@ exec { # This configuration item is used only when the `program` # configuration item is set, and when `wait = yes` is set. # -# output_pairs = reply +# output_pairs = &reply # # shell_escape:: Escape the environment variables. diff --git a/src/modules/rlm_exec/rlm_exec.c b/src/modules/rlm_exec/rlm_exec.c index 31e4a6973b..fb7f8a4fb3 100644 --- a/src/modules/rlm_exec/rlm_exec.c +++ b/src/modules/rlm_exec/rlm_exec.c @@ -40,30 +40,26 @@ RCSID("$Id$") typedef struct { bool wait; char const *program; - char const *input; - char const *output; tmpl_t *input_list; tmpl_t *output_list; bool shell_escape; bool env_inherit; fr_time_delta_t timeout; bool timeout_is_set; - - tmpl_t *tmpl; + tmpl_t *tmpl; } rlm_exec_t; static const CONF_PARSER module_config[] = { { FR_CONF_OFFSET("wait", FR_TYPE_BOOL, rlm_exec_t, wait), .dflt = "yes" }, { FR_CONF_OFFSET("program", FR_TYPE_STRING | FR_TYPE_XLAT, rlm_exec_t, program) }, - { FR_CONF_OFFSET("input_pairs", FR_TYPE_STRING, rlm_exec_t, input) }, - { FR_CONF_OFFSET("output_pairs", FR_TYPE_STRING, rlm_exec_t, output) }, + { FR_CONF_OFFSET("input_pairs", FR_TYPE_TMPL, rlm_exec_t, input_list) }, + { FR_CONF_OFFSET("output_pairs", FR_TYPE_TMPL, rlm_exec_t, output_list) }, { FR_CONF_OFFSET("shell_escape", FR_TYPE_BOOL, rlm_exec_t, shell_escape), .dflt = "yes" }, { FR_CONF_OFFSET("env_inherit", FR_TYPE_BOOL, rlm_exec_t, env_inherit), .dflt = "no" }, { FR_CONF_OFFSET_IS_SET("timeout", FR_TYPE_TIME_DELTA, rlm_exec_t, timeout) }, CONF_PARSER_TERMINATOR }; - static xlat_action_t exec_xlat_resume(TALLOC_CTX *ctx, fr_dcursor_t *out, xlat_ctx_t const *xctx, request_t *request, UNUSED fr_value_box_list_t *in) @@ -135,7 +131,7 @@ static xlat_action_t exec_xlat(TALLOC_CTX *ctx, UNUSED fr_dcursor_t *out, return XLAT_ACTION_DONE; } - MEM(exec = talloc_zero(request, fr_exec_state_t)); /* Fixme - Should be frame ctx */ + MEM(exec = talloc_zero(unlang_interpret_frame_talloc_ctx(request), fr_exec_state_t)); if (fr_exec_start(exec, exec, request, in, @@ -165,40 +161,25 @@ static int mod_bootstrap(module_inst_ctx_t const *mctx) rlm_exec_t *inst = talloc_get_type_abort(mctx->inst->data, rlm_exec_t); CONF_SECTION *conf = mctx->inst->conf; xlat_t *xlat; - tmpl_rules_t list_rules = (tmpl_rules_t) { - .attr = { - .dict_def = fr_dict_internal(), - .list_def = request_attr_request, - .prefix = TMPL_ATTR_REF_PREFIX_AUTO - } - }; xlat = xlat_func_register_module(NULL, mctx, mctx->inst->name, exec_xlat, FR_TYPE_STRING); xlat_func_args_set(xlat, exec_xlat_args); - if (inst->input) { - if ((tmpl_afrom_attr_substr(inst, NULL, &inst->input_list, - &FR_SBUFF_IN(inst->input, strlen(inst->input)), NULL, &list_rules) < 0) || - !tmpl_is_list(inst->input_list)) { - cf_log_perr(conf, "Invalid input list '%s'", inst->input); - return -1; - } + if (inst->input_list && !tmpl_is_list(inst->input_list)) { + cf_log_perr(conf, "Invalid input list '%s'", inst->input_list->name); + return -1; } - if (inst->output) { - if ((tmpl_afrom_attr_substr(inst, NULL, &inst->output_list, - &FR_SBUFF_IN(inst->output, strlen(inst->output)), NULL, &list_rules) < 0) || - !tmpl_is_list(inst->output_list)) { - cf_log_err(conf, "Invalid output list '%s'", inst->output); - return -1; - } + if (inst->output_list && !tmpl_is_list(inst->output_list)) { + cf_log_err(conf, "Invalid output list '%s'", inst->output_list->name); + return -1; } /* * Sanity check the config. If we're told to NOT wait, * then the output pairs must not be defined. */ - if (!inst->wait && (inst->output != NULL)) { + if (!inst->wait && (inst->output_list != NULL)) { cf_log_err(conf, "Cannot read output pairs if wait = no"); return -1; } @@ -288,7 +269,7 @@ static unlang_action_t mod_exec_nowait_resume(rlm_rcode_t *p_result, module_ctx_ /* * Decide what input/output the program takes. */ - if (inst->input) { + if (inst->input_list) { env_pairs = tmpl_list_head(request, tmpl_list(inst->input_list)); if (!env_pairs) { RETURN_MODULE_INVALID; @@ -380,7 +361,7 @@ static unlang_action_t mod_exec_wait_resume(rlm_rcode_t *p_result, module_ctx_t switch (rcode) { case RLM_MODULE_OK: case RLM_MODULE_UPDATED: - if (inst->output && !fr_value_box_list_empty(&m->box)) { + if (inst->output_list && !fr_value_box_list_empty(&m->box)) { TALLOC_CTX *ctx; fr_pair_list_t vps, *output_pairs; fr_value_box_t *box = fr_value_box_list_head(&m->box); @@ -450,12 +431,12 @@ static unlang_action_t CC_HINT(nonnull) mod_exec_dispatch(rlm_rcode_t *p_result, /* * Decide what input/output the program takes. */ - if (inst->input) { + if (inst->input_list) { env_pairs = tmpl_list_head(request, tmpl_list(inst->input_list)); if (!env_pairs) RETURN_MODULE_INVALID; } - if (inst->output) { + if (inst->output_list) { if (!tmpl_list_head(request, tmpl_list(inst->output_list))) { RETURN_MODULE_INVALID; } diff --git a/src/tests/modules/exec/module.conf b/src/tests/modules/exec/module.conf index a66e64cec4..27680b9451 100644 --- a/src/tests/modules/exec/module.conf +++ b/src/tests/modules/exec/module.conf @@ -1,13 +1,13 @@ exec exec_async { wait = no - input_pairs = request + input_pairs = &request shell_escape = yes timeout = 10 } exec exec_async_mod { wait = no - input_pairs = request + input_pairs = &request shell_escape = yes timeout = 10 program = "/bin/sh -c 'echo \'Tmp-String-0 = welcome\''" @@ -15,15 +15,15 @@ exec exec_async_mod { exec exec_sync { wait = yes - input_pairs = control + input_pairs = &control shell_escape = yes timeout = 1 } exec exec_sync_mod { wait = yes - input_pairs = control - output_pairs = control + input_pairs = &control + output_pairs = &control shell_escape = yes timeout = 10 program = "/bin/sh -c 'echo \'Tmp-String-0 = welcome\''" @@ -31,8 +31,8 @@ exec exec_sync_mod { exec exec_sync_attrs { wait = yes - input_pairs = request - output_pairs = control + input_pairs = &request + output_pairs = &control shell_escape = yes timeout = 10 program = "/bin/sh $ENV{MODULE_TEST_DIR}/attrs.sh %{User-Name}" @@ -40,7 +40,7 @@ exec exec_sync_attrs { exec exec_sync_fail { wait = yes - output_pairs = control + output_pairs = &control timeout = 10 program = "/bin/sh $ENV{MODULE_TEST_DIR}/fail.sh" }