]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
Merge pull request #1953 in SNORT/snort3 from ~OKHOMIAK/snort3:snort2lua_variable_exp...
authorMichael Altizer (mialtize) <mialtize@cisco.com>
Fri, 31 Jan 2020 05:46:28 +0000 (05:46 +0000)
committerMichael Altizer (mialtize) <mialtize@cisco.com>
Fri, 31 Jan 2020 05:46:28 +0000 (05:46 +0000)
Squashed commit of the following:

commit 02f1799f1ed55f6763603fb2aa3470fc0741a3ee
Author: Oleksii Khomiakovskyi <okhomiak@cisco.com>
Date:   Tue Jan 21 09:49:35 2020 +0200

    snort2lua: conversion of path containing variables

tools/snort2lua/conversion_state.h
tools/snort2lua/preprocessor_states/pps_reputation.cc

index 61fef0598a12446ab07e378205f212f9d60965c7..b7fa77009d54254da1685ad4c77244628e980417 100644 (file)
@@ -75,6 +75,50 @@ protected:
         return false;
     }
 
+    inline bool parse_path_option(const std::string& opt_name,
+        std::istringstream& stream)
+    {
+        std::string val;
+
+        if (stream >> val)
+        {
+            std::size_t prev_pos = 0;
+            while (true)
+            {
+                auto env_start = val.find('$', prev_pos);
+                if (env_start == std::string::npos)
+                {
+                    if (prev_pos)
+                        val.push_back('\'');
+                    break;
+                }
+
+                if (env_start)
+                {
+                    if (!prev_pos)
+                    {
+                        val.insert(prev_pos, "$\'");
+                        env_start += 2;
+                    }
+                    val.replace(env_start, 1, "\' .. ");
+                }
+
+                auto env_end = val.find('/', env_start + 1);
+                if (env_end == std::string::npos)
+                    break;
+
+                val.replace(env_end, 1, " .. \'/");
+                prev_pos = env_end + 5;
+            }
+
+            table_api.add_option(opt_name, val);
+            return true;
+        }
+
+        table_api.add_comment("snort.conf missing argument for: " + opt_name + " <string>");
+        return false;
+    }
+
     inline bool parse_int_option(const std::string& opt_name,
         std::istringstream& stream, bool append)
     {
index d1026e83e7a96eb950b71014dfffbeeb1a694b2f..b09ebe3779f8a8d4720748ff1ef9de28cb209825 100644 (file)
@@ -73,16 +73,7 @@ bool Reputation::convert(std::istringstream& data_stream)
 
         else if (keyword == "blacklist")
         {
-            std::string file_name;
-            if( arg_stream >> file_name)
-            {
-                tmpval = table_api.add_option("blacklist", file_name);
-            }
-            else
-            {
-                data_api.failed_conversion(arg_stream, "reputation: blacklist <missing_arg>");
-                tmpval = false;
-            }
+            tmpval = parse_path_option("blacklist", arg_stream);
         }
         else if (keyword == "memcap")
         {
@@ -142,16 +133,7 @@ bool Reputation::convert(std::istringstream& data_stream)
         }
         else if (keyword == "whitelist")
         {
-            std::string file_name;
-            if( arg_stream >> file_name)
-            {
-                tmpval = table_api.add_option("whitelist", file_name);
-            }
-            else
-            {
-                data_api.failed_conversion(arg_stream, "reputation: whitelist <missing_arg>");
-                tmpval = false;
-            }
+            tmpval = parse_path_option("whitelist", arg_stream);
         }
         else
         {