Allow module status to be forced to any module code
authorAlan T. DeKok <aland@freeradius.org>
Thu, 27 Feb 2014 16:12:55 +0000 (11:12 -0500)
committerAlan T. DeKok <aland@freeradius.org>
Mon, 3 Mar 2014 18:27:16 +0000 (18:27 +0000)
src/include/modpriv.h
src/main/command.c
src/main/modcall.c

index 5cbaaab..a27bedb 100644 (file)
@@ -58,7 +58,8 @@ typedef struct module_instance_t {
        pthread_mutex_t         *mutex;
 #endif
        CONF_SECTION            *cs;
-       int                     dead;
+       int                     force;
+       int                     code;
        fr_module_hup_t         *mh;
 } module_instance_t;
 
index e6c8b32..9a07fbe 100644 (file)
@@ -1493,7 +1493,9 @@ static int command_set_module_config(rad_listen_t *listener, int argc, char *arg
        return 1;               /* success */
 }
 
-static int command_set_module_state(rad_listen_t *listener, int argc, char *argv[])
+extern const FR_NAME_NUMBER mod_rcode_table[];
+
+static int command_set_module_status(rad_listen_t *listener, int argc, char *argv[])
 {
        CONF_SECTION *cs;
        module_instance_t *mi;
@@ -1514,14 +1516,23 @@ static int command_set_module_state(rad_listen_t *listener, int argc, char *argv
 
 
        if (strcmp(argv[1], "alive") == 0) {
-               mi->dead = FALSE;
+               mi->force = FALSE;
 
        } else if (strcmp(argv[1], "dead") == 0) {
-               mi->dead = TRUE;
+               mi->code = RLM_MODULE_FAIL;
+               mi->force = TRUE;
 
        } else {
-               cprintf(listener, "ERROR: Unknown status \"%s\"\n", argv[2]);
-               return 0;
+               int rcode;
+
+               rcode = fr_str2int(mod_rcode_table, argv[1], -1);
+               if (rcode < 0) {
+                       cprintf(listener, "ERROR: Unknown status \"%s\"\n", argv[1]);
+                       return 0;
+               }
+
+               mi->code = rcode;
+               mi->force = TRUE;
        }
 
        return 1;               /* success */
@@ -1822,9 +1833,9 @@ static fr_command_table_t command_table_set_module[] = {
          "set module config <module> variable value - set configuration for <module>",
          command_set_module_config, NULL },
 
-       { "state", FR_WRITE,
-         "set module state NAME [alive|dead] - set the module NAME to be alive or dead (always return \"fail\")",
-         command_set_module_state, NULL },
+       { "status", FR_WRITE,
+         "set module status <module> [alive|...] - set the module status to be alive (operating normally), or force a particular code (ok,fail, etc.)",
+         command_set_module_status, NULL },
 
        { NULL, 0, NULL, NULL, NULL }
 };
index 469e2da..df384ca 100644 (file)
@@ -290,8 +290,8 @@ static int call_modsingle(int component, modsingle *sp, REQUEST *request)
               comp2str[component], sp->modinst->name,
               sp->modinst->entry->name, request->number);
 
-       if (sp->modinst->dead) {
-               myresult = RLM_MODULE_FAIL;
+       if (sp->modinst->force) {
+               myresult = sp->modinst->code;
                goto fail;
        }