Initalize detection engine by configuration prefix.
DetectEngineCtxInitWithPrefix(const char *prefix)
Takes the detection engine configuration from:
<prefix>.<config>
If prefix is NULL the regular config will be used.
Update sure that DetectLoadCompleteSigPath considers the prefix when
retrieving the configuration.
return -1;
}
-static DetectEngineCtx *DetectEngineCtxInitReal(int minimal)
+static DetectEngineCtx *DetectEngineCtxInitReal(int minimal, const char *prefix)
{
DetectEngineCtx *de_ctx;
return de_ctx;
}
+ if (prefix != NULL) {
+ strlcpy(de_ctx->config_prefix, prefix, sizeof(de_ctx->config_prefix));
+ }
+
if (ConfGetBool("engine.init-failure-fatal", (int *)&(de_ctx->failure_fatal)) != 1) {
SCLogDebug("ConfGetBool could not load the value.");
}
DetectEngineCtx *DetectEngineCtxInitMinimal(void)
{
- return DetectEngineCtxInitReal(1);
+ return DetectEngineCtxInitReal(1, NULL);
}
DetectEngineCtx *DetectEngineCtxInit(void)
{
- return DetectEngineCtxInitReal(0);
+ return DetectEngineCtxInitReal(0, NULL);
+}
+
+DetectEngineCtx *DetectEngineCtxInitWithPrefix(const char *prefix)
+{
+ return DetectEngineCtxInitReal(0, prefix);
}
static void DetectEngineCtxFreeThreadKeywordData(DetectEngineCtx *de_ctx)
/* prototypes */
void DetectEngineRegisterAppInspectionEngines(void);
+DetectEngineCtx *DetectEngineCtxInitWithPrefix(const char *prefix);
DetectEngineCtx *DetectEngineCtxInit(void);
DetectEngineCtx *DetectEngineCtxInitMinimal(void);
void DetectEngineCtxFree(DetectEngineCtx *);
* \retval filemd5 pointer to DetectFileMd5Data on success
* \retval NULL on failure
*/
-static DetectFileMd5Data *DetectFileMd5Parse (char *str)
+static DetectFileMd5Data *DetectFileMd5Parse (const DetectEngineCtx *de_ctx, char *str)
{
DetectFileMd5Data *filemd5 = NULL;
FILE *fp = NULL;
}
/* get full filename */
- filename = DetectLoadCompleteSigPath(str);
+ filename = DetectLoadCompleteSigPath(de_ctx, str);
if (filename == NULL) {
goto error;
}
DetectFileMd5Data *filemd5 = NULL;
SigMatch *sm = NULL;
- filemd5 = DetectFileMd5Parse(str);
+ filemd5 = DetectFileMd5Parse(de_ctx, str);
if (filemd5 == NULL)
goto error;
* \retval luajit pointer to DetectLuaData on success
* \retval NULL on failure
*/
-static DetectLuaData *DetectLuaParse (char *str)
+static DetectLuaData *DetectLuaParse (const DetectEngineCtx *de_ctx, char *str)
{
DetectLuaData *luajit = NULL;
}
/* get full filename */
- luajit->filename = DetectLoadCompleteSigPath(str);
+ luajit->filename = DetectLoadCompleteSigPath(de_ctx, str);
if (luajit->filename == NULL) {
goto error;
}
DetectLuaData *luajit = NULL;
SigMatch *sm = NULL;
- luajit = DetectLuaParse(str);
+ luajit = DetectLuaParse(de_ctx, str);
if (luajit == NULL)
goto error;
* \param sig_file The name of the file
* \retval str Pointer to the string path + sig_file
*/
-char *DetectLoadCompleteSigPath(char *sig_file)
+char *DetectLoadCompleteSigPath(const DetectEngineCtx *de_ctx, char *sig_file)
{
char *defaultpath = NULL;
char *path = NULL;
+ char varname[128] = "default-rule-path";
+
+ if (strlen(de_ctx->config_prefix) > 0) {
+ snprintf(varname, sizeof(varname), "%s.default-rule-path",
+ de_ctx->config_prefix);
+ }
/* Path not specified */
if (PathIsRelative(sig_file)) {
- if (ConfGet("default-rule-path", &defaultpath) == 1) {
+ if (ConfGet(varname, &defaultpath) == 1) {
SCLogDebug("Default path: %s", defaultpath);
size_t path_len = sizeof(char) * (strlen(defaultpath) +
strlen(sig_file) + 2);
int goodtotal = 0;
int badtotal = 0;
+ char varname[128] = "rule-files";
+
+ if (strlen(de_ctx->config_prefix) > 0) {
+ snprintf(varname, sizeof(varname), "%s.rule-files",
+ de_ctx->config_prefix);
+ }
+
if (RunmodeGetCurrent() == RUNMODE_ENGINE_ANALYSIS) {
fp_engine_analysis_set = SetupFPAnalyzer();
rule_engine_analysis_set = SetupRuleAnalyzer();
/* ok, let's load signature files from the general config */
if (!(sig_file != NULL && sig_file_exclusive == TRUE)) {
- rule_files = ConfGetNode("rule-files");
+ rule_files = ConfGetNode(varname);
if (rule_files != NULL) {
if (!ConfNodeIsSequence(rule_files)) {
SCLogWarning(SC_ERR_INVALID_ARGUMENT,
}
else {
TAILQ_FOREACH(file, &rule_files->head, next) {
- sfile = DetectLoadCompleteSigPath(file->val);
+ sfile = DetectLoadCompleteSigPath(de_ctx, file->val);
SCLogDebug("Loading rule file: %s", sfile);
cntf++;
struct SCProfileKeywordDetectCtx_ *profile_keyword_ctx_per_list[DETECT_SM_LIST_MAX];
#endif
+ char config_prefix[64];
+
/** minimal: essentially a stub */
int minimal;
int SigGroupCleanup (DetectEngineCtx *de_ctx);
void SigAddressPrepareBidirectionals (DetectEngineCtx *);
-char *DetectLoadCompleteSigPath(char *sig_file);
+char *DetectLoadCompleteSigPath(const DetectEngineCtx *, char *sig_file);
int SigLoadSignatures (DetectEngineCtx *, char *, int);
void SigTableList(const char *keyword);
void SigTableSetup(void);