From: Russ Combs Date: Wed, 16 Jul 2014 01:45:13 +0000 (-0400) Subject: added per module documentation X-Git-Tag: 3.0.0-233~1444^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=525e6ed536f80fc69b45aa166771e90ecbf3b659;p=thirdparty%2Fsnort3.git added per module documentation --- diff --git a/doc/Makefile.am b/doc/Makefile.am index ecda761c5..cba73eceb 100644 --- a/doc/Makefile.am +++ b/doc/Makefile.am @@ -7,6 +7,7 @@ builtin.txt \ commands.txt \ config.txt \ gids.txt \ +modules.txt \ options.txt \ version.txt @@ -53,6 +54,11 @@ config.txt: $(snort) gids.txt: $(snort) $(snort) --markup --help-gids | sort -n -k 1.4 > $@ +modules.txt: $(snort) + for m in `$(snort) --list-modules` ; do \ + $(snort) --markup --help-module $$m ; \ + done > $@ + options.txt: $(snort) $(snort) --markup --help-options | sort > $@ diff --git a/doc/snort_manual.txt b/doc/snort_manual.txt index 014e3c0fa..d0ba037b0 100644 --- a/doc/snort_manual.txt +++ b/doc/snort_manual.txt @@ -18,6 +18,10 @@ include::tips.txt[] include::differences.txt[] +== Modules + +include::modules.txt[] + == Command Line Options include::options.txt[] diff --git a/src/log/messages.cc b/src/log/messages.cc index aa61514d0..2d60d5716 100644 --- a/src/log/messages.cc +++ b/src/log/messages.cc @@ -54,7 +54,7 @@ static int already_fatal = 0; /* * Function: LogMessage(const char *, ...) * - * Purpose: Print a message to stderr or with logfacility. + * Purpose: Print a message to stdout or with logfacility. * * Arguments: format => the formatted error string to print out * ... => format commands/fillers @@ -69,7 +69,7 @@ void LogMessage(const char *format,...) if (snort_conf == NULL) { va_start(ap, format); - vfprintf(stderr, format, ap); + vfprintf(stdout, format, ap); va_end(ap); return; } @@ -86,7 +86,7 @@ void LogMessage(const char *format,...) } else { - vfprintf(stderr, format, ap); + vfprintf(stdout, format, ap); } va_end(ap); diff --git a/src/managers/module_manager.cc b/src/managers/module_manager.cc index 32181f764..1ee4f6351 100644 --- a/src/managers/module_manager.cc +++ b/src/managers/module_manager.cc @@ -65,6 +65,9 @@ static bool s_markup = false; // markup foo (for asciidoc) //------------------------------------------------------------------------- +static const char* head() +{ return s_markup ? "=== " : ""; } + static const char* item() { return s_markup ? "* " : ""; } @@ -483,6 +486,14 @@ unsigned ModuleManager::get_errors() return err; } +void ModuleManager::list_modules() +{ + s_modules.sort(comp_mods); + + for ( auto* p : s_modules ) + LogMessage("%s\n", p->mod->get_name()); +} + void ModuleManager::dump_modules() { s_modules.sort(comp_mods); @@ -493,6 +504,28 @@ void ModuleManager::dump_modules() d.dump(p->mod->get_name()); } +static const char* mod_types[PT_MAX] = +{ + "data", + "codec", + "logger", + "ips option", + "so rule", + "inspector", + "search engine" +}; + +static const char* mod_type(const BaseApi* api) +{ + if ( !api ) + return "basic"; + + if ( api->type > PT_MAX ) + return "error"; + + return mod_types[api->type]; +} + void ModuleManager::show_module(bool markup, const char* name) { s_modules.sort(comp_gids); @@ -506,32 +539,33 @@ void ModuleManager::show_module(bool markup, const char* name) if ( strcmp(m->get_name(), name) ) continue; - LogMessage("\nModule: %s\n", name); + cout << endl << head() << name << endl << endl; + cout << "Type: " << mod_type(p->api) << endl << endl; if ( const Parameter* p = m->get_parameters() ) { if ( p->type < Parameter::PT_MAX ) { - LogMessage("\nConfiguration:\n"); + cout << endl << "Configuration: " << endl << endl; show_configs(markup, name); } } if ( m->get_commands() ) { - LogMessage("\nCommands:\n"); + cout << endl << "Commands: " << endl << endl; show_commands(markup, name); } if ( m->get_rules() ) { - LogMessage("\nRules:\n"); + cout << endl << "Rules: " << endl << endl; show_rules(markup, name); } if ( m->get_pegs() ) { - LogMessage("\nPeg counts:\n"); + cout << endl << "Peg counts: " << endl << endl; show_pegs(markup, name); } } diff --git a/src/managers/module_manager.h b/src/managers/module_manager.h index 7dce1a4ff..575d7a12e 100644 --- a/src/managers/module_manager.h +++ b/src/managers/module_manager.h @@ -35,12 +35,15 @@ public: static void add_module(class Module*, const struct BaseApi* = nullptr); static Module* get_module(const char*); + static void list_modules(); static void dump_modules(); + static void show_module(bool markup, const char*); static void show_configs(bool markup, const char* = nullptr); static void show_commands(bool markup, const char* = nullptr); static void show_gids(bool markup, const char* = nullptr); static void show_pegs(bool markup, const char* = nullptr); + static void show_rules(bool markup, const char* = nullptr); static void load_rules(SnortConfig*); diff --git a/src/parser/cmd_line.cc b/src/parser/cmd_line.cc index 460c17ff1..d97648723 100644 --- a/src/parser/cmd_line.cc +++ b/src/parser/cmd_line.cc @@ -257,7 +257,7 @@ static void config_help_signals(SnortConfig*, const char*) exit(0); } -enum HelpType { HT_CFG, HT_CMD, HT_GID, HT_IPS, HT_MOD, HT_BUF }; +enum HelpType { HT_CFG, HT_CMD, HT_GID, HT_IPS, HT_MOD, HT_BUF, HT_LST }; static void show_help(SnortConfig* sc, const char* val, HelpType ht) { @@ -285,6 +285,9 @@ static void show_help(SnortConfig* sc, const char* val, HelpType ht) case HT_BUF: InspectorManager::dump_buffers(); break; + case HT_LST: + ModuleManager::list_modules(); + break; } ModuleManager::term(); PluginManager::release_plugins(); @@ -327,6 +330,11 @@ static void config_help_module(SnortConfig* sc, const char* val) show_help(sc, val, HT_MOD); } +static void config_list_modules(SnortConfig* sc, const char* val) +{ + show_help(sc, val, HT_LST); +} + static void config_lua(SnortConfig*, const char* val) { Shell::set_overrides(val); @@ -803,6 +811,9 @@ static ConfigFunc basic_opts[] = { "help-signals", config_help_signals, "dump available control signals" }, + { "list-modules", config_list_modules, + "list all known modules" }, + { "lua", config_lua, " extend/override conf with chunk; may be repeated" },