]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
updating Snort2Lua. Reflects updated Snort++
authorJosh <jrosenba@cisco.com>
Mon, 25 Aug 2014 18:53:48 +0000 (14:53 -0400)
committerJosh <jrosenba@cisco.com>
Mon, 25 Aug 2014 18:53:48 +0000 (14:53 -0400)
tools/snort2lua/config_states/CMakeLists.txt
tools/snort2lua/config_states/Makefile.am
tools/snort2lua/config_states/config_one_string_option.cc
tools/snort2lua/config_states/config_profile.cc
tools/snort2lua/data/data_types/dt_option.h
tools/snort2lua/data/data_types/dt_table.cc
tools/snort2lua/data/data_types/dt_table.h
tools/snort2lua/data/dt_table_api.cc
tools/snort2lua/data/dt_table_api.h
tools/snort2lua/utils/s2l_util.cc
tools/snort2lua/utils/s2l_util.h

index 7657ee3519d6160f807cfeb5893363c0a7a7edfa..9c5a8b7749f4ad2a13b4cf05abd26897aa9905aa 100644 (file)
@@ -1,6 +1,7 @@
 
 
 add_library( config_states
+    config_alertfile.cc
     config_binding.cc
     config_checksums.cc
     config_classification.cc
index ea5794cf396fd63f90b1c6d46120b8a98f05e9c1..933defccbf0c63c7dfc92d9a13d51aa7daeebbc0 100644 (file)
@@ -4,6 +4,7 @@ AUTOMAKE_OPTIONS=foreign no-dependencies
 noinst_LIBRARIES = libconfig_states.a
 
 libconfig_states_a_SOURCES = \
+config_alertfile.cc \
 config_binding.cc \
 config_checksums.cc \
 config_classification.cc \
index a69605ec2397f19ae7025ee2bac181cdc584d78b..4c797af4a78b269e4783627af56d1b983fc50e70 100644 (file)
@@ -58,36 +58,31 @@ public:
         }
 
         // get length (stringstream will not read spaces...which we want)
-        const std::streamoff pos = stream.tellg();
-        stream.seekg(0, stream.end);
-        const std::streamoff length = stream.tellg() - pos;
-        stream.seekg(pos);
+        std::string arg_s = util::get_remain_data(stream);
 
-        // read argument
-        char *arg_c = new char[length + 1];
-        stream.read(arg_c, length);
-        arg_c[length] = '\0';
-        std::string arg_s(arg_c);
-        delete[] arg_c;
-        util::trim(arg_s);
 
+        if (arg_s.empty())
+        {
+            data_api.failed_conversion(stream, "<missing_argument>");
+            return false;
+        }
 
-        bool retval;
         table_api.open_table(*lua_table);
 
         if((lua_option != nullptr) && snort_option->compare(*lua_option))
         {
             table_api.add_diff_option_comment("config " + *snort_option +
                 ":", *lua_option);
-            retval = table_api.add_option(*lua_option, arg_s);
+            table_api.add_option(*lua_option, arg_s);
         }
         else
         {
-            retval = table_api.add_option(*snort_option, arg_s);
+            table_api.add_option(*snort_option, arg_s);
         }
 
         table_api.close_table();
-        return retval;
+        stream.setstate(std::ios::eofbit); // done parsing this line
+        return true;
     }
 
 private:
@@ -123,21 +118,6 @@ static const std::string react = "react";
 static const std::string output = "output";
 
 
-
-/*************************************************
- ******************  alert_file  *****************
- *************************************************/
-
-static const std::string alertfile = "alertfile";
-static const std::string alert_file = "alert_file";
-static const ConvertMap alertfile_api =
-{
-    alertfile,
-    config_string_ctor<&alertfile, &alerts, &alert_file>,
-};
-
-const ConvertMap* alertfile_map = &alertfile_api;
-
 /*************************************************
  *******************  bpf_file  ******************
  *************************************************/
index b613664d9d1b8971f41cbb5dd61eb7fe21f7fd1a..171d4aa32a235b4acafb7b4daacf1a1e739dcb3d 100644 (file)
@@ -62,6 +62,11 @@ bool Profilers<table_name>::convert(std::istringstream& data_stream)
         if (!(arg_stream >> keyword))
             tmpval = false;
 
+        else if (!keyword.compare("filename"))
+        {
+            table_api.add_deleted_comment("profile_*: filename ...");
+        }
+
         else if (!keyword.compare("print"))
         {
             table_api.add_diff_option_comment("print", "count");
@@ -99,29 +104,16 @@ bool Profilers<table_name>::convert(std::istringstream& data_stream)
                 tmpval = table_api.add_option("sort", val);
         }
 
-        else if (!keyword.compare("filename"))
-        {
-            table_api.open_table("file");
-            tmpval = parse_string_option("name", arg_stream);
-
-            std::string append;
-            if ((arg_stream >> append) &&
-                (!append.compare("append")))
-            {
-                if (!table_api.add_option("append", true))
-                    tmpval = false;
-            }
-
-            table_api.close_table();
-        }
-
         else
         {
             tmpval = false;
         }
 
-        if (retval && !tmpval)
+        if (!tmpval)
+        {
+            data_api.failed_conversion(data_stream, keyword);
             retval = false;
+        }
     }
 
     table_api.close_table();
index d7c90cb45b72e88bee34eccdf09e1ae9854a044b..99412839753e8a4935007cdda597e24737df10c9 100644 (file)
@@ -34,7 +34,8 @@ public:
     Option(std::string name, std::string val, int depth);
     virtual ~Option();
 
-    inline std::string get_name(){ return name; };
+    inline std::string get_name()
+    { return name; };
  
     // overloading operators
     friend std::ostream &operator<<( std::ostream&, const Option &);
index c3db05e1aa08a78c85a34f03fb8e83771d6f2f08..3c3673df3edc0f939707b21d2bd9bc9692d69a2c 100644 (file)
@@ -137,6 +137,16 @@ bool Table::add_list(std::string name, std::string next_elem)
     return var->add_value(next_elem);
 }
 
+bool Table::has_option(const std::string opt_name)
+{
+    for (Option* o : options)
+        if (!opt_name.compare(o->get_name()))
+            return true;
+
+    return false;
+}
+
+
 bool Table::has_option(Option opt)
 {
     for (Option* o : options)
index 162cfd29191ba89445b07514e49e67e6d124340c..ea41144a63868b97439e7fe49d0a3faa389f5b43 100644 (file)
@@ -47,6 +47,7 @@ public:
     bool add_option(std::string, std::string val);
     bool add_list(std::string, std::string next_elem);
     void add_comment(std::string comment);
+    bool has_option(const std::string);
 
     friend std::ostream &operator<<( std::ostream&, const Table &);
 
index 1efdb30907bbd40cc07d496f13a297edf7b0bae6..43f0fd6dab3070da4a192b2f51d38417d97dee7c 100644 (file)
@@ -201,6 +201,17 @@ bool TableApi::add_comment(std::string comment)
     return true;
 }
 
+bool TableApi::option_exists(const std::string name)
+{
+    if (open_tables.size() == 0)
+    {
+        data_api.developer_error("Must open table before calling option_exists() !!");
+        return false;
+    }
+
+    return open_tables.top()->has_option(name);
+}
+
 bool TableApi::add_diff_option_comment(std::string orig_var, std::string new_var)
 {
     std::string error_string = "option change: '" + orig_var + "' --> '"
index 9b86c002079165254a101704337ab23ee61bf10a..403bea5fe7cac2ec8ec97d2268dcf442ae29daae 100644 (file)
@@ -65,6 +65,11 @@ void print_tables( std::ostream &out);
 bool empty()
 { return (tables.size() == 0); }
 
+
+/*
+ * Accessing and choosing specific tables.
+ */
+
 // open a table at the topmost layer. i.e., the table will not be nested inside any other table.
 void open_top_level_table(std::string name);
 // open a nested named table --> 'name = {...}')
@@ -74,9 +79,15 @@ void open_table();
 // close the nested table.  go to previous table level
 void close_table();
 
-// ADDING DATA AND FIELDS TO CURRENT TABLE
 void swap_tables(std::vector<Table*>& new_tables);
 
+
+/*
+ * Adding/accessing data to the specific table chosen above!!
+ * These methods will all throw a developer warning if called without
+ * selecting a table!
+ */
+
 // add an string, bool, or int option to the table. --> table = { name = var |'var'};
 bool add_option(const std::string name, const std::string val);
 bool add_option(const std::string name, const int val);
@@ -95,6 +106,9 @@ bool add_deleted_comment(std::string dep_var);
 bool add_unsupported_comment(std::string unsupported_var);
 
 
+// return true if this name exists as an option name for the selected table
+bool option_exists(const std::string name);
+
 
 private:
 std::vector<Table*> tables;
index 648d6ca459513c0c90fa271ac77194a8bbcbda99..4df0301f1a31d221710bb1e65ddfd46e5bf0fb3a 100644 (file)
@@ -183,6 +183,26 @@ bool get_string(std::istringstream& stream,
     }
 }
 
+
+std::string get_remain_data(std::istringstream& stream)
+{
+    // get string length
+    const std::streamoff pos = stream.tellg();
+    stream.seekg(0, stream.end);
+    const std::streamoff length = stream.tellg() - pos;
+    stream.seekg(pos);
+
+    // read argument
+    char *arg_c = new char[length + 1];
+    stream.read(arg_c, length);
+    arg_c[length] = '\0';
+    std::string arg_s(arg_c);
+    delete[] arg_c;
+    util::trim(arg_s);
+    return arg_s;
+}
+
+
 std::string get_rule_option_args(std::istringstream& stream)
 {
     std::string args = std::string();
index 90eb5ddc624a307b2dd24da72ce1db2517f8329f..0b59c187a0d396b177e94e03642a7f61a22d2dbc 100644 (file)
@@ -57,7 +57,8 @@ std::string &trim(std::string &s);
 bool file_exists(const std::string& name);
 
 
-/* Takes in a stream and a string of delimeters. The function will extract the charachters
+/*
+ * Takes in a stream and a string of delimeters. The function will extract the charachters
  * from the stream until it hits one of the delimeters.  The substring will be set to the
  * third parameter.  The stream itself will point to the chrachter after the first delim.
  *
@@ -75,6 +76,14 @@ bool get_string(std::istringstream& data_stream,
                 std::string& option,
                 const std::string delimeters);
 
+/*
+ * Returns the rest of the data_streams data as one argument.
+ * Usefule when parsing filenames with spaces or other
+ * characters which can get removed by c++ libraries
+ *
+ * NO SIDE EFFECTS
+ */
+std::string get_remain_data(std::istringstream& data_stream);
 
 std::string get_rule_option_args(std::istringstream& data_stream);