]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
Merge pull request #62 in SNORT/snort3 from crc/target to master
authorRuss Combs (rucombs) <rucombs@cisco.com>
Thu, 8 Oct 2015 17:49:03 +0000 (13:49 -0400)
committerRuss Combs (rucombs) <rucombs@cisco.com>
Thu, 8 Oct 2015 17:49:03 +0000 (13:49 -0400)
Squashed commit of the following:

commit 87a44d762639d80b7076a6cbaf97beb0db2f2a15
Author: Russ Combs <rucombs@cisco.com>
Date:   Tue Sep 29 14:03:14 2015 -0400

    define commands with parameters
    add file name to reload commands

src/framework/module.cc
src/framework/module.h
src/main.cc
src/main/snort.cc
src/main/snort.h
src/main/snort_module.cc
src/managers/module_manager.cc
src/parser/parser.cc
src/parser/parser.h

index b9e9a3b5e2512d00a81e09149ac76304ab7617f1..871cd98d1e2362b70ea937747f6e55319d7135cc 100644 (file)
@@ -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;
 }
 
index 80c167a437df076b84edfb4061819afa4c9ab5cd..d66407187717cbc78c4dec3ff240ae82516dee90 100644 (file)
@@ -38,6 +38,7 @@
 // lists in snort_defaults.lua or some such.  Each list item, however, will
 // have any defaults applied.
 
+#include <string>
 #include <vector>
 #include <luajit-2.0/lua.hpp>
 
 #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<PegCount> counts;
     int num_counts;
 };
index e2b61a8213946f8f073972df93f0bfb31db1a0de..d199dac6d2933bec9abc3b1e6016034646bd5d20 100644 (file)
@@ -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";
index 23320d53ffcb488b93f359fe69d53f532cea1c42..270efe6a0f2962c0cfdaa98ab7088d8aca74ae00 100644 (file)
@@ -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() )
index 49699d80fd41444fac8915b4dd1a02c4338eb166..e54e413096f310c2f77235eca80bf2ba693b2346 100644 (file)
@@ -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();
 
index eca0ef3617dd97cb41e36728ee4f4d3c8d18d1e1..5e414a4e3724ef972b8f93ffa1160bc079a87815 100644 (file)
@@ -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
 
index 8b3633cde51906d6bf04dd6398d44ead38110c17..c8fe31cc1430807fbcd1adb7b45da951e0eedbfe 100644 (file)
@@ -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++;
         }
index 11506ae44f923d87815d0eceda4d54fa46db3a59..d64929b62652fab7618eef9db075dde34637be4d 100644 (file)
@@ -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 = "";
index bc4e2ca305c555a03216df86b777a97e52f34237..94fff5a8a897cee058f6fc513e066daae724b469 100644 (file)
@@ -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*);