"correlate unified2 events with configuration" },
{ "include", Parameter::PT_STRING, nullptr, nullptr,
- "legacy snort rules and includes" },
+ "snort rules and includes" },
+
+ { "includer", Parameter::PT_STRING, "(optional)", nullptr,
+ "for internal use; where includes are included from" },
// FIXIT-L no default; it breaks initialization by -Q
{ "mode", Parameter::PT_ENUM, "tap | inline | inline-test", nullptr,
else if ( v.is("include") )
p->include = v.get_string();
+ else if ( v.is("includer") )
+ p->includer = v.get_string();
+
else if ( v.is("mode") )
p->policy_mode = (PolicyMode)v.get_uint8();
policy_mode = POLICY_MODE__MAX;
var_table = nullptr;
- parse_from = get_parse_file();
var_id = 1;
ip_vartable = sfvt_alloc_table();
PolicyMode policy_mode = POLICY_MODE__MAX;
bool enable_builtin_rules;
+ std::string includer;
std::string include;
std::string rules;
- std::string parse_from;
uint32_t var_id;
void pop_include_path();
]]
-function include(file)
- local base_name = ffi.C.push_include_path(file)
- dofile(ffi.string(base_name))
- ffi.C.pop_include_path()
-end
-
function snort_traverse(tab, fqn)
local key, val
local name
local idx = 0
local what = type(val)
-
+
if ( not fqn ) then
name = key
end
end
+---------------------------------------------------------------------------
+-- path magic for includes
+---------------------------------------------------------------------------
+
+function path_push(file)
+ if ( _snort_path == nil ) then
+ _snort_path = { }
+ end
+ _snort_path[#_snort_path + 1] = file
+end
+
+function path_pop()
+ if ( _snort_path == nil ) then
+ return
+ end
+ table.remove(_snort_path, #_snort_path)
+end
+
+function path_top()
+ if ( _snort_path == nil ) then
+ return nil
+ end
+ return _snort_path[#_snort_path]
+end
+
+function include(file)
+ local cname = ffi.C.push_include_path(file)
+ local fname = ffi.string(cname);
+ path_push(fname)
+ dofile(fname)
+ local iname = path_top()
+ if ( (ips ~= nil) and (ips.includer == nil) and (iname ~= nil) ) then
+ ips.includer = iname
+ end
+ path_pop()
+ ffi.C.pop_include_path()
+end
+
if ( !path.length() )
path = get_parse_file();
size_t idx = path.rfind('/');
- if ( idx == std::string::npos )
- idx = 0;
- path.erase(idx);
+ if ( idx != std::string::npos )
+ path.erase(idx);
+ else
+ path = ".";
return valid_file(file, path);
}
{
assert(arg);
arg = ExpandVars(sc, arg);
- std::string file;
+ std::string file = get_ips_policy()->includer;
const char* code = get_config_file(arg, file);
ModuleManager::load_rules(sc);
const char* fname = p->include.c_str();
- std::string file = p->parse_from;
+ std::string file = p->includer;
if ( fname && *fname )
{