]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
Pull request #3838: Snort2lua reference upd
authorOleksii Shumeiko -X (oshumeik - SOFTSERVE INC at Cisco) <oshumeik@cisco.com>
Thu, 11 May 2023 14:13:54 +0000 (14:13 +0000)
committerOleksii Shumeiko -X (oshumeik - SOFTSERVE INC at Cisco) <oshumeik@cisco.com>
Thu, 11 May 2023 14:13:54 +0000 (14:13 +0000)
Merge in SNORT/snort3 from ~YVELYKOZ/snort3:snort2lua_reference_upd to master

Squashed commit of the following:

commit 8db269261c14e17be57daa913a5924154541e6c6
Author: Yehor Velykozhon <yvelykoz@cisco.com>
Date:   Thu May 4 16:06:25 2023 +0300

    snort2lua: remove 'reference' option during conversion

tools/snort2lua/rule_states/CMakeLists.txt
tools/snort2lua/rule_states/rule_reference.cc [new file with mode: 0644]
tools/snort2lua/rule_states/rule_unchanged.cc

index ab12965b9624434c5911cd33ae840479a15e6fe8..1b3812858e3bce0ab12810ff1067d7a86a42fc42 100644 (file)
@@ -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 (file)
index 0000000..b3d5c80
--- /dev/null
@@ -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 <yvelykoz@cisco.com>
+
+#include <string>
+
+#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: <scheme>, <id>");
+        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
+
index cdbaddd164a5297c52ad67ed911dea677174850d..b8ae9ca35ca283ddf7f2315bd484cf376a5f2d31 100644 (file)
@@ -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  *************
  ************************************/