]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
multi-detect: make threshold prefix aware
authorVictor Julien <victor@inliniac.net>
Wed, 8 Apr 2015 13:59:46 +0000 (15:59 +0200)
committerVictor Julien <victor@inliniac.net>
Thu, 23 Jul 2015 17:36:15 +0000 (19:36 +0200)
Make threshold loading prefix aware, so it can be part of tenant
configuration.

If the setting is missing from the tenant, the global setting is tried
and if that too is missing, the global default is used.

Note: currently per host thresholds are tracked globally and NOT per
tenant.

src/util-threshold-config.c

index 9f107a1e0f890f128d3dad49538c42cdd5dd87d4..6698b16fa6db7421ffa1f5b7900ae3fa4e9da103 100644 (file)
@@ -103,14 +103,27 @@ static pcre_extra *regex_suppress_study = NULL;
  * \retval log_filename Pointer to a string containing the path for the
  *                      Threshold Config file.
  */
-char *SCThresholdConfGetConfFilename(void)
+static char *SCThresholdConfGetConfFilename(const DetectEngineCtx *de_ctx)
 {
     char *log_filename = NULL;
+    char config_value[256] = "";
 
-    if (ConfGet("threshold-file", &log_filename) != 1) {
-        log_filename = (char *)THRESHOLD_CONF_DEF_CONF_FILEPATH;
-    }
+    if (de_ctx != NULL && strlen(de_ctx->config_prefix) > 0) {
+        snprintf(config_value, sizeof(config_value),
+                 "%s.threshold-file", de_ctx->config_prefix);
 
+        /* try loading prefix setting, fall back to global if that
+         * fails. */
+        if (ConfGet(config_value, &log_filename) != 1) {
+            if (ConfGet("threshold-file", &log_filename) != 1) {
+                log_filename = (char *)THRESHOLD_CONF_DEF_CONF_FILEPATH;
+            }
+        }
+    } else {
+        if (ConfGet("threshold-file", &log_filename) != 1) {
+            log_filename = (char *)THRESHOLD_CONF_DEF_CONF_FILEPATH;
+        }
+    }
     return log_filename;
 }
 
@@ -138,7 +151,7 @@ int SCThresholdConfInitContext(DetectEngineCtx *de_ctx, FILE *utfd)
     int opts = 0;
 
     if (fd == NULL) {
-        filename = SCThresholdConfGetConfFilename();
+        filename = SCThresholdConfGetConfFilename(de_ctx);
         if ( (fd = fopen(filename, "r")) == NULL) {
             SCLogWarning(SC_ERR_FOPEN, "Error opening file: \"%s\": %s", filename, strerror(errno));
             goto error;
@@ -212,7 +225,6 @@ error:
  */
 void SCThresholdConfDeInitContext(DetectEngineCtx *de_ctx, FILE *fd)
 {
-
     if (fd != NULL)
         fclose(fd);