-/* Copyright (C) 2007-2020 Open Information Security Foundation
+/* Copyright (C) 2007-2022 Open Information Security Foundation
*
* You can copy, redistribute or modify this Program under the terms of
* the GNU General Public License version 2 as published by the Free
(void)SRepInit(de_ctx);
SCClassConfLoadClassficationConfigFile(de_ctx, NULL);
- SCRConfLoadReferenceConfigFile(de_ctx, NULL);
+ if (SCRConfLoadReferenceConfigFile(de_ctx, NULL) < 0) {
+ if (RunmodeGetCurrent() == RUNMODE_CONF_TEST)
+ goto error;
+ }
if (ActionInitConfig() < 0) {
goto error;
-/* Copyright (C) 2007-2019 Open Information Security Foundation
+/* Copyright (C) 2007-2022 Open Information Security Foundation
*
* You can copy, redistribute or modify this Program under the terms of
* the GNU General Public License version 2 as published by the Free
const char *filename = SCRConfGetConfFilename(de_ctx);
if ((fd = fopen(filename, "r")) == NULL) {
#ifdef UNITTESTS
- if (RunmodeIsUnittests())
+ if (RunmodeIsUnittests()) {
return NULL; // silently fail
+ }
#endif
SCLogError(SC_ERR_FOPEN, "Error opening file: \"%s\": %s", filename,
strerror(errno));
*
* \param de_ctx Pointer to the Detection Engine Context.
*/
-static void SCRConfParseFile(DetectEngineCtx *de_ctx, FILE *fd)
+static bool SCRConfParseFile(DetectEngineCtx *de_ctx, FILE *fd)
{
char line[1024];
uint8_t i = 1;
+ int runmode = RunmodeGetCurrent();
+ bool is_conf_test_mode = runmode == RUNMODE_CONF_TEST;
while (fgets(line, sizeof(line), fd) != NULL) {
if (SCRConfIsLineBlankOrComment(line))
continue;
- SCRConfAddReference(de_ctx, line);
+ if (SCRConfAddReference(de_ctx, line) != 0) {
+ if (is_conf_test_mode) {
+ return false;
+ }
+ }
i++;
}
SCLogInfo("Added \"%d\" reference types from the reference.config file",
de_ctx->reference_conf_ht->count);
#endif /* UNITTESTS */
- return;
+ return true;
}
/**
fd = SCRConfInitContextAndLocalResources(de_ctx, fd);
if (fd == NULL) {
#ifdef UNITTESTS
- if (RunmodeIsUnittests() && fd == NULL) {
+ if (RunmodeIsUnittests()) {
return -1;
}
#endif
return -1;
}
- SCRConfParseFile(de_ctx, fd);
+ bool rc = SCRConfParseFile(de_ctx, fd);
SCRConfDeInitLocalResources(de_ctx, fd);
- return 0;
+ return rc ? 0 : -1;
}
/**