From: Victor Julien Date: Wed, 8 Apr 2015 13:31:52 +0000 (+0200) Subject: multi-detect: make reference prefix aware X-Git-Tag: suricata-3.0RC1~199 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a6e3cec9e560f0fe8c9e297e557d9f2f9a939192;p=thirdparty%2Fsuricata.git multi-detect: make reference prefix aware Make reference 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. --- diff --git a/src/util-reference-config.c b/src/util-reference-config.c index a2f09bd360..299897ab35 100644 --- a/src/util-reference-config.c +++ b/src/util-reference-config.c @@ -51,7 +51,7 @@ char SCRConfReferenceHashCompareFunc(void *data1, uint16_t datalen1, void SCRConfReferenceHashFree(void *ch); /* used to get the reference.config file path */ -static char *SCRConfGetConfFilename(void); +static char *SCRConfGetConfFilename(const DetectEngineCtx *de_ctx); void SCReferenceConfInit(void) { @@ -122,7 +122,7 @@ static FILE *SCRConfInitContextAndLocalResources(DetectEngineCtx *de_ctx, FILE * * instead use an input stream against a buffer containing the * reference strings */ if (fd == NULL) { - filename = SCRConfGetConfFilename(); + filename = SCRConfGetConfFilename(de_ctx); if ((fd = fopen(filename, "r")) == NULL) { #ifdef UNITTESTS if (RunmodeIsUnittests()) @@ -159,11 +159,26 @@ static FILE *SCRConfInitContextAndLocalResources(DetectEngineCtx *de_ctx, FILE * * \retval log_filename Pointer to a string containing the path for the * reference.config file. */ -static char *SCRConfGetConfFilename(void) +static char *SCRConfGetConfFilename(const DetectEngineCtx *de_ctx) { char *path = NULL; - if (ConfGet("reference-config-file", &path) != 1) { - return (char *)SC_RCONF_DEFAULT_FILE_PATH; + char config_value[256] = ""; + + if (de_ctx != NULL && strlen(de_ctx->config_prefix) > 0) { + snprintf(config_value, sizeof(config_value), + "%s.reference-config-file", de_ctx->config_prefix); + + /* try loading prefix setting, fall back to global if that + * fails. */ + if (ConfGet(config_value, &path) != 1) { + if (ConfGet("reference-config-file", &path) != 1) { + return (char *)SC_RCONF_DEFAULT_FILE_PATH; + } + } + } else { + if (ConfGet("reference-config-file", &path) != 1) { + return (char *)SC_RCONF_DEFAULT_FILE_PATH; + } } return path; }