]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
Merge pull request #1027 in SNORT/snort3 from snort2lua_ims to master
authorMichael Altizer (mialtize) <mialtize@cisco.com>
Fri, 29 Sep 2017 15:53:42 +0000 (11:53 -0400)
committerMichael Altizer (mialtize) <mialtize@cisco.com>
Fri, 29 Sep 2017 15:53:42 +0000 (11:53 -0400)
Squashed commit of the following:

commit 9fe6d6a02b6e82834cbfd2f0c1ebf85f04c066ab
Author: Michael Altizer <mialtize@cisco.com>
Date:   Thu Sep 28 13:52:59 2017 -0400

    appid: Fix performance issues reported by cppcheck

commit aafb9275f17aa4ef91250402751ee80185f41c68
Author: Michael Altizer <mialtize@cisco.com>
Date:   Thu Sep 28 13:49:44 2017 -0400

    memory: Align allocator metadata such that returned memory is also max_align_t-aligned

commit feca8e5d4dbd0a08854f534287d2a45b98fd3a5d
Author: Michael Altizer <mialtize@cisco.com>
Date:   Thu Sep 28 01:13:27 2017 -0400

    build: Clean up a few ICC 2018 and GCC 7 warnings

commit 9532792af8405365856ee56b0c6416c0c231bc4d
Author: Michael Altizer <mialtize@cisco.com>
Date:   Thu Sep 28 01:09:29 2017 -0400

    build: Add NORETURN_ASSERT to tag functions that will always assert

commit 4df0a1d9f5079474d46f757b28c3621157d8d05b
Author: Michael Altizer <mialtize@cisco.com>
Date:   Thu Sep 28 00:29:36 2017 -0400

    uboat,fbstreamer: Fix issues reported by cppcheck

commit 2152f1ab13736173c7bd3d029fa5294a4b22edfd
Author: Michael Altizer <mialtize@cisco.com>
Date:   Thu Sep 28 00:21:55 2017 -0400

    snort2lua: Fix various issues reported by cppcheck

commit d2fa14de02578809294926a981c70d9a4554f0cf
Author: Michael Altizer <mialtize@cisco.com>
Date:   Wed Sep 27 15:30:37 2017 -0400

    snort2lua: Fix initialization order in Converter constructor

commit 26ae4d24ab624c4d0874ae0ab9ca97587d339cde
Author: Michael Altizer <mialtize@cisco.com>
Date:   Wed Sep 20 16:29:59 2017 -0400

    log/messages: Redirect stderr to syslog as well

commit 39bd64bee437f935650af17ac39f6bbbd6c840ac
Author: Michael Altizer <mialtize@cisco.com>
Date:   Wed Sep 20 12:38:00 2017 -0400

    snort2lua: Implement firewall preproc and sfunified2 output conversions

76 files changed:
src/connectors/tcp_connector/tcp_connector.cc
src/detection/fp_detect.cc
src/log/messages.cc
src/log/messages.h
src/log/packet_tracer.cc
src/main/shell.cc
src/main/shell.h
src/main/snort.cc
src/main/snort_types.h
src/memory/memory_manager.cc
src/network_inspectors/appid/appid_peg_counts.cc
src/network_inspectors/appid/appid_peg_counts.h
src/service_inspectors/http_inspect/http_header_normalizer.cc
src/service_inspectors/http_inspect/http_inspect.cc
src/sfip/sf_ipvar.cc
src/stream/file/stream_file.cc
src/stream/icmp/stream_icmp.cc
src/stream/ip/stream_ip.cc
src/stream/tcp/stream_tcp.cc
src/stream/udp/stream_udp.cc
src/stream/user/stream_user.cc
tools/flatbuffers/fbstreamer.cc
tools/snort2lua/config_states/config_profile.cc
tools/snort2lua/conversion_state.h
tools/snort2lua/data/data_types/dt_include.cc
tools/snort2lua/data/data_types/dt_include.h
tools/snort2lua/data/data_types/dt_option.cc
tools/snort2lua/data/data_types/dt_option.h
tools/snort2lua/data/data_types/dt_rule.cc
tools/snort2lua/data/data_types/dt_rule.h
tools/snort2lua/data/data_types/dt_rule_option.cc
tools/snort2lua/data/data_types/dt_rule_option.h
tools/snort2lua/data/data_types/dt_rule_suboption.cc
tools/snort2lua/data/data_types/dt_rule_suboption.h
tools/snort2lua/data/data_types/dt_table.cc
tools/snort2lua/data/data_types/dt_table.h
tools/snort2lua/data/data_types/dt_var.cc
tools/snort2lua/data/data_types/dt_var.h
tools/snort2lua/data/dt_data.cc
tools/snort2lua/data/dt_data.h
tools/snort2lua/data/dt_rule_api.cc
tools/snort2lua/data/dt_rule_api.h
tools/snort2lua/data/dt_table_api.cc
tools/snort2lua/data/dt_table_api.h
tools/snort2lua/helpers/converter.cc
tools/snort2lua/helpers/converter.h
tools/snort2lua/helpers/s2l_util.cc
tools/snort2lua/helpers/s2l_util.h
tools/snort2lua/keyword_states/kws_attribute_table.cc
tools/snort2lua/keyword_states/kws_event_filter.cc
tools/snort2lua/output_states/out_sfunified2.cc
tools/snort2lua/output_states/out_syslog.cc
tools/snort2lua/output_states/out_test.cc
tools/snort2lua/preprocessor_states/pps_dcerpc.cc
tools/snort2lua/preprocessor_states/pps_dcerpc_server.cc
tools/snort2lua/preprocessor_states/pps_dcerpc_server.h
tools/snort2lua/preprocessor_states/pps_dnp3.cc
tools/snort2lua/preprocessor_states/pps_dns.cc
tools/snort2lua/preprocessor_states/pps_firewall.cc
tools/snort2lua/preprocessor_states/pps_ftp_telnet_protocol.cc
tools/snort2lua/preprocessor_states/pps_gtp.cc
tools/snort2lua/preprocessor_states/pps_http_inspect_server.cc
tools/snort2lua/preprocessor_states/pps_imap.cc
tools/snort2lua/preprocessor_states/pps_modbus.cc
tools/snort2lua/preprocessor_states/pps_pop.cc
tools/snort2lua/preprocessor_states/pps_sip.cc
tools/snort2lua/preprocessor_states/pps_smtp.cc
tools/snort2lua/preprocessor_states/pps_ssh.cc
tools/snort2lua/preprocessor_states/pps_ssl.cc
tools/snort2lua/preprocessor_states/pps_stream5_global.cc
tools/snort2lua/preprocessor_states/pps_stream5_tcp.cc
tools/snort2lua/rule_states/rule_content.cc
tools/snort2lua/rule_states/rule_http_encode.cc
tools/snort2lua/rule_states/rule_tag.cc
tools/snort2lua/snort2lua.cc
tools/u2boat/u2boat.cc

index 5852ba509acb57ce50596a737223af103347a477..585d36cd9ac657fea7bfe9d5692710aae04e2239 100644 (file)
@@ -429,7 +429,7 @@ static Connector* tcp_connector_tinit(ConnectorConfig* config)
         return nullptr;
     }
 
-    sprintf(port_string, "%5d", (cfg->base_port + instance));
+    snprintf(port_string, sizeof(port_string), "%5hu", static_cast<uint16_t>(cfg->base_port + instance));
 
     TcpConnector* tcp_connector;
 
index 5b291807ca60b95008f6a1c7cb573daa801ffbf6..5e976530eb0d5d5d2798b9cd6d31e6b7dc08654d 100644 (file)
@@ -105,7 +105,7 @@ static inline void fpLogOther(
     if ( EventTrace_IsEnabled() )
         EventTrace_Log(p, otn, action);
 
-    PacketTracer::log("Event: %d:%d:%d, Action %s\n",
+    PacketTracer::log("Event: %u:%u:%u, Action %s\n",
         otn->sigInfo.gid, otn->sigInfo.sid, otn->sigInfo.rev,
         get_action_string((RuleType)action));
 
index 249049387e1c3769e2ff9b5bc6e8da0aad0a7344..227eff1a30fb9974ebfdaae9f15136bf0553909b 100644 (file)
@@ -178,7 +178,7 @@ void LogMessage(FILE* fh, const char* format,...)
     va_list ap;
     va_start(ap, format);
 
-    WriteLogMessage(fh, fh != stdout, format, ap);
+    WriteLogMessage(fh, (fh != stdout && fh != stderr), format, ap);
 
     va_end(ap);
 }
@@ -303,7 +303,7 @@ void ErrorMessage(const char* format,...)
     }
 }
 
-void log_safec_error(const char* msg, void*, int e)
+NORETURN_ASSERT void log_safec_error(const char* msg, void*, int e)
 {
     static THREAD_LOCAL unsigned safec_errors = 0;
 
index af595badd6b14ad065456da9d9e5f6aa353e2ec1..16c654bf400553f3285a3b815e38a7eecad0757d 100644 (file)
@@ -61,7 +61,7 @@ SO_PUBLIC void ErrorMessage(const char*, ...) __attribute__((format (printf, 1,
 // FIXIT-M do not call FatalError() during runtime
 [[noreturn]] SO_PUBLIC void FatalError(const char*, ...) __attribute__((format (printf, 1, 2)));
 
-[[noreturn]] void log_safec_error(const char*, void*, int);
+NORETURN_ASSERT void log_safec_error(const char*, void*, int);
 
 class Dumper
 {
index 97fea0c6264517949cf918e6c6755fdb5aabf723..6ff2f6729b54be7db4bb73eddd16ab2e43eca183 100644 (file)
@@ -166,7 +166,7 @@ void PacketTracer::add_header_info(Packet* p)
         p->ptrs.ip_api.get_src()->ntop(sipstr, sizeof(sipstr));
         p->ptrs.ip_api.get_dst()->ntop(dipstr, sizeof(dipstr));
 
-        log("%s:%u -> %s:%u proto %u\n",
+        log("%s:%hu -> %s:%hu proto %u\n",
             sipstr, p->ptrs.sp, dipstr, p->ptrs.dp, (unsigned)p->ptrs.ip_api.proto());
         log("Packet: %s", p->get_type());
         if (p->type() == PktType::TCP)
index e2ab37b16a1050eb1877b4f3b6159983441f6cbb..d2722ddf57d111aefe9a49614ca736c7dd0594f5 100644 (file)
@@ -47,7 +47,7 @@ using namespace std;
 
 string Shell::fatal;
 
-int Shell::panic(lua_State* L)
+[[noreturn]] int Shell::panic(lua_State* L)
 {
     fatal = lua_tostring(L, -1);
     throw runtime_error(fatal);
index 844fd6717010979ec0165ead6f0921ced82e2406..742154291bc58210489a3386a14ce7be3d152597 100644 (file)
@@ -47,7 +47,7 @@ public:
     { return loaded; }
 
 private:
-    static int panic(lua_State*);
+    [[noreturn]] static int panic(lua_State*);
     static std::string fatal;
 
 private:
index 72331ee3724d6953d0f7d68e4f159b4ee3fdbb12..7e5cf50344af0f4200aad3554979ff7814d3acc4 100644 (file)
@@ -978,7 +978,7 @@ DAQ_Verdict Snort::packet_callback(
     int inject = 0;
     verdict = update_verdict(verdict, inject);
 
-    PacketTracer::log("NAP id %d, IPS id %d, Verdict %s\n",
+    PacketTracer::log("NAP id %u, IPS id %u, Verdict %s\n",
         get_network_policy()->policy_id, get_ips_policy()->policy_id,
         SFDAQ::verdict_to_string(verdict));
 
index 23c5c4119af3605d1b27577f90df504fb52d3081..806a01f0813c7da594ed907bc1066b6d5e552dd1 100644 (file)
@@ -40,6 +40,12 @@ typedef uint16_t Port;
 
 #define UNUSED(x) (void)(x)
 
+#ifdef NDEBUG
+#define NORETURN_ASSERT
+#else
+#define NORETURN_ASSERT [[noreturn]]
+#endif
+
 #ifndef SO_PUBLIC
 #if defined _WIN32 || defined __CYGWIN__
 #  ifdef __GNUC__
index c827176638df34f2e5dc68fa4faeccc23188abf1..c1da9d2d65fa2198dd009e367c6b673128e50f78 100644 (file)
@@ -41,7 +41,9 @@ namespace memory
 // metadata
 // -----------------------------------------------------------------------------
 
-struct Metadata
+// NOTE: This structure must be aligned to max_align_t as long as we are prepending
+//       it to memory allocations so that the returned memory is also aligned.
+struct alignas(max_align_t) Metadata
 {
 #if defined(REG_TEST) || defined(UNIT_TEST)
     static constexpr size_t SANITY_CHECK_VALUE = 0xabcdef;
index 52717493864f23d38fe01d9f9199bee1f141cf8f..0d05c6e0d66629cc7040510fc10dcef66200f790 100644 (file)
@@ -52,8 +52,8 @@ void AppIdPegCounts::cleanup_pegs()
     delete appid_peg_counts;
 }
 
-void AppIdPegCounts::init_detector_peg_info(std::string& app_name, std::string name_suffix,
-    std::string help_suffix)
+void AppIdPegCounts::init_detector_peg_info(const std::string& app_name, const std::string& name_suffix,
+    const std::string& help_suffix)
 {
     std::string name = app_name + name_suffix;
     std::string help = "count of ";
index 48ac004dacd04105eb5fca1f3c6df0faec704014..b76f2eeabbc4c36acea5ffccac6f1c77fd2bccb9 100644 (file)
@@ -131,7 +131,7 @@ private:
      static std::vector<PegInfo> appid_pegs;
      static THREAD_LOCAL std::vector<PegCount>* appid_peg_counts;
 
-     static void init_detector_peg_info(std::string& app_name, std::string name_suffix,
-         std::string help_suffix);
+     static void init_detector_peg_info(const std::string& app_name, const std::string& name_suffix,
+         const std::string& help_suffix);
 };
 #endif
index fc6ce9eaafc68cb4aee4e77362b4d2301a55d695..16458238a499aaf73b6694a6835f5038a09a8a5f 100644 (file)
@@ -99,10 +99,8 @@ void HeaderNormalizer::normalize(const HeaderId head_id, const int count,
     // number of normalization functions is odd or even, the initial buffer is chosen so that the
     // final normalization leaves the normalized header value in norm_value.
 
-    uint8_t* const norm_value = new uint8_t[buffer_length];
-    uint8_t* const temp_space = new uint8_t[buffer_length];
-    memset(norm_value, 0, buffer_length);
-    memset(temp_space, 0, buffer_length);
+    uint8_t* const norm_value = new uint8_t[buffer_length]();
+    uint8_t* const temp_space = new uint8_t[buffer_length]();
     uint8_t* const norm_start = (num_normalizers%2 == 0) ? norm_value : temp_space;
     uint8_t* working = norm_start;
     int32_t data_length = 0;
index 2df18f2c55736b0ce7b1e77915f456727e5ba848..a8335e3bc35f3e8060a1010e6eb3b03920f9e61c 100644 (file)
@@ -281,7 +281,7 @@ void HttpInspect::eval(Packet* p)
     {
         if (HttpTestManager::use_test_output())
         {
-            fprintf(HttpTestManager::get_output_file(), "Sent to detection %u octets\n\n",
+            fprintf(HttpTestManager::get_output_file(), "Sent to detection %hu octets\n\n",
                 p->dsize);
             fflush(HttpTestManager::get_output_file());
         }
index 5a97a8eb2ec7583bb43e431d447942fbb24837d4..0dd141f4fbdd7a50d32c4d7757a37e42e6f1e3e5 100644 (file)
@@ -31,7 +31,7 @@
 
 #include "sf_ipvar.h"
 
-#include <assert.h>
+#include <cassert>
 #include "utils/util.h"
 
 #include "sf_cidr.h"
@@ -39,7 +39,9 @@
 
 #ifdef UNIT_TEST
 #include "catch/catch.hpp"
+#include "utils/util_cstring.h"
 #endif
+
 #define LIST_OPEN '['
 #define LIST_CLOSE ']'
 
@@ -1085,8 +1087,7 @@ bool sfvar_ip_in(sfip_var_t* var, const SfIp* ip)
 #ifdef UNIT_TEST
 #define SFIPVAR_TEST_BUFF_LEN 512
 static char sfipvar_test_buff[SFIPVAR_TEST_BUFF_LEN];
-extern int safe_snprintf(char* s, size_t n, const char* format, ... );
-void print_var_list(sfip_node_t* var_list, bool print_bits = false)
+static void print_var_list(sfip_node_t* var_list, bool print_bits = false)
 {
     int n = 0;
     for(sfip_node_t* p = var_list; p; p = p->next)
index 0f686fea07ac83fb36594fafe5dea99c2dae51c1..9fcec9501380ae9519a029a6601698de2f9e29d8 100644 (file)
@@ -36,12 +36,12 @@ public:
     StreamFile(bool b)
     { config.upload = b; }
 
-    void eval(Packet*) override;
+    NORETURN_ASSERT void eval(Packet*) override;
 
     StreamFileConfig config;
 };
 
-void StreamFile::eval(Packet*)
+NORETURN_ASSERT void StreamFile::eval(Packet*)
 {
     // session::process() instead
     assert(false);
index c96a782615e4278c440a1bdf60b52c5341034fb3..2285d2d06062e840f23ec4998b0b74e5099c8a01 100644 (file)
@@ -55,7 +55,7 @@ public:
     ~StreamIcmp();
 
     void show(SnortConfig*) override;
-    void eval(Packet*) override;
+    NORETURN_ASSERT void eval(Packet*) override;
 
 private:
     StreamIcmpConfig* config;
@@ -76,7 +76,7 @@ void StreamIcmp::show(SnortConfig*)
     icmp_show(config);
 }
 
-void StreamIcmp::eval(Packet*)
+NORETURN_ASSERT void StreamIcmp::eval(Packet*)
 {
     // session::process() instead
     assert(false);
index f293f86047614635e699fc2205d2cb39f522d768..bfc9124c5af446676806ce3a254d23b2a0f9bd03 100644 (file)
@@ -76,7 +76,7 @@ public:
     bool configure(SnortConfig*) override;
     void show(SnortConfig*) override;
 
-    void eval(Packet*) override;
+    NORETURN_ASSERT void eval(Packet*) override;
 
 public:
     StreamIpConfig* config;
@@ -107,7 +107,7 @@ void StreamIp::show(SnortConfig* sc)
     defrag->show(sc);
 }
 
-void StreamIp::eval(Packet*)
+NORETURN_ASSERT void StreamIp::eval(Packet*)
 {
     // session::process() instead
     assert(false);
index af3c638417c18c8ce8b18edf1f4b5f8b66fbc514..bb93eb833d06dfcb3c7a9d2ef67e74cf95ea865c 100644 (file)
@@ -44,7 +44,7 @@ public:
     void tinit() override;
     void tterm() override;
 
-    void eval(Packet*) override;
+    NORETURN_ASSERT void eval(Packet*) override;
 
 public:
     TcpStreamConfig* config;
@@ -81,7 +81,7 @@ void StreamTcp::tterm()
     TcpHAManager::tterm();
 }
 
-void StreamTcp::eval(Packet*)
+NORETURN_ASSERT void StreamTcp::eval(Packet*)
 {
     // uses session::process() instead
     assert(false);
index 36e26c1f220ceab84ab34bae934e45b9400f3c8c..db787cc6cf6d3fe9f91bbd0ac631466621ad653e 100644 (file)
@@ -62,7 +62,7 @@ public:
     ~StreamUdp();
 
     void show(SnortConfig*);
-    void eval(Packet*);
+    NORETURN_ASSERT void eval(Packet*);
 
 public:
     StreamUdpConfig* config;
@@ -84,7 +84,7 @@ void StreamUdp::show(SnortConfig*)
         udp_show(config);
 }
 
-void StreamUdp::eval(Packet*)
+NORETURN_ASSERT void StreamUdp::eval(Packet*)
 {
     // session::process() instead
     assert(false);
index 999a0358828b2fbd5e7f4564696fb0170a86c37c..be7ce750d40d06af8ee67ef555540740090deed7 100644 (file)
@@ -55,7 +55,7 @@ public:
 
     void show(SnortConfig*) override;
 
-    void eval(Packet*) override;
+    NORETURN_ASSERT void eval(Packet*) override;
 
 public:
     StreamUserConfig* config;
@@ -76,7 +76,7 @@ void StreamUser::show(SnortConfig*)
     user_show(config);
 }
 
-void StreamUser::eval(Packet*)
+NORETURN_ASSERT void StreamUser::eval(Packet*)
 {
     // session::process() instead
     assert(false);
index c9f569340ae0d42026e1652697cdff4a6f3745fc..8279cb349cf209b33a88d7bbddf8ca580c50f8b2 100644 (file)
@@ -64,7 +64,7 @@ static void help()
          << "-t: Tail mode for reading live files\n";
 }
 
-static void error(string e)
+static void error(const string& e)
 {
     if( done )
         return;
index 9059c3eadfe2c281dbc376781a3956d91f0f0d4e..e2fe041ef2648473082e5c13db680a8bd9c7fac8 100644 (file)
@@ -37,7 +37,7 @@ public:
     virtual bool convert(std::istringstream& data_stream);
 
     template<typename T>
-    bool add_or_append(const std::string opt_name, T val)
+    bool add_or_append(const std::string& opt_name, T val)
     {
         if ( table_api.option_exists(opt_name) )
         {
@@ -50,7 +50,7 @@ public:
     }
 
     template<typename T>
-    bool append_if_exists(const std::string opt_name, T val)
+    bool append_if_exists(const std::string& opt_name, T val)
     {
         if ( table_api.option_exists(opt_name) )
         {
index d1c65048af54fd9fa2cbfb814dafddfcd206823b..01c5a873aa3043e7782e38849eb870dca5c67796 100644 (file)
@@ -93,7 +93,7 @@ protected:
         return false;
     }
 
-    inline bool parse_string_option(std::string opt_name,
+    inline bool parse_string_option(const std::string& opt_name,
         std::istringstream& stream)
     {
         std::string val;
@@ -107,11 +107,11 @@ protected:
             return true;
         }
 
-        table_api.add_comment("snort.conf missing argument for: " + opt_name + " <int>");
+        table_api.add_comment("snort.conf missing argument for: " + opt_name + " <string>");
         return false;
     }
 
-    inline bool parse_int_option(std::string opt_name,
+    inline bool parse_int_option(const std::string& opt_name,
         std::istringstream& stream, bool append)
     {
         int val;
@@ -130,7 +130,7 @@ protected:
     }
 
     // parse and add a curly bracketed list to the table
-    inline bool parse_curly_bracket_list(std::string list_name, std::istringstream& stream)
+    inline bool parse_curly_bracket_list(const std::string& list_name, std::istringstream& stream)
     {
         std::string elem;
         bool retval = true;
@@ -145,14 +145,14 @@ protected:
     }
 
     // parse and add a yes/no boolean option.
-    inline bool parse_yn_bool_option(std::string opt_name, std::istringstream& stream, bool append)
+    inline bool parse_yn_bool_option(const std::string& opt_name, std::istringstream& stream, bool append, const char* yes = "yes", const char* no = "no")
     {
         std::string val;
 
         if (!(stream >> val))
             return false;
 
-        else if (!val.compare("yes"))
+        else if (!val.compare(yes))
         {
             if (append)
             {
@@ -162,7 +162,7 @@ protected:
             else
                 return table_api.add_option(opt_name, true);
         }
-        else if (!val.compare("no"))
+        else if (!val.compare(no))
         {
             if (append)
             {
@@ -178,7 +178,7 @@ protected:
     }
 
     // parse a curly bracketed bit and add it to the table
-    inline bool parse_bracketed_byte_list(std::string list_name, std::istringstream& stream)
+    inline bool parse_bracketed_byte_list(const std::string& list_name, std::istringstream& stream)
     {
         std::string elem;
         bool retval = true;
@@ -216,7 +216,7 @@ protected:
     }
 
     // parse and add a curly bracket list '{...}' which is currently unsupported in Snort++
-    inline bool parse_bracketed_unsupported_list(std::string list_name, std::istringstream& stream)
+    inline bool parse_bracketed_unsupported_list(const std::string& list_name, std::istringstream& stream)
     {
         std::string tmp = "";
         std::string elem;
@@ -234,7 +234,7 @@ protected:
         return table_api.add_option("--" + list_name, tmp);
     }
 
-    inline bool parse_deleted_option(std::string opt_name,
+    inline bool parse_deleted_option(const std::string& opt_name,
         std::istringstream& stream)
     {
         std::string val;
index ef30a61f07071dc3453f71f75d87d430727fb991..0130c4941392c8e66cd2158bba057925d9f2f02d 100644 (file)
@@ -19,7 +19,7 @@
 
 #include "data/data_types/dt_include.h"
 
-Include::Include(std::string include_name) : file_name(include_name) { }
+Include::Include(const std::string& include_name) : file_name(include_name) { }
 Include::~Include() { }
 
 // overloading operators
index 0cfef4a325be0de56f4acfb9271b08a62188d58a..4cce6888b6b0bcf032ab30c4878d4ebf1eb4389a 100644 (file)
@@ -27,7 +27,7 @@ class Include
 {
 public:
 
-    Include(std::string file_name);
+    Include(const std::string& file_name);
     virtual ~Include();
 
     // overloading operators
index 92ef8ca62806ea03d29798ae042ccc431527174b..0ad7029588bb0852fd9d7a0c4dd14156dce3b9ce 100644 (file)
@@ -36,7 +36,7 @@ Option::Option(std::string val, int d)
     }
 }
 
-Option::Option(std::string n, int val, int d)
+Option::Option(const std::string& n, int val, int d)
 {
     this->name = n;
     this->value = std::to_string(val);
@@ -44,7 +44,7 @@ Option::Option(std::string n, int val, int d)
     this->type = OptionType::INT;
 }
 
-Option::Option(std::string n, bool v, int d)
+Option::Option(const std::string& n, bool v, int d)
 {
     this->name = n;
     this->value = (v) ? "true" : "false";
@@ -52,7 +52,7 @@ Option::Option(std::string n, bool v, int d)
     this->type = OptionType::BOOL;
 }
 
-Option::Option(std::string opt_name, std::string val, int d)
+Option::Option(const std::string& opt_name, std::string val, int d)
 {
     this->name = opt_name;
     this->depth = d;
index 0260f1c09138e77b81741ddc41cf32d557344c04..b46079a6c491668af5ce0ce9fb1915f76e72dcba 100644 (file)
@@ -28,15 +28,15 @@ class Option
 {
 public:
     Option(std::string val, int depth);
-    Option(std::string name, int val, int depth);
-    Option(std::string name, bool val, int depth);
-    Option(std::string name, std::string val, int depth);
+    Option(const std::string& name, int val, int depth);
+    Option(const std::string& name, bool val, int depth);
+    Option(const std::string& name, std::string val, int depth);
     virtual ~Option();
 
-    inline std::string get_name()
+    inline const std::string& get_name()
     { return name; }
 
-    inline std::string get_value()
+    inline const std::string& get_value()
     { return value; }
 
     void set_print_whitespace(bool w)
index 4f9c602f8a04e6d385c2db2a681343f05dbf1a56..0908f707890e5bafb6f6148e42b0bf15c05e03ac 100644 (file)
@@ -34,7 +34,7 @@ Rule::~Rule()
         delete ro;
 }
 
-bool Rule::add_hdr_data(std::string data)
+bool Rule::add_hdr_data(const std::string& data)
 {
     if (num_hdr_data < hdr_data.size())
     {
@@ -49,37 +49,37 @@ bool Rule::add_hdr_data(std::string data)
     }
 }
 
-void Rule::update_rule_action(std::string new_type)
+void Rule::update_rule_action(const std::string& new_type)
 { hdr_data[0] = new_type; }
 
 void Rule::bad_rule()
 { is_bad_rule = true; }
 
-void Rule::add_comment(std::string new_comment)
+void Rule::add_comment(const std::string& new_comment)
 { comments.push_back("# " + new_comment); }
 
 void Rule::make_comment()
 { is_comment = true; }
 
-void Rule::add_option(std::string keyword)
+void Rule::add_option(const std::string& keyword)
 {
     RuleOption* r = new RuleOption(keyword);
     options.push_back(r);
 }
 
-void Rule::add_option(std::string keyword, std::string data)
+void Rule::add_option(const std::string& keyword, const std::string& data)
 {
     RuleOption* r = new RuleOption(keyword, data);
     options.push_back(r);
 }
 
-void Rule::add_suboption(std::string keyword)
+void Rule::add_suboption(const std::string& keyword)
 { options.back()->add_suboption(keyword); }
 
-void Rule::add_suboption(std::string keyword, std::string val)
+void Rule::add_suboption(const std::string& keyword, const std::string& val)
 { options.back()->add_suboption(keyword, val); }
 
-void Rule::set_curr_options_buffer(std::string new_buffer, bool add_option)
+void Rule::set_curr_options_buffer(const std::string& new_buffer, bool add_option)
 {
     /* set the buffer if
      * 1) No buffer has been set and this is not the default "pkt_data" buffer
index 9afb571da9afdf334bbbab511138e087dfe13238..c74c69c2e9ade5be7bc9f729dc3214f39c15368e 100644 (file)
@@ -33,15 +33,15 @@ public:
     Rule();
     virtual ~Rule();
 
-    bool add_hdr_data(std::string data);
-    void add_option(std::string keyword);
-    void add_option(std::string keyword, std::string data);
-    void add_suboption(std::string keyword);
-    void add_suboption(std::string keyword, std::string val);
-    void set_curr_options_buffer(std::string buffer, bool add_option);
-    void update_rule_action(std::string);
-
-    void add_comment(std::string comment);
+    bool add_hdr_data(const std::string& data);
+    void add_option(const std::string& keyword);
+    void add_option(const std::string& keyword, const std::string& data);
+    void add_suboption(const std::string& keyword);
+    void add_suboption(const std::string& keyword, const std::string& val);
+    void set_curr_options_buffer(const std::string& buffer, bool add_option);
+    void update_rule_action(const std::string&);
+
+    void add_comment(const std::string& comment);
     void bad_rule();
     void make_comment();
 
index b76a98dfb6feb8fdc4c052c3cd443645a5f6ce9c..84ff25acfd88b2b85c9ac91624d2439711a6f96a 100644 (file)
 #include "data/data_types/dt_rule_option.h"
 #include "data/data_types/dt_rule_suboption.h"
 
-RuleOption::RuleOption(std::string n) :
+RuleOption::RuleOption(const std::string& n) :
     name(n),
     value(std::string())
 { }
 
-RuleOption::RuleOption(std::string n, std::string v)
+RuleOption::RuleOption(const std::string& n, const std::string& v)
     :   name(n),
     value(v)
 { }
@@ -36,15 +36,15 @@ RuleOption::~RuleOption()
         delete rso;
 }
 
-bool RuleOption::add_suboption(std::string subopt_name)
+bool RuleOption::add_suboption(const std::string& subopt_name)
 {
     RuleSubOption* subopt = new RuleSubOption(subopt_name);
     sub_options.push_back(subopt);
     return true;
 }
 
-bool RuleOption::add_suboption(std::string subopt_name,
-    std::string val)
+bool RuleOption::add_suboption(const std::string& subopt_name,
+    const std::string& val)
 {
     RuleSubOption* subopt = new RuleSubOption(subopt_name, val);
     sub_options.push_back(subopt);
index ed399de95c80f56b864c1405ad738867d07756d7..ef94fa06045b59dfec1d92865e69a607b9d8c332 100644 (file)
@@ -29,14 +29,14 @@ class RuleSubOption;
 class RuleOption
 {
 public:
-    RuleOption(std::string name);
-    RuleOption(std::string name, std::string val);
+    RuleOption(const std::string& name);
+    RuleOption(const std::string& name, const std::string& val);
     virtual ~RuleOption();
 
-    inline std::string get_name() { return name; }
+    inline const std::string& get_name() { return name; }
 
-    bool add_suboption(std::string name);
-    bool add_suboption(std::string name, std::string val);
+    bool add_suboption(const std::string& name);
+    bool add_suboption(const std::string& name, const std::string& val);
 
     // overloading operators
     friend std::ostream& operator<<(std::ostream&, const RuleOption&);
index 6a776338f893d66181caff9eb3d241198af5f4ab..b1af9da0f946c8c5815192abda74dfd6802820e4 100644 (file)
 #include <string>
 #include "data/data_types/dt_rule_suboption.h"
 
-RuleSubOption::RuleSubOption(std::string n)
+RuleSubOption::RuleSubOption(const std::string& n)
     :   name(n),
     value(std::string())
 {
 }
 
-RuleSubOption::RuleSubOption(std::string n, std::string v)
+RuleSubOption::RuleSubOption(const std::string& n, const std::string& v)
     :   name(n),
     value(v)
 {
index d4e7d8c55b1a7c69f5439e25237fc1766b24464b..691649fe458b964d059d85816df6720f2682d632 100644 (file)
@@ -27,8 +27,8 @@
 class RuleSubOption
 {
 public:
-    RuleSubOption(std::string name);
-    RuleSubOption(std::string name, std::string val);
+    RuleSubOption(const std::string& name);
+    RuleSubOption(const std::string& name, const std::string& val);
     virtual ~RuleSubOption();
 
     // overloading operators
index 318d707dd8471a47abe676a93567b788caa3f95e..857514a3df1cf98ae91cf021818706361f864720 100644 (file)
@@ -23,7 +23,7 @@
 #include "data/data_types/dt_var.h"
 #include "data/data_types/dt_comment.h"
 
-static inline Table* find_table(std::vector<Table*> vec, std::string name)
+static inline Table* find_table(std::vector<Table*> vec, const std::string& name)
 {
     if (name.empty())
         return nullptr;
@@ -43,7 +43,7 @@ Table::Table(int d)
         Comments::CommentType::SINGLE_LINE);
 }
 
-Table::Table(std::string table_name, int d)
+Table::Table(const std::string& table_name, int d)
 {
     this->name = table_name;
     this->depth = d;
@@ -87,7 +87,7 @@ Table* Table::open_table()
     return t;
 }
 
-Table* Table::open_table(std::string table_name)
+Table* Table::open_table(const std::string& table_name)
 {
     Table* t = find_table(tables, table_name);
 
@@ -99,14 +99,14 @@ Table* Table::open_table(std::string table_name)
     return t;
 }
 
-bool Table::add_option(std::string value)
+bool Table::add_option(const std::string& value)
 {
     Option* o = new Option(value, depth + 1);
     options.push_back(o);
     return true;
 }
 
-bool Table::add_option(std::string opt_name, int value)
+bool Table::add_option(const std::string& opt_name, int value)
 {
     if (has_option(opt_name, value))
         return true;
@@ -116,7 +116,7 @@ bool Table::add_option(std::string opt_name, int value)
     return true;
 }
 
-bool Table::add_option(std::string opt_name, bool value)
+bool Table::add_option(const std::string& opt_name, bool value)
 {
     if (has_option(opt_name, value))
         return true;
@@ -126,7 +126,7 @@ bool Table::add_option(std::string opt_name, bool value)
     return true;
 }
 
-bool Table::add_option(std::string opt_name, std::string value)
+bool Table::add_option(const std::string& opt_name, const std::string& value)
 {
     if (has_option(opt_name, value))
         return true;
@@ -136,7 +136,7 @@ bool Table::add_option(std::string opt_name, std::string value)
     return true;
 }
 
-void Table::append_option(std::string opt_name, int value)
+void Table::append_option(const std::string& opt_name, int value)
 {
     if (!has_option(opt_name, value))
     {
@@ -145,7 +145,7 @@ void Table::append_option(std::string opt_name, int value)
     }
 }
 
-void Table::append_option(std::string opt_name, bool value)
+void Table::append_option(const std::string& opt_name, bool value)
 {
     if (!has_option(opt_name, value))
     {
@@ -154,7 +154,7 @@ void Table::append_option(std::string opt_name, bool value)
     }
 }
 
-void Table::append_option(std::string opt_name, std::string value)
+void Table::append_option(const std::string& opt_name, const std::string& value)
 {
     if (!has_option(opt_name, value))
     {
@@ -163,7 +163,7 @@ void Table::append_option(std::string opt_name, std::string value)
     }
 }
 
-bool Table::add_list(std::string list_name, std::string next_elem)
+bool Table::add_list(const std::string& list_name, const std::string& next_elem)
 {
     for (auto l : lists)
         if (l->get_name() == list_name)
@@ -174,7 +174,7 @@ bool Table::add_list(std::string list_name, std::string next_elem)
     return var->add_value(next_elem);
 }
 
-bool Table::has_option(const std::string opt_name)
+bool Table::has_option(const std::string& opt_name)
 {
     for (Option* o : options)
         if (!opt_name.compare(o->get_name()))
@@ -187,7 +187,7 @@ bool Table::has_option(const std::string opt_name)
     return false;
 }
 
-bool Table::get_option(const std::string opt_name, std::string& value)
+bool Table::get_option(const std::string& opt_name, std::string& value)
 {
     for (Option* o : options)
         if (!opt_name.compare(o->get_name()))
@@ -206,7 +206,7 @@ bool Table::get_option(const std::string opt_name, std::string& value)
     return false;
 }
 
-bool Table::has_option(Option opt)
+bool Table::has_option(const Option& opt)
 {
     for (Option* o : options)
         if ( (*o) == opt)
@@ -219,25 +219,25 @@ bool Table::has_option(Option opt)
     return false;
 }
 
-bool Table::has_option(std::string opt_name, int val)
+bool Table::has_option(const std::string& opt_name, int val)
 {
     Option opt(opt_name, val, depth + 1);
     return has_option(opt);
 }
 
-bool Table::has_option(std::string opt_name, bool val)
+bool Table::has_option(const std::string& opt_name, bool val)
 {
     Option opt(opt_name, val, depth + 1);
     return has_option(opt);
 }
 
-bool Table::has_option(std::string opt_name, std::string val)
+bool Table::has_option(const std::string& opt_name, const std::string& val)
 {
     Option opt(opt_name, val, depth + 1);
     return has_option(opt);
 }
 
-void Table::add_comment(std::string c)
+void Table::add_comment(const std::string& c)
 {
     comments->add_sorted_text(c);
 }
index dabe484d2351bcb1426af876f6b890957c5e66f2..a7c8d1a8fb40abbd4775422333d95e1e18339ce2 100644 (file)
@@ -32,30 +32,30 @@ class Table
 {
 public:
     Table(int depth);
-    Table(std::string name, int depth);
+    Table(const std::string& name, int depth);
     virtual ~Table();
 
-    inline std::string get_name() { return name; }
+    inline const std::string& get_name() { return name; }
     void set_one_line(bool o) { one_line = o; }
     void set_print_whitespace(bool w) { print_whitespace = w; }
     bool has_differences();
     Table* open_table();
-    Table* open_table(std::string);
-    bool add_option(std::string val);
-    bool add_option(std::string, int val);
-    bool add_option(std::string, bool val);
-    bool add_option(std::string, std::string val);
-    bool add_list(std::string, std::string next_elem);
-    void add_comment(std::string comment);
-    bool has_option(const std::string);
-    bool get_option(const std::string opt_name, std::string& value);
+    Table* open_table(const std::string&);
+    bool add_option(const std::string& val);
+    bool add_option(const std::string&, int val);
+    bool add_option(const std::string&, bool val);
+    bool add_option(const std::string&, const std::string& val);
+    bool add_list(const std::string&, const std::string& next_elem);
+    void add_comment(const std::string& comment);
+    bool has_option(const std::string&);
+    bool get_option(const std::string& opt_name, std::string& value);
 
     /*  emit options after table has finished printing.
         These options will be appended to the previous table as supposed
         to overwriting the entire table */
-    void append_option(std::string opt_name, int val);
-    void append_option(std::string opt_name, bool val);
-    void append_option(std::string opt_name, std::string val);
+    void append_option(const std::string& opt_name, int val);
+    void append_option(const std::string& opt_name, bool val);
+    void append_option(const std::string& opt_name, const std::string& val);
 
     friend std::ostream& operator<<(std::ostream&, const Table&);
 
@@ -71,10 +71,10 @@ private:
     std::vector<Variable*> lists;
     std::vector<Option*> append_options;
 
-    bool has_option(std::string name, int val);
-    bool has_option(std::string name, bool val);
-    bool has_option(std::string name, std::string val);
-    bool has_option(Option o);
+    bool has_option(const std::string& name, int val);
+    bool has_option(const std::string& name, bool val);
+    bool has_option(const std::string& name, const std::string& val);
+    bool has_option(const Option& o);
 };
 
 #endif
index 99e346a32333de6847db3f6920ca416fad4caedd..75afb32bfe9cbe40f7d36031ec1034de8db377f1 100644 (file)
 #include "data/dt_data.h"
 #include "helpers/s2l_util.h"
 
-Variable::Variable(std::string name, int depth)
+Variable::Variable(const std::string& name, int depth)
 {
     this->name = name;
     this->depth = depth;
 }
 
-Variable::Variable(std::string name)
+Variable::Variable(const std::string& name)
 {
     this->name = name;
     this->depth = 0;
@@ -130,7 +130,7 @@ bool Variable::add_value(std::string elem)
 
 static inline void print_newline(std::ostream& out,
     std::size_t& count,
-    std::string whitespace)
+    const std::string& whitespace)
 {
     out << "\n" << whitespace;
     count = whitespace.size();
index 35240d94c053a3e45e34c9ef9715c84df24e15ad..a86c9eb141e51f64c7d97976373d97b8f90500c8 100644 (file)
@@ -29,11 +29,11 @@ class DataApi;
 class Variable
 {
 public:
-    Variable(std::string name, int depth);
-    Variable(std::string name);
+    Variable(const std::string& name, int depth);
+    Variable(const std::string& name);
     virtual ~Variable();
 
-    inline std::string get_name() { return name; }
+    inline const std::string& get_name() { return name; }
     std::string get_value(DataApi*);
     bool add_value(std::string);
     
index 37c70d771ec1332094e46ff8a93f0fd19f5bc8fd..3d29155e5b67e19b43594ff07d0105a4e846449c 100644 (file)
@@ -84,7 +84,6 @@ std::string DataApi::expand_vars(const std::string& string)
     char varmodifier;
     const char* varcontents;
     std::size_t varname_completed, i, j, iv, jv, l_string, name_only;
-    char c;
     int quote_toggle = 0;
 
     if (string.empty() || string.rfind('$') == std::string::npos)
@@ -95,7 +94,7 @@ std::string DataApi::expand_vars(const std::string& string)
 
     while (i < l_string && j < std::string::npos)
     {
-        c = string[i++];
+        char c = string[i++];
 
         if (c == '"')
         {
@@ -241,13 +240,13 @@ std::string DataApi::get_file_line()
     return error_string;
 }
 
-void DataApi::error(const std::string error)
+void DataApi::error(const std::string& error)
 {
     errors->add_text(error);
     errors_count++;
 }
 
-void DataApi::failed_conversion(const std::istringstream& stream, const std::string unknown_option)
+void DataApi::failed_conversion(const std::istringstream& stream, const std::string& unknown_option)
 {
     // we only need to go through this once.
     if (!curr_data_bad)
@@ -289,7 +288,7 @@ bool DataApi::add_include_file(std::string file_name)
     return true;
 }
 
-void DataApi::developer_error(std::string error_string)
+void DataApi::developer_error(const std::string& error_string)
 {
     dev_warnings++;
 
index c97a8f644944029e3de97308315d9ad3c834b5eb..761018c8a1ac338139e2dab0f37bacc68d31c291 100644 (file)
@@ -66,7 +66,7 @@ public:
     inline static bool is_difference_mode() { return mode == PrintMode::DIFFERENCES; }
 
     // For problems with the Snort2Lua code, NOT with the snort configuration
-    static void developer_error(std::string comment);
+    static void developer_error(const std::string& comment);
 
     // given a Snort-style string, replace all of the variables with their values.
     std::string expand_vars(const std::string&);
@@ -113,10 +113,10 @@ public:
     // Call when failed to convert a line.
     // stream == the stringstream object which failed to convert
     // unknown_option is the specific option which caused the failure.
-    void failed_conversion(const std::istringstream& stream, const std::string unkown_option = "");
-    void error(const std::string);
+    void failed_conversion(const std::istringstream& stream, const std::string& unkown_option = "");
+    void error(const std::string&);
 
-    void set_current_file(std::string& file)
+    void set_current_file(const std::string& file)
     { current_file = &file; }
 
     void set_current_line(unsigned line)
@@ -142,7 +142,7 @@ private:
     Comments* unsupported;
 
     bool curr_data_bad;  // keep track whether current 'conversion' is already bad
-    std::string* current_file;
+    const std::string* current_file;
     unsigned current_line;
 
     std::string get_file_line();
index d4b8af9d7993ecd55090fa0ae8bfb50c9383ce2c..f3d4585cacd8722b00c55c67475ecc83cdea89e0 100644 (file)
@@ -87,7 +87,7 @@ void RuleApi::make_rule_a_comment()
     curr_rule->make_comment();
 }
 
-void RuleApi::bad_rule(std::istringstream& stream, std::string bad_option)
+void RuleApi::bad_rule(std::istringstream& stream, const std::string& bad_option)
 {
     if (!curr_rule)
         begin_rule();
@@ -104,7 +104,7 @@ void RuleApi::bad_rule(std::istringstream& stream, std::string bad_option)
     bad_rules->add_text("^^^^ unknown_option=" + bad_option);
 }
 
-void RuleApi::include_rule_file(std::string file_name)
+void RuleApi::include_rule_file(const std::string& file_name)
 {
     if (curr_rule)
     {
@@ -119,7 +119,7 @@ void RuleApi::include_rule_file(std::string file_name)
     }
 }
 
-void RuleApi::add_hdr_data(std::string data)
+void RuleApi::add_hdr_data(const std::string& data)
 {
     if (!curr_rule)
         begin_rule();
@@ -127,7 +127,7 @@ void RuleApi::add_hdr_data(std::string data)
     curr_rule->add_hdr_data(data);
 }
 
-void RuleApi::update_rule_action(std::string new_type)
+void RuleApi::update_rule_action(const std::string& new_type)
 {
     if (!curr_rule)
     {
@@ -140,7 +140,7 @@ void RuleApi::update_rule_action(std::string new_type)
     }
 }
 
-void RuleApi::add_option(std::string opt_name)
+void RuleApi::add_option(const std::string& opt_name)
 {
     if (!curr_rule)
         begin_rule();
@@ -148,7 +148,7 @@ void RuleApi::add_option(std::string opt_name)
     curr_rule->add_option(opt_name);
 }
 
-void RuleApi::add_option(std::string opt_name, std::string val)
+void RuleApi::add_option(const std::string& opt_name, const std::string& val)
 {
     if (!curr_rule)
         begin_rule();
@@ -156,7 +156,7 @@ void RuleApi::add_option(std::string opt_name, std::string val)
     curr_rule->add_option(opt_name, val);
 }
 
-void RuleApi::add_suboption(std::string keyword)
+void RuleApi::add_suboption(const std::string& keyword)
 {
     if (curr_rule)
         curr_rule->add_suboption(keyword);
@@ -164,8 +164,8 @@ void RuleApi::add_suboption(std::string keyword)
         DataApi::developer_error("Add some header data before adding content!!");
 }
 
-void RuleApi::add_suboption(std::string keyword,
-    std::string val)
+void RuleApi::add_suboption(const std::string& keyword,
+    const std::string& val)
 {
     if (curr_rule)
         curr_rule->add_suboption(keyword, val);
@@ -173,7 +173,7 @@ void RuleApi::add_suboption(std::string keyword,
         DataApi::developer_error("Add some header data before adding content!!");
 }
 
-void RuleApi::set_curr_options_buffer(std::string buffer, bool add_option)
+void RuleApi::set_curr_options_buffer(const std::string& buffer, bool add_option)
 {
     if (curr_rule)
         curr_rule->set_curr_options_buffer(buffer, add_option);
@@ -181,7 +181,7 @@ void RuleApi::set_curr_options_buffer(std::string buffer, bool add_option)
         DataApi::developer_error("Add some header data before adding content!!");
 }
 
-void RuleApi::add_comment(std::string comment)
+void RuleApi::add_comment(const std::string& comment)
 {
     if (!curr_rule)
         begin_rule();
index afa38830e60f5e0c6105ca3089dd04492e561723..cd394963a988f9ed2501524da35969b6f8230d2f 100644 (file)
@@ -56,20 +56,20 @@ public:
     void swap_rules(std::vector<Rule*>&); // FIXIT-L ?
 
     // include a snort-style rule file!
-    void include_rule_file(std::string file_name);
+    void include_rule_file(const std::string& file_name);
 
     // Create a given rule
-    void add_hdr_data(std::string data);
-    void update_rule_action(std::string new_type);
-    void add_option(std::string keyword);
-    void add_option(std::string keyword, std::string val);
-    void add_suboption(std::string keyword);
-    void add_suboption(std::string keyword, std::string val);
-    void set_curr_options_buffer(std::string buffer, bool add_option=false);
-
-    void add_comment(std::string coment);
+    void add_hdr_data(const std::string& data);
+    void update_rule_action(const std::string& new_type);
+    void add_option(const std::string& keyword);
+    void add_option(const std::string& keyword, const std::string& val);
+    void add_suboption(const std::string& keyword);
+    void add_suboption(const std::string& keyword, const std::string& val);
+    void set_curr_options_buffer(const std::string& buffer, bool add_option=false);
+
+    void add_comment(const std::string& comment);
     void make_rule_a_comment();
-    void bad_rule(std::istringstream& stream, std::string bad_option);
+    void bad_rule(std::istringstream& stream, const std::string& bad_option);
 
 private:
     static std::size_t error_count;
index 54523ba23246b502e1b2cefec72682662cd15f28..40439da4cc7c01615739e0cd7d4d0a92eda8520c 100644 (file)
@@ -164,7 +164,7 @@ void TableApi::close_table()
 }
 
 template<typename T>
-bool TableApi::do_add_option(const std::string opt_name, T val, const std::string s_val)
+bool TableApi::do_add_option(const std::string& opt_name, T val, const std::string& s_val)
 {
     if ( should_delegate() )
         return delegate->add_option(opt_name, val);
@@ -181,7 +181,7 @@ bool TableApi::do_add_option(const std::string opt_name, T val, const std::strin
     return true;
 }
 
-bool TableApi::add_option(const std::string val)
+bool TableApi::add_option(const std::string& val)
 {
     if ( should_delegate() )
         return delegate->add_option(val);
@@ -198,13 +198,13 @@ bool TableApi::add_option(const std::string val)
     return true;
 }
 
-bool TableApi::add_option(const std::string option_name, const std::string val)
+bool TableApi::add_option(const std::string& option_name, const std::string& val)
 { return do_add_option(option_name, val, val); }
 
-bool TableApi::add_option(const std::string option_name, const int val)
+bool TableApi::add_option(const std::string& option_name, const int val)
 { return do_add_option(option_name, val, std::to_string(val)); }
 
-bool TableApi::add_option(const std::string option_name, const bool val)
+bool TableApi::add_option(const std::string& option_name, const bool val)
 { return do_add_option(option_name, val, std::to_string(val)); }
 
 // compilers are fickle and dangerous creatures.  Ensure a literal gets
@@ -212,7 +212,7 @@ bool TableApi::add_option(const std::string option_name, const bool val)
 bool TableApi::add_option(const char* const v)
 { return add_option(std::string(v)); }
 
-bool TableApi::add_option(const std::string name, const char* const v)
+bool TableApi::add_option(const std::string& name, const char* const v)
 { return add_option(name, std::string(v)); }
 
 void TableApi::create_append_data(std::string& fqn, Table*& t)
@@ -238,7 +238,7 @@ void TableApi::create_append_data(std::string& fqn, Table*& t)
 }
 
 template<typename T>
-void TableApi::do_append_option(const std::string option_name, const T val, const std::string s_val)
+void TableApi::do_append_option(const std::string& option_name, const T val, const std::string& s_val)
 {
     if ( should_delegate() )
     {
@@ -264,16 +264,16 @@ void TableApi::do_append_option(const std::string option_name, const T val, cons
             + option_name + " = " + s_val);
 }
 
-void TableApi::append_option(const std::string option_name, const std::string val)
+void TableApi::append_option(const std::string& option_name, const std::string& val)
 { do_append_option(option_name, val, val); }
 
-void TableApi::append_option(const std::string option_name, const int val)
+void TableApi::append_option(const std::string& option_name, const int val)
 { do_append_option(option_name, val, std::to_string(val)); }
 
-void TableApi::append_option(const std::string option_name, const bool val)
+void TableApi::append_option(const std::string& option_name, const bool val)
 { do_append_option(option_name, val, std::to_string(val)); }
 
-void TableApi::append_option(const std::string name, const char* const v)
+void TableApi::append_option(const std::string& name, const char* const v)
 { append_option(name, std::string(v)); }
 
 bool TableApi::add_list(std::string list_name, std::string next_elem)
@@ -321,7 +321,7 @@ bool TableApi::add_comment(std::string comment)
     return true;
 }
 
-bool TableApi::option_exists(const std::string name)
+bool TableApi::option_exists(const std::string& name)
 {
     if ( should_delegate() )
         return delegate->option_exists(name);
@@ -411,7 +411,7 @@ void TableApi::swap_tables(std::vector<Table*>& new_tables)
     tables.swap(new_tables);
 }
 
-bool TableApi::get_option_value(const std::string name, std::string& value)
+bool TableApi::get_option_value(const std::string& name, std::string& value)
 {
     if ( should_delegate() )
         return delegate->get_option_value(name, value);
index 3cac643f2e75468ec4548a30d8c0e4fa50282055..7d51f0d736ffab7839f2f924010bd1697f33f9d3 100644 (file)
@@ -102,21 +102,21 @@ public:
  * The add_option variants without an option name are used to add "anonymous" options
  * for the purpose of creating arrays.
  */
-    bool add_option(const std::string val);
+    bool add_option(const std::string& val);
     bool add_option(const char* const v);
-    bool add_option(const std::string opt_name, const std::string val);
-    bool add_option(const std::string opt_name, const int val);
-    bool add_option(const std::string opt_name, const bool val);
-    bool add_option(const std::string opt_name, const char* const v);
+    bool add_option(const std::string& opt_name, const std::string& val);
+    bool add_option(const std::string& opt_name, const int val);
+    bool add_option(const std::string& opt_name, const bool val);
+    bool add_option(const std::string& opt_name, const char* const v);
 
 // sometimes, you may need to create a default option, before overwriting that
 // option later. For instance, if you have a default table, and then you
 // need to overwrite a single option in that default table, you can use these
 // methods to overwrite that option.
-    void append_option(const std::string opt_name, const std::string val);
-    void append_option(const std::string opt_name, const int val);
-    void append_option(const std::string opt_name, const bool val);
-    void append_option(const std::string opt_name, const char* const v);
+    void append_option(const std::string& opt_name, const std::string& val);
+    void append_option(const std::string& opt_name, const int val);
+    void append_option(const std::string& opt_name, const bool val);
+    void append_option(const std::string& opt_name, const char* const v);
 
 // add an option with a list of variables -->  table = { name = 'elem1 elem2 ...' }
 // corresponds to Parameter::PT_MULTI
@@ -131,17 +131,17 @@ public:
     bool add_unsupported_comment(std::string unsupported_var);
 
 // return true if this name exists as an option name for the selected table
-    bool option_exists(const std::string name);
+    bool option_exists(const std::string& name);
 // return true if this name exists as an option name for the selected table
 // and value updated successfully
-    bool get_option_value(const std::string name, std::string& value);
+    bool get_option_value(const std::string& name, std::string& value);
 
 private:
     template<typename T>
-    bool do_add_option(const std::string opt_name, const T val, const std::string s_val);
+    bool do_add_option(const std::string& opt_name, const T val, const std::string& s_val);
 
     template<typename T> 
-    void do_append_option(const std::string opt_name, const T val, const std::string s_val);
+    void do_append_option(const std::string& opt_name, const T val, const std::string& s_val);
 
     void create_append_data(std::string& fqn, Table*& t);
     bool should_delegate() const;
index c05c80fc3eb332f1380645f2f640f58e28a967e7..8c0834056370b544fc6d8ab21f1f76c92e04485b 100644 (file)
@@ -42,8 +42,8 @@ bool Converter::convert_rules_mult_files = true;
 bool Converter::convert_conf_mult_files = true;
 
 Converter::Converter()
-    :   state(nullptr),
-    table_api(&top_table_api, table_delegation),
+    :   table_api(&top_table_api, table_delegation),
+    state(nullptr),
     error(false),
     multiline_state(false)
 {
@@ -74,7 +74,7 @@ void Converter::reset_state()
     rule_api.reset_state();
 }
 
-int Converter::parse_include_file(std::string input_file)
+int Converter::parse_include_file(const std::string& input_file)
 {
     std::vector<Variable*> vars;
     std::vector<Table*> tables;
@@ -164,7 +164,7 @@ int Converter::parse_include_file(std::string input_file)
     return rc;
 }
 
-int Converter::parse_file(std::string input_file, bool reset)
+int Converter::parse_file(const std::string& input_file, bool reset)
 {
     std::ifstream in;
     std::string orig_text;
@@ -334,8 +334,8 @@ void Converter::add_bindings()
         binders.pop_back();
 }
 
-int Converter::convert(std::string input,
-    std::string output_file,
+int Converter::convert(const std::string& input,
+    const std::string& output_file,
     std::string rule_file,
     std::string error_file)
 {
index 76ecbf283665302f1853aa43a6e7a1816b65c8c0..bf8e47dcef8cb29b692a7387732a8a18bded4ac7 100644 (file)
@@ -67,20 +67,20 @@ public:
     Binder& make_binder();
     Binder& make_pending_binder(int ips_policy_id);
 
-    int convert(std::string input,
-        std::string output,
+    int convert(const std::string& input,
+        const std::string& output,
         std::string rules,         // defaults to output_file
         std::string errors);         // defaults to output_file
 
     // parse a file without creating an entirely new Lua configuration
-    int parse_include_file(std::string input_file);
+    int parse_include_file(const std::string& input_file);
 
     // set the next parsing state.
     void set_state(ConversionState* c, bool delete_old = true);
     // reset the current parsing state
     void reset_state();
     // parse an include file.  Use this function to ensure all set options are properly
-    int parse_file(std::string file, bool reset = true);
+    int parse_file(const std::string& file, bool reset = true);
 
     bool failed_conversions() const
     { return data_api.failed_conversions() || rule_api.failed_conversions(); }
index b9154b8e80e8825bf97be16460097f5d9c94fa04..25c506704fa82aa7dc0e897e5643224cdc02a66d 100644 (file)
@@ -143,7 +143,7 @@ std::string& sanitize_lua_string(std::string& s)
     return s;
 }
 
-std::size_t get_substr_length(std::string str, std::size_t max_length)
+std::size_t get_substr_length(const std::string& str, std::size_t max_length)
 {
     std::size_t str_len;
 
@@ -164,7 +164,7 @@ std::size_t get_substr_length(std::string str, std::size_t max_length)
 
 bool get_string(std::istringstream& stream,
     std::string& option,
-    const std::string delimiters)
+    const std::string& delimiters)
 {
     if (delimiters.empty() || !stream.good())
     {
@@ -247,7 +247,7 @@ std::string get_rule_option_args(std::istringstream& stream)
 }
 
 std::string rule_option_find_val(std::istringstream& data_stream,
-    std::string opt_name)
+    const std::string& opt_name)
 {
     std::string rule_keyword;
     std::string val = std::string();
index 6514a15c5408c1f06c1d454f25417e758bf26c5d..b3d023b3235a3033332f4cf960e2bd6f3bf031b6 100644 (file)
@@ -72,7 +72,7 @@ bool file_exists(const std::string& name);
  */
 bool get_string(std::istringstream& data_stream,
     std::string& option,
-    const std::string delimiters);
+    const std::string& delimiters);
 
 /*
  * Returns the rest of the data_streams data as one argument.
@@ -100,7 +100,7 @@ std::string get_rule_option_args(std::istringstream& data_stream);
  *
  */
 std::string rule_option_find_val(std::istringstream& data_stream,
-    std::string opt_name);
+    const std::string& opt_name);
 
 // remove any ']]' and double spaces from this string.
 std::string& sanitize_lua_string(std::string& s);
@@ -108,7 +108,7 @@ std::string& sanitize_lua_string(std::string& s);
 // find the location of the first space before max_str_length.
 // if no space exists before max_str_length, return the first space
 // after max_length. Otherwise, return std::string::npos
-std::size_t get_substr_length(std::string s, std::size_t max_length);
+std::size_t get_substr_length(const std::string& s, std::size_t max_length);
 
 bool case_compare(std::string, std::string);
 bool is_regular_file(std::string& path);
index 715e5c8a948cc4a31421482029364eacb5e4f10c..342659d10e9eb21f06a6ae28ac20313409e50be1 100644 (file)
@@ -278,8 +278,6 @@ void AttributeTable::parse_os()
                     "hosts.tcp_policy = hpux11");
                 table_api.add_option("tcp_policy", "hpux11");
             }
-            else if (!policy.compare("macos"))
-                table_api.add_option("tcp_policy", "macos");
 
             else if (!policy.compare("unknown"))
                 table_api.add_deleted_comment("<STREAM_POLICY>unknown</STREAM_POLICY>");
index 5d036bd0e49a382a379e3a5d24fa89cfdc0a2cce..070bc5a4154726df46b5e345d45ad867defe5952 100644 (file)
@@ -31,7 +31,7 @@ namespace
 class Filter : public ConversionState
 {
 public:
-    Filter(Converter& c, std::string s) : ConversionState(c), type(s) { }
+    Filter(Converter& c, const std::string& s) : ConversionState(c), type(s) { }
     virtual ~Filter() { }
     virtual bool convert(std::istringstream& data_stream);
 
index b83e88a136b1184919369ba6b48997cbbce2c426..e43b92e887641e8e9245ba92bde7e00e1691c17b 100644 (file)
@@ -15,7 +15,7 @@
 // with this program; if not, write to the Free Software Foundation, Inc.,
 // 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 //--------------------------------------------------------------------------
-// out_sfunified2.cc author Carter Waxman <cwaxman@cisco.com>
+// out_sfunified2.cc author Michael Altizer <mialtize@cisco.com>
 
 #include <sstream>
 
@@ -28,25 +28,77 @@ namespace output
 {
     namespace
     {
-        //FIXIT-L add when available
-        static std::string header = "output sf_unified2: ";
-
-        template<std::string* header_text>
-        static ConversionState* unified2_ctor(Converter& c)
-        { return new UnsupportedState<header_text>(c); }
+        class SfUnified2 : public ConversionState
+        {
+        public:
+            SfUnified2(Converter& c) : ConversionState(c) { }
+            virtual ~SfUnified2() { }
+            virtual bool convert(std::istringstream& data_stream);
+        };
 
     } // namespace
 
+
+    bool SfUnified2::convert(std::istringstream& data_stream)
+    {
+        std::string args;
+        bool retval = true;
+
+        table_api.open_table("firewall_logging");
+
+        while (std::getline(data_stream, args, ','))
+        {
+            bool tmpval = true;
+            std::string keyword;
+
+            std::istringstream arg_stream(args);
+            arg_stream >> keyword;
+
+            if (keyword.empty())
+                continue;
+
+            else if (!keyword.compare("nostamp"))
+                tmpval = table_api.add_option("no_timestamp", true);
+
+            else if (!keyword.compare("mpls_event_types"))
+                tmpval = table_api.add_option("mpls_event_types", true);
+
+            else if (!keyword.compare("vlan_event_types"))
+                tmpval = table_api.add_option("vlan_event_types", true);
+
+            else if (!keyword.compare("filename"))
+                tmpval = parse_string_option("filename", arg_stream);
+
+            else if (!keyword.compare("limit"))
+                tmpval = parse_int_option("file_size_limit", arg_stream, false);
+
+            else
+                tmpval = false;
+
+            if (retval)
+                retval = tmpval;
+        }
+
+        return retval;
+    }
+
     /**************************
      *******  A P I ***********
      **************************/
 
-    static const ConvertMap unified2_api =
+    static ConversionState* ctor(Converter& c)
+    {
+        c.get_table_api().open_top_level_table("firewall_logging"); // in case there are no arguments
+        c.get_table_api().close_table();
+        return new SfUnified2(c);
+    }
+
+    static const ConvertMap sfunified2_api =
     {
         "sf_unified2",
-        unified2_ctor<&header>,
+        ctor,
     };
 
-    const ConvertMap* sfunified2_map = &unified2_api;
+    const ConvertMap* sfunified2_map = &sfunified2_api;
 } // output namespace
 
index a0578682ab6ae56fec06eff217bc21894b7273db..98a163fec6da8c5800173df2cd621587a8102fce 100644 (file)
@@ -73,11 +73,6 @@ bool AlertSyslog::convert(std::istringstream& data_stream)
             table_api.add_diff_option_comment("log_auth", "facility = auth");
             tmpval = table_api.add_option("facility", "auth");
         }
-        else if (!keyword.compare("log_auth"))
-        {
-            table_api.add_diff_option_comment("log_auth", "facility = auth");
-            tmpval = table_api.add_option("facility", "auth");
-        }
         else if (!keyword.compare("log_authpriv"))
         {
             table_api.add_diff_option_comment("log_authpriv", "facility = authpriv");
index 75eea5e684be22b9f138311d409f2c448fc0dd5b..86e072c99f7b0368496a0526b6d5b331bb55e3d3 100644 (file)
@@ -42,7 +42,6 @@ bool AlertTest::convert(std::istringstream& data_stream)
     std::string keyword;
     std::string args = std::string();
     bool retval = true;
-    std::string units;
 
     table_api.open_top_level_table("alert_test");
 
index 99b5d404dc23fb0416c61252fa736e95eae40e3d..9e56a97f761aa289558f354d5f650b14df5a251f 100644 (file)
@@ -31,18 +31,18 @@ public:
     virtual bool convert(std::istringstream& data);
 
 private:
-    bool add_deleted_comment_to_defaults(std::string option);
-    bool add_option_to_all(std::string option, const bool val, bool co_only);
-    bool add_option_to_all(std::string option, const int val, bool co_only);
-    bool add_option_to_type(std::string type, std::string option, std::string value);
-    bool add_option_to_type(std::string type, std::string option);
-    bool parse_int_and_add_to_all(std::string opt_name, std::istringstream& stream, bool co_only);
-    bool parse_string_and_add_to_type(std::string type, std::string opt_name,
+    bool add_deleted_comment_to_defaults(const std::string& option);
+    bool add_option_to_all(const std::string& option, const bool val, bool co_only);
+    bool add_option_to_all(const std::string& option, const int val, bool co_only);
+    bool add_option_to_type(const std::string& type, const std::string& option, const std::string& value);
+    bool add_option_to_type(const std::string& type, const std::string& option);
+    bool parse_int_and_add_to_all(const std::string& opt_name, std::istringstream& stream, bool co_only);
+    bool parse_string_and_add_to_type(const std::string& type, const std::string& opt_name,
         std::istringstream& stream);
 };
 
 
-bool Dcerpc::add_option_to_all(std::string option, const bool val, bool co_only)
+bool Dcerpc::add_option_to_all(const std::string& option, const bool val, bool co_only)
 {
     bool tmpval = true;
 
@@ -62,7 +62,7 @@ bool Dcerpc::add_option_to_all(std::string option, const bool val, bool co_only)
     return tmpval;
 }
 
-bool Dcerpc::add_option_to_all(std::string option, const int val, bool co_only)
+bool Dcerpc::add_option_to_all(const std::string& option, const int val, bool co_only)
 {
     bool tmpval = true;
 
@@ -83,11 +83,9 @@ bool Dcerpc::add_option_to_all(std::string option, const int val, bool co_only)
     return tmpval;
 }
 
-bool Dcerpc::add_option_to_type(std::string type, std::string option, const std::string val)
+bool Dcerpc::add_option_to_type(const std::string& type, const std::string& option, const std::string& val)
 {
-    bool tmpval = true;
-
-    tmpval = add_option_to_table(table_api, "dce_" + type, option, val);
+    bool tmpval = add_option_to_table(table_api, "dce_" + type, option, val);
     for (int i=0; i < DcerpcServer::get_binding_id(); i++)
     {
         tmpval = add_option_to_table(table_api, "dce_" + type + std::to_string(i), option, val) &&
@@ -97,7 +95,7 @@ bool Dcerpc::add_option_to_type(std::string type, std::string option, const std:
     return tmpval;
 }
 
-bool Dcerpc::add_option_to_type(std::string type, std::string option)
+bool Dcerpc::add_option_to_type(const std::string& type, const std::string& option)
 {
     bool tmpval = add_option_to_table(table_api, "dce_" + type, option, true);
     for (int i=0; i < DcerpcServer::get_binding_id(); i++)
@@ -109,7 +107,7 @@ bool Dcerpc::add_option_to_type(std::string type, std::string option)
     return tmpval;
 }
 
-bool Dcerpc::add_deleted_comment_to_defaults(std::string option)
+bool Dcerpc::add_deleted_comment_to_defaults(const std::string& option)
 {
     bool tmpval = true;
 
@@ -120,7 +118,7 @@ bool Dcerpc::add_deleted_comment_to_defaults(std::string option)
     return tmpval;
 }
 
-bool Dcerpc::parse_int_and_add_to_all(std::string opt_name, std::istringstream& stream, bool
+bool Dcerpc::parse_int_and_add_to_all(const std::string& opt_name, std::istringstream& stream, bool
     co_only)
 {
     int val;
@@ -133,7 +131,7 @@ bool Dcerpc::parse_int_and_add_to_all(std::string opt_name, std::istringstream&
     return false;
 }
 
-bool Dcerpc::parse_string_and_add_to_type(std::string type, std::string opt_name,
+bool Dcerpc::parse_string_and_add_to_type(const std::string& type, const std::string& opt_name,
     std::istringstream& stream)
 {
     std::string val;
index 8ba75f2ca216c12de2988ddb272ff12dd2c9bb07..26cfa42fd5ae2f1006b8545870215bf348a6c189 100644 (file)
@@ -64,8 +64,8 @@ std::map <std::string, std::vector<uint16_t> > default_ports
 // Utility functions
 ////////////////////////
 
-bool add_option_to_table(TableApi& table_api,std::string table_name, std::string
-    option, const std::string val)
+bool add_option_to_table(TableApi& table_api, const std::string& table_name,
+    const std::string& option, const std::string& val)
 {
     table_api.open_table(table_name);
     bool tmpval = table_api.add_option(option, val);
@@ -74,8 +74,8 @@ bool add_option_to_table(TableApi& table_api,std::string table_name, std::string
     return tmpval;
 }
 
-bool add_option_to_table(TableApi& table_api,std::string table_name, std::string
-    option, const int val)
+bool add_option_to_table(TableApi& table_api, const std::string& table_name,
+    const std::string& option, const int val)
 {
     table_api.open_table(table_name);
     bool tmpval = table_api.add_option(option, val);
@@ -84,8 +84,8 @@ bool add_option_to_table(TableApi& table_api,std::string table_name, std::string
     return tmpval;
 }
 
-bool add_option_to_table(TableApi& table_api,std::string table_name, std::string
-    option, const bool val)
+bool add_option_to_table(TableApi& table_api, const std::string& table_name,
+    const std::string& option, const bool val)
 {
     table_api.open_table(table_name);
     bool tmpval = table_api.add_option(option, val);
@@ -94,7 +94,8 @@ bool add_option_to_table(TableApi& table_api,std::string table_name, std::string
     return tmpval;
 }
 
-bool add_deleted_comment_to_table(TableApi& table_api, std::string table_name, std::string option)
+bool add_deleted_comment_to_table(TableApi& table_api, const std::string& table_name,
+    const std::string& option)
 {
     table_api.open_table(table_name);
     bool tmpval = table_api.add_deleted_comment(option);
@@ -223,7 +224,7 @@ bool DcerpcServer::parse_smb_file_inspection(std::istringstream& data_stream)
     return tmpval;
 }
 
-void DcerpcServer::add_default_ports(std::string type,  std::map<std::string,Binder*> bind)
+void DcerpcServer::add_default_ports(const std::string& type,  std::map<std::string,Binder*> bind)
 {
     for (auto port : default_ports[type])
     {
@@ -232,7 +233,7 @@ void DcerpcServer::add_default_ports(std::string type,  std::map<std::string,Bin
 }
 
 // add single port / range
-bool DcerpcServer::parse_and_add_ports(std::string ports, std::string type, std::map<std::string,
+bool DcerpcServer::parse_and_add_ports(const std::string& ports, const std::string& type, std::map<std::string,
     Binder*> bind, bool bind_port_to_tcp)
 {
     if (ports.empty())
@@ -459,14 +460,14 @@ bool DcerpcServer::parse_detect(std::istringstream& data_stream,
 
         case DCE_DETECT_LIST_STATE__PORTS_END:
         {
-            char c;
-
             if (one_type)
             {
                 return true;
             }
             else // wait for list terminator or item separator
             {
+                char c;
+
                 if (!data_stream.get(c))
                     return false;
 
@@ -615,7 +616,7 @@ bool DcerpcServer::parse_nets(std::istringstream& data_stream, std::map<std::str
     return true;
 }
 
-bool DcerpcServer::add_option_to_transports(std::string option, std::string value, bool co_only)
+bool DcerpcServer::add_option_to_transports(const std::string& option, const std::string& value, bool co_only)
 {
     bool retval = true;
 
index d328cdbde9dc1ad1a48c78f9fe1eafbe6d04bec5..7a3aa6886fa94abe1a3b0f78ad728eb33a9436e6 100644 (file)
@@ -47,14 +47,14 @@ private:
     bool parse_smb_file_inspection(std::istringstream& data_stream);
     bool parse_detect(std::istringstream& data_stream, std::map<std::string, Binder*> bind, bool
         is_detect);
-    void add_default_ports(std::string type, std::map<std::string, Binder*> bind);
-    bool parse_and_add_ports(std::string ports, std::string type,  std::map<std::string,
+    void add_default_ports(const std::string& type, std::map<std::string, Binder*> bind);
+    bool parse_and_add_ports(const std::string& ports, const std::string& type,  std::map<std::string,
         Binder*> bind, bool bind_port_to_tcp);
     bool init_net_created_table();
     bool init_new_tables(bool is_default);
     bool parse_nets(std::istringstream& data_stream, std::map<std::string,
         Binder*> bind);
-    bool add_option_to_transports(std::string option, std::string value, bool co_only);
+    bool add_option_to_transports(const std::string& option, const std::string& value, bool co_only);
     std::map<std::string, bool> detect_ports_set;
     std::map<std::string, bool> autodetect_ports_set;
     std::map<std::string, std::string> table_name;
@@ -62,16 +62,16 @@ private:
 };
 
 bool add_option_to_table(
-    TableApi&, std::string table_name, std::string option, const std::string val);
+    TableApi&, const std::string& table_name, const std::string& option, const std::string& val);
 
 bool add_option_to_table(
-    TableApi&, std::string table_name, std::string option, const int val);
+    TableApi&, const std::string& table_name, const std::string& option, const int val);
 
 bool add_option_to_table(
-    TableApi&, std::string table_name, std::string option, const bool val);
+    TableApi&, const std::string& table_name, const std::string& option, const bool val);
 
 bool add_deleted_comment_to_table(
-    TableApi&, std::string table_name, std::string option);
+    TableApi&, const std::string& table_name, const std::string& option);
 } // namespace dce
 } // namespace preprocessors
 
index 56efe396dc4815b3617b9c7a3d3a4fd31c766972..f5305547557259b2fdf4edf3c2b661673947831f 100644 (file)
@@ -98,7 +98,6 @@ bool Dnp3::convert(std::istringstream& data_stream)
         }
         else if (!keyword.compare("ports"))
         {
-            std::string tmp = "";
             table_api.add_diff_option_comment("ports", "bindings");
 
             if ((data_stream >> keyword) && !keyword.compare("{"))
index 3ee456a644545f5c7f7615dfaa8070d5c7f6fd12..ee2a7b324c4d5196e8295e329e843cf6ba2fafce 100644 (file)
@@ -67,7 +67,6 @@ bool Dns::convert(std::istringstream& data_stream)
 
         else if (!keyword.compare("ports"))
         {
-            std::string tmp = "";
             table_api.add_diff_option_comment("ports", "bindings");
 
             if ((data_stream >> keyword) && !keyword.compare("{"))
index eebec7ef11199f70a9411fe2167d567f56d312ea..eabe1c5d7cbde320ce6ce127a84ae0ceb15ac2c4 100644 (file)
@@ -15,7 +15,7 @@
 // with this program; if not, write to the Free Software Foundation, Inc.,
 // 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 //--------------------------------------------------------------------------
-// pps_firewall.cc author Carter Waxman <cwaxman@cisco.com>
+// pps_firewall.cc author Michael Altizer <mialtize@cisco.com>
 
 #include <sstream>
 #include <vector>
 
 namespace preprocessors
 {
+    namespace
+    {
+        class Firewall : public ConversionState
+        {
+        public:
+            Firewall(Converter& c) : ConversionState(c) { }
+            ~Firewall() { }
+            bool convert(std::istringstream& data) override;
+        };
+    } // namespace
 
-//FIXIT-L add when supported
-static std::string header = "preprocessor firewall: ";
+    bool Firewall::convert(std::istringstream& data_stream)
+    {
+        bool retval = true;
 
-static ConversionState* ctor(Converter& c)
-{ return new UnsupportedState<&header>(c); }
+        table_api.open_table("firewall");
 
-static const ConvertMap firewall_api =
-{
-    "firewall",
-    ctor,
-};
+        std::string keyword;
+        while (data_stream >> keyword)
+        {
+            bool tmpval = true;
+
+            if (!keyword.compare("fw_rule_path"))
+                tmpval = parse_string_option("fw_rule_path", data_stream);
+            else if (!keyword.compare("qos_rule_path"))
+                tmpval = parse_string_option("qos_rule_path", data_stream);
+            else if (!keyword.compare("dns_rule_path"))
+                tmpval = parse_string_option("dns_rule_path", data_stream);
+            else if (!keyword.compare("url_rule_path"))
+                tmpval = parse_string_option("url_rule_path", data_stream);
+            else if (!keyword.compare("file_rule_path"))
+                // FIXIT-L This is currently just not implemented, not actually deleted
+                tmpval = parse_deleted_option("file_rule_path", data_stream);
+            else if (!keyword.compare("whitelist"))
+                tmpval = parse_string_option("whitelist_path", data_stream);
+            else if (!keyword.compare("blacklist"))
+                tmpval = parse_string_option("blacklist_path", data_stream);
+            else if (!keyword.compare("fw_log_name"))
+                tmpval = parse_deleted_option("fw_log_name", data_stream);
+            else if (!keyword.compare("fw_log_time"))
+                tmpval = parse_int_option("fw_roll_log_interval", data_stream, false);
+            else if (!keyword.compare("fw_log_size"))
+                tmpval = parse_int_option("max_log_file_size", data_stream, false);
+            else if (!keyword.compare("fw_log_dns"))
+                tmpval = table_api.add_option("dns_log_enabled", true);
+            else if (!keyword.compare("fw_log_url"))
+                tmpval = table_api.add_option("url_log_enabled", true);
+            else if (!keyword.compare("fw_url_file"))
+                tmpval = parse_deleted_option("fw_url_file", data_stream);
+            else if (!keyword.compare("fw_url_perf"))
+                tmpval = parse_string_option("url_perf_filename", data_stream);
+            else if (!keyword.compare("fw_url_len"))
+                tmpval = parse_int_option("max_url_log_len", data_stream, false);
+            else if (!keyword.compare("enable_url_cache_miss"))
+                tmpval = table_api.add_option("url_cache_miss_enabled", true);
+            else if (!keyword.compare("fw_user_stats"))
+                tmpval = parse_string_option("user_stats_filename", data_stream);
+            else if (!keyword.compare("fw_app_stats"))
+                tmpval = parse_string_option("app_stats_filename", data_stream);
+            else if (!keyword.compare("fw_qos_rule_stats"))
+                tmpval = parse_string_option("qos_rule_stats_filename", data_stream);
+            else if (!keyword.compare("fw_intf_stats"))
+                tmpval = parse_string_option("intf_stats_filename", data_stream);
+            else if (!keyword.compare("fw_stats_time"))
+                tmpval = parse_int_option("fw_stats_interval", data_stream, false);
+            else if (!keyword.compare("fw_urlq_memcap"))
+                tmpval = parse_int_option("url_queue_memcap", data_stream, false);
+            else if (!keyword.compare("fw_urlc_memcap"))
+                tmpval = parse_int_option("url_cache_memcap", data_stream, false);
+            else if (!keyword.compare("fw_usrq_memcap"))
+                tmpval = parse_int_option("user_queue_memcap", data_stream, false);
+            else if (!keyword.compare("fw_usrc_memcap"))
+                tmpval = parse_int_option("user_cache_memcap", data_stream, false);
+            else if (!keyword.compare("fw_malwq_memcap"))
+                tmpval = parse_int_option("malware_queue_memcap", data_stream, false);
+            else if (!keyword.compare("fw_malwc_memcap"))
+                tmpval = parse_int_option("malware_cache_memcap", data_stream, false);
+            else if (!keyword.compare("fw_archiveq_memcap"))
+                tmpval = parse_int_option("archive_queue_memcap", data_stream, false);
+            else if (!keyword.compare("fw_archivec_memcap"))
+                tmpval = parse_int_option("archive_cache_memcap", data_stream, false);
+            else if (!keyword.compare("fw_log_iprep"))
+                tmpval = parse_yn_bool_option("iprep_logging_enabled", data_stream, false, "enable", "disable");
+            else if (!keyword.compare("fw_log_file_id"))
+                tmpval = parse_deleted_option("fw_log_file_id", data_stream);
+            else if (!keyword.compare("fw_skip_cert"))
+                tmpval = table_api.add_option("skip_https_cert", true);
+            else if (!keyword.compare("fw_log_host"))
+                tmpval = table_api.add_option("log_host_only", true);
+            else if (!keyword.compare("fw_ips_classic"))
+                tmpval = table_api.add_option("log_orig_ips", true);
+            else if (!keyword.compare("fw_required"))
+                tmpval = table_api.add_option("externally_required", true);
+            else if (!keyword.compare("ha_http"))
+                tmpval = parse_int_option("ha_http_len", data_stream, false);
+            else if (!keyword.compare("fw_bypass_time"))
+                tmpval = parse_int_option("bypass_timeout", data_stream, false);
+            else if (!keyword.compare("fw_file_memcap"))
+                tmpval = parse_int_option("file_queue_memcap", data_stream, false);
+            else if (!keyword.compare("fw_file_geo4map"))
+                tmpval = parse_string_option("geo_ipv4_map_path", data_stream);
+            else if (!keyword.compare("fw_file_geo6map"))
+                tmpval = parse_string_option("geo_ipv6_map_path", data_stream);
+            else if (!keyword.compare("fw_file_storage_path"))
+                tmpval = parse_string_option("file_storage_path", data_stream);
+            else if (!keyword.compare("fw_file_extraction_mode"))
+                tmpval = parse_int_option("file_extraction_mode", data_stream, false);
+            else if (!keyword.compare("file_sandbox_min"))
+                tmpval = parse_int_option("file_sandbox_min", data_stream, false);
+            else if (!keyword.compare("file_sandbox_max"))
+                tmpval = parse_int_option("file_sandbox_max", data_stream, false);
+            else if (!keyword.compare("file_cache_test"))
+                tmpval = table_api.add_option("file_cache_test_enabled", true);
+            else if (!keyword.compare("fw_file_perf"))
+                tmpval = parse_string_option("file_perf_filename", data_stream);
+            else if (!keyword.compare("capture_missed_disp"))
+                tmpval = table_api.add_option("capture_missed_disp", true);
+            else if (!keyword.compare("debug_future_date"))
+                tmpval = table_api.add_option("future_date_debug_enabled", true);
+            else if (!keyword.compare("identity_rule_path"))
+                tmpval = parse_string_option("identity_rule_path", data_stream);
+            else if (!keyword.compare("interface_ip_map_path"))
+                tmpval = parse_string_option("intf_ip_map_path", data_stream);
+            else if (!keyword.compare("daqif_path"))
+                tmpval = parse_string_option("daq_intf_path", data_stream);
+            else if (!keyword.compare("running_config_network_path"))
+                tmpval = parse_string_option("running_network_config_path", data_stream);
+            else
+                tmpval = false;
+
+            if (!tmpval)
+            {
+                data_api.failed_conversion(data_stream, keyword);
+                retval = false;
+            }
+        }
+
+        return retval;
+    }
+
+    /**************************
+     *******  A P I ***********
+     **************************/
+
+    static ConversionState* ctor(Converter& c)
+    {
+        return new Firewall(c);
+    }
+
+    static const ConvertMap firewall_api =
+    {
+        "firewall",
+        ctor,
+    };
 
-const ConvertMap* firewall_map = &firewall_api;
+    const ConvertMap* firewall_map = &firewall_api;
 } // namespace preprocessors
 
index 5222f6399fa612c264af209d285e0bc680ff8459..a34482b2d108876568314e4db6c0898ce1426354 100644 (file)
@@ -79,7 +79,6 @@ bool FtpServer::parse_alt_max_cmd(std::istringstream& stream)
 {
     int len;
     std::string elem;
-    std::string format = std::string();
 
     if (!(stream >> len))
         return false;
index 763b08a04c2190f5c8edc6a0120212f93ab48edf..bff6e9f125fdf838a56d94dc9480d55e85dfe01d 100644 (file)
@@ -79,7 +79,6 @@ bool Gtp::convert(std::istringstream& data_stream)
 
         if (!keyword.compare("ports"))
         {
-            std::string tmp = "";
             table_api.add_diff_option_comment("ports", "bindings");
 
             if ((data_stream >> keyword) && !keyword.compare("{"))
index 92a63f296e1906c70401d3feaf815f31a89d24e7..ffd6e1b5f2e9ee0f53c3d80e11b07886673136b1 100644 (file)
@@ -293,7 +293,6 @@ bool HttpInspectServer::convert(std::istringstream& data_stream)
 
         else if (!keyword.compare("ports"))
         {
-            std::string tmp = "";
             table_api.add_diff_option_comment("ports", "bindings");
 
             if ((data_stream >> keyword) && !keyword.compare("{"))
index 7b829f4c0e8b5d53d450e1eab0ac08b00cc46bde..eb080329fc5e8620011039ac3affca2809f5df5e 100644 (file)
@@ -95,7 +95,6 @@ bool Imap::convert(std::istringstream& data_stream)
 
         else if (!keyword.compare("ports"))
         {
-            std::string tmp = "";
             table_api.add_diff_option_comment("ports", "bindings");
 
             if ((data_stream >> keyword) && !keyword.compare("{"))
index e9f31b0af50f697a283cb25944c5f8233bb6f1f8..98539f9131116f18c5ee60210b296dfec8c945a1 100644 (file)
@@ -77,7 +77,6 @@ bool Modbus::convert(std::istringstream& data_stream)
 
         if (!keyword.compare("ports"))
         {
-            std::string tmp = "";
             table_api.add_diff_option_comment("ports", "bindings");
 
             if ((data_stream >> keyword) && !keyword.compare("{"))
index 42011ea37d2cd82f850a83f64207c69a27dabfd8..0d5a84e0cce3017f70d5d96c09e8a580e562688e 100644 (file)
@@ -95,7 +95,6 @@ bool Pop::convert(std::istringstream& data_stream)
 
         else if (!keyword.compare("ports"))
         {
-            std::string tmp = "";
             table_api.add_diff_option_comment("ports", "bindings");
 
             if ((data_stream >> keyword) && !keyword.compare("{"))
index a0fa754f0c9b6a7dace48268c1b351087d6b5989..ea12245857df1708ae196e7214f80b1d885d358f 100644 (file)
@@ -124,7 +124,6 @@ bool Sip::convert(std::istringstream& data_stream)
 
         else if (!keyword.compare("ports"))
         {
-            std::string tmp = "";
             table_api.add_diff_option_comment("ports", "bindings");
 
             if ((arg_stream >> keyword) && !keyword.compare("{"))
index 0250a0b33923cf9135f34480a1638da503e5624e..83104eba9fce5916b513733c903c8193c0d157f5 100644 (file)
@@ -71,7 +71,6 @@ bool Smtp::parse_alt_max_cmd(std::istringstream& stream)
 {
     int len;
     std::string elem;
-    std::string format = std::string();
 
     if (!(stream >> len))
         return false;
@@ -303,7 +302,6 @@ bool Smtp::convert(std::istringstream& data_stream)
         }
         else if (!keyword.compare("ports"))
         {
-            std::string tmp = "";
             table_api.add_diff_option_comment("ports", "bindings");
 
             if ((data_stream >> keyword) && !keyword.compare("{"))
index a440c1b75b9a197679246b0a217acfa517bba261..d572c9bb026878590382c6e6ceea922a79b19d92 100644 (file)
@@ -97,7 +97,6 @@ bool Ssh::convert(std::istringstream& data_stream)
 
         else if (!keyword.compare("server_ports"))
         {
-            std::string tmp = "";
             table_api.add_diff_option_comment("server_ports", "bindings");
 
             if ((data_stream >> keyword) && !keyword.compare("{"))
index 49e6076256318c4d41260910ffef7ef4362c11d0..ec361668757e9665b2225a472b35e6e9361bee77 100644 (file)
@@ -71,7 +71,6 @@ bool Ssl::convert(std::istringstream& data_stream)
         }
         else if (!keyword.compare("ports"))
         {
-            std::string tmp = "";
             table_api.add_diff_option_comment("ports", "bindings");
 
             if (arg_stream >> keyword)
index dc5e2916105631220cd7b9c3506b9e17aa53b065..c9585449987a66be162bd3391e6a48870d0c6249 100644 (file)
@@ -93,12 +93,6 @@ bool StreamGlobal::convert(std::istringstream& data_stream)
             tmpval = parse_int_option("max_sessions", arg_stream, false);
             table_api.close_table();
         }
-        else if (!keyword.compare("max_tcp"))
-        {
-            table_api.open_table("tcp_cache");
-            tmpval = parse_int_option("max_sessions", arg_stream, false);
-            table_api.close_table();
-        }
         else if (!keyword.compare("tcp_cache_nominal_timeout"))
         {
             table_api.open_table("tcp_cache");
index c54158e5fbd329c5fdb7f922fa07efd600519733..a90efe84cfec0b26135a571cedd7e62bf3b9b621 100644 (file)
@@ -177,7 +177,6 @@ bool StreamTcp::parse_ports(std::istringstream& arg_stream)
 bool StreamTcp::parse_protocol(std::istringstream& arg_stream)
 {
     std::string dir;
-    std::string lua_dir;
     std::string protocol;
     std::vector<std::string>* protocols;
     Binder* bind;
index d04eef3ff22978cdad0694ad620efa087f862024..1679e4869fb41bd573625f14a42c741b5d32ac1d 100644 (file)
@@ -222,7 +222,6 @@ bool Content<option_name>::convert(std::istringstream& data_stream)
     while ( extract_payload(arg_stream, keyword) )
     {
         std::istringstream opts(keyword);
-        std::string tmp_str;
         val = "";
 
         opts >> keyword;  // guaranteed to work since get_string is true
index f382e9dc377c6fbc4a4321a583e9101b77673e9c..c5544d5a34d11120c448b3a3185369ffe26fbec8 100644 (file)
@@ -40,9 +40,8 @@ public:
 
 bool HttpEncode::convert(std::istringstream& data_stream)
 {
-    std::string tmp;
     rule_api.add_comment("option deleted: http_encode");
-    tmp = util::get_rule_option_args(data_stream);
+    util::get_rule_option_args(data_stream);
     return set_next_rule_state(data_stream);
 }
 
index ee11837c68b34dc4f3b7a3e351a5e1ca7e358d73..0239ce42f5effb562ad868187aba09d6b0c8e7f5 100644 (file)
@@ -42,11 +42,6 @@ bool Tag::convert(std::istringstream& data_stream)
     std::string args;
     std::string value;
     std::string type;
-    int seconds = 0;
-    int bytes = 0;
-    int packets = 0;
-    bool is_host = false;
-    bool valid = true;
 
     args = util::get_rule_option_args(data_stream);
     std::istringstream arg_stream(args);
@@ -59,6 +54,12 @@ bool Tag::convert(std::istringstream& data_stream)
     }
     else
     {
+        int seconds = 0;
+        int bytes = 0;
+        int packets = 0;
+        bool is_host = false;
+        bool valid = true;
+
         if (!value.compare("host"))
             is_host = true;
 
@@ -84,7 +85,7 @@ bool Tag::convert(std::istringstream& data_stream)
                     {
                         opt_val = std::stoi(value);
                     }
-                    catch (std::exception e)
+                    catch (std::exception &e)
                     {
                         rule_api.bad_rule(data_stream, "can't convert " + value + ":" + e.what());
                         valid = false;
index 25141aed6aed7593ef67ae0201b950aeaf011d28..ceb7928e127d0cdcb35ecc952b954ef75cad9cd9 100644 (file)
@@ -29,7 +29,7 @@
  **************  MAIN FILES  *****************
  *********************************************/
 
-static void print_line(std::string s)
+static void print_line(const std::string& s)
 {
     if (!DataApi::is_quiet_mode())
         std::cout << s << std::endl;
index 228c30f44dc40b0e2c3e6cc62d4edf86059e06d7..e9140d096fbeb5a27ae4866691dde8311fb210cb 100644 (file)
@@ -304,6 +304,7 @@ int main(int argc, char* argv[])
     }
     if ((output_file = fopen(output_filename, "w")) == NULL)
     {
+        fclose(input_file);
         fprintf(stderr, "Unable to open/create file: %s\n", output_filename);
         return FAILURE;
     }