From: Shivani Bhardwaj Date: Tue, 6 Nov 2018 15:59:10 +0000 (+0530) Subject: Check default conf before command line options X-Git-Tag: 1.0.1~20 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=840f69cf033cd3ec43581a797a5c5e7ba25d351f;p=thirdparty%2Fsuricata-update.git Check default conf before command line options 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. --- diff --git a/suricata/update/config.py b/suricata/update/config.py index 5a6f4de..312f07e 100644 --- a/suricata/update/config.py +++ b/suricata/update/config.py @@ -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) diff --git a/suricata/update/main.py b/suricata/update/main.py index 8c1c929..b1ad7f0 100644 --- a/suricata/update/main.py +++ b/suricata/update/main.py @@ -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() diff --git a/suricata/update/net.py b/suricata/update/net.py index 074520a..208e4bd 100644 --- a/suricata/update/net.py +++ b/suricata/update/net.py @@ -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]