]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
revised help options
authorRuss Combs <rucombs@cisco.com>
Thu, 2 Oct 2014 20:08:50 +0000 (16:08 -0400)
committerRuss Combs <rucombs@cisco.com>
Thu, 2 Oct 2014 20:08:50 +0000 (16:08 -0400)
ChangeLog
src/main/help.cc
src/main/snort.cc
src/main/snort.h
src/main/snort_module.cc
src/managers/module_manager.cc
src/parser/cmd_line.cc
src/stream/udp/udp_session.cc

index 40b959cab06c3037953fd383b6a5bc123419f12b..76e7e07da9c72106432e3f1e13dfa5e9e74eb434 100644 (file)
--- 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
index 9f3ea526afca8f2b7669833aab06256e13104b37..602a0062b4ea7e2cd9be59ffba637486a8b23aef 100644 (file)
@@ -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 <rucombs@cisco.com>
 
 #include "help.h"
 
@@ -29,6 +29,7 @@
 #include <string>
 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 [<module prefix>] output matching builtin rules\n"
 "--help-buffers output available inspection buffers\n"
 "--help-commands [<module prefix>] 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);
 }
index b3123554b3e007d8bc10a05720c16050e6135371..bb6f2634748af45883bc421c1da14468b0befe34 100644 (file)
@@ -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();
index b0d3af184797b654775e7b5b5c1c6b964df4425f..901eb85a1a98b9b997edc8eda5277452721967c5 100644 (file)
@@ -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 */
index f7953b10dc6f112fbe91121b2bc124294e43c343..178cb70d03b3ee1b30b18728c6b214e4bd663f29 100644 (file)
@@ -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,
       "<n> 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();
 
index 9a668ffce0ca31fd170f060b204ff05e2faf91fd..addff32bd04a9df45160184f7beb53d2e2fe090a 100644 (file)
@@ -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*)
index 6b851548e8e93cb82506a266604a5794712c1429..f22cb20c7a9dfa266b6d8bc61b36b09217a949fa 100644 (file)
@@ -27,6 +27,7 @@
 #include <string>
 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);
index 69dca252b8f1802488dd7efa0d5821e1c4c64857..e6a1249d8973e49961ff1d65f61798c46dab0ac5 100644 (file)
@@ -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;