From: Nick Porter Date: Tue, 10 Jun 2025 09:11:41 +0000 (+0100) Subject: Allow reading binary data using rlm_exec X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4b1178dbaf91ea22ee901c047ee58a3201d0eade;p=thirdparty%2Ffreeradius-server.git Allow reading binary data using rlm_exec --- diff --git a/src/modules/rlm_exec/rlm_exec.c b/src/modules/rlm_exec/rlm_exec.c index 7f515139399..cc539f4218d 100644 --- a/src/modules/rlm_exec/rlm_exec.c +++ b/src/modules/rlm_exec/rlm_exec.c @@ -53,6 +53,7 @@ typedef struct { bool env_inherit; fr_time_delta_t timeout; bool timeout_is_set; + bool xlat_read_binary; } rlm_exec_t; static const conf_parser_t module_config[] = { @@ -62,6 +63,7 @@ static const conf_parser_t module_config[] = { { FR_CONF_OFFSET("shell_escape", rlm_exec_t, shell_escape), .dflt = "yes" }, { FR_CONF_OFFSET("env_inherit", rlm_exec_t, env_inherit), .dflt = "no" }, { FR_CONF_OFFSET_IS_SET("timeout", FR_TYPE_TIME_DELTA, 0, rlm_exec_t, timeout) }, + { FR_CONF_OFFSET("xlat_read_binary", rlm_exec_t, xlat_read_binary) }, CONF_PARSER_TERMINATOR }; @@ -81,6 +83,7 @@ static xlat_action_t exec_xlat_oneshot_wait_resume(TALLOC_CTX *ctx, fr_dcursor_t xlat_ctx_t const *xctx, request_t *request, UNUSED fr_value_box_list_t *in) { + rlm_exec_t const *inst = talloc_get_type_abort_const(xctx->mctx->mi->data, rlm_exec_t); fr_exec_state_t *exec = talloc_get_type_abort(xctx->rctx, fr_exec_state_t); fr_value_box_t *vb; @@ -100,16 +103,18 @@ static xlat_action_t exec_xlat_oneshot_wait_resume(TALLOC_CTX *ctx, fr_dcursor_t MEM(vb = fr_value_box_alloc_null(ctx)); - /* - * Remove any trailing line endings and trim buffer - */ - fr_sbuff_trim(&exec->stdout_buff, sbuff_char_line_endings); - fr_sbuff_trim_talloc(&exec->stdout_buff, SIZE_MAX); + if (!inst->xlat_read_binary) { + /* + * Remove any trailing line endings and trim buffer + */ + fr_sbuff_trim(&exec->stdout_buff, sbuff_char_line_endings); + fr_sbuff_trim_talloc(&exec->stdout_buff, SIZE_MAX); + } /* * Use the buffer for the output vb */ - fr_value_box_strdup_shallow(vb, NULL, fr_sbuff_buff(&exec->stdout_buff), true); + fr_value_box_bstrndup_shallow(vb, NULL, fr_sbuff_buff(&exec->stdout_buff), fr_sbuff_used(&exec->stdout_buff), true); fr_dcursor_append(out, vb);