]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Allow reading binary data using rlm_exec
authorNick Porter <nick@portercomputing.co.uk>
Tue, 10 Jun 2025 09:11:41 +0000 (10:11 +0100)
committerNick Porter <nick@portercomputing.co.uk>
Tue, 10 Jun 2025 09:11:41 +0000 (10:11 +0100)
src/modules/rlm_exec/rlm_exec.c

index 7f5151393996fd1dd1c44bcc7faac652fe821108..cc539f4218dee59dc2d3eb9fcecb4676947aa07b 100644 (file)
@@ -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);