From: Russ Combs Date: Thu, 2 Oct 2014 20:08:50 +0000 (-0400) Subject: revised help options X-Git-Tag: 3.0.0-233~1397^2~26 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1b85ff10e86f7c2248be2bc9f8845f782c3c6cb7;p=thirdparty%2Fsnort3.git revised help options --- diff --git a/ChangeLog b/ChangeLog index 40b959cab..76e7e07da 100644 --- a/ChangeLog +++ b/ChangeLog @@ -21,6 +21,7 @@ -- parsing fixes -- updated config_changes.txt -- fixed doc format and added errors.txt +-- revised help options (again) to be more consistent with other (gnu style) programs 121 -- valgrind fixes diff --git a/src/main/help.cc b/src/main/help.cc index 9f3ea526a..602a0062b 100644 --- a/src/main/help.cc +++ b/src/main/help.cc @@ -1,6 +1,5 @@ /* ** Copyright (C) 2014 Cisco and/or its affiliates. All rights reserved. -** Copyright (C) 2013-2013 Sourcefire, Inc. ** ** This program is free software; you can redistribute it and/or modify ** it under the terms of the GNU General Public License Version 2 as @@ -17,6 +16,7 @@ ** along with this program; if not, write to the Free Software ** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ +// help.cc author Russ Combs #include "help.h" @@ -29,6 +29,7 @@ #include using namespace std; +#include "main.h" #include "config_file.h" #include "helpers/process.h" #include "main/snort.h" @@ -49,8 +50,8 @@ static const char* snort_help = "\n" "Snort has several options to get more help:\n" "\n" -"--help list command line options\n" -"--help! this overview of help\n" +"-? list command line options\n" +"--help this overview of help\n" "--help-builtin [] output matching builtin rules\n" "--help-buffers output available inspection buffers\n" "--help-commands [] output matching commands\n" @@ -85,6 +86,8 @@ static const char* snort_help = "++ IPS rules may also have a wild card parameter, which is indicated by a *.\n" " Only used for metadata that Snort ignores.\n" "++ The snort module has command line options starting with a -.\n" +"\n" +"Report bugs to bugs@snort.org.\n" ; //------------------------------------------------------------------------- @@ -120,10 +123,12 @@ void help_basic(SnortConfig*, const char*) exit(0); } -void help_usage(SnortConfig*, const char* val) +void help_usage(SnortConfig*, const char*) { - fprintf(stdout, "USAGE: %s [-options]\n", "snort"); - help_args(val); + fprintf(stdout, "usage:\n"); + fprintf(stdout, "%s [-options] -c conf [-T]: validate conf\n", "snort"); + fprintf(stdout, "%s [-options] -c conf -i iface: process live\n", "snort"); + fprintf(stdout, "%s [-options] -c conf -r pcap: process readback\n", "snort"); exit(1); } @@ -269,7 +274,6 @@ void help_version(SnortConfig*, const char*) void list_interfaces(SnortConfig*, const char*) { - DisplayBanner(); PrintAllInterfaces(); exit(0); } diff --git a/src/main/snort.cc b/src/main/snort.cc index b3123554b..bb6f26347 100644 --- a/src/main/snort.cc +++ b/src/main/snort.cc @@ -61,7 +61,6 @@ using namespace std; #include "rules.h" #include "treenodes.h" #include "snort_debug.h" -#include "main/snort_config.h" #include "util.h" #include "parser.h" #include "packet_io/trough.h" @@ -75,10 +74,11 @@ using namespace std; #include "packet_time.h" #include "perf_monitor/perf_base.h" #include "perf_monitor/perf.h" -//#include "sflsq.h" #include "ips_options/ips_flowbits.h" #include "event_queue.h" #include "framework/mpse.h" +#include "main/build.h" +#include "main/snort_config.h" #include "main/shell.h" #include "main/analyzer.h" #include "managers/module_manager.h" @@ -293,20 +293,22 @@ static void SnortInit(int argc, char **argv) snort_cmd_line_conf = parse_cmd_line(argc, argv); snort_conf = snort_cmd_line_conf; - /* Tell 'em who wrote it, and what "it" is */ - if (!ScLogQuiet()) - PrintVersion(); - - InitProtoNames(); - SFAT_Init(); - + LogMessage("--------------------------------------------------\n"); + LogMessage("o\")~ Snort++ %s-%s\n", VERSION, BUILD); LogMessage("--------------------------------------------------\n"); ModuleManager::init(); ScriptManager::load_scripts(snort_cmd_line_conf->script_path); PluginManager::load_plugins(snort_cmd_line_conf->plugin_path); - ModuleManager::dump_modules(); - PluginManager::dump_plugins(); + + if ( snort_conf->run_flags & RUN_FLAG__SHOW_PLUGINS ) + { + ModuleManager::dump_modules(); + PluginManager::dump_plugins(); + } + + InitProtoNames(); + SFAT_Init(); FileAPIInit(); register_profiles(); diff --git a/src/main/snort.h b/src/main/snort.h index b0d3af184..901eb85a1 100644 --- a/src/main/snort.h +++ b/src/main/snort.h @@ -116,7 +116,8 @@ enum RunFlag RUN_FLAG__NO_PCRE = 0x01000000, /* If stream5 is configured, the STATEFUL flag is set. This is * somewhat misnamed and is used to assure a session is established */ - RUN_FLAG__ASSURE_EST = 0x02000000 /* config stateful */ + RUN_FLAG__ASSURE_EST = 0x02000000, + RUN_FLAG__SHOW_PLUGINS = 0x04000000 // --show-plugins ,RUN_FLAG__TREAT_DROP_AS_IGNORE= 0x10000000, /* --treat-drop-as-ignore */ RUN_FLAG__PCAP_RELOAD = 0x20000000, /* --pcap-reload */ diff --git a/src/main/snort_module.cc b/src/main/snort_module.cc index f7953b10d..178cb70d0 100644 --- a/src/main/snort_module.cc +++ b/src/main/snort_module.cc @@ -347,6 +347,9 @@ static const Parameter s_params[] = { "--shell", Parameter::PT_IMPLIED, nullptr, nullptr, "enable the interactive command line", }, + { "--show-plugins", Parameter::PT_IMPLIED, nullptr, nullptr, + "list module and plugin versions", }, + { "--skip", Parameter::PT_INT, "0:", nullptr, " skip 1st n packets", }, @@ -396,7 +399,7 @@ public: bool SnortModule::set(const char*, Value& v, SnortConfig* sc) { if ( v.is("-?") ) - help_usage(sc, v.get_string()); + help_options(sc, v.get_string()); else if ( v.is("-A") ) config_alert_mode(sc, v.get_string()); @@ -556,9 +559,6 @@ bool SnortModule::set(const char*, Value& v, SnortConfig* sc) sc->run_flags |= RUN_FLAG__INLINE_TEST; else if ( v.is("--help") ) - help_usage(sc, v.get_string()); - - else if ( v.is("--help!") ) help_basic(sc, v.get_string()); else if ( v.is("--help-builtin") ) @@ -664,6 +664,9 @@ bool SnortModule::set(const char*, Value& v, SnortConfig* sc) else if ( v.is("--shell") ) sc->run_flags |= RUN_FLAG__SHELL; + else if ( v.is("--show-plugins") ) + sc->run_flags |= RUN_FLAG__SHOW_PLUGINS; + else if ( v.is("--skip") ) sc->pkt_skip = v.get_long(); diff --git a/src/managers/module_manager.cc b/src/managers/module_manager.cc index 9a668ffce..addff32bd 100644 --- a/src/managers/module_manager.cc +++ b/src/managers/module_manager.cc @@ -560,6 +560,7 @@ void ModuleManager::show_module(const char* name) return; } s_modules.sort(comp_gids); + unsigned c = 0; for ( auto p : s_modules ) { @@ -602,12 +603,16 @@ void ModuleManager::show_module(const char* name) cout << endl << "Peg counts: " << endl << endl; show_pegs(name); } + c++; } + if ( !c ) + cout << "no match" << endl; } void ModuleManager::show_configs(const char* pfx, bool exact) { s_modules.sort(comp_mods); + unsigned c = 0; for ( auto p : s_modules ) { @@ -637,13 +642,18 @@ void ModuleManager::show_configs(const char* pfx, bool exact) } if ( !pfx ) cout << endl; + + c++; } + if ( !c ) + cout << "no match" << endl; } void ModuleManager::show_commands(const char* pfx) { s_modules.sort(comp_mods); unsigned len = pfx ? strlen(pfx) : 0; + unsigned n = 0; for ( auto p : s_modules ) { @@ -668,13 +678,17 @@ void ModuleManager::show_commands(const char* pfx) cout << endl; c++; } + n++; } + if ( !n ) + cout << "no match" << endl; } void ModuleManager::show_gids(const char* pfx) { s_modules.sort(comp_gids); unsigned len = pfx ? strlen(pfx) : 0; + unsigned c = 0; for ( auto p : s_modules ) { @@ -695,13 +709,17 @@ void ModuleManager::show_gids(const char* pfx) cout << ": " << Markup::sanitize(m->get_name()); cout << endl; } + c++; } + if ( !c ) + cout << "no match" << endl; } void ModuleManager::show_pegs(const char* pfx) { s_modules.sort(comp_gids); unsigned len = pfx ? strlen(pfx) : 0; + unsigned c = 0; for ( auto p : s_modules ) { @@ -725,13 +743,17 @@ void ModuleManager::show_pegs(const char* pfx) cout << endl; ++pegs; } + c++; } + if ( !c ) + cout << "no match" << endl; } void ModuleManager::show_rules(const char* pfx) { s_modules.sort(comp_gids); unsigned len = pfx ? strlen(pfx) : 0; + unsigned c = 0; for ( auto p : s_modules ) { @@ -756,7 +778,10 @@ void ModuleManager::show_rules(const char* pfx) cout << endl; r++; } + c++; } + if ( !c ) + cout << "no match" << endl; } void ModuleManager::load_commands(SnortConfig* sc) @@ -822,6 +847,7 @@ void ModuleManager::dump_rules(const char* pfx) { s_modules.sort(comp_gids); unsigned len = pfx ? strlen(pfx) : 0; + unsigned c = 0; for ( auto p : s_modules ) { @@ -849,7 +875,10 @@ void ModuleManager::dump_rules(const char* pfx) r++; } + c++; } + if ( !c ) + cout << "no match" << endl; } void ModuleManager::dump_stats (SnortConfig*) diff --git a/src/parser/cmd_line.cc b/src/parser/cmd_line.cc index 6b851548e..f22cb20c7 100644 --- a/src/parser/cmd_line.cc +++ b/src/parser/cmd_line.cc @@ -27,6 +27,7 @@ #include using namespace std; +#include "main/help.h" #include "main/snort_module.h" #include "framework/module.h" #include "framework/parameter.h" @@ -148,18 +149,28 @@ SnortConfig* parse_cmd_line(int argc, char* argv[]) ArgList al(argc, argv); const char* key, *val; + unsigned c = 0; // get special options first while ( al.get_arg(key, val) ) + { ::set(key, val, sc, false); + c++; + } // now get the rest al.reset(); while ( al.get_arg(key, val) ) + { ::set(key, val, sc, true); + c++; + } - check_flags(sc); + if ( !c ) + help_usage(sc, ""); + else + check_flags(sc); if ( int k = get_parse_errors() ) FatalError("see prior %d errors\n", k); diff --git a/src/stream/udp/udp_session.cc b/src/stream/udp/udp_session.cc index 69dca252b..e6a1249d8 100644 --- a/src/stream/udp/udp_session.cc +++ b/src/stream/udp/udp_session.cc @@ -153,8 +153,6 @@ bool UdpSession::setup(Packet* p) UpdateFlowIPState(&sfFlow, &flow->client_ip, &flow->server_ip, SFS_STATE_UDP_CREATED); - flow->s5_state.direction = FROM_SENDER; - if ( flow_con->expected_flow(flow, p) ) return false;