LogMessage(fmt, ind, caption, delim, prefix, res.c_str());
}
+
+void ConfigLogger::log_list(const char* list)
+{
+ if ( !list or !list[0] )
+ return;
+
+ std::stringstream ss(list);
+ std::string res;
+ std::string val;
+
+ while (ss >> val)
+ {
+ if ( res.length() + val.length() > max_line_len )
+ {
+ LogMessage("\t\t%s\n", res.c_str());
+ res.clear();
+ }
+
+ if (!res.empty())
+ res += ' ';
+
+ res += val;
+ }
+
+ LogMessage("\t\t%s\n", res.c_str());
+}
} //namespace snort
static void log_value(const char* caption, double n, bool subopt = false);
static void log_value(const char* caption, const char* str, bool subopt = false);
static void log_list(const char* caption, const char* list, const char* prefix = " ", bool subopt = false);
+ static void log_list(const char* list);
private:
static constexpr int indention = 25;
static constexpr int max_line_len = 75;
return false;
const Whitelist& whitelist = sh->get_whitelist();
+ const Whitelist& internal_whitelist = sh->get_internal_whitelist();
const Whitelist& whitelist_prefixes = sh->get_whitelist_prefixes();
for ( const auto& prefix : whitelist_prefixes )
if ( whitelist.find(key) != whitelist.end() )
return true;
+ if ( internal_whitelist.find(key) != internal_whitelist.end() )
+ return true;
+
return false;
}
loaded = false;
load_string(lua, ModuleManager::get_lua_bootstrap());
+ bootstrapped = true;
if ( load_defaults )
load_string(lua, ModuleManager::get_lua_coreinit());
}
}
+//-------------------------------------------------------------------------
+// Helper methods
+//-------------------------------------------------------------------------
+
+static void print_list(const Shell::Whitelist& wlist, const std::string& msg)
+{
+ LogMessage("\t%s\n", msg.c_str());
+ std::string list;
+
+ for ( const auto& wl : wlist )
+ {
+ list += wl;
+ list += ", ";
+ }
+
+ if ( !list.empty() )
+ list.erase(list.end() - 2, list.end());
+
+ ConfigLogger::log_list(list.c_str());
+}
+
//-------------------------------------------------------------------------
// private methods
//-------------------------------------------------------------------------
if ( !whitelist.empty() )
{
output = "Lua Whitelist Keywords for " + file + ":";
- LogMessage("\t%s\n",output.c_str());
- for ( const auto& wl : whitelist )
- LogMessage("\t\t%s\n", wl.c_str());
+ print_list(whitelist, output);
}
if ( !whitelist_prefixes.empty() )
{
output = "Lua Whitelist Prefixes for " + file + ":";
- LogMessage("\t%s\n",output.c_str());
- for ( const auto& wlp : whitelist_prefixes )
- LogMessage("\t\t%s\n", wlp.c_str());
+ print_list(whitelist_prefixes, output);
}
}
Whitelist* wlist = nullptr;
if ( is_prefix )
wlist = &whitelist_prefixes;
+ else if ( !bootstrapped )
+ wlist = &internal_whitelist;
else
wlist = &whitelist;
void clear_whitelist()
{
whitelist.clear();
+ internal_whitelist.clear();
whitelist_prefixes.clear();
}
const Whitelist& get_whitelist() const
{ return whitelist; }
+ const Whitelist& get_internal_whitelist() const
+ { return internal_whitelist; }
+
const Whitelist& get_whitelist_prefixes() const
{ return whitelist_prefixes; }
private:
bool loaded;
+ bool bootstrapped = false;
lua_State* lua;
std::string file;
std::string parse_from;
std::string overrides;
Whitelist whitelist;
+ Whitelist internal_whitelist;
Whitelist whitelist_prefixes;
};