]> git.ipfire.org Git - thirdparty/suricata-update.git/commitdiff
config: prefer configuration specified files 330/head
authorJason Ish <jason.ish@oisf.net>
Tue, 4 Jul 2023 18:56:08 +0000 (12:56 -0600)
committerJason Ish <jason.ish@oisf.net>
Tue, 4 Jul 2023 22:23:54 +0000 (16:23 -0600)
Suricata-Update was preferring the existence of "disable.conf" in
$sysconfdir over it be specified in the update.yaml.

Refactor the auto-conf to only search and apply the default
$sysconfdir files if they don't already exist in the config.

Additonally, now that the default, if not set or found will be none,
log a warning if a specific configuration file is not found instead of
silently ignoring.

Ticket: #6172

suricata/update/config.py
suricata/update/main.py

index a6271cb1647cc9c67c928769f3c7a12200ae4fe3..ad95996046f4a59323db5dea2898ffabf48c3292 100644 (file)
@@ -73,10 +73,6 @@ else:
     ]
 
 DEFAULT_CONFIG = {
-    "disable-conf": "/etc/suricata/disable.conf",
-    "enable-conf": "/etc/suricata/enable.conf",
-    "drop-conf": "/etc/suricata/drop.conf",
-    "modify-conf": "/etc/suricata/modify.conf",
     "sources": [],
     LOCAL_CONF_KEY: [],
 
@@ -228,23 +224,30 @@ def init(args):
 
         # Fixup the default locations for Suricata-Update configuration files, but only if
         # they exist, otherwise keep the defaults.
+        conf_search_path = ["/etc"]
         if "sysconfdir" in build_info:
-            configs = (
-                ("disable-conf", "disable.conf"),
-                ("enable-conf", "enable.conf"),
-                ("drop-conf", "drop.conf"),
-                ("modify-conf", "modify.conf"),
-            )
             sysconfdir = build_info["sysconfdir"]
-            for key, filename in configs:
-                config_path = os.path.join(sysconfdir, "suricata", filename)
+            if not sysconfdir in conf_search_path:
+                conf_search_path.insert(0, sysconfdir)
+        configs = (
+            ("disable-conf", "disable.conf"),
+            ("enable-conf", "enable.conf"),
+            ("drop-conf", "drop.conf"),
+            ("modify-conf", "modify.conf"),
+        )
+        for key, filename in configs:
+            if getattr(args, key.replace("-", "_"), None) is not None:
+                continue
+            if _config.get(key) is not None:
+                continue
+            for conf_dir in conf_search_path:
+                config_path = os.path.join(conf_dir, "suricata", filename)
                 logger.debug("Looking for {}".format(config_path))
                 if os.path.exists(config_path):
                     logger.debug("Found {}".format(config_path))
-                    val = getattr(args, key.replace("-", "_"), None)
-                    if val is None:
-                        logger.debug("Changing default for {} to {}".format(key, config_path))
-                        _config[key] = config_path
+                    logger.debug("Using {} for {}".format(config_path, key))
+                    _config[key] = config_path
+                    break
 
     # If suricata-conf not provided on the command line or in the
     # configuration file, look for it.
index d562ef0789575d24ca6b1fa1a75cd5c09d87044a..4a0e7a6dfa2b67e2f81e88bfa74269b7ae61173d 100644 (file)
@@ -1135,27 +1135,39 @@ def _main():
 
     # Load user provided disable filters.
     disable_conf_filename = config.get("disable-conf")
-    if disable_conf_filename and os.path.exists(disable_conf_filename):
-        logger.info("Loading %s.", disable_conf_filename)
-        disable_matchers += load_matchers(disable_conf_filename)
+    if disable_conf_filename:
+        if os.path.exists(disable_conf_filename):
+            logger.info("Loading %s.", disable_conf_filename)
+            disable_matchers += load_matchers(disable_conf_filename)
+        else:
+            logger.warn("disable-conf file does not exist: {}".format(disable_conf_filename))
 
     # Load user provided enable filters.
     enable_conf_filename = config.get("enable-conf")
-    if enable_conf_filename and os.path.exists(enable_conf_filename):
-        logger.info("Loading %s.", enable_conf_filename)
-        enable_matchers += load_matchers(enable_conf_filename)
+    if enable_conf_filename:
+        if os.path.exists(enable_conf_filename):
+            logger.info("Loading %s.", enable_conf_filename)
+            enable_matchers += load_matchers(enable_conf_filename)
+        else:
+            logger.warn("enable-conf file does not exist: {}".format(enable_conf_filename))
 
     # Load user provided modify filters.
     modify_conf_filename = config.get("modify-conf")
-    if modify_conf_filename and os.path.exists(modify_conf_filename):
-        logger.info("Loading %s.", modify_conf_filename)
-        modify_filters += load_filters(modify_conf_filename)
+    if modify_conf_filename:
+        if os.path.exists(modify_conf_filename):
+            logger.info("Loading %s.", modify_conf_filename)
+            modify_filters += load_filters(modify_conf_filename)
+        else:
+            logger.warn("modify-conf file does not exist: {}".format(modify_conf_filename))
 
     # Load user provided drop filters.
     drop_conf_filename = config.get("drop-conf")
-    if drop_conf_filename and os.path.exists(drop_conf_filename):
-        logger.info("Loading %s.", drop_conf_filename)
-        drop_filters += load_drop_filters(drop_conf_filename)
+    if drop_conf_filename:
+        if os.path.exists(drop_conf_filename):
+            logger.info("Loading %s.", drop_conf_filename)
+            drop_filters += load_drop_filters(drop_conf_filename)
+        else:
+            logger.warn("drop-conf file does not exist: {}".format(drop_conf_filename))
 
     # Load the Suricata configuration if we can.
     suriconf = None