Reorder radius_exec_program arguments to be consistent with the rest of the server
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Thu, 2 Oct 2014 23:58:54 +0000 (00:58 +0100)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Thu, 2 Oct 2014 23:59:41 +0000 (00:59 +0100)
src/include/radiusd.h
src/main/evaluate.c
src/main/exec.c
src/main/map.c
src/main/modcall.c
src/main/threads.c
src/main/tls.c
src/modules/rlm_exec/rlm_exec.c
src/modules/rlm_ldap/attrmap.c
src/modules/rlm_mschap/rlm_mschap.c

index 01c1006..79f7b4e 100644 (file)
@@ -610,9 +610,9 @@ pid_t radius_start_program(char const *cmd, REQUEST *request, bool exec_wait,
                           VALUE_PAIR *input_pairs, bool shell_escape);
 int radius_readfrom_program(REQUEST *request, int fd, pid_t pid, int timeout,
                            char *answer, int left);
-int radius_exec_program(REQUEST *request, char const *cmd, bool exec_wait, bool shell_escape,
-                       char *user_msg, size_t msg_len, int timeout,
-                       VALUE_PAIR *input_pairs, VALUE_PAIR **output_pairs) CC_HINT(nonnull (1, 2));
+int radius_exec_program(char *out, size_t outlen, VALUE_PAIR **output_pairs,
+                       REQUEST *request, char const *cmd, VALUE_PAIR *input_pairs,
+                       bool exec_wait, bool shell_escape, int timeout) CC_HINT(nonnull (4, 5));
 void exec_trigger(REQUEST *request, CONF_SECTION *cs, char const *name, int quench)
      CC_HINT(nonnull (3));
 
index c599fb6..83e82ba 100644 (file)
@@ -107,7 +107,7 @@ int radius_expand_tmpl(char **out, REQUEST *request, value_pair_tmpl_t const *vp
        case TMPL_TYPE_EXEC:
                EVAL_DEBUG("TMPL EXEC");
                *out = talloc_array(request, char, 1024);
-               if (radius_exec_program(request, vpt->name, true, false, *out, 1024, EXEC_TIMEOUT, NULL, NULL) != 0) {
+               if (radius_exec_program(*out, 1024, NULL, request, vpt->name, NULL, true, false, EXEC_TIMEOUT) != 0) {
                        TALLOC_FREE(*out);
                        return -1;
                }
index 8718bd3..41e7e96 100644 (file)
@@ -493,22 +493,23 @@ int radius_readfrom_program(REQUEST *request, int fd, pid_t pid, int timeout,
 
 /** Execute a program.
  *
+ * @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 - child 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.
+ * @param[in] input_pairs list of value pairs - these will be available in the environment of the child.
  * @param[in] exec_wait set to 1 if you want to read from or write to child.
  * @param[in] shell_escape values before passing them as arguments.
- * @param[in] user_msg buffer to append plaintext (non valuepair) output.
- * @param[in] msg_len length of user_msg buffer.
  * @param[in] timeout amount of time to wait, in seconds.
- * @param[in] input_pairs list of value pairs - these will be available in the environment of the child.
- * @param[out] output_pairs list of value pairs - child stdout will be parsed and added into this list
- *     of value pairs.
+
  * @return 0 if exec_wait==0, exit code if exec_wait!=0, -1 on error.
  */
-int radius_exec_program(REQUEST *request, char const *cmd, bool exec_wait, bool shell_escape,
-                       char *user_msg, size_t msg_len, int timeout,
-                       VALUE_PAIR *input_pairs, VALUE_PAIR **output_pairs)
+int radius_exec_program(char *out, size_t outlen, VALUE_PAIR **output_pairs,
+                       REQUEST *request, char const *cmd, VALUE_PAIR *input_pairs,
+                       bool exec_wait, bool shell_escape, int timeout)
 
 {
        pid_t pid;
@@ -524,7 +525,7 @@ int radius_exec_program(REQUEST *request, char const *cmd, bool exec_wait, bool
 
        RDEBUG2("Executing: %s:", cmd);
 
-       if (user_msg) *user_msg = '\0';
+       if (out) *out = '\0';
 
        pid = radius_start_program(cmd, request, exec_wait, NULL, &from_child, input_pairs, shell_escape);
        if (pid < 0) {
@@ -588,17 +589,17 @@ int radius_exec_program(REQUEST *request, char const *cmd, bool exec_wait, bool
 
                if (userparse(request, answer, output_pairs) == T_INVALID) {
                        RERROR("Failed parsing output from: %s: %s", cmd, fr_strerror());
-                       strlcpy(user_msg, answer, len);
+                       strlcpy(out, answer, len);
                        ret = -1;
                }
        /*
         *      We've not been told to extract output pairs,
-        *      just copy the programs output to the user_msg
+        *      just copy the programs output to the out
         *      buffer.
         */
 
-       } else if (user_msg) {
-               strlcpy(user_msg, answer, msg_len);
+       } else if (out) {
+               strlcpy(out, answer, outlen);
        }
 
        /*
index d1c24e4..21b4248 100644 (file)
@@ -653,10 +653,9 @@ static int map_exec_to_vp(VALUE_PAIR **out, REQUEST *request, value_pair_map_t c
         *      if dst is an attribute, then we create an attribute of that type and then
         *      call pairparsevalue on the output of the script.
         */
-       result = radius_exec_program(request, map->rhs->name, true, true,
-                                    answer, sizeof(answer), EXEC_TIMEOUT,
-                                    input_pairs ? *input_pairs : NULL,
-                                    (map->lhs->type == TMPL_TYPE_LIST) ? &output_pairs : NULL);
+       result = radius_exec_program(answer, sizeof(answer), (map->lhs->type == TMPL_TYPE_LIST) ? &output_pairs : NULL,
+                                    request, map->rhs->name, input_pairs ? *input_pairs : NULL,
+                                    true, true, EXEC_TIMEOUT);
        talloc_free(expanded);
        if (result != 0) {
                talloc_free(output_pairs);
index 0cb7f24..9a2486d 100644 (file)
@@ -1011,8 +1011,8 @@ redo:
                        radius_xlat(buffer, sizeof(buffer), request, mx->xlat_name, NULL, NULL);
                } else {
                        RDEBUG("`%s`", mx->xlat_name);
-                       radius_exec_program(request, mx->xlat_name, false, true, NULL, 0,
-                                           EXEC_TIMEOUT, request->packet->vps, NULL);
+                       radius_exec_program(NULL, 0, NULL, request, mx->xlat_name, request->packet->vps,
+                                           false, true, EXEC_TIMEOUT);
                }
 
                goto next_sibling;
index a9f2a3c..011721c 100644 (file)
@@ -1470,5 +1470,5 @@ void exec_trigger(REQUEST *request, CONF_SECTION *cs, char const *name, int quen
        }
 
        DEBUG("Trigger %s -> %s", name, value);
-       radius_exec_program(request, value, false, true, NULL, 0, EXEC_TIMEOUT, vp, NULL);
+       radius_exec_program(NULL, 0, NULL, request, value, vp, false, true, EXEC_TIMEOUT);
 }
index b83c528..2cf7c7a 100644 (file)
@@ -1926,8 +1926,9 @@ int cbtls_verify(int ok, X509_STORE_CTX *ctx)
                        }
 
                        RDEBUG("Verifying client certificate: %s", conf->verify_client_cert_cmd);
-                       if (radius_exec_program(request, conf->verify_client_cert_cmd, true, true, NULL, 0,
-                                               EXEC_TIMEOUT, request->packet->vps, NULL) != 0) {
+                       if (radius_exec_program(NULL, 0, NULL, request, conf->verify_client_cert_cmd,
+                                               request->packet->vps,
+                                               true, true, EXEC_TIMEOUT) != 0) {
                                AUTH("tls: Certificate CN (%s) fails external verification!", common_name);
                                my_ok = 0;
                        } else {
index 59f4006..49452ed 100644 (file)
@@ -181,9 +181,8 @@ static ssize_t exec_xlat(void *instance, REQUEST *request, char const *fmt, char
         *      This function does it's own xlat of the input program
         *      to execute.
         */
-       result = radius_exec_program(request, fmt, inst->wait, inst->shell_escape,
-                                    out, outlen, inst->timeout,
-                                    input_pairs ? *input_pairs : NULL, NULL);
+       result = radius_exec_program(out, outlen, NULL, request, fmt,  input_pairs ? *input_pairs : NULL,
+                                    inst->wait, inst->shell_escape, inst->timeout);
        if (result != 0) {
                out[0] = '\0';
                return -1;
@@ -343,10 +342,9 @@ static rlm_rcode_t CC_HINT(nonnull) mod_exec_dispatch(void *instance, REQUEST *r
         *      This function does it's own xlat of the input program
         *      to execute.
         */
-       status = radius_exec_program(request, inst->program, inst->wait, inst->shell_escape,
-                                    out, sizeof(out), inst->timeout,
-                                    inst->input ? *input_pairs : NULL,
-                                    inst->output ? &answer : NULL);
+       status = radius_exec_program(out, sizeof(out), inst->output ? &answer : NULL, request,
+                                    inst->program, inst->input ? *input_pairs : NULL,
+                                    inst->wait, inst->shell_escape, inst->timeout);
        rcode = rlm_exec_status2rcode(request, out, strlen(out), status);
 
        /*
@@ -394,9 +392,8 @@ static rlm_rcode_t CC_HINT(nonnull) mod_post_auth(void *instance, REQUEST *reque
        }
 
        tmp = NULL;
-       status = radius_exec_program(request, vp->vp_strvalue, we_wait, inst->shell_escape,
-                                    out, sizeof(out), inst->timeout,
-                                    request->packet->vps, &tmp);
+       status = radius_exec_program(out, sizeof(out), &tmp, request, vp->vp_strvalue, request->packet->vps,
+                                    we_wait, inst->shell_escape, inst->timeout);
        rcode = rlm_exec_status2rcode(request, out, strlen(out), status);
 
        /*
@@ -452,9 +449,8 @@ static rlm_rcode_t CC_HINT(nonnull) mod_accounting(void *instance, REQUEST *requ
                return RLM_MODULE_NOOP;
        }
 
-       status = radius_exec_program(request, vp->vp_strvalue, we_wait, inst->shell_escape,
-                                    out, sizeof(out), inst->timeout,
-                                    request->packet->vps, NULL);
+       status = radius_exec_program(out, sizeof(out), NULL, request, vp->vp_strvalue, request->packet->vps,
+                                    we_wait, inst->shell_escape, inst->timeout);
        return rlm_exec_status2rcode(request, out, strlen(out), status);
 }
 
index 60ee40f..ddb4b00 100644 (file)
@@ -301,9 +301,9 @@ int rlm_ldap_map_xlat(REQUEST *request, value_pair_map_t const *maps, rlm_ldap_m
                        int result;
 
                        input_pairs = radius_list(request, PAIR_LIST_REQUEST);
-                       result = radius_exec_program(request, map->rhs->name, true, true, answer,
-                                                    sizeof(answer), EXEC_TIMEOUT,
-                                                    input_pairs ? *input_pairs : NULL, NULL);
+                       result = radius_exec_program(answer, sizeof(answer), NULL, request,
+                                                    map->rhs->name, input_pairs ? *input_pairs : NULL,
+                                                    true, true, EXEC_TIMEOUT);
                        if (result != 0) {
                                return -1;
                        }
index 376ded3..ea5ff49 100644 (file)
@@ -1060,9 +1060,8 @@ static int CC_HINT(nonnull (1, 2, 4, 5 ,6)) do_mschap(rlm_mschap_t *inst, REQUES
                /*
                 *      Run the program, and expect that we get 16
                 */
-               result = radius_exec_program(request, inst->ntlm_auth, true, true,
-                                            buffer, sizeof(buffer), inst->ntlm_auth_timeout,
-                                            NULL, NULL);
+               result = radius_exec_program(buffer, sizeof(buffer), NULL, request, inst->ntlm_auth, NULL,
+                                            true, true, inst->ntlm_auth_timeout);
                if (result != 0) {
                        char *p;