Allow other yaml files to be included in the main yaml.

remotes/origin/HEAD
Victor Julien 14 years ago
parent adb5d05fb5
commit 489b8b8bcc

@ -42,6 +42,7 @@
#include "conf.h"
#include "util-unittest.h"
#include "util-debug.h"
#include "util-path.h"
static ConfNode *root = NULL;
static ConfNode *root_backup = NULL;
@ -702,6 +703,41 @@ ConfNodeChildValueIsTrue(ConfNode *node, const char *key)
return val != NULL ? ConfValIsTrue(val) : 0;
}
/**
* \brief Create the path for an include entry
* \param file The name of the file
* \retval str Pointer to the string path + sig_file
*/
char *ConfLoadCompleteIncludePath(char *file)
{
char *defaultpath = NULL;
char *path = NULL;
/* Path not specified */
if (PathIsRelative(file)) {
if (ConfGet("include-path", &defaultpath) == 1) {
SCLogDebug("Default path: %s", defaultpath);
size_t path_len = sizeof(char) * (strlen(defaultpath) +
strlen(file) + 2);
path = SCMalloc(path_len);
if (path == NULL)
return NULL;
strlcpy(path, defaultpath, path_len);
if (path[strlen(path) - 1] != '/')
strlcat(path, "/", path_len);
strlcat(path, file, path_len);
} else {
path = SCStrdup(file);
}
} else {
path = SCStrdup(file);
}
return path;
}
#ifdef UNITTESTS
/**

@ -80,5 +80,6 @@ ConfNode *ConfNodeLookupKeyValue(ConfNode *base, const char *key, const char *va
int ConfGetChildValue(ConfNode *base, char *name, char **vptr);
int ConfGetChildValueInt(ConfNode *base, char *name, intmax_t *val);
int ConfGetChildValueBool(ConfNode *base, char *name, int *val);
char *ConfLoadCompleteIncludePath(char *);
#endif /* ! __CONF_H__ */

@ -1153,6 +1153,21 @@ int main(int argc, char **argv)
/* Error already displayed. */
exit(EXIT_FAILURE);
}
ConfNode *file;
ConfNode *includes = ConfGetNode("include");
if (includes != NULL) {
TAILQ_FOREACH(file, &includes->head, next) {
char *ifile = ConfLoadCompleteIncludePath(file->val);
SCLogInfo("Including: %s", ifile);
if (ConfYamlLoadFile(ifile) != 0) {
/* Error already displayed. */
exit(EXIT_FAILURE);
}
}
}
} else if (run_mode != RUNMODE_UNITTEST){
SCLogError(SC_ERR_OPENING_FILE, "Configuration file has not been provided");
usage(argv[0]);

Loading…
Cancel
Save