From: Josh Date: Wed, 16 Jul 2014 21:18:55 +0000 (-0400) Subject: Merge branch 'master' of /nfs/home/rucombs/Snort++ into snort2lua X-Git-Tag: 3.0.0-233~1175^2~21 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c23db8be7ca010a1d50649df2759cda31d96c4b3;p=thirdparty%2Fsnort3.git Merge branch 'master' of /nfs/home/rucombs/Snort++ into snort2lua Conflicts: lua/snort.lua --- c23db8be7ca010a1d50649df2759cda31d96c4b3 diff --cc tools/snort2lua/conversion_state.h index 08fd43a9a,7a78f29bc..e3d7baa1a --- a/tools/snort2lua/conversion_state.h +++ b/tools/snort2lua/conversion_state.h @@@ -258,22 -245,23 +258,18 @@@ protected inline bool set_next_rule_state(std::istringstream& stream) { std::string keyword; - int pos = stream.tellg(); - std::getline(stream, keyword, ':'); - util::trim(keyword); - - if (keyword.empty()) - return true; - // std::getline(stream, keyword, ':'); - // if (keyword.find_first_not_of(' ') == std::string::npos) - // return true; - - do + while(std::getline(stream, keyword, ':')) { - util::trim(keyword); - int semi_colon_pos = keyword.find(';'); + std::size_t semi_colon_pos = keyword.find(';'); if (semi_colon_pos != std::string::npos) { - // found a nested option without a colon - // 2 == last charachter of option + semi_colon - stream.seekg(pos + semi_colon_pos +2); + // found an option without a colon, so set stream + // to semi-colon + std::streamoff off = 1 + (std::streamoff)(pos) + + (std::streamoff)(semi_colon_pos); + stream.seekg(off); keyword = keyword.substr(0, semi_colon_pos); } diff --cc tools/snort2lua/data/dt_comment.cc index 1d58edb38,9d567d4b7..64956069c --- a/tools/snort2lua/data/dt_comment.cc +++ b/tools/snort2lua/data/dt_comment.cc @@@ -127,12 -124,9 +127,12 @@@ std::ostream &operator<<( std::ostream if (str.size() == 0) out << "\n"; + else if (c.type == Comments::CommentType::MULTI_LINE) - util::sanitize_multi_line_string(util::ltrim(str)); ++ util::sanitize_lua_string(util::ltrim(str)); + while(!str.empty()) { - int substr_len = max_line_length; + std::size_t substr_len = max_line_length; // determine the first space before 80 charachters // if there are no spaces, print the entire string diff --cc tools/snort2lua/data/dt_rule.cc index 2100f0bde,932439be7..72b113890 --- a/tools/snort2lua/data/dt_rule.cc +++ b/tools/snort2lua/data/dt_rule.cc @@@ -21,7 -21,6 +21,8 @@@ #include "data/dt_rule.h" +#include "data/dt_data.h" // included for print mode ++#include "util/util.h" Rule::Rule() : num_hdr_data(0), @@@ -130,25 -125,23 +131,26 @@@ std::ostream &operator<<( std::ostream else out << " "; -- out << rule.hdr_data[i]; ++ std::string tmp = rule.hdr_data[i]; ++ out << util::sanitize_lua_string(tmp); } - out << " ("; - first_line = true; - - for (auto* r : rule.options) + if (!rule.options.empty()) { - if (first_line) - first_line = false; - else - out << ";"; - out << " " << (*r); - } + out << " ("; + first_line = true; - out << " )"; + for (auto* r : rule.options) + { + if (first_line) + first_line = false; + else + out << ";"; + out << " " << (*r); + } + out << " )"; + } return out; } diff --cc tools/snort2lua/data/dt_var.cc index bd3940a53,ca5f027fd..660c34af8 --- a/tools/snort2lua/data/dt_var.cc +++ b/tools/snort2lua/data/dt_var.cc @@@ -139,7 -137,7 +139,7 @@@ std::ostream& operator<<( std::ostream print_newline(out, count, whitespace); -- util::sanitize_multi_line_string(v->data); ++ util::sanitize_lua_string(v->data); out << "[[ "; count += 3; diff --cc tools/snort2lua/rule_states/CMakeLists.txt index 29658b0db,0cd5e0783..f0c97c323 --- a/tools/snort2lua/rule_states/CMakeLists.txt +++ b/tools/snort2lua/rule_states/CMakeLists.txt @@@ -7,6 -6,6 +7,7 @@@ add_library( rule_state rule_metadata.cc rule_pcre.cc rule_unchanged.cc ++ rule_urilen.cc rule_api.cc rule_api.h ) diff --cc tools/snort2lua/rule_states/rule_unchanged.cc index 0f17e6151,51361891b..d783e9535 --- a/tools/snort2lua/rule_states/rule_unchanged.cc +++ b/tools/snort2lua/rule_states/rule_unchanged.cc @@@ -548,19 -548,33 +548,6 @@@ static const ConvertMap rule_threshold const ConvertMap* threshold_map = &rule_threshold; --/************************************ -- ************* URILEN ************* -- ************************************/ -- --static const std::string urilen = "urilen"; --static const ConvertMap rule_urilen = --{ -- urilen, -- unchanged_rule_ctor<&urilen>, --}; -- --const ConvertMap* urilen_map = &rule_urilen; - - -/************************************ - *********** FILE_DATA ************ - ************************************/ - -static const std::string file_data = "file_data"; -static const ConvertMap rule_file_data = -{ - file_data, - unchanged_rule_ctor<&file_data, false>, -}; - -const ConvertMap* file_data_map = &rule_file_data; -- /************************************ *********** BYTE_TEST ************ ************************************/ diff --cc tools/snort2lua/util/util.cc index 1f344c4cb,101a96033..0d89823a6 --- a/tools/snort2lua/util/util.cc +++ b/tools/snort2lua/util/util.cc @@@ -57,10 -56,10 +57,10 @@@ const ConvertMap* find_map(const std::v return nullptr; } --std::string &sanitize_multi_line_string(std::string &s) ++std::string &sanitize_lua_string(std::string &s) { - int found = s.find("]]"); + std::size_t found = s.find("]]"); while (found != std::string::npos) { s.insert(found + 1, " "); diff --cc tools/snort2lua/util/util.h index ff449a1fa,12b9647ad..71f40e9ab --- a/tools/snort2lua/util/util.h +++ b/tools/snort2lua/util/util.h @@@ -64,32 -64,9 +64,32 @@@ inline std::string &trim(std::string &s return ltrim(rtrim(s)); } + +// return true if this file exists. False otherwise. +bool file_exists (const std::string& name); + +/* 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. + * + * PARAMS: + * data_stream - the data stream from which to find a substring. + * delimeters - The string of delimeters. + * options - The found substring will be place in this parameter. If the + * stream is empty or no charachters have been extracted, then + * this parameter wil be set to an empty string. + * RETURNS: + * True - when the string is found. + * False - whenma substing was unable to be extracted. + */ +bool get_string(std::istringstream& data_stream, std::string& option, std::string delimeters); + + std::string get_rule_option_args(std::istringstream& data_stream); -// remove any ']]' from this string. -std::string &sanitize_multi_line_string(std::string &s); + +// remove any ']]' and double spaces from this string. - std::string &sanitize_multi_line_string(std::string &s); ++std::string &sanitize_lua_string(std::string &s); + // find the location of the first space before max_str_lenght. // if no space exists before max_str_length, return the first space // after max_length. Otherwise, return std::string::npos