bool set_number(const char*, double);
bool set_string(const char*, const char*);
bool set_alias(const char*, const char*);
+void clear_alias();
]]
function snort_traverse(tab, fqn)
for i,v in ipairs(env.binder) do
if ( v.use and type(v.use) == "table" ) then
if ( v.use.name and v.use.type ) then
- ffi.C.set_alias(v.use.name, v.use.type)
- local tab = env[v.use.name]
+ if ( ffi.C.set_alias(v.use.name, v.use.type) ) then
+ local tab = env[v.use.name]
- if ( tab ) then
- snort_whitelist_append(v.use.name)
- snort_set(nil, v.use.name, env[v.use.name])
+ if ( tab ) then
+ snort_whitelist_append(v.use.name)
+ snort_set(nil, v.use.name, env[v.use.name])
+ end
+
+ ffi.C.clear_alias()
end
end
end
mutex ModuleManager::stats_mutex;
static string s_current;
-static string s_name;
-static string s_type;
+static string s_aliased_name;
+static string s_aliased_type;
// for callbacks from Lua
static SnortConfig* s_config = nullptr;
bool set_bool(const char* fqn, bool val);
bool set_number(const char* fqn, double val);
bool set_string(const char* fqn, const char* val);
+
bool set_alias(const char* from, const char* to);
+ void clear_alias();
const char* push_include_path(const char* file);
void pop_include_path();
static void set_type(string& fqn)
{
- if ( s_type.empty() )
+ if ( s_aliased_type.empty() )
return;
size_t pos = fqn.find_first_of('.');
if ( pos == fqn.npos )
pos = fqn.size();
- fqn.replace(0, pos, s_type);
+ fqn.replace(0, pos, s_aliased_type);
}
static void set_top(string& fqn)
return true;
}
+
//-------------------------------------------------------------------------
// ffi methods
//-------------------------------------------------------------------------
+SO_PUBLIC void clear_alias()
+{
+ s_aliased_name.clear();
+ s_aliased_type.clear();
+}
+
SO_PUBLIC bool set_alias(const char* from, const char* to)
{
- s_name = from;
- s_type = to;
+ const Module* m = ModuleManager::get_module(to);
+
+ if ( !m or !m->is_bindable() )
+ return false;
+
+ if ( (m->get_usage() == Module::GLOBAL) and from )
+ {
+ ParseError("global module type '%s' can't be aliased", to);
+ return false;
+ }
+
+ if ( ModuleManager::get_module(from) )
+ {
+ ParseError("alias name can't be an existing module '%s'", from);
+ return false;
+ }
+
+ s_aliased_name = from;
+ s_aliased_type = to;
+
return true;
}
// FIXIT-M only basic modules, inspectors and ips actions can be reloaded at present
if ( ( Snort::is_reloading() ) and h->api
and h->api->type != PT_INSPECTOR and h->api->type != PT_IPS_ACTION )
+ {
return false;
+ }
Module* m = h->mod;
const Parameter* p = nullptr;
}
string unique_key = key;
- if ( !s_name.empty() )
- unique_key = s_name;
+ if ( !s_aliased_name.empty() )
+ unique_key = s_aliased_name;
if ( s_current != unique_key )
{
else if (h->api && top)
{
- if ( !s_name.empty() )
- PluginManager::instantiate(h->api, h->mod, s_config, s_name.c_str());
+ if ( !s_aliased_name.empty() )
+ PluginManager::instantiate(h->api, h->mod, s_config, s_aliased_name.c_str());
else
PluginManager::instantiate(h->api, h->mod, s_config);
}
}
- if ( top )
- {
- s_name.clear();
- s_type.clear();
- }
-
Shell::config_close_table();
}