From: Oleksii Shumeiko -X (oshumeik - SOFTSERVE INC at Cisco) Date: Thu, 11 May 2023 14:13:54 +0000 (+0000) Subject: Pull request #3838: Snort2lua reference upd X-Git-Tag: 3.1.62.0~6 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=84b3dd43ab480331ef6c7b0b3578cd81aad9e71a;p=thirdparty%2Fsnort3.git Pull request #3838: Snort2lua reference upd Merge in SNORT/snort3 from ~YVELYKOZ/snort3:snort2lua_reference_upd to master Squashed commit of the following: commit 8db269261c14e17be57daa913a5924154541e6c6 Author: Yehor Velykozhon Date: Thu May 4 16:06:25 2023 +0300 snort2lua: remove 'reference' option during conversion --- diff --git a/tools/snort2lua/rule_states/CMakeLists.txt b/tools/snort2lua/rule_states/CMakeLists.txt index ab12965b9..1b3812858 100644 --- a/tools/snort2lua/rule_states/CMakeLists.txt +++ b/tools/snort2lua/rule_states/CMakeLists.txt @@ -14,6 +14,7 @@ add_library( rule_states OBJECT rule_metadata.cc rule_pcre.cc rule_react.cc + rule_reference.cc rule_replace.cc rule_resp.cc rule_sd_pattern.cc diff --git a/tools/snort2lua/rule_states/rule_reference.cc b/tools/snort2lua/rule_states/rule_reference.cc new file mode 100644 index 000000000..b3d5c80c2 --- /dev/null +++ b/tools/snort2lua/rule_states/rule_reference.cc @@ -0,0 +1,78 @@ +//-------------------------------------------------------------------------- +// Copyright (C) 2023-2023 Cisco and/or its affiliates. All rights reserved. +// +// 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_reference.cc author Yehor Velykozhon + +#include + +#include "conversion_state.h" +#include "helpers/converter.h" +#include "helpers/s2l_util.h" +#include "rule_api.h" + +namespace rules +{ +namespace +{ +class Reference : public ConversionState +{ +public: + Reference(Converter& c) : ConversionState(c) { } + bool convert(std::istringstream& data) override; +}; +} // namespace + +bool Reference::convert(std::istringstream& data_stream) +{ + std::string args = util::get_rule_option_args(data_stream); + + size_t separator_pos = args.find_first_of(','); + + if (separator_pos == args.npos) + { + rule_api.add_comment("Option \"reference\" requires 2 argument: , "); + rule_api.add_comment("Original value of \"reference\" option: " + args); + return set_next_rule_state(data_stream); + } + + bool separator_first_symbol = separator_pos == 0; + bool separator_last_symbol = separator_pos == (args.size() - 1); + + if (separator_first_symbol or separator_last_symbol) + rule_api.bad_rule(data_stream, "reference requires 2 non-empty arguments"); + else + rule_api.add_option("reference", args); + + return set_next_rule_state(data_stream); +} + +/************************** + ******* A P I *********** + **************************/ + +static ConversionState* reference_ctor(Converter& c) +{ return new Reference(c); } + +static const ConvertMap rule_reference = +{ + "reference", + reference_ctor, +}; + +const ConvertMap* reference_map = &rule_reference; +} // namespace rules + diff --git a/tools/snort2lua/rule_states/rule_unchanged.cc b/tools/snort2lua/rule_states/rule_unchanged.cc index cdbaddd16..b8ae9ca35 100644 --- a/tools/snort2lua/rule_states/rule_unchanged.cc +++ b/tools/snort2lua/rule_states/rule_unchanged.cc @@ -95,19 +95,6 @@ static const ConvertMap rule_rev = const ConvertMap* rev_map = &rule_rev; -/************************************ - ******** REFERENCE *************** - ************************************/ - -static const std::string reference = "reference"; -static const ConvertMap rule_reference = -{ - reference, - unchanged_rule_ctor<& reference>, -}; - -const ConvertMap* reference_map = &rule_reference; - /************************************ ********** CLASSTYPE ************* ************************************/