From: Victor Julien Date: Wed, 8 Apr 2015 12:55:16 +0000 (+0200) Subject: multi-detect: make classification prefix aware X-Git-Tag: suricata-3.0RC1~200 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5fff2507497cc0d442a9e9670a145ea42a240e78;p=thirdparty%2Fsuricata.git multi-detect: make classification prefix aware Make classification 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-classification-config.c b/src/util-classification-config.c index 3711dd32b1..e88d4f20c5 100644 --- a/src/util-classification-config.c +++ b/src/util-classification-config.c @@ -54,7 +54,7 @@ uint32_t SCClassConfClasstypeHashFunc(HashTable *ht, void *data, uint16_t datale char SCClassConfClasstypeHashCompareFunc(void *data1, uint16_t datalen1, void *data2, uint16_t datalen2); void SCClassConfClasstypeHashFree(void *ch); -static char *SCClassConfGetConfFilename(void); +static char *SCClassConfGetConfFilename(const DetectEngineCtx *de_ctx); void SCClassConfInit(void) { @@ -124,7 +124,7 @@ FILE *SCClassConfInitContextAndLocalResources(DetectEngineCtx *de_ctx, FILE *fd) * instead use an input stream against a buffer containing the * classification strings */ if (fd == NULL) { - filename = SCClassConfGetConfFilename(); + filename = SCClassConfGetConfFilename(de_ctx); if ( (fd = fopen(filename, "r")) == NULL) { #ifdef UNITTESTS if (RunmodeIsUnittests()) @@ -160,12 +160,26 @@ FILE *SCClassConfInitContextAndLocalResources(DetectEngineCtx *de_ctx, FILE *fd) * \retval log_filename Pointer to a string containing the path for the * Classification Config file. */ -static char *SCClassConfGetConfFilename(void) +static char *SCClassConfGetConfFilename(const DetectEngineCtx *de_ctx) { char *log_filename = NULL; - - if (ConfGet("classification-file", &log_filename) != 1) { - log_filename = (char *)SC_CLASS_CONF_DEF_CONF_FILEPATH; + char config_value[256] = ""; + + if (de_ctx != NULL && strlen(de_ctx->config_prefix) > 0) { + snprintf(config_value, sizeof(config_value), + "%s.classification-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("classification-file", &log_filename) != 1) { + log_filename = (char *)SC_CLASS_CONF_DEF_CONF_FILEPATH; + } + } + } else { + if (ConfGet("classification-file", &log_filename) != 1) { + log_filename = (char *)SC_CLASS_CONF_DEF_CONF_FILEPATH; + } } return log_filename;