};
static std::stack<Location> files;
+static int rules_file_depth = 0;
const char* get_parse_file()
{
{
assert(arg);
arg = ExpandVars(sc, arg);
- std::string file = get_ips_policy()->includer;
+ std::string file = !rules_file_depth ? get_ips_policy()->includer : get_parse_file();
const char* code = get_config_file(arg, file);
return;
}
push_parse_location(code, file.c_str(), arg);
- ParseConfigFile(sc, file.c_str());
+ parse_rules_file(sc, file.c_str());
pop_parse_location();
}
return p ? p->RuleList : nullptr;
}
-void ParseConfigFile(SnortConfig* sc, const char* fname)
+void parse_rules_file(SnortConfig* sc, const char* fname)
{
if ( !fname )
return;
fname, get_error(errno));
return;
}
+ ++rules_file_depth;
parse_stream(fs, sc);
+ --rules_file_depth;
}
-void ParseConfigString(SnortConfig* sc, const char* s)
+void parse_rules_string(SnortConfig* sc, const char* s)
{
std::string rules = s;
std::stringstream ss(rules);
// file may hold original parse path on entry
const char* get_config_file(const char* arg, std::string& file);
-void ParseConfigFile(snort::SnortConfig*, const char* fname);
-void ParseConfigString(snort::SnortConfig*, const char* str);
+void parse_rules_file(snort::SnortConfig*, const char* fname);
+void parse_rules_string(snort::SnortConfig*, const char* str);
void ParseIpVar(snort::SnortConfig*, const char* name, const char* s);
void parse_include(snort::SnortConfig*, const char*);
/* Init sid-gid -> otn map */
sc->otn_map = OtnLookupNew();
if (sc->otn_map == nullptr)
- ParseAbort("ParseRulesFile otn_map ghash_new failed.");
+ ParseAbort("otn_map ghash_new failed.");
}
static RuleListNode* addNodeToOrderedList(RuleListNode* ordered_list,
if ( p->enable_builtin_rules )
ModuleManager::load_rules(sc);
- const char* fname = p->include.c_str();
- std::string file = p->includer;
-
- if ( fname && *fname )
+ if ( !p->include.empty() )
{
- const char* code = get_config_file(fname, file);
- push_parse_location(code, file.c_str(), fname);
- ParseConfigFile(sc, file.c_str());
+ std::string path = p->includer;
+ const char* file = p->include.c_str();
+ const char* code = get_config_file(file, path);
+ push_parse_location(code, path.c_str(), file);
+ parse_rules_file(sc, path.c_str());
pop_parse_location();
}
if ( !p->rules.empty() )
{
- push_parse_location("C", file.c_str(), "ips.rules");
- ParseConfigString(sc, p->rules.c_str());
+ push_parse_location("C", p->includer.c_str(), "ips.rules");
+ parse_rules_string(sc, p->rules.c_str());
pop_parse_location();
}
if ( !p->states.empty() )
{
- push_parse_location("C", file.c_str(), "ips.states");
- ParseConfigString(sc, p->states.c_str());
+ push_parse_location("C", p->includer.c_str(), "ips.states");
+ parse_rules_string(sc, p->states.c_str());
pop_parse_location();
}
{
p->includer.clear();
push_parse_location("W", "./", "rule args");
- ParseConfigString(sc, s_aux_rules.c_str());
+ parse_rules_string(sc, s_aux_rules.c_str());
pop_parse_location();
}