]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
add preliminary support for partial commands
authorAlan T. DeKok <aland@freeradius.org>
Wed, 11 Jul 2018 20:26:41 +0000 (16:26 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Wed, 11 Jul 2018 20:27:14 +0000 (16:27 -0400)
src/main/radmin.c
src/modules/proto_control/conduit.h
src/modules/proto_control/proto_control_unix.c
src/modules/proto_control/radmin.c

index 0db63216588e4fc17bd73cf683562f268beb7307..0f655031f3d2879df8d9f6ce96007b75bae8ed77 100644 (file)
@@ -658,7 +658,10 @@ int fr_radmin_run(fr_cmd_info_t *info, FILE *fp, FILE *fp_err, char *str, bool r
        int argc, rcode;
 
        argc = fr_command_str_to_argv(radmin_cmd, info, str);
-       if (argc < 0) return -1;
+       if (argc < 0) {
+               fprintf(fp_err, "%s\n", fr_strerror());
+               return -1;
+       }
 
        if (!info->runnable) {
                return 0;
index bc52a00bc5153bb3cb5d85673abf7802cbf2e497..2bee03b27f2670d46549dbfa711e58b0c024a765 100644 (file)
@@ -50,6 +50,7 @@ typedef enum fr_conduit_origin_t {
 
 typedef enum fr_conduit_result_t {
        FR_CONDUIT_FAIL = 0,
+       FR_CONDUIT_PARTIAL,
        FR_CONDUIT_SUCCESS
 } fr_conduit_result_t;
 
index feeb8509e16e741367ec7301971310704be471e3..d43f4365a2110c730f83f1b943abc48cea93087e 100644 (file)
@@ -122,8 +122,9 @@ static ssize_t mod_read_command(void *instance, UNUSED void **packet_ctx, UNUSED
 {
        proto_control_unix_t            *inst = talloc_get_type_abort(instance, proto_control_unix_t);
        fr_conduit_hdr_t                *hdr = (fr_conduit_hdr_t *) buffer;
-       uint32_t                        status = FR_CONDUIT_FAIL;
+       uint32_t                        status;
        uint8_t                         *cmd = buffer + sizeof(*hdr);
+       int                             rcode;
        char                            string[1024];
 
        hdr->length = ntohl(hdr->length);
@@ -136,12 +137,23 @@ static ssize_t mod_read_command(void *instance, UNUSED void **packet_ctx, UNUSED
        memcpy(string, cmd, hdr->length);
        string[hdr->length] = '\0';
 
-       if (fr_radmin_run(inst->info, inst->stdout, inst->stderr, string, inst->read_only) == 1) {
+       rcode = fr_radmin_run(inst->info, inst->stdout, inst->stderr, string, inst->read_only);
+       if (rcode < 0) {
+               status = FR_CONDUIT_FAIL;
+       } else if (rcode == 0) {
+               /*
+                *      The other end should keep track of it's
+                *      context, and send us full lines.
+                */
+               (void) fr_command_clear(0, inst->info);
+               status = FR_CONDUIT_PARTIAL;
+       } else {
                status = FR_CONDUIT_SUCCESS;
        }
 
        fr_conduit_write(inst->sockfd, FR_CONDUIT_STDOUT, "\n", 1);
 
+       status = htonl(status);
        (void) fr_conduit_write(inst->sockfd, FR_CONDUIT_CMD_STATUS, &status, sizeof(status));
 
        return 0;
index a4dce1fa8a6e6584cd1c6e8d1206adc8e80e169e..4c1e30132103ee183782853989ea2faf0c028935 100644 (file)
@@ -856,7 +856,10 @@ int main(int argc, char **argv)
                        exit(EXIT_FAILURE);
 
                } else if (len == FR_CONDUIT_SUCCESS) {
-                       break;
+                       continue;
+
+               } else if (len == FR_CONDUIT_PARTIAL) {
+                       continue;
 
                } else if (len == FR_CONDUIT_FAIL) {
                        exit_status = EXIT_FAILURE;