]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
Merge branch 'master' of /nfs/home/rucombs/Snort++ into snort2lua
authorJosh <jrosenba@cisco.com>
Wed, 16 Jul 2014 21:18:55 +0000 (17:18 -0400)
committerJosh <jrosenba@cisco.com>
Wed, 16 Jul 2014 21:20:44 +0000 (17:20 -0400)
Conflicts:
lua/snort.lua

1  2 
src/codecs/link/cd_mpls_module.cc
src/main/modules.cc
tools/snort2lua/conversion_state.h
tools/snort2lua/data/dt_comment.cc
tools/snort2lua/data/dt_rule.cc
tools/snort2lua/data/dt_var.cc
tools/snort2lua/rule_states/CMakeLists.txt
tools/snort2lua/rule_states/rule_unchanged.cc
tools/snort2lua/rule_states/rule_urilen.cc
tools/snort2lua/util/util.cc
tools/snort2lua/util/util.h

Simple merge
Simple merge
index 08fd43a9acb7b0108808d430873eaeda5fad5af6,7a78f29bc5d9906a0fa7d4ac1a8439ee28883e33..e3d7baa1af7dd9e1a2157728e8b8d522ff3ac5ff
@@@ -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);
              }
  
index 1d58edb38571d68e347fbd10fb8ddc3a996c21c4,9d567d4b70522eb50b958c673219bf3926d85d52..64956069cd51d24fbdddd271f807eb454922c5ac
@@@ -127,12 -124,9 +127,12 @@@ std::ostream &operator<<( std::ostream
          if (str.size() == 0)
              out << "\n";
  
-             util::sanitize_multi_line_string(util::ltrim(str));
 +        else if (c.type == Comments::CommentType::MULTI_LINE)
++            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
index 2100f0bdea679409c63c07f711f1f1b889015dd5,932439be767d99ee1b84690fb9b0f5fb5f6fcedc..72b113890737e9636cc7ce7382f57e5639a1236c
@@@ -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;
  }
index bd3940a53101b9af6c2f0a056276d033395cccab,ca5f027fd80442655f8b719d6c508f0496db688a..660c34af8c9f3350af7500c7911f176926ce444d
@@@ -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;
  
index 29658b0db85cde709612ef32f46ae3696fe7cd73,0cd5e07833a29a4c091ad41e37fd84e85debc51b..f0c97c323d3fb77940f1f6f1fc5d1a81f2b1732d
@@@ -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
  )
index 0f17e61517909082c9e2250464c2ad1fef841de4,51361891b5027b63e40782050248a5fc2fb3caa5..d783e9535ce19ee7c809e980c8e339aa8ef17cc9
@@@ -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  ************
   ************************************/
index 0000000000000000000000000000000000000000,0000000000000000000000000000000000000000..79713f8c5055cff98096188e72c8a9671b25ce39
new file mode 100644 (file)
--- /dev/null
--- /dev/null
@@@ -1,0 -1,0 +1,107 @@@
++/*
++** Copyright (C) 2014 Cisco and/or its affiliates. All rights reserved.
++ * Copyright (C) 2002-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
++ * published by the Free Software Foundation.  You may not use, modify or
++ * distribute this program under any other version of the GNU General
++ * Public License.
++ *
++ * This program is distributed in the hope that it will be useful,
++ * but WITHOUT ANY WARRANTY; without even the implied warranty of
++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
++ * GNU General Public License for more details.
++ *
++ * You should have received a copy of the GNU General Public License
++ * along with this program; if not, write to the Free Software
++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
++ */
++// rule_urilen.cc author Josh Rosenbaum <jorosenba@cisco.com>
++
++#include <sstream>
++#include <vector>
++
++#include "conversion_state.h"
++#include "util/converter.h"
++#include "rule_states/rule_api.h"
++#include "util/util.h"
++
++namespace rules
++{
++
++namespace {
++
++
++class Urilen : public ConversionState
++{
++public:
++    Urilen(Converter* cv, LuaData* ld) : ConversionState(cv, ld) {};
++    virtual ~Urilen() {};
++    virtual bool convert(std::istringstream& data);
++};
++
++} // namespace
++
++bool Urilen::convert(std::istringstream& data_stream)
++{
++    std::string args;
++    std::string value;
++    bool retval = true;
++
++    args = util::get_rule_option_args(data_stream);
++    std::istringstream arg_stream(args);
++
++    // if there are no arguments, the option had a colon before a semicolon.
++    // we are therefore done with this rule.
++    if (util::get_string(arg_stream, value, ","))
++    {
++        retval = ld->add_rule_option("urilen", value);
++        ld->select_option("urilen");
++
++        if (util::get_string(arg_stream, value, ","))
++        {
++            bool tmpval = true;
++
++            if (!value.compare("raw"))
++                tmpval = ld->add_rule_option_before_selected("http_raw_uri");
++
++            else if (!value.compare("norm"))
++                tmpval = ld->add_rule_option_before_selected("http_uri");
++
++            else
++                ld->bad_rule("invalid arguments: " + args, data_stream);
++
++            if (retval && !tmpval)
++                retval = false;
++        }
++    }
++    else
++    {
++        ld->bad_rule("urilen: option required", data_stream);
++    }
++
++    ld->unselect_option();
++    return set_next_rule_state(data_stream) && retval;
++}
++
++/**************************
++ *******  A P I ***********
++ **************************/
++
++
++static ConversionState* ctor(Converter* cv, LuaData* ld)
++{
++    return new Urilen(cv, ld);
++}
++
++static const std::string urilen = "urilen";
++static const ConvertMap rule_urilen =
++{
++    "urilen",
++    ctor,
++};
++
++const ConvertMap* urilen_map = &rule_urilen;
++
++} // namespace rules
index 1f344c4cb292e75786b714a9d21b886a3fd06301,101a96033b89adf22430b6801c9a3fbe9e5f440f..0d89823a6181458ea390d5f3a3f48ffdf2779f04
@@@ -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, " ");
index ff449a1fa2be9e297554c65d4b952259f8678c1d,12b9647ad160598733916c40829f3da2df9004a5..71f40e9ab9ca10f7172b3836b24b77e84b0ab7d6
@@@ -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