]> git.ipfire.org Git - thirdparty/suricata-update.git/commitdiff
Check default conf before command line options
authorShivani Bhardwaj <shivanib134@gmail.com>
Tue, 6 Nov 2018 15:59:10 +0000 (21:29 +0530)
committerShivani Bhardwaj <shivanib134@gmail.com>
Tue, 6 Nov 2018 16:28:59 +0000 (21:58 +0530)
The default configuration file must be checked for the availability of
`user-agent` option even if it is None.

This behavior has been implemented by Jason Ish.

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

index 5a6f4de7b6f8839988378ce320329f1a6c31373f..312f07e19a7050b632858110ee8dd77184453457 100644 (file)
@@ -92,6 +92,10 @@ _config = {}
 # The filename the config was read from, if any.
 filename = None
 
+def has(key):
+    """Return true if a configuration key exists."""
+    return key in _config
+
 def set(key, value):
     """Set a configuration value."""
     _config[key] = value
@@ -167,7 +171,6 @@ def init(args):
                 filename = DEFAULT_UPDATE_YAML_PATH
 
     # Apply command line arguments to the config.
-
     for arg in vars(args):
         if arg == "local":
             for local in args.local:
@@ -176,7 +179,7 @@ def init(args):
         elif arg == "data_dir" and args.data_dir:
             logger.debug("Setting data directory to %s", args.data_dir)
             _config[DATA_DIRECTORY_KEY] = args.data_dir
-        elif getattr(args, arg):
+        elif getattr(args, arg) is not None:
             key = arg.replace("_", "-")
             val = getattr(args, arg)
             logger.debug("Setting configuration value %s -> %s", key, val)
index 8c1c9297bb804cb41357bb1567d9439bcdfcdec2..b1ad7f091d06a27c6d27f6eb728cb39bb429b9f5 100644 (file)
@@ -1227,12 +1227,6 @@ def _main():
     # User-Agent.
     suricata.update.net.set_user_agent_suricata_version(suricata_version.full)
 
-    # Load custom user-agent-string.
-    user_agent = config.get("user-agent")
-    if user_agent:
-        logger.info("Using user-agent: %s.", user_agent)
-        suricata.update.net.set_custom_user_agent(user_agent)
-
     if args.subcommand:
         if hasattr(args, "func"):
             return args.func()
index 074520aa05bcb6457509fcb19930805f6dea8b7e..208e4bd69c030abd32b4152d73434b457e0359fd 100644 (file)
@@ -53,9 +53,13 @@ def set_user_agent_suricata_version(version):
 
 def build_user_agent():
     params = []
-
-    if custom_user_agent is not None:
-        return custom_user_agent
+    has_custom_user_agent = config.has("user-agent")
+    if has_custom_user_agent:
+        user_agent = config.get("user-agent")
+        if user_agent is None or len(user_agent.strip()) == 0:
+            logger.debug("Suppressing HTTP User-Agent header")
+            return None
+        return user_agent
 
     uname_system = platform.uname()[0]