]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
fixup cmd line processing
authorRuss Combs <rucombs@cisco.com>
Thu, 21 Aug 2014 11:25:26 +0000 (07:25 -0400)
committerRuss Combs <rucombs@cisco.com>
Thu, 21 Aug 2014 11:25:26 +0000 (07:25 -0400)
src/framework/parameter.cc
src/main.cc
src/main/help.cc
src/main/snort.cc
src/main/snort_module.cc
src/parser/cmd_line.cc

index 85e5959cd93046af911ab3a13afd17a1765d0af7..b0853a33a76c59a74769ffb4d7e17c8b9abf3cfc 100644 (file)
@@ -101,6 +101,9 @@ static bool valid_real(Value& v, const char* r)
 
 static bool valid_string(Value& v, const char* r)
 {
+    if ( r && !strcmp(r, "(optional)") )
+        return true;
+
     unsigned len = strlen(v.get_string());
 
     if ( !r )
index 7ab4df30f906cc3899ef04c5e9deb0a2fd443389..d25e812cfd835edce59bd5b3740caf40b0141b65 100644 (file)
@@ -619,11 +619,10 @@ static bool set_mode()
     if ( unit_test_enabled() )
         exit(unit_test());
 #endif
-    unsigned n = get_parse_errors();
 
-    if ( n )
+    if ( int k = get_parse_errors() )
     {
-        ParseAbort("%d config errors found", n);
+        ParseAbort("see prior %d errors", k);
         return false;
     }
     if ( ScTestMode() ||
index a192cade76da9388c38f3e68e11fb09967133713..cacb0a302237adc38867ef800dc3c0d9dde157e9 100644 (file)
 using namespace std;
 
 #include "config_file.h"
-#include "parser.h"
-#include "vars.h"
-#include "detection/detect.h"
 #include "helpers/process.h"
-#include "main/analyzer.h"
-#include "main/shell.h"
+#include "main/snort.h"
 #include "main/snort_module.h"
 #include "managers/event_manager.h"
 #include "managers/so_manager.h"
 #include "managers/inspector_manager.h"
 #include "managers/module_manager.h"
 #include "managers/plugin_manager.h"
-#include "packet_io/trough.h"
 #include "packet_io/sfdaq.h"
 #include "packet_io/intf.h"
-#include "parser/parser.h"
 #include "utils/util.h"
 #include "helpers/markup.h"
 #include "framework/module.h"
index c45c8cfd2fd6379ee90f84f38acf858efa02f10d..2af89e39d0fb2c72bcb4293a3299bc1a8d62d986 100644 (file)
@@ -488,8 +488,8 @@ void snort_setup(int argc, char* argv[])
     InitGroups(ScUid(), ScGid());
     SnortUnprivilegedInit();
 
-    if ( get_parse_errors() )
-        FatalError("see prior %d errors\n", get_parse_errors());
+    if ( int k = get_parse_errors() )
+        FatalError("see prior %d errors\n", k);
 
     set_quick_exit(false);
 }
index 03c20d0648fcbd048cf2b0a70ddf026d2ba232e8..bf8090dbf793b6dea4a1e725351bbbbd436ac040 100644 (file)
@@ -225,7 +225,7 @@ static const Parameter snort_params[] =
       "creates stub rule files of all loaded rules libraries" },
 
     { "--dump-dynamic-rules", Parameter::PT_STRING, nullptr, nullptr,
-      "<path> creates stub rule files of all loaded rules libraries" },
+      "<path> creates stub rule file of all loaded rules libraries" },
 
     { "--dirty-pig", Parameter::PT_IMPLIED, nullptr, nullptr,
       "don't flush packets and release memory on shutdown" },
@@ -236,25 +236,25 @@ static const Parameter snort_params[] =
     { "--help", Parameter::PT_IMPLIED, nullptr, nullptr,
       "overview of help" },
 
-    { "--help-builtin", Parameter::PT_STRING, nullptr, nullptr,
+    { "--help-builtin", Parameter::PT_STRING, "(optional)", nullptr,
       "<module prefix> output matching builtin rules" },
 
     { "--help-buffers", Parameter::PT_IMPLIED, nullptr, nullptr,
       "output available inspection buffers" },
 
-    { "--help-commands", Parameter::PT_STRING, nullptr, nullptr,
+    { "--help-commands", Parameter::PT_STRING, "(optional)", nullptr,
       "[<module prefix>] output matching commands" },
 
-    { "--help-config", Parameter::PT_STRING, nullptr, nullptr,
+    { "--help-config", Parameter::PT_STRING, "(optional)", nullptr,
       "[<module prefix>] output matching config options" },
 
-    { "--help-gids", Parameter::PT_STRING, nullptr, nullptr,
+    { "--help-gids", Parameter::PT_STRING, "(optional)", nullptr,
       "[<module prefix>] output matching generators" },
 
     { "--help-module", Parameter::PT_STRING, nullptr, nullptr,
       "<module> output description of given module" },
 
-    { "--help-options", Parameter::PT_STRING, nullptr, nullptr,
+    { "--help-options", Parameter::PT_STRING, "(optional)", nullptr,
       "<option prefix> output matching command line option quick help" },
 
     { "--help-signals", Parameter::PT_IMPLIED, nullptr, nullptr,
@@ -652,8 +652,14 @@ bool SnortModule::set(const char*, Value& v, SnortConfig* sc)
 // singleton
 //-------------------------------------------------------------------------
 
-static SnortModule snort_module;
+static SnortModule* snort_module = nullptr;
 
 Module* get_snort_module()
-{ return &snort_module; }
+{
+    if ( !snort_module )
+        snort_module = new SnortModule;
+
+    return snort_module;
+}
+
 
index 05e2b47183726f347ad2d3ab0765f78dd49851d3..653855758ae5334ef680e68d5e3b4fc738767e07 100644 (file)
 #include "config.h"
 #endif
 
-#include <syslog.h>
-#include <iostream>
 #include <string>
 using namespace std;
 
-#include "config_file.h"
-#include "vars.h"
-#include "detection/detect.h"
-#include "helpers/process.h"
-#include "main/analyzer.h"
-#include "main/snort.h"
 #include "main/snort_module.h"
-#include "main/shell.h"
 #include "framework/module.h"
 #include "framework/parameter.h"
-#include "managers/event_manager.h"
-#include "managers/so_manager.h"
-#include "managers/inspector_manager.h"
-#include "managers/module_manager.h"
-#include "managers/plugin_manager.h"
 #include "packet_io/trough.h"
-#include "packet_io/sfdaq.h"
-#include "packet_io/intf.h"
 #include "parser/arg_list.h"
 #include "parser/parser.h"
 #include "utils/util.h"
-#include "helpers/markup.h"
 
 //-------------------------------------------------------------------------
 
@@ -95,8 +78,12 @@ static bool set_arg(
     bool ok = true;
 
     if ( p->type == Parameter::PT_IMPLIED )
-        v.set(true);
-
+    {
+        if ( *val )
+            ok = false;
+        else
+            v.set(true);
+    }
     else if ( p->type == Parameter::PT_INT )
     {
         char* end = nullptr;
@@ -144,10 +131,13 @@ static void set(
     p = Parameter::find(p, key);
 
     if ( !p )
-        ParseError("unknown option %s %s\n", key, val);
+        ParseError("unknown option %s %s", key, val);
     
     else if ( !set_arg(m, p, k.c_str(), val, sc) )
-        ParseError("can't set %s %s\n", key, val);
+    {
+        ParseError("can't set %s %s", key, val);
+        ParseError("usage: %s %s", key, p->help);
+    }
 }
 
 //-------------------------------------------------------------------------
@@ -170,6 +160,10 @@ SnortConfig* parse_cmd_line(int argc, char* argv[])
         set(key, val, sc, true);
 
     check_flags(sc);
+
+    if ( int k = get_parse_errors() )
+        FatalError("see prioir %d errors\n", k);
+
     return sc;
 }