From: Russ Combs (rucombs) Date: Thu, 8 Oct 2015 17:49:03 +0000 (-0400) Subject: Merge pull request #62 in SNORT/snort3 from crc/target to master X-Git-Tag: 3.0.0-233~799 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=445e62c43f442e2e183b5d648fae86174d6da44a;p=thirdparty%2Fsnort3.git Merge pull request #62 in SNORT/snort3 from crc/target to master Squashed commit of the following: commit 87a44d762639d80b7076a6cbaf97beb0db2f2a15 Author: Russ Combs Date: Tue Sep 29 14:03:14 2015 -0400 define commands with parameters add file name to reload commands --- diff --git a/src/framework/module.cc b/src/framework/module.cc index b9e9a3b5e..871cd98d1 100644 --- a/src/framework/module.cc +++ b/src/framework/module.cc @@ -26,14 +26,28 @@ static const Parameter null_params[] = { nullptr, Parameter::PT_MAX, nullptr, nullptr, nullptr } }; +std::string Command::get_arg_list() const +{ + std::string args = "("; + const Parameter* p = params; + + while ( p and p->name ) + { + if ( p != params ) + args += ", "; + args += p->name; + ++p; + } + args += ")"; + return args; +} + void Module::init(const char* s, const char* h) { name = s; help = h; params = null_params; list = false; - cmds = nullptr; - rules = nullptr; num_counts = -1; } diff --git a/src/framework/module.h b/src/framework/module.h index 80c167a43..d66407187 100644 --- a/src/framework/module.h +++ b/src/framework/module.h @@ -38,6 +38,7 @@ // lists in snort_defaults.lua or some such. Each list item, however, will // have any defaults applied. +#include #include #include @@ -46,13 +47,14 @@ #include "framework/parameter.h" #include "framework/counts.h" -struct SnortConfig; - struct Command { const char* name; lua_CFunction func; + const Parameter* params; const char* help; + + std::string get_arg_list() const; }; struct RuleMap @@ -62,6 +64,7 @@ struct RuleMap }; struct ProfileStats; +struct SnortConfig; class SO_PUBLIC Module { @@ -152,9 +155,6 @@ private: const Parameter* params; bool list; - const Command* cmds; - const RuleMap* rules; - std::vector counts; int num_counts; }; diff --git a/src/main.cc b/src/main.cc index e2b61a821..d199dac6d 100644 --- a/src/main.cc +++ b/src/main.cc @@ -297,16 +297,19 @@ int main_rotate_stats(lua_State*) return 0; } -int main_reload_config(lua_State*) +int main_reload_config(lua_State* L) { if ( swapper ) { request.respond("== reload pending; retry\n"); return 0; } + Lua::ManageStack(L, 1); + const char* fname = luaL_checkstring(L, 1); + request.respond(".. reloading configuration\n"); SnortConfig* old = snort_conf; - SnortConfig* sc = Snort::get_reload_config(); + SnortConfig* sc = Snort::get_reload_config(fname); if ( !sc ) { @@ -325,14 +328,27 @@ int main_reload_config(lua_State*) return 0; } -int main_reload_hosts(lua_State*) +int main_reload_hosts(lua_State* L) { if ( swapper ) { request.respond("== reload pending; retry\n"); return 0; } - request.respond(".. reloading hosts table\n"); + Lua::ManageStack(L, 1); + const char* fname = luaL_checkstring(L, 1); + + if ( fname and *fname ) + request.respond(".. reloading hosts table\n"); + else + { + request.respond("== filename required\n"); + return 0; + } + + Shell sh = Shell(fname); + sh.configure(snort_conf); + tTargetBasedConfig* old = SFAT_GetConfig(); tTargetBasedConfig* tc = SFAT_Swap(); @@ -410,6 +426,7 @@ int main_help(lua_State*) while ( cmd->name ) { string info = cmd->name; + info += cmd->get_arg_list(); info += ": "; info += cmd->help; info += "\n"; diff --git a/src/main/snort.cc b/src/main/snort.cc index 23320d53f..270efe6a0 100644 --- a/src/main/snort.cc +++ b/src/main/snort.cc @@ -506,14 +506,14 @@ void Snort::cleanup() // FIXIT-M refactor this so startup and reload call the same core function to // instantiate things that can be reloaded -SnortConfig* Snort::get_reload_config() +SnortConfig* Snort::get_reload_config(const char* fname) { reloading = true; ModuleManager::reset_errors(); trim_heap(); parser_init(); - SnortConfig* sc = ParseSnortConf(snort_cmd_line_conf); + SnortConfig* sc = ParseSnortConf(snort_cmd_line_conf, fname); sc->merge(snort_cmd_line_conf); if ( ModuleManager::get_errors() || !sc->verify() ) diff --git a/src/main/snort.h b/src/main/snort.h index 49699d80f..e54e41309 100644 --- a/src/main/snort.h +++ b/src/main/snort.h @@ -40,7 +40,7 @@ typedef void (* MainHook_f)(Packet*); class Snort { public: - static SnortConfig* get_reload_config(); + static SnortConfig* get_reload_config(const char* fname); static void setup(int argc, char* argv[]); static void cleanup(); diff --git a/src/main/snort_module.cc b/src/main/snort_module.cc index eca0ef361..5e414a4e3 100644 --- a/src/main/snort_module.cc +++ b/src/main/snort_module.cc @@ -55,27 +55,33 @@ using namespace std; // commands //------------------------------------------------------------------------- +static const Parameter s_reload[] = +{ + { "filename", Parameter::PT_STRING, nullptr, nullptr, + "name of file to load" }, + + { nullptr, Parameter::PT_MAX, nullptr, nullptr, nullptr } +}; + #ifdef BUILD_SHELL static const Command snort_cmds[] = { - { "show_plugins", main_dump_plugins, "show available plugins" }, - { "dump_stats", main_dump_stats, "show summary statistics" }, - { "rotate_stats", main_rotate_stats, "roll perfmonitor log files" }, - { "reload_config", main_reload_config, "load new configuration" }, - - // FIXIT-M need to load hosts from dedicated file - //{ "reload_hosts", main_reload_hosts, "load a new hosts table" }, + { "show_plugins", main_dump_plugins, nullptr, "show available plugins" }, + { "dump_stats", main_dump_stats, nullptr, "show summary statistics" }, + { "rotate_stats", main_rotate_stats, nullptr, "roll perfmonitor log files" }, + { "reload_config", main_reload_config, s_reload, "load new configuration" }, + { "reload_hosts", main_reload_hosts, s_reload, "load a new hosts table" }, // FIXIT-M rewrite trough to permit updates on the fly - //{ "process", main_process, "process given pcap" }, + //{ "process", main_process, nullptr, "process given pcap" }, - { "pause", main_pause, "suspend packet processing" }, - { "resume", main_resume, "continue packet processing" }, - { "detach", main_detach, "exit shell w/o shutdown" }, - { "quit", main_quit, "shutdown and dump-stats" }, - { "help", main_help, "this output" }, + { "pause", main_pause, nullptr, "suspend packet processing" }, + { "resume", main_resume, nullptr, "continue packet processing" }, + { "detach", main_detach, nullptr, "exit shell w/o shutdown" }, + { "quit", main_quit, nullptr, "shutdown and dump-stats" }, + { "help", main_help, nullptr, "this output" }, - { nullptr, nullptr, nullptr } + { nullptr, nullptr, nullptr, nullptr } }; #endif diff --git a/src/managers/module_manager.cc b/src/managers/module_manager.cc index 8b3633cde..c8fe31cc1 100644 --- a/src/managers/module_manager.cc +++ b/src/managers/module_manager.cc @@ -1020,7 +1020,8 @@ void ModuleManager::show_commands(const char* pfx, bool exact) cout << Markup::escape(p->mod->get_name()); cout << "." << Markup::escape(c->name); cout << Markup::emphasis_off(); - cout << "(): " << Markup::escape(c->help); + cout << c->get_arg_list(); + cout << ": " << Markup::escape(c->help); cout << endl; c++; } diff --git a/src/parser/parser.cc b/src/parser/parser.cc index 11506ae44..d64929b62 100644 --- a/src/parser/parser.cc +++ b/src/parser/parser.cc @@ -513,7 +513,7 @@ static void parse_file(SnortConfig* sc, Shell* sh) * configuration file to parse the rules. * ***************************************************************************/ -SnortConfig* ParseSnortConf(const SnortConfig* boot_conf) +SnortConfig* ParseSnortConf(const SnortConfig* boot_conf, const char* fname) { SnortConfig* sc = new SnortConfig; @@ -521,7 +521,8 @@ SnortConfig* ParseSnortConf(const SnortConfig* boot_conf) sc->warning_flags = boot_conf->warning_flags; VarNode* tmp = boot_conf->var_list; - const char* fname = get_snort_conf(); + if ( !fname ) + fname = get_snort_conf(); if ( !fname ) fname = ""; diff --git a/src/parser/parser.h b/src/parser/parser.h index bc4e2ca30..94fff5a8a 100644 --- a/src/parser/parser.h +++ b/src/parser/parser.h @@ -44,8 +44,7 @@ void push_parse_location(const char* name, unsigned line = 0); void pop_parse_location(); void inc_parse_position(); -/* rule setup funcs */ -SnortConfig* ParseSnortConf(const SnortConfig*); +SnortConfig* ParseSnortConf(const SnortConfig*, const char* fname = nullptr); void ParseRules(SnortConfig*); void OrderRuleLists(SnortConfig*, const char*);