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.
pull/1608/head
Victor Julien 11 years ago
parent 5fff250749
commit a6e3cec9e5

@ -51,7 +51,7 @@ char SCRConfReferenceHashCompareFunc(void *data1, uint16_t datalen1,
void SCRConfReferenceHashFree(void *ch); void SCRConfReferenceHashFree(void *ch);
/* used to get the reference.config file path */ /* used to get the reference.config file path */
static char *SCRConfGetConfFilename(void); static char *SCRConfGetConfFilename(const DetectEngineCtx *de_ctx);
void SCReferenceConfInit(void) void SCReferenceConfInit(void)
{ {
@ -122,7 +122,7 @@ static FILE *SCRConfInitContextAndLocalResources(DetectEngineCtx *de_ctx, FILE *
* instead use an input stream against a buffer containing the * instead use an input stream against a buffer containing the
* reference strings */ * reference strings */
if (fd == NULL) { if (fd == NULL) {
filename = SCRConfGetConfFilename(); filename = SCRConfGetConfFilename(de_ctx);
if ((fd = fopen(filename, "r")) == NULL) { if ((fd = fopen(filename, "r")) == NULL) {
#ifdef UNITTESTS #ifdef UNITTESTS
if (RunmodeIsUnittests()) 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 * \retval log_filename Pointer to a string containing the path for the
* reference.config file. * reference.config file.
*/ */
static char *SCRConfGetConfFilename(void) static char *SCRConfGetConfFilename(const DetectEngineCtx *de_ctx)
{ {
char *path = NULL; char *path = NULL;
if (ConfGet("reference-config-file", &path) != 1) { char config_value[256] = "";
return (char *)SC_RCONF_DEFAULT_FILE_PATH;
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; return path;
} }

Loading…
Cancel
Save