]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
Don't require an action-order configuration section. If not present,
authorJason Ish <jason.ish@emulex.com>
Wed, 17 Sep 2014 17:52:12 +0000 (11:52 -0600)
committerVictor Julien <victor@inliniac.net>
Wed, 1 Oct 2014 12:41:13 +0000 (14:41 +0200)
use the defaults.

src/util-action.c

index 583e371ab828a1c0596c7e2c225ae8a165f49f2b..2b349748989174603d1aa1f42f81ea3d5989dca8 100644 (file)
@@ -107,7 +107,11 @@ int ActionInitConfig()
 
     /* Let's load the order of actions from the general config */
     action_order = ConfGetNode("action-order");
-    if (action_order != NULL) {
+    if (action_order == NULL) {
+        /* No configuration, use defaults. */
+        return 0;
+    }
+    else {
         TAILQ_FOREACH(action, &action_order->head, next) {
             SCLogDebug("Loading action order : %s", action->val);
             action_flag = ActionAsciiToFlag(action->val);
@@ -1547,10 +1551,46 @@ cleanup:
         DetectEngineCtxFree(de_ctx);
     }
 
+    /* Restore default values */
+    action_order_sigs[0] = ACTION_PASS;
+    action_order_sigs[1] = ACTION_DROP;
+    action_order_sigs[2] = ACTION_REJECT;
+    action_order_sigs[3] = ACTION_ALERT;
+
 end:
     return res;
 }
 
+/**
+ * \test Check that the expected defaults are loaded if the
+ *     action-order configuration is not present.
+ */
+int UtilActionTest24(void)
+{
+    int res = 1;
+    char config[] = "%YAML 1.1\n"
+        "---\n";
+
+    ConfCreateContextBackup();
+    ConfInit();
+    ConfYamlLoadString(config, strlen(config));
+
+    if (ActionInitConfig() != 0) {
+        res = 0;
+        goto done;
+    }
+    if (action_order_sigs[0] != ACTION_PASS ||
+        action_order_sigs[1] != ACTION_DROP ||
+        action_order_sigs[2] != ACTION_REJECT ||
+        action_order_sigs[3] != ACTION_ALERT) {
+        res = 0;
+    }
+
+done:
+    ConfRestoreContextBackup();
+    return res;
+}
+
 #endif
 
 /* Register unittests */
@@ -1582,5 +1622,6 @@ void UtilActionRegisterTests(void)
     UtRegisterTest("UtilActionTest21", UtilActionTest21, 1);
     UtRegisterTest("UtilActionTest22", UtilActionTest22, 1);
     UtRegisterTest("UtilActionTest23", UtilActionTest23, 1);
+    UtRegisterTest("UtilActionTest24", UtilActionTest24, 1);
 #endif
 }