From: Alan T. DeKok Date: Sun, 29 Oct 2023 13:01:14 +0000 (-0400) Subject: radius_exec_program_legacy() doesn't ever get passed output_pairs X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b3506d3a807fc5f6b714048e8bd54ab9abacded7;p=thirdparty%2Ffreeradius-server.git radius_exec_program_legacy() doesn't ever get passed output_pairs so remove unused code and arguments. --- diff --git a/src/lib/server/exec_legacy.c b/src/lib/server/exec_legacy.c index 075c9eac65d..69530c63336 100644 --- a/src/lib/server/exec_legacy.c +++ b/src/lib/server/exec_legacy.c @@ -456,11 +456,8 @@ int radius_readfrom_program_legacy(int fd, pid_t pid, fr_time_delta_t timeout, c /** Execute a program. * - * @param[in,out] ctx to allocate new fr_pair_t (s) in. * @param[out] out buffer to append plaintext (non valuepair) output. * @param[in] outlen length of out buffer. - * @param[out] output_pairs list of value pairs - Data on child's stdout will be parsed and - * added into this list of value pairs. * @param[in] request Current request (may be NULL). * @param[in] cmd Command to execute. This is parsed into argv[] parts, then each individual argv * part is xlat'ed. @@ -474,15 +471,13 @@ int radius_readfrom_program_legacy(int fd, pid_t pid, fr_time_delta_t timeout, c * - exit code if exec_wait!=0. * - -1 on failure. */ -int radius_exec_program_legacy(TALLOC_CTX *ctx, char *out, size_t outlen, fr_pair_list_t *output_pairs, +int radius_exec_program_legacy(char *out, size_t outlen, request_t *request, char const *cmd, fr_pair_list_t *input_pairs, bool exec_wait, bool shell_escape, fr_time_delta_t timeout) { pid_t pid; int stdout_pipe; - char *p; pid_t child_pid; - int comma = 0; int status, ret = 0; ssize_t len; char answer[4096]; @@ -522,51 +517,7 @@ int radius_exec_program_legacy(TALLOC_CTX *ctx, char *out, size_t outlen, fr_pai goto wait; } - /* - * Parse the output, if any. - */ - if (output_pairs) { - fr_pair_list_t vps; - - fr_pair_list_init(&vps); - /* - * HACK: Replace '\n' with ',' so that - * fr_pair_list_afrom_str() can parse the buffer in - * one go (the proper way would be to - * fix fr_pair_list_afrom_str(), but oh well). - */ - for (p = answer; *p; p++) { - if (*p == '\n') { - *p = comma ? ' ' : ','; - p++; - comma = 0; - } - if (*p == ',') { - comma++; - } - } - - /* - * Replace any trailing comma by a NUL. - */ - if (answer[len - 1] == ',') { - answer[--len] = '\0'; - } - - if (fr_pair_list_afrom_str(ctx, fr_dict_root(request->dict), answer, sizeof(answer), &vps) == T_INVALID) { - RPERROR("Failed parsing output from: %s", cmd); - if (out) strlcpy(out, answer, len); - ret = -1; - } - - /* - * We want to mark the new attributes as tainted, - * but not the existing ones. - */ - fr_pair_list_tainted(&vps); - fr_pair_list_append(output_pairs, &vps); - - } else if (out) { + if (out) { /* * We've not been told to extract output pairs, * just copy the programs output to the out diff --git a/src/lib/server/exec_legacy.h b/src/lib/server/exec_legacy.h index 28840929194..7251d485671 100644 --- a/src/lib/server/exec_legacy.h +++ b/src/lib/server/exec_legacy.h @@ -41,9 +41,9 @@ pid_t radius_start_program_legacy(int *stdin_fd, int *stdout_fd, int *stderr_fd, int radius_readfrom_program_legacy(int fd, pid_t pid, fr_time_delta_t timeout, char *answer, int left); -int radius_exec_program_legacy(TALLOC_CTX *ctx, char *out, size_t outlen, fr_pair_list_t *output_pairs, +int radius_exec_program_legacy(char *out, size_t outlen, request_t *request, char const *cmd, fr_pair_list_t *input_pairs, - bool exec_wait, bool shell_escape, fr_time_delta_t timeout) CC_HINT(nonnull (5, 6)); + bool exec_wait, bool shell_escape, fr_time_delta_t timeout) CC_HINT(nonnull (3, 4)); #ifdef __cplusplus } diff --git a/src/lib/server/map.c b/src/lib/server/map.c index 8ff0c79a3c6..893dd242daf 100644 --- a/src/lib/server/map.c +++ b/src/lib/server/map.c @@ -1433,7 +1433,7 @@ static int map_exec_to_vp(TALLOC_CTX *ctx, fr_pair_list_t *out, request_t *reque * if dst is an attribute, then we create an attribute of that type and then * call fr_pair_value_from_str on the output of the script. */ - result = radius_exec_program_legacy(ctx, answer, sizeof(answer), NULL, + result = radius_exec_program_legacy(answer, sizeof(answer), request, map->rhs->name, input_pairs ? input_pairs : NULL, true, true, fr_time_delta_from_sec(EXEC_TIMEOUT)); talloc_free(expanded); diff --git a/src/lib/server/tmpl_eval.c b/src/lib/server/tmpl_eval.c index d930082fcd9..8fc66a01642 100644 --- a/src/lib/server/tmpl_eval.c +++ b/src/lib/server/tmpl_eval.c @@ -314,7 +314,7 @@ ssize_t _tmpl_to_type(void *out, return -1; } - if (radius_exec_program_legacy(request, (char *)buff, bufflen, NULL, request, vpt->name, NULL, + if (radius_exec_program_legacy((char *)buff, bufflen, request, vpt->name, NULL, true, false, fr_time_delta_from_sec(EXEC_TIMEOUT)) != 0) return -1; fr_value_box_strdup_shallow(&value_to_cast, NULL, (char *)buff, true); src_type = FR_TYPE_STRING; @@ -592,7 +592,7 @@ ssize_t _tmpl_to_atype(TALLOC_CTX *ctx, void *out, RDEBUG4("EXPAND TMPL EXEC"); MEM(fr_value_box_bstr_alloc(tmp_ctx, &buff, &value, NULL, 1024, true)); - if (radius_exec_program_legacy(request, buff, 1024, NULL, request, vpt->name, NULL, + if (radius_exec_program_legacy(buff, 1024, request, vpt->name, NULL, true, false, fr_time_delta_from_sec(EXEC_TIMEOUT)) != 0) { error: talloc_free(tmp_ctx); diff --git a/src/modules/rlm_mschap/rlm_mschap.c b/src/modules/rlm_mschap/rlm_mschap.c index f0e8576c613..739408daf57 100644 --- a/src/modules/rlm_mschap/rlm_mschap.c +++ b/src/modules/rlm_mschap/rlm_mschap.c @@ -1251,7 +1251,7 @@ static int CC_HINT(nonnull (1, 2, 4, 5, 6)) do_mschap(rlm_mschap_t const *inst, /* * Run the program, and expect that we get 16 */ - result = radius_exec_program_legacy(request, buffer, sizeof(buffer), NULL, request, inst->ntlm_auth, NULL, + result = radius_exec_program_legacy(buffer, sizeof(buffer), request, inst->ntlm_auth, NULL, true, true, inst->ntlm_auth_timeout); if (result != 0) { char *p;