]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
various parse error handling changes
authorRuss Combs <rucombs@cisco.com>
Tue, 7 Oct 2014 13:41:43 +0000 (09:41 -0400)
committerRuss Combs <rucombs@cisco.com>
Tue, 7 Oct 2014 13:41:43 +0000 (09:41 -0400)
12 files changed:
ChangeLog
src/main/shell.cc
src/main/snort.cc
src/main/snort_config.cc
src/managers/module_manager.cc
src/managers/plugin_manager.cc
src/parser/parse_conf.cc
src/parser/parser.cc
src/parser/parser.h
src/service_inspectors/ftp_telnet/ftp_module.cc
src/utils/util.cc
src/utils/util.h

index f191d9ad4087a34c8014d3a24d2e978e7ac30e43..bf8eef6ac67e16bf2376517d97ba62139fe2aaa0 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -20,6 +20,7 @@
 -- added path to dynamically loaded plugins output with --list-plugins
 -- commented out mpse start up foo - needs reformatting
 -- added snort.detach() and fixed -j parsing
+-- various parsing changes for improved error handling
 
 122
 -- pulled thread pinning from Josh
index 3dc56eea2b0de49f75dc8d3d53e1177f9591ee8a..daca3d2b803b245c6101b4dd6e29da179d4d67a3 100644 (file)
@@ -109,12 +109,6 @@ static void config_lua(
         load_overrides(L, s);
 
     run_config(L, "_G");
-
-    if ( int k = ModuleManager::get_errors() )
-    {
-        if ( snort_is_starting() )
-            FatalError("see prior %d errors\n", k);
-    }
 }
 
 //-------------------------------------------------------------------------
index 2887634ad0e96914cc154355613b020ec8338c5b..e8439f0c7ea4f7ef8c1b06bff3cbfebeef6573af 100644 (file)
@@ -333,9 +333,9 @@ static void SnortInit(int argc, char **argv)
 
     // Must be after CodecManager::instantiate()
     if ( !InspectorManager::configure(snort_conf) )
-        FatalError("can't initialize inspectors\n");
+        ParseError("can't initialize inspectors");
 
-    if ( ScLogVerbose() )
+    else if ( ScLogVerbose() )
         InspectorManager::print_config(snort_conf);
 
     ParseRules(snort_conf);
@@ -368,7 +368,7 @@ static void SnortInit(int argc, char **argv)
     SFAT_Start();
 
 #ifdef PPM_MGR
-    PPM_PRINT_CFG(&snort_conf->ppm_cfg);
+    //PPM_PRINT_CFG(&snort_conf->ppm_cfg);
 #endif
 
     /* Finish up the pcap list and put in the queues */
@@ -377,7 +377,7 @@ static void SnortInit(int argc, char **argv)
     // FIXIT-L stuff like this that is also done in snort_config.cc::VerifyReload()
     // should be refactored
     if ((snort_conf->bpf_filter == NULL) && (snort_conf->bpf_file != NULL))
-        snort_conf->bpf_filter = read_infile(snort_conf->bpf_file);
+        snort_conf->bpf_filter = read_infile("packets.bpf_file", snort_conf->bpf_file);
 
     if (snort_conf->bpf_filter != NULL)
         LogMessage("Snort BPF option: %s\n", snort_conf->bpf_filter);
@@ -649,7 +649,7 @@ SnortConfig* get_reload_config()
     }
 
 #ifdef PPM_MGR
-    PPM_PRINT_CFG(&sc->ppm_cfg);
+    //PPM_PRINT_CFG(&sc->ppm_cfg);
 #endif
 
     return sc;
index df69c08747209a0be543de7ec3c7e4955a61843b..0a3f4699446e67801d25d22cb3d330bb488bbdb9 100644 (file)
@@ -498,7 +498,7 @@ int VerifyReload(SnortConfig *sc)
     }
 
     if ((sc->bpf_filter == NULL) && (sc->bpf_file != NULL))
-        sc->bpf_filter = read_infile(sc->bpf_file);
+        sc->bpf_filter = read_infile("packets.bpf_file", sc->bpf_file);
 
     if ((sc->bpf_filter != NULL) && (snort_conf->bpf_filter != NULL))
     {
index 4138063103f9fa89463563394d9fdd9daab3b9e4..a5cb5d7e0375b4df98f6b1d91cb680a6b2067b86 100644 (file)
@@ -322,7 +322,7 @@ static bool set_param(Module* mod, const char* fqn, Value& val)
 {
     if ( !mod->set(fqn, val, s_config) )
     {
-        ErrorMessage("ERROR: %s is invalid\n", fqn);
+        ParseError("%s is invalid", fqn);
         ++s_errors;
     }
 
@@ -350,7 +350,7 @@ static bool set_value(const char* fqn, Value& v)
  
     if ( !p )
     {
-        ErrorMessage("ERROR can't find %s\n", fqn);
+        ParseError("can't find %s", fqn);
         ++s_errors;
         return false;
     }
@@ -363,11 +363,11 @@ static bool set_value(const char* fqn, Value& v)
     }
 
     if ( v.get_type() == Value::VT_STR )
-        ErrorMessage("ERROR invalid %s = '%s'\n", fqn, v.get_string());
+        ParseError("invalid %s = '%s'", fqn, v.get_string());
     else if ( v.get_real() == v.get_long() )
-        ErrorMessage("ERROR invalid %s = %ld\n", fqn, v.get_long());
+        ParseError("invalid %s = %ld", fqn, v.get_long());
     else
-        ErrorMessage("ERROR invalid %s = %g\n", fqn, v.get_real());
+        ParseError("invalid %s = %g", fqn, v.get_real());
 
     ++s_errors;
     return false;
@@ -423,12 +423,12 @@ SO_PUBLIC bool open_table(const char* s, int idx)
 
         if ( !p )
         {
-            ParseError("can't find %s\n", s);
+            ParseError("can't find %s", s);
             return false;
         }
         else if ((idx > 0) && (p->type == Parameter::PT_TABLE))
         {
-            ParseError("%s is a table. All elements must be named\n", s);
+            ParseError("%s is a table; all elements must be named", s);
             return false;
         }
     }
@@ -862,7 +862,7 @@ static void make_rule(ostream& os, const Module* m, const RuleMap* r)
 // (we don't want to suppress it because it could mean something is broken)
 void ModuleManager::load_rules(SnortConfig* sc)
 {
-    // FIXIT-M callers of ParseConfigString() should not have to push parse loc
+    s_modules.sort(comp_gids);
     push_parse_location("builtin");
 
     for ( auto p : s_modules )
index 60aec25e2c89c99bafe1c60bbcc604db7d56d66e..766012815f7daffcb727611b86d83d50094f84d4 100644 (file)
@@ -475,7 +475,14 @@ void PluginManager::instantiate(
 void PluginManager::instantiate(
     const BaseApi* api, Module* mod, SnortConfig* sc, const char* name)
 {
-    assert(api->type == PT_INSPECTOR);
-    InspectorManager::instantiate((InspectApi*)api, mod, sc, name);
+    if ( api->type == PT_INSPECTOR )
+        InspectorManager::instantiate((InspectApi*)api, mod, sc, name);
+
+    else if ( api->type == PT_DATA )
+        // FIXIT-H instantiate PT_DATA with name
+        DataManager::instantiate((DataApi*)api, mod, sc/*, name*/);
+
+    else
+        assert(false);
 }
 
index 302db4bd5514b2c22e9e7e2b4f51b3a3cc11f27b..46e31a371126283889d24767c7a3366e2c44c241 100644 (file)
@@ -112,12 +112,17 @@ void push_parse_location(const char* file, unsigned line)
 
     Location loc(file, line);
     files.push(loc);
+    LogMessage("Loading %s:\n", file);
 }
 
 void pop_parse_location()
 {
     if ( !files.empty() )
+    {
+        Location& loc = files.top();
+        LogMessage("Finished %s.\n", loc.file.c_str());
         files.pop();
+    }
 }
 
 void inc_parse_position()
index 2f51dcd63406a5fc2e5aa0c6187b543aa9dfe84e..b8ec94fc58bab11062ec466ce1b7087061b66225 100644 (file)
@@ -580,7 +580,6 @@ static void parse_file(SnortConfig* sc, Shell* sh)
     if ( !fname || !*fname )
         return;
 
-    LogMessage("Loading %s:\n", fname);
     push_parse_location(fname);
     sh->configure(sc);
     pop_parse_location();
@@ -1118,8 +1117,8 @@ void ParseError(const char *format, ...)
     unsigned file_line;
     get_parse_location(file_name, file_line);
 
-    if (file_name != NULL)
-        LogMessage("ERROR: %s(%d) %s\n", file_name, file_line, buf);
+    if (file_line )
+        LogMessage("ERROR: %s:%d %s\n", file_name, file_line, buf);
     else
         LogMessage("ERROR: %s\n", buf);
 
@@ -1141,8 +1140,8 @@ void ParseWarning(const char *format, ...)
     unsigned file_line;
     get_parse_location(file_name, file_line);
 
-    if (file_name != NULL)
-        LogMessage("WARNING: %s(%d) %s\n", file_name, file_line, buf);
+    if ( file_line )
+        LogMessage("WARNING: %s:%d %s\n", file_name, file_line, buf);
     else
         LogMessage("WARNING: %s\n", buf);
 
index e50d18015db9d18f4fced7d6a662a601bb009fec..0a8362c7dc11d77f27ea18dedac4cd3ee050f7f2 100644 (file)
@@ -42,7 +42,7 @@ unsigned get_parse_warnings();
 
 const char* get_parse_file();
 void get_parse_location(const char*& name, unsigned& line);
-void push_parse_location(const char* name, unsigned line = 1);
+void push_parse_location(const char* name, unsigned line = 0);
 
 void pop_parse_location();
 void inc_parse_position();
index 07a1f4e6b8acc5075f57badc13d3d575759f2618..8cdf04ac7e66725f31a2ebeed078b210e01c6e29 100644 (file)
@@ -58,7 +58,7 @@ static const Parameter ftp_client_params[] =
     { "bounce", Parameter::PT_BOOL, nullptr, "false",
       "check for bounces" },
 
-    { "bounce_to", Parameter::PT_TABLE, client_bounce_params, nullptr,
+    { "bounce_to", Parameter::PT_LIST, client_bounce_params, nullptr,
       "allow bounces to CIDRs / ports" },
 
     { "ignore_telnet_erase_cmds", Parameter::PT_BOOL, nullptr, "false",
index 33fcb48fa8b00ce423b12488348f0a2730569e15..ae6658fedd1741c1d5557d7ad3db8f29d5d0c2ab 100644 (file)
@@ -487,7 +487,7 @@ void CleanupProtoNames(void)
 
 /****************************************************************************
  *
- * Function: read_infile(char *)
+ * Function: read_infile(const char* key, const char* file)
  *
  * Purpose: Reads the BPF filters in from a file.  Ripped from tcpdump.
  *
@@ -496,7 +496,7 @@ void CleanupProtoNames(void)
  * Returns: the processed BPF string
  *
  ****************************************************************************/
-char *read_infile(char *fname)
+char *read_infile(const char* key, const char* fname)
 {
     int fd, cc;
     char *cp, *cmt;
@@ -506,7 +506,7 @@ char *read_infile(char *fname)
 
     if(fd < 0)
     {
-        ParseError("can't open %s: %s\n", fname, get_error(errno));
+        ParseError("can't open %s = %s: %s\n", key, fname, get_error(errno));
         return nullptr;
     }
 
index 6e64882c7251c67a92a388ad7287c1b14d5fc6e2..58fe8c6a371cef69b6f9556849f0b01253591a74 100644 (file)
@@ -81,7 +81,7 @@ int gmt2local(time_t);
 void ts_print(register const struct timeval *, char *);
 void strip(char *);
 void CheckLogDir(void);
-char *read_infile(char *);
+char *read_infile(const char* key, const char* fname);
 void CleanupProtoNames(void);
 void CreatePidFile(pid_t);
 void ClosePidFile(void);