]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
Regression tests correctly converting. All config options now correclty converted
authorJosh <jrosenba@cisco.com>
Fri, 11 Jul 2014 21:18:28 +0000 (17:18 -0400)
committerJosh <jrosenba@cisco.com>
Wed, 16 Jul 2014 20:29:56 +0000 (16:29 -0400)
58 files changed:
src/codecs/link/cd_mpls_module.cc
src/main/modules.cc
tools/snort2lua/config_states/CMakeLists.txt
tools/snort2lua/config_states/config_api.cc
tools/snort2lua/config_states/config_binding.cc [new file with mode: 0644]
tools/snort2lua/config_states/config_decode_esp.cc [new file with mode: 0644]
tools/snort2lua/config_states/config_default_rule_state.cc [new file with mode: 0644]
tools/snort2lua/config_states/config_deleted.cc [new file with mode: 0644]
tools/snort2lua/config_states/config_detection.cc
tools/snort2lua/config_states/config_event_queue.cc
tools/snort2lua/config_states/config_event_trace.cc [new file with mode: 0644]
tools/snort2lua/config_states/config_file.cc
tools/snort2lua/config_states/config_ignore_ports.cc [new file with mode: 0644]
tools/snort2lua/config_states/config_ipv6_frag.cc [new file with mode: 0644]
tools/snort2lua/config_states/config_memcaps.cc [new file with mode: 0644]
tools/snort2lua/config_states/config_mpls_payload_type.cc [new file with mode: 0644]
tools/snort2lua/config_states/config_no_option.cc [new file with mode: 0644]
tools/snort2lua/config_states/config_one_int_option.cc [new file with mode: 0644]
tools/snort2lua/config_states/config_one_string_option.cc [new file with mode: 0644]
tools/snort2lua/config_states/config_options.cc [deleted file]
tools/snort2lua/config_states/config_options.h [deleted file]
tools/snort2lua/config_states/config_order.cc [new file with mode: 0644]
tools/snort2lua/config_states/config_profile.cc [new file with mode: 0644]
tools/snort2lua/config_states/config_response.cc [new file with mode: 0644]
tools/snort2lua/config_states/config_tunnel_verdicts.cc [new file with mode: 0644]
tools/snort2lua/conversion_state.h
tools/snort2lua/data/CMakeLists.txt
tools/snort2lua/data/dt_comment.cc
tools/snort2lua/data/dt_comment.h
tools/snort2lua/data/dt_data.cc
tools/snort2lua/data/dt_rule.cc
tools/snort2lua/data/dt_rule.h
tools/snort2lua/data/dt_rule_option.cc [moved from tools/snort2lua/data/rule/rd_option.cc with 98% similarity]
tools/snort2lua/data/dt_rule_option.h [moved from tools/snort2lua/data/rule/rd_option.h with 94% similarity]
tools/snort2lua/data/dt_rule_suboption.cc [moved from tools/snort2lua/data/rule/rd_suboption.cc with 93% similarity]
tools/snort2lua/data/dt_rule_suboption.h [moved from tools/snort2lua/data/rule/rd_suboption.h with 91% similarity]
tools/snort2lua/data/dt_var.cc
tools/snort2lua/data/dt_var.h
tools/snort2lua/data/rule/CMakeLists.txt [deleted file]
tools/snort2lua/data/rule/rd_string.cc [deleted file]
tools/snort2lua/keyword_states/kws_config.cc
tools/snort2lua/keyword_states/kws_rule.cc
tools/snort2lua/keyword_states/kws_rule_state.cc
tools/snort2lua/output_states/out_null.cc
tools/snort2lua/output_states/out_unixsock.cc
tools/snort2lua/preprocessor_states/CMakeLists.txt
tools/snort2lua/preprocessor_states/pps_bo.cc
tools/snort2lua/preprocessor_states/pps_frag3_global.cc
tools/snort2lua/preprocessor_states/pps_normalizers.cc
tools/snort2lua/preprocessor_states/pps_smtp.cc [deleted file]
tools/snort2lua/preprocessor_states/pps_stream_tcp.cc
tools/snort2lua/preprocessor_states/preprocessor_api.cc
tools/snort2lua/rule_states/rule_content.cc
tools/snort2lua/rule_states/rule_pcre.cc
tools/snort2lua/snort2lua.cc
tools/snort2lua/util/converter.cc
tools/snort2lua/util/util.cc
tools/snort2lua/util/util.h

index e2eee6f712d2cfac9ff9c96bdbb2d780bb848ef9..ad7effd09a368ec41b53d262cdbef847e9e71d2a 100644 (file)
@@ -31,7 +31,7 @@ static const Parameter mpls_params[] =
     { "enable_mpls_overlapping_ip", Parameter::PT_BOOL, nullptr, "false",
       "enable if private network addresses overlap and must be differentiated by MPLS label(s)" },
 
-    { "max_mpls_label_chain_len", Parameter::PT_INT, "-1:", "-1",
+    { "max_mpls_stack_depth", Parameter::PT_INT, "-1:", "-1",
       "set MPLS stack depth" },
 
     { "mpls_payload_type", Parameter::PT_ENUM, "eth | ip4 | ip6", "ip4",
@@ -75,7 +75,7 @@ bool MplsModule::set(const char*, Value& v, SnortConfig* sc)
         if ( v.get_bool() )
             sc->run_flags |= RUN_FLAG__MPLS_OVERLAPPING_IP; // FIXIT move to existing bitfield
     }
-    else if ( v.is("max_mpls_label_chain_len") )
+    else if ( v.is("max_mpls_stack_depth") )
         sc->mpls_stack_depth = v.get_long();
 
     else if ( v.is("mpls_payload_type") )
index 5c4803f20c56026d05e67371e301d3ecce591c81..2d96bbcd402fc3821595bf20f1645f2c3e4c52b5 100644 (file)
@@ -812,6 +812,9 @@ bool ActiveModule::set(const char*, Value& v, SnortConfig* sc)
 
 static const Parameter packets_params[] =
 {
+    { "address_space_agnostic", Parameter::PT_BOOL, nullptr, "false",
+      "file with BPF to select traffic for Snort" },
+
     { "bpf_file", Parameter::PT_STRING, nullptr, nullptr,
       "file with BPF to select traffic for Snort" },
 
index fcf2e011a2da947d98804972f0fe87b0cf2911d5..3bdd641c2f450dd810373c95e330a424a61420e0 100644 (file)
@@ -1,14 +1,29 @@
 
 
 add_library( config_states
+    config_binding.cc
     config_checksums.cc
     config_classification.cc
+    config_decode_esp.cc
+    config_default_rule_state.cc
+    config_deleted.cc
     config_detection.cc
+    config_event_trace.cc
     config_file.cc
     config_event_queue.cc
-    config_options.cc
+    config_ignore_ports.cc
+    config_ipv6_frag.cc
+    config_memcaps.cc
+    config_mpls_payload_type.cc
+    config_no_option.cc
+    config_one_int_option.cc
+    config_one_string_option.cc
+    config_order.cc
     config_ppm.cc
+    config_profile.cc
     config_reference.cc
+    config_response.cc
+    config_tunnel_verdicts.cc
     config_api.h
     config_api.cc
 )
index 2fd9c48f342263eb67ef21b4bf7bbae17c897b2c..25e969aecbbf7128d555aaeca7afcc9bd6aabb79 100644 (file)
 
 namespace config
 {
-
-extern const ConvertMap* autogenerate_decode_rules_map;
+extern const ConvertMap* addressspace_agnostic_map;
+extern const ConvertMap* alert_with_interface_name_map;
+extern const ConvertMap* alertfile_map;
+extern const ConvertMap* asn1_map;
+extern const ConvertMap* autogenerate_preprocessor_decoder_rules_map;
+extern const ConvertMap* binding_map;
+extern const ConvertMap* bpf_file_map;
 extern const ConvertMap* checksum_mode_map;
 extern const ConvertMap* checksum_drop_map;
 extern const ConvertMap* chroot_map;
 extern const ConvertMap* classification_map;
+extern const ConvertMap* cs_dir_map;
+extern const ConvertMap* daemon_map;
+extern const ConvertMap* daq_map;
+extern const ConvertMap* daq_dir_map;
+extern const ConvertMap* daq_mode_map;
+extern const ConvertMap* daq_var_map;
+extern const ConvertMap* decode_data_link_map;
+extern const ConvertMap* decode_esp_map;
+extern const ConvertMap* default_rule_state_map;
 extern const ConvertMap* detection_map;
+extern const ConvertMap* detection_filter_map;
+extern const ConvertMap* disable_attribute_reload_thread_map;
+extern const ConvertMap* disable_decode_alerts_map;
+extern const ConvertMap* disable_decode_drops_map;
+extern const ConvertMap* disable_inline_init_failopen_map;
+extern const ConvertMap* disable_ipopt_alerts_map;
+extern const ConvertMap* disable_ipopt_drops_map;
+extern const ConvertMap* disable_tcpopt_alerts_map;
+extern const ConvertMap* disable_tcpopt_drops_map;
+extern const ConvertMap* disable_tcpopt_experimental_alerts_map;
+extern const ConvertMap* disable_tcpopt_experimental_drops_map;
+extern const ConvertMap* disable_tcpopt_obsolete_alerts_map;
+extern const ConvertMap* disable_tcpopt_obsolete_drops_map;
+extern const ConvertMap* disable_tcpopt_ttcp_alerts_map;
+extern const ConvertMap* disable_ttcp_alerts_map;
+extern const ConvertMap* disable_ttcp_drops_map;
+extern const ConvertMap* dirty_pig_map;
+extern const ConvertMap* dump_chars_only_map;
+extern const ConvertMap* dump_dynamic_rules_path_map;
+extern const ConvertMap* dump_payload_map;
+extern const ConvertMap* dump_payload_verbose_map;
+extern const ConvertMap* enable_decode_drops_map;
+extern const ConvertMap* enable_decode_oversized_alerts_map;
+extern const ConvertMap* enable_decode_oversized_drops_map;
+extern const ConvertMap* enable_deep_teredo_inspection_map;
+extern const ConvertMap* enable_ipopt_drops_map;
 extern const ConvertMap* enable_gtp_map;
+extern const ConvertMap* enable_mpls_multicast_map;
+extern const ConvertMap* enable_mpls_overlapping_ip_map;
+extern const ConvertMap* enable_tcpopt_drops_map;
+extern const ConvertMap* enable_tcpopt_experimental_drops_map;
+extern const ConvertMap* enable_tcpopt_obsolete_drops_map;
+extern const ConvertMap* enable_tcpopt_ttcp_drops_map;
+extern const ConvertMap* enable_ttcp_drops_map;
+extern const ConvertMap* event_filter_map;
 extern const ConvertMap* event_queue_map;
+extern const ConvertMap* event_trace_map;
 extern const ConvertMap* file_map;
-extern const ConvertMap* flowbit_size_map;
+extern const ConvertMap* flexresp2_attempts_map;
+extern const ConvertMap* flexresp2_interface_map;
+extern const ConvertMap* flexresp2_memcap_map;
+extern const ConvertMap* flexresp2_rows_map;
+extern const ConvertMap* flowbits_size_map;
+extern const ConvertMap* ignore_ports_map;
+extern const ConvertMap* include_vlan_in_alerts_map;
+extern const ConvertMap* interface_map;
+extern const ConvertMap* layer2resets_map;
+extern const ConvertMap* ipv6_frag_map;
+extern const ConvertMap* log_ipv6_extra_data_map;
+extern const ConvertMap* logdir_map;
+extern const ConvertMap* max_attribute_hosts_map;
+extern const ConvertMap* max_attribute_services_per_host_map;
+extern const ConvertMap* max_metadata_services_map;
+extern const ConvertMap* max_mpls_labelchain_len_map;
+extern const ConvertMap* mpls_payload_type_map;
+extern const ConvertMap* min_ttl_map;
+extern const ConvertMap* new_ttl_map;
+extern const ConvertMap* nolog_map;
+extern const ConvertMap* nopcre_map;;
+extern const ConvertMap* no_promisc_map;
+extern const ConvertMap* obfuscate_map;
+extern const ConvertMap* order_map;
 extern const ConvertMap* paf_max_map;
 extern const ConvertMap* pcre_match_limit_map;
 extern const ConvertMap* pcre_match_limit_recursion_map;
+extern const ConvertMap* pkt_count_map;
 extern const ConvertMap* ppm_map;
+extern const ConvertMap* policy_mode_map;
+extern const ConvertMap* policy_version_map;
+extern const ConvertMap* profile_preprocs_map;
+extern const ConvertMap* profile_rules_map;
+extern const ConvertMap* quiet_map;
+extern const ConvertMap* rate_filter_map;
+extern const ConvertMap* react_map;
 extern const ConvertMap* reference_map;
+extern const ConvertMap* reference_net_map;
+extern const ConvertMap* response_map;
 extern const ConvertMap* set_gid_map;
 extern const ConvertMap* set_uid_map;
+extern const ConvertMap* show_year_map;
 extern const ConvertMap* snaplen_map;
+extern const ConvertMap* so_rule_memcap_map;
+extern const ConvertMap* stateful_map;
+extern const ConvertMap* tagged_packet_limit_map;
+extern const ConvertMap* threshold_map;
+extern const ConvertMap* tunnel_verdicts_map;
+extern const ConvertMap* umask_map;
+extern const ConvertMap* utc_map;
+extern const ConvertMap* verbose_map;
+extern const ConvertMap* vlan_agnostic_map;
 
 
 const std::vector<const ConvertMap*> config_api = 
 {
-    autogenerate_decode_rules_map,
+    addressspace_agnostic_map,
+    alert_with_interface_name_map,
+    alertfile_map,
+    asn1_map,
+    autogenerate_preprocessor_decoder_rules_map,
+    binding_map,
+    bpf_file_map,
     checksum_mode_map,
     checksum_drop_map,
     chroot_map,
     classification_map,
+    cs_dir_map,
+    daemon_map,
+    daq_map,
+    daq_dir_map,
+    daq_mode_map,
+    daq_var_map,
+    decode_data_link_map,
+    decode_esp_map,
+    default_rule_state_map,
     detection_map,
+    detection_filter_map,
+    disable_attribute_reload_thread_map,
+    disable_decode_alerts_map,
+    disable_decode_drops_map,
+    disable_inline_init_failopen_map,
+    disable_ipopt_alerts_map,
+    disable_ipopt_drops_map,
+    disable_tcpopt_alerts_map,
+    disable_tcpopt_drops_map,
+    disable_tcpopt_experimental_alerts_map,
+    disable_tcpopt_experimental_drops_map,
+    disable_tcpopt_obsolete_alerts_map,
+    disable_tcpopt_obsolete_drops_map,
+    disable_tcpopt_ttcp_alerts_map,
+    disable_ttcp_alerts_map,
+    disable_ttcp_drops_map,
+    dirty_pig_map,
+    dump_chars_only_map,
+    dump_dynamic_rules_path_map,
+    dump_payload_map,
+    dump_payload_verbose_map,
+    enable_decode_drops_map,
+    enable_decode_oversized_alerts_map,
+    enable_decode_oversized_drops_map,
+    enable_deep_teredo_inspection_map,
+    enable_ipopt_drops_map,
     enable_gtp_map,
+    enable_mpls_multicast_map,
+    enable_mpls_overlapping_ip_map,
+    enable_tcpopt_drops_map,
+    enable_tcpopt_experimental_drops_map,
+    enable_tcpopt_obsolete_drops_map,
+    enable_tcpopt_ttcp_drops_map,
+    enable_ttcp_drops_map,
     event_queue_map,
+    event_filter_map,
+    event_trace_map,
     file_map,
-    flowbit_size_map,
+    flexresp2_attempts_map,
+    flexresp2_interface_map,
+    flexresp2_memcap_map,
+    flexresp2_rows_map,
+    flowbits_size_map,
+    ignore_ports_map,
+    include_vlan_in_alerts_map,
+    interface_map,
+    ipv6_frag_map,
+    layer2resets_map,
+    log_ipv6_extra_data_map,
+    logdir_map,
+    min_ttl_map,
+    max_attribute_hosts_map,
+    max_attribute_services_per_host_map,
+    max_metadata_services_map,
+    max_mpls_labelchain_len_map,
+    mpls_payload_type_map,
+    new_ttl_map,
+    nolog_map,
+    nopcre_map,
+    no_promisc_map,
+    obfuscate_map,
+    order_map,
     paf_max_map,
     pcre_match_limit_map,
     pcre_match_limit_recursion_map,
+    pkt_count_map,
     ppm_map,
+    policy_mode_map,
+    policy_version_map,
+    profile_preprocs_map,
+    profile_rules_map,
+    quiet_map,
+    rate_filter_map,
+    react_map,
     reference_map,
+    reference_net_map,
+    response_map,
     set_gid_map,
     set_uid_map,
+    show_year_map,
     snaplen_map,
+    so_rule_memcap_map,
+    stateful_map,
+    tagged_packet_limit_map,
+    threshold_map,
+    tunnel_verdicts_map,
+    umask_map,
+    utc_map,
+    verbose_map,
+    vlan_agnostic_map,
 };
 
 } // namespace config
+
+#if 0
+
+UNSUPPORTED OPTIONS -- these will all be included at a later date.
+
+./src/parser.h:#define CONFIG_OPT__POLICY                          "policy_id"
+./src/parser.h:# define CONFIG_OPT__SIDE_CHANNEL                    "sidechannel"
+./src/parser.h:#define CONFIG_OPT__PROTECTED_CONTENT               "protected_content"
+./src/parser.h:#define CONFIG_OPT__NAP_POLICY_MODE                 "na_policy_mode"
+#endif
diff --git a/tools/snort2lua/config_states/config_binding.cc b/tools/snort2lua/config_states/config_binding.cc
new file mode 100644 (file)
index 0000000..ad989e8
--- /dev/null
@@ -0,0 +1,107 @@
+/*
+** Copyright (C) 2014 Cisco and/or its affiliates. All rights reserved.
+ * Copyright (C) 2002-2013 Sourcefire, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License Version 2 as
+ * published by the Free Software Foundation.  You may not use, modify or
+ * distribute this program under any other version of the GNU General
+ * Public License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+// config_binding.cc author Josh Rosenbaum <jorosenba@cisco.com>
+
+#include <sstream>
+#include <vector>
+
+#include "conversion_state.h"
+#include "util/converter.h"
+#include "util/util.h"
+
+namespace config
+{
+
+namespace {
+
+class Binding : public ConversionState
+{
+public:
+    Binding(Converter* cv, LuaData* ld) : ConversionState(cv, ld) {};
+    virtual ~Binding() {};
+    virtual bool convert(std::istringstream& data_stream);
+};
+
+} // namespace
+
+bool Binding::convert(std::istringstream& data_stream)
+{
+    bool retval = true;
+    std::string binding_type;
+    std::string file;
+    std::string when;
+    std::string val;
+
+    if ((!(data_stream >> file)) ||
+        (!(data_stream >> binding_type)))
+        return false;
+
+    if (!binding_type.compare("policy_id"))
+        when = "policy_id";
+
+    else if (!binding_type.compare("vlan"))
+        when = "vlans";
+
+    else if (!binding_type.compare("net"))
+        when = "nets";
+
+    else
+        return false;
+
+
+    // we need at least one argument
+    if (!util::get_string(data_stream, val, ","))
+        return false;
+
+    ld->open_table("binder");
+    ld->open_table();
+    ld->open_table("when");
+    ld->add_list_to_table(when, val);
+
+    while (util::get_string(data_stream, val, ","))
+        ld->add_list_to_table(when, val);
+
+    ld->close_table(); // "when"
+    ld->open_table("use");
+    ld->add_option_to_table("file", file);
+    ld->close_table(); // "use"
+    ld->close_table(); // anonymous table
+    ld->close_table(); // "binder"
+    return retval;
+}
+
+/**************************
+ *******  A P I ***********
+ **************************/
+
+static ConversionState* ctor(Converter* cv, LuaData* ld)
+{
+    return new Binding(cv, ld);
+}
+
+static const ConvertMap binding_api =
+{
+    "binding",
+    ctor,
+};
+
+const ConvertMap* binding_map = &binding_api;
+
+} // namespace config
diff --git a/tools/snort2lua/config_states/config_decode_esp.cc b/tools/snort2lua/config_states/config_decode_esp.cc
new file mode 100644 (file)
index 0000000..5c79800
--- /dev/null
@@ -0,0 +1,101 @@
+/*
+** Copyright (C) 2014 Cisco and/or its affiliates. All rights reserved.
+ * Copyright (C) 2002-2013 Sourcefire, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License Version 2 as
+ * published by the Free Software Foundation.  You may not use, modify or
+ * distribute this program under any other version of the GNU General
+ * Public License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+// config_decode_esp.cc author Josh Rosenbaum <jorosenba@cisco.com>
+
+#include <sstream>
+#include <vector>
+
+#include "conversion_state.h"
+#include "util/converter.h"
+#include "util/util.h"
+
+namespace config
+{
+
+namespace {
+
+
+class DecodeEsp : public ConversionState
+{
+public:
+    DecodeEsp(Converter* cv, LuaData* ld) : ConversionState(cv, ld) {};
+    virtual ~DecodeEsp() {};
+    virtual bool convert(std::istringstream& data_stream);
+};
+
+} // namespace
+
+
+bool DecodeEsp::convert(std::istringstream& data_stream)
+{
+    std::string type;
+    bool retval = true;
+
+    if (!(data_stream >> type))
+        return false;
+
+
+    ld->open_table("cd_esp");
+
+    if (!type.compare("1") ||
+        !type.compare("on") ||
+        !type.compare("yes") ||
+        !type.compare("true") ||
+        !type.compare("enable"))
+    {
+        ld->add_diff_option_comment("config decode_esp: " + type, "decode_esp = true");
+        retval = ld->add_option_to_table("decode_esp", true);
+    }
+    else if (!type.compare("0") ||
+        !type.compare("no") ||
+        !type.compare("off") ||
+        !type.compare("false") ||
+        !type.compare("disable"))
+    {
+        ld->add_diff_option_comment("config decode_esp: " + type, "decode_esp = false");
+        retval = ld->add_option_to_table("decode_esp", false);
+    }
+    else
+        return false;
+
+    // stop parsing, even if additional options available
+    data_stream.setstate(std::ios::eofbit);
+    return retval;
+}
+
+/**************************
+ *******  A P I ***********
+ **************************/
+
+
+static ConversionState* ctor(Converter* cv, LuaData* ld)
+{
+    return new DecodeEsp(cv, ld);
+}
+
+static const ConvertMap decode_esp_api =
+{
+    "decode_esp",
+    ctor,
+};
+
+const ConvertMap* decode_esp_map = &decode_esp_api;
+
+} // namespace config
diff --git a/tools/snort2lua/config_states/config_default_rule_state.cc b/tools/snort2lua/config_states/config_default_rule_state.cc
new file mode 100644 (file)
index 0000000..a42084f
--- /dev/null
@@ -0,0 +1,83 @@
+/*
+** Copyright (C) 2014 Cisco and/or its affiliates. All rights reserved.
+ * Copyright (C) 2002-2013 Sourcefire, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License Version 2 as
+ * published by the Free Software Foundation.  You may not use, modify or
+ * distribute this program under any other version of the GNU General
+ * Public License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+// config_default_rule_state.cc author Josh Rosenbaum <jorosenba@cisco.com>
+
+#include <sstream>
+#include <vector>
+
+#include "conversion_state.h"
+#include "util/converter.h"
+#include "util/util.h"
+
+namespace config
+{
+
+namespace {
+
+class DefaultRuleState : public ConversionState
+{
+public:
+    DefaultRuleState(Converter* cv, LuaData* ld) : ConversionState(cv, ld) {};
+    virtual ~DefaultRuleState() {};
+    virtual bool convert(std::istringstream& data_stream);
+};
+
+} // namespace
+
+bool DefaultRuleState::convert(std::istringstream& data_stream)
+{
+    bool retval = true;
+    std::string val;
+
+    ld->open_table("alerts");
+
+    if (data_stream >> val &&
+        util::case_compare(val, "disableD"))
+    {
+        ld->add_option_to_table("default_rule_state", false);
+    }
+    else
+    {
+        ld->add_option_to_table("default_rule_state", true);
+    }
+
+
+    ld->close_table();
+    return retval;
+}
+
+/**************************
+ *******  A P I ***********
+ **************************/
+
+static ConversionState* ctor(Converter* cv, LuaData* ld)
+{
+    return new DefaultRuleState(cv, ld);
+}
+
+static const ConvertMap default_rule_state_api =
+{
+    "default_rule_state",
+    ctor,
+};
+
+const ConvertMap* default_rule_state_map = &default_rule_state_api;
+
+} // namespace config
diff --git a/tools/snort2lua/config_states/config_deleted.cc b/tools/snort2lua/config_states/config_deleted.cc
new file mode 100644 (file)
index 0000000..1d96f23
--- /dev/null
@@ -0,0 +1,502 @@
+/*
+** Copyright (C) 2014 Cisco and/or its affiliates. All rights reserved.
+ * Copyright (C) 2002-2013 Sourcefire, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License Version 2 as
+ * published by the Free Software Foundation.  You may not use, modify or
+ * distribute this program under any other version of the GNU General
+ * Public License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+// config_deleted.cc author Josh Rosenbaum <jorosenba@cisco.com>
+
+#include <sstream>
+#include <vector>
+
+#include "conversion_state.h"
+#include "util/converter.h"
+#include "util/util.h"
+
+namespace config
+{
+
+namespace {
+
+
+class Deleted : public ConversionState
+{
+public:
+    Deleted(Converter* cv, LuaData* ld) : ConversionState(cv, ld) {};
+    virtual ~Deleted() {};
+    virtual bool convert(std::istringstream& data_stream);
+};
+
+} // namespace
+
+
+bool Deleted::convert(std::istringstream& data_stream)
+{
+    data_stream.setstate(std::ios::eofbit); // these deleted, not failures
+    return true;
+}
+
+template<const std::string *snort_option>
+static ConversionState* deleted_ctor(Converter* cv, LuaData* ld)
+{
+    // set here since not all delted configs have options
+    if (!ld->is_quiet_mode())
+    {
+        ld->open_table("deleted_snort_config_options");
+        ld->add_deprecated_comment("config " + *snort_option + "[:.*]");
+        ld->close_table();
+    }
+
+    return new Deleted(cv, ld);
+}
+
+/*************************************************
+ ********************  cs_dir  *******************
+ *************************************************/
+
+static const std::string cs_dir = "cs_dir";
+static const ConvertMap cs_dir_api =
+{
+    cs_dir,
+    deleted_ctor<&cs_dir>,
+};
+
+const ConvertMap* cs_dir_map = &cs_dir_api;
+
+/*************************************************
+ *******  disable-attribute-reload-thread  *******
+ *************************************************/
+
+static const std::string disable_attribute_reload_thread = "disable-attribute-reload-thread";
+static const ConvertMap disable_attribute_reload_thread_api =
+{
+    disable_attribute_reload_thread,
+    deleted_ctor<&disable_attribute_reload_thread>,
+};
+
+const ConvertMap* disable_attribute_reload_thread_map = &disable_attribute_reload_thread_api;
+
+/*************************************************
+ ************  disable_decode_alerts  ************
+ *************************************************/
+
+static const std::string disable_decode_alerts = "disable_decode_alerts";
+static const ConvertMap disable_decode_alerts_api =
+{
+    disable_decode_alerts,
+    deleted_ctor<&disable_decode_alerts>,
+};
+
+const ConvertMap* disable_decode_alerts_map = &disable_decode_alerts_api;
+
+/*************************************************
+ *************  disable_decode_drops *************
+ *************************************************/
+
+static const std::string disable_decode_drops = "disable_decode_drops";
+static const ConvertMap disable_decode_drops_api =
+{
+    disable_decode_drops,
+    deleted_ctor<&disable_decode_drops>,
+};
+
+const ConvertMap* disable_decode_drops_map = &disable_decode_drops_api;
+
+/*************************************************
+ *************  disable_ipopt_alerts  ************
+ *************************************************/
+
+static const std::string disable_ipopt_alerts = "disable_ipopt_alerts";
+static const ConvertMap disable_ipopt_alerts_api =
+{
+    disable_ipopt_alerts,
+    deleted_ctor<&disable_ipopt_alerts>,
+};
+
+const ConvertMap* disable_ipopt_alerts_map = &disable_ipopt_alerts_api;
+
+/*************************************************
+ *************  disable_ipopt_drops  *************
+ *************************************************/
+
+static const std::string disable_ipopt_drops = "disable_ipopt_drops";
+static const ConvertMap disable_ipopt_drops_api =
+{
+    disable_ipopt_drops,
+    deleted_ctor<&disable_ipopt_drops>,
+};
+
+const ConvertMap* disable_ipopt_drops_map = &disable_ipopt_drops_api;
+
+/*************************************************
+ ************  disable_tcpopt_alerts  ************
+ *************************************************/
+
+static const std::string disable_tcpopt_alerts = "disable_tcpopt_alerts";
+static const ConvertMap disable_tcpopt_alerts_api =
+{
+    disable_tcpopt_alerts,
+    deleted_ctor<&disable_tcpopt_alerts>,
+};
+
+const ConvertMap* disable_tcpopt_alerts_map = &disable_tcpopt_alerts_api;
+
+/*************************************************
+ *************  disable_tcpopt_drops  ************
+ *************************************************/
+
+static const std::string disable_tcpopt_drops = "disable_tcpopt_drops";
+static const ConvertMap disable_tcpopt_drops_api =
+{
+    disable_tcpopt_drops,
+    deleted_ctor<&disable_tcpopt_drops>,
+};
+
+const ConvertMap* disable_tcpopt_drops_map = &disable_tcpopt_drops_api;
+
+/*************************************************
+ ******  disable_tcpopt_experimental_alerts  *****
+ *************************************************/
+
+static const std::string disable_tcpopt_experimental_alerts = "disable_tcpopt_experimental_alerts";
+static const ConvertMap disable_tcpopt_experimental_alerts_api =
+{
+    disable_tcpopt_experimental_alerts,
+    deleted_ctor<&disable_tcpopt_experimental_alerts>,
+};
+
+const ConvertMap* disable_tcpopt_experimental_alerts_map = &disable_tcpopt_experimental_alerts_api;
+
+/*************************************************
+ *******  disable_tcpopt_experimental_drops ******
+ *************************************************/
+
+static const std::string disable_tcpopt_experimental_drops = "disable_tcpopt_experimental_drops";
+static const ConvertMap disable_tcpopt_experimental_drops_api =
+{
+    disable_tcpopt_experimental_drops,
+    deleted_ctor<&disable_tcpopt_experimental_drops>,
+};
+
+const ConvertMap* disable_tcpopt_experimental_drops_map = &disable_tcpopt_experimental_drops_api;
+
+/*************************************************
+ ********  disable_tcpopt_obsolete_alerts  *******
+ *************************************************/
+
+static const std::string disable_tcpopt_obsolete_alerts = "disable_tcpopt_obsolete_alerts";
+static const ConvertMap disable_tcpopt_obsolete_alerts_api =
+{
+    disable_tcpopt_obsolete_alerts,
+    deleted_ctor<&disable_tcpopt_obsolete_alerts>,
+};
+
+const ConvertMap* disable_tcpopt_obsolete_alerts_map = &disable_tcpopt_obsolete_alerts_api;
+
+/*************************************************
+ *********  disable_tcpopt_obsolete_drops  ********
+ *************************************************/
+
+static const std::string disable_tcpopt_obsolete_drops = "disable_tcpopt_obsolete_drops";
+static const ConvertMap disable_tcpopt_obsolete_drops_api =
+{
+    disable_tcpopt_obsolete_drops,
+    deleted_ctor<&disable_tcpopt_obsolete_drops>,
+};
+
+const ConvertMap* disable_tcpopt_obsolete_drops_map = &disable_tcpopt_obsolete_drops_api;
+
+/*************************************************
+ **********  disable_tcpopt_ttcp_alerts  **********
+ *************************************************/
+
+static const std::string disable_tcpopt_ttcp_alerts = "disable_tcpopt_ttcp_alerts";
+static const ConvertMap disable_tcpopt_ttcp_alerts_api =
+{
+    disable_tcpopt_ttcp_alerts,
+    deleted_ctor<&disable_tcpopt_ttcp_alerts>,
+};
+
+const ConvertMap* disable_tcpopt_ttcp_alerts_map = &disable_tcpopt_ttcp_alerts_api;
+
+/*************************************************
+ **************  disable_ttcp_drops  **************
+ *************************************************/
+
+static const std::string disable_ttcp_drops = "disable_ttcp_drops";
+static const ConvertMap disable_ttcp_drops_api =
+{
+    disable_ttcp_drops,
+    deleted_ctor<&disable_ttcp_drops>,
+};
+
+const ConvertMap* disable_ttcp_drops_map = &disable_ttcp_drops_api;
+
+/*************************************************
+ ************  dump-dynamic-rules-path  ***********
+ *************************************************/
+
+static const std::string dump_dynamic_rules_path = "dump-dynamic-rules-path";
+static const ConvertMap dump_dynamic_rules_path_api =
+{
+    dump_dynamic_rules_path,
+    deleted_ctor<&dump_dynamic_rules_path>,
+};
+
+const ConvertMap* dump_dynamic_rules_path_map = &dump_dynamic_rules_path_api;
+
+/*************************************************
+ *************  enable_decode_drops  *************
+ *************************************************/
+
+static const std::string enable_decode_drops = "enable_decode_drops";
+static const ConvertMap enable_decode_drops_api =
+{
+    enable_decode_drops,
+    deleted_ctor<&enable_decode_drops>,
+};
+
+const ConvertMap* enable_decode_drops_map = &enable_decode_drops_api;
+
+/*************************************************
+ *************  disable_ttcp_alerts  *************
+ *************************************************/
+
+static const std::string disable_ttcp_alerts = "disable_ttcp_alerts";
+static const ConvertMap disable_ttcp_alerts_api =
+{
+    disable_ttcp_alerts,
+    deleted_ctor<&disable_ttcp_alerts>,
+};
+
+const ConvertMap* disable_ttcp_alerts_map = &disable_ttcp_alerts_api;
+
+/*************************************************
+ ********  enable_decode_oversized_alerts  *******
+ *************************************************/
+
+static const std::string enable_decode_oversized_alerts = "enable_decode_oversized_alerts";
+static const ConvertMap enable_decode_oversized_alerts_api =
+{
+    enable_decode_oversized_alerts,
+    deleted_ctor<&enable_decode_oversized_alerts>,
+};
+
+const ConvertMap* enable_decode_oversized_alerts_map = &enable_decode_oversized_alerts_api;
+
+
+/*************************************************
+ ********  enable_decode_oversized_drops  ********
+ *************************************************/
+
+static const std::string enable_decode_oversized_drops = "enable_decode_oversized_drops";
+static const ConvertMap enable_decode_oversized_drops_api =
+{
+    enable_decode_oversized_drops,
+    deleted_ctor<&enable_decode_oversized_drops>,
+};
+
+const ConvertMap* enable_decode_oversized_drops_map = &enable_decode_oversized_drops_api;
+
+/*************************************************
+ **************  enable_ipopt_drops  *************
+ *************************************************/
+
+static const std::string enable_ipopt_drops = "enable_ipopt_drops";
+static const ConvertMap enable_ipopt_drops_api =
+{
+    enable_ipopt_drops,
+    deleted_ctor<&enable_ipopt_drops>,
+};
+
+const ConvertMap* enable_ipopt_drops_map = &enable_ipopt_drops_api;
+
+/*************************************************
+ *************  enable_tcpopt_drops  *************
+ *************************************************/
+
+static const std::string enable_tcpopt_drops = "enable_tcpopt_drops";
+static const ConvertMap enable_tcpopt_drops_api =
+{
+    enable_tcpopt_drops,
+    deleted_ctor<&enable_tcpopt_drops>,
+};
+
+const ConvertMap* enable_tcpopt_drops_map = &enable_tcpopt_drops_api;
+
+/*************************************************
+ *******  enable_tcpopt_experimental_drops  ******
+ *************************************************/
+
+static const std::string enable_tcpopt_experimental_drops = "enable_tcpopt_experimental_drops";
+static const ConvertMap enable_tcpopt_experimental_drops_api =
+{
+    enable_tcpopt_experimental_drops,
+    deleted_ctor<&enable_tcpopt_experimental_drops>,
+};
+
+const ConvertMap* enable_tcpopt_experimental_drops_map = &enable_tcpopt_experimental_drops_api;
+
+/*************************************************
+ *********  enable_tcpopt_obsolete_drops  ********
+ *************************************************/
+
+static const std::string enable_tcpopt_obsolete_drops = "enable_tcpopt_obsolete_drops";
+static const ConvertMap enable_tcpopt_obsolete_drops_api =
+{
+    enable_tcpopt_obsolete_drops,
+    deleted_ctor<&enable_tcpopt_obsolete_drops>,
+};
+
+const ConvertMap* enable_tcpopt_obsolete_drops_map = &enable_tcpopt_obsolete_drops_api;
+
+/*************************************************
+ ***********  enable_tcpopt_ttcp_drops  ***********
+ *************************************************/
+
+static const std::string enable_tcpopt_ttcp_drops = "enable_tcpopt_ttcp_drops";
+static const ConvertMap enable_tcpopt_ttcp_drops_api =
+{
+    enable_tcpopt_ttcp_drops,
+    deleted_ctor<&enable_tcpopt_ttcp_drops>,
+};
+
+const ConvertMap* enable_tcpopt_ttcp_drops_map = &enable_tcpopt_ttcp_drops_api;
+
+/*************************************************
+ ***********  enable_ttcp_drops  ***********
+ *************************************************/
+
+static const std::string enable_ttcp_drops = "enable_ttcp_drops";
+static const ConvertMap enable_ttcp_drops_api =
+{
+    enable_ttcp_drops,
+    deleted_ctor<&enable_ttcp_drops>,
+};
+
+const ConvertMap* enable_ttcp_drops_map = &enable_ttcp_drops_api;
+
+/*************************************************
+ **************  flexresp2_attempts  *************
+ *************************************************/
+
+static const std::string flexresp2_attempts = "flexresp2_attempts";
+static const ConvertMap flexresp2_attempts_api =
+{
+    flexresp2_attempts,
+    deleted_ctor<&flexresp2_attempts>,
+};
+
+const ConvertMap* flexresp2_attempts_map = &flexresp2_attempts_api;
+
+/*************************************************
+ *************  flexresp2_interface  *************
+ *************************************************/
+
+static const std::string flexresp2_interface = "flexresp2_interface";
+static const ConvertMap flexresp2_interface_api =
+{
+    flexresp2_interface,
+    deleted_ctor<&flexresp2_interface>,
+};
+const ConvertMap* flexresp2_interface_map = &flexresp2_interface_api;
+
+/*************************************************
+ ***************  flexresp2_memcap  **************
+ *************************************************/
+
+
+static const std::string flexresp2_memcap = "flexresp2_memcap";
+static const ConvertMap flexresp2_memcap_api =
+{
+    flexresp2_memcap,
+    deleted_ctor<&flexresp2_memcap>,
+};
+const ConvertMap* flexresp2_memcap_map = &flexresp2_memcap_api;
+
+/*************************************************
+ ****************  flexresp2_rows  ***************
+ *************************************************/
+
+static const std::string flexresp2_rows = "flexresp2_rows";
+static const ConvertMap flexresp2_rows_api =
+{
+    flexresp2_rows,
+    deleted_ctor<&flexresp2_rows>,
+};
+const ConvertMap* flexresp2_rows_map = &flexresp2_rows_api;
+
+/*************************************************
+ ************  include_vlan_in_alerts  ***********
+ *************************************************/
+
+static const std::string include_vlan_in_alerts = "include_vlan_in_alerts";
+static const ConvertMap include_vlan_in_alerts_api =
+{
+    include_vlan_in_alerts,
+    deleted_ctor<&include_vlan_in_alerts>,
+};
+const ConvertMap* include_vlan_in_alerts_map = &include_vlan_in_alerts_api;
+
+/*************************************************
+ ******************  interface  ******************
+ *************************************************/
+
+static const std::string interface = "interface";
+static const ConvertMap interface_api =
+{
+    interface,
+    deleted_ctor<&interface>,
+};
+const ConvertMap* interface_map = &interface_api;
+
+/*************************************************
+ *****************  layer2resets  ****************
+ *************************************************/
+
+static const std::string layer2resets = "layer2resets";
+static const ConvertMap layer2resets_api =
+{
+    layer2resets,
+    deleted_ctor<&layer2resets>,
+};
+const ConvertMap* layer2resets_map = &layer2resets_api;
+
+/*************************************************
+ ****************  policy_version  ***************
+ *************************************************/
+
+static const std::string policy_version = "policy_version";
+static const ConvertMap policy_version_api =
+{
+    policy_version,
+    deleted_ctor<&policy_version>,
+};
+const ConvertMap* policy_version_map = &policy_version_api;
+
+/*************************************************
+ ****************  so_rule_memcap  ***************
+ *************************************************/
+
+static const std::string so_rule_memcap = "so_rule_memcap";
+static const ConvertMap so_rule_memcap_api =
+{
+    so_rule_memcap,
+    deleted_ctor<&so_rule_memcap>,
+};
+const ConvertMap* so_rule_memcap_map = &so_rule_memcap_api;
+
+} // namespace config
\ No newline at end of file
index c5cb6ac26712ebde5240ab681d54c9aaf367e82b..6452f69cab09222dc736a57fd826694e65b46084 100644 (file)
@@ -45,23 +45,19 @@ bool Detection::convert(std::istringstream& data_stream)
 {
 
     bool retval = true;
-    std::string keyword;
+    std::string args;
 
     ld->open_table("search_engine");
     ld->add_comment_to_table("This table was previous 'config detection: ...");
 
-    while(data_stream >> keyword)
+    while(util::get_string(data_stream, args, ", "))
     {
         bool tmpval = true;
+        std::string keyword;
+        std::istringstream arg_stream(args);
 
-        if(keyword.back() == ',')
-            keyword.pop_back();
-
-        if(keyword.empty())
-            continue;
-
-        if(!keyword.compare("max_queue_events"))
-            tmpval = parse_int_option("max_queue_events", data_stream);
+        if (!(arg_stream >> keyword)) // impossible to fail. get_string() will return false first.
+            tmpval = false;
 
         else if (!keyword.compare("no_stream_inserts"))
             tmpval = ld->add_option_to_table("no_stream_inserts", true);
@@ -81,18 +77,6 @@ bool Detection::convert(std::istringstream& data_stream)
             tmpval = ld->add_option_to_table("split_any_any", true);
         }
 
-        else if(!keyword.compare("max-pattern-len"))
-        {
-            ld->add_diff_option_comment("max-pattern-len", "max_pattern_len");
-            tmpval = parse_int_option("max_pattern_len", data_stream);
-        }
-
-        else if(!keyword.compare("bleedover-port-limit"))
-        {
-            ld->add_diff_option_comment("bleedover-port-limit", "bleedover_port_limit");
-            tmpval = parse_int_option("bleedover_port_limit", data_stream);
-        }
-
         else if(!keyword.compare("bleedover-warnings-enabled"))
         {
             ld->add_diff_option_comment("bleedover-warnings-enabled", "bleedover_warnings_enabled");
@@ -135,13 +119,45 @@ bool Detection::convert(std::istringstream& data_stream)
             tmpval = ld->add_option_to_table("debug_print_fast_pattern", true);
         }
 
+        else if(!keyword.compare("max_queue_events"))
+        {
+            std::string val;
+
+            if (util::get_string(data_stream, val, ", "))
+                tmpval = ld->add_option_to_table("max_queue_events", std::stoi(val));
+            else
+                tmpval = false;
+        }
+
+        else if(!keyword.compare("max-pattern-len"))
+        {
+            std::string val;
+            ld->add_diff_option_comment("max-pattern-len", "max_pattern_len");
+
+            if (util::get_string(data_stream, val, ", "))
+                tmpval = ld->add_option_to_table("max_pattern_len", std::stoi(val));
+            else
+                tmpval = false;
+        }
+
+        else if(!keyword.compare("bleedover-port-limit"))
+        {
+            std::string val;
+            ld->add_diff_option_comment("bleedover-port-limit", "bleedover_port_limit");
+
+            if (util::get_string(data_stream, val, ", "))
+                tmpval = ld->add_option_to_table("max_pattern_len", std::stoi(val));
+            else
+                tmpval = false;
+        }
+
         else if (!keyword.compare("search-method"))
         {
             ld->add_diff_option_comment("search-method", "search_method");
             std::string method;
             std::string new_method;
 
-            if (!(data_stream >> method))
+            if (!util::get_string(data_stream, method, ", "))
             {
                 retval = false;
                 continue;
@@ -188,7 +204,7 @@ bool Detection::convert(std::istringstream& data_stream)
                 new_method = "ac_full_q";
 
                 if(!ld->add_option_to_table("split_any_any", true))
-                    retval = false;
+                    tmpval = false;
             }
 
             else
@@ -210,8 +226,8 @@ bool Detection::convert(std::istringstream& data_stream)
         else
             tmpval = false;
 
-        if (retval)
-            retval = tmpval;
+        if (retval && !tmpval)
+            retval = false;
     }
 
     return retval;
index 87f5de53c8727c6daae6ef6d8d5d98b4950d105a..b5d80e92e680c2dff9b23ee02c9ccc0b3b5803ab 100644 (file)
@@ -48,21 +48,48 @@ bool EventQueue::convert(std::istringstream& data_stream)
 
     ld->open_table("event_queue");
 
-    while (data_stream >> keyword)
+    while (util::get_string(data_stream, keyword, ", "))
     {
         bool tmpval = true;
 
-        if (!keyword.compare("max_queue"))
-            tmpval = parse_int_option("max_queue", data_stream);
+
+        if (!keyword.compare("process_all_events"))
+            tmpval = ld->add_option_to_table("process_all_events", true);
+
+        else if (!keyword.compare("max_queue"))
+        {
+            std::string val;
+
+            if(util::get_string(data_stream, val, ", "))
+                tmpval = ld->add_option_to_table("max_queue", std::stoi(val));
+            else
+                tmpval = false;
+        }
 
         else if (!keyword.compare("log"))
-            tmpval = parse_int_option("log", data_stream);
+        {
+            std::string val;
 
-        else if (!keyword.compare("order_events"))
-            tmpval = parse_string_option("order_events", data_stream);
+            if(util::get_string(data_stream, val, ", "))
+                tmpval = ld->add_option_to_table("log", std::stoi(val));
+            else
+                tmpval = false;
+        }
 
-        if (retval)
-            retval = tmpval;
+        else if (!keyword.compare("order_events"))
+        {
+            std::string val;
+            if(util::get_string(data_stream, val, ", "))
+                tmpval = ld->add_option_to_table("order_events", val);
+            else
+                tmpval = false;
+        }
+
+        else
+            tmpval = false;
+
+        if (retval && !tmpval)
+            retval = false;
     }
 
     return retval;
diff --git a/tools/snort2lua/config_states/config_event_trace.cc b/tools/snort2lua/config_states/config_event_trace.cc
new file mode 100644 (file)
index 0000000..ee97100
--- /dev/null
@@ -0,0 +1,94 @@
+/*
+** Copyright (C) 2014 Cisco and/or its affiliates. All rights reserved.
+ * Copyright (C) 2002-2013 Sourcefire, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License Version 2 as
+ * published by the Free Software Foundation.  You may not use, modify or
+ * distribute this program under any other version of the GNU General
+ * Public License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+// config_event_trace.cc author Josh Rosenbaum <jorosenba@cisco.com>
+
+#include <sstream>
+#include <vector>
+
+#include "conversion_state.h"
+#include "util/converter.h"
+#include "util/util.h"
+
+namespace config
+{
+
+namespace {
+
+class EventTrace : public ConversionState
+{
+public:
+    EventTrace(Converter* cv, LuaData* ld) : ConversionState(cv, ld) {};
+    virtual ~EventTrace() {};
+    virtual bool convert(std::istringstream& data_stream);
+};
+
+} // namespace
+
+bool EventTrace::convert(std::istringstream& data_stream)
+{
+    bool retval = true;
+    std::string keyword;
+    std::string arg;
+
+    ld->open_table("output");
+    ld->open_table("event_trace");
+
+    while (util::get_string(data_stream, keyword, ", ") &&
+            util::get_string(data_stream, arg, ", "))
+    {
+        bool tmpval = true;
+
+        if (!keyword.compare("file"))
+            tmpval = ld->add_option_to_table("file", arg);
+
+        else if (!keyword.compare("max_data"))
+            tmpval = ld->add_option_to_table("max_data", std::stoi(arg));
+
+        else
+            tmpval = false;
+
+
+        if (retval && !tmpval)
+            retval = false;
+    }
+
+    ld->close_table();
+    ld->close_table();
+    return retval;
+}
+
+/**************************
+ *******  A P I ***********
+ **************************/
+
+static ConversionState* ctor(Converter* cv, LuaData* ld)
+{
+    return new EventTrace(cv, ld);
+}
+
+static const ConvertMap event_trace_api =
+{
+    "event_trace",
+    ctor,
+};
+
+const ConvertMap* event_trace_map = &event_trace_api;
+
+} // namespace config
index 9a9c681b3f86311569fa03c90cbac2c1e1becfc3..ca9a164c62e0fa046e34c92a105ec3ffc7e87a13 100644 (file)
@@ -47,35 +47,29 @@ bool File::convert(std::istringstream& data_stream)
     bool retval = true;
 
     ld->open_table("file_id");
-    while(std::getline(data_stream, args, ','))
+    while(util::get_string(data_stream, args, ","))
     {
         std::istringstream arg_stream(args);
         std::string keyword = std::string();
         bool tmpval = true;
 
         if (!(arg_stream >> keyword))
-        {
-            retval = false;
-            continue;
-        }
-
-        if (keyword.empty())
-            continue;
-#if 0
-        // UNSUPPORTED OPTIONS.  these options were added after 2.9.6
+            tmpval = false;
 
+        // vvvvvvvv -- UNSUPPORTED OPTIONS.  these options were added after 2.9.6
         else if (!keyword.compare("file_capture_memcap"))
-            ld->add_deprecated_comment("file_capture_memcap");
+            ld->add_unsupported_comment("file_capture_memcap");
 
         else if (!keyword.compare("file_capture_max"))
-            ld->add_deprecated_comment("file_capture_max");
+            ld->add_unsupported_comment("file_capture_max");
 
         else if (!keyword.compare("file_capture_min"))
-            ld->add_deprecated_comment("file_capture_min");
+            ld->add_unsupported_comment("file_capture_min");
 
         else if (!keyword.compare("file_capture_block_size"))
-            ld->add_deprecated_comment("file_capture_block_size");
-#endif
+            ld->add_unsupported_comment("file_capture_block_size");
+        // ^^^^^^^^^ -- UNSUPPORTED OPTIONS.  these options were added after 2.9.6
+
         else if (!keyword.compare("show_data_depth"))
             tmpval = parse_int_option("show_data_depth", arg_stream);
 
@@ -109,6 +103,12 @@ bool File::convert(std::istringstream& data_stream)
             tmpval = parse_int_option("block_timeout", arg_stream);
         }
 
+        else if (!keyword.compare("file_lookup_timeout"))
+        {
+            ld->add_diff_option_comment("config file: file_lookup_timeout", "lookup_timeout");
+            tmpval = parse_int_option("lookup_timeout", arg_stream);
+        }
+
         else
             tmpval = false;
 
diff --git a/tools/snort2lua/config_states/config_ignore_ports.cc b/tools/snort2lua/config_states/config_ignore_ports.cc
new file mode 100644 (file)
index 0000000..8a546a1
--- /dev/null
@@ -0,0 +1,125 @@
+/*
+** Copyright (C) 2014 Cisco and/or its affiliates. All rights reserved.
+ * Copyright (C) 2002-2013 Sourcefire, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License Version 2 as
+ * published by the Free Software Foundation.  You may not use, modify or
+ * distribute this program under any other version of the GNU General
+ * Public License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+// config_ignore_ports.cc author Josh Rosenbaum <jorosenba@cisco.com>
+
+#include <sstream>
+#include <vector>
+
+#include "conversion_state.h"
+#include "util/converter.h"
+#include "util/util.h"
+
+namespace config
+{
+
+namespace {
+
+class IgnorePorts : public ConversionState
+{
+public:
+    IgnorePorts(Converter* cv, LuaData* ld) : ConversionState(cv, ld) {};
+    virtual ~IgnorePorts() {};
+    virtual bool convert(std::istringstream& data_stream);
+};
+
+} // namespace
+
+bool IgnorePorts::convert(std::istringstream& data_stream)
+{
+    bool retval = true;
+    std::string keyword;
+    std::string port;
+
+    ld->open_table("binder");
+    ld->open_table(); // anonymouse table
+
+    // if the keyword is not 'tcp' or 'udp', return false;
+    if (!(data_stream >> keyword) ||
+        (keyword.compare("udp") && keyword.compare("tcp")) )
+        return false;
+
+    ld->open_table("when");
+
+    while (data_stream >> port)
+    {
+        bool tmpval = true;
+        const std::size_t colon_pos = port.find(':');
+        if (colon_pos == std::string::npos)
+        {
+            tmpval = ld->add_list_to_table("ports", port);
+        }
+
+        else if (colon_pos == 0)
+        {
+            int high = std::stoi(port.substr(1));
+            for (int i = 0; i <= high; i++)
+            {
+                bool tmpval2 = ld->add_list_to_table("ports", std::to_string(i));
+
+                if (tmpval && !tmpval2)
+                    tmpval = false;
+            }
+        }
+
+        else
+            {
+            int low = std::stoi(port.substr(0, colon_pos));
+            int high = std::stoi(port.substr(colon_pos + 1));
+
+            for (int i = low; i <= high; i++)
+            {
+                bool tmpval2 = ld->add_list_to_table("ports", std::to_string(i));
+
+                if (tmpval && !tmpval2)
+                    tmpval = false;
+            }
+        }
+
+        if (retval && !tmpval)
+            retval = false;
+    }
+
+    ld->close_table();
+    ld->open_table("use");
+    ld->add_option_to_table("action", "allow");
+    ld->close_table(); // table = "use"
+    ld->close_table(); // table = anonymous
+    ld->close_table(); // table = "binder"
+    return retval;
+}
+
+/**************************
+ *******  A P I ***********
+ **************************/
+
+static ConversionState* ctor(Converter* cv, LuaData* ld)
+{
+    return new IgnorePorts(cv, ld);
+}
+
+static const ConvertMap config_ignore_ports =
+{
+    "ignore_ports",
+    ctor,
+};
+
+const ConvertMap* ignore_ports_map = &config_ignore_ports;
+
+} // namespace config
diff --git a/tools/snort2lua/config_states/config_ipv6_frag.cc b/tools/snort2lua/config_states/config_ipv6_frag.cc
new file mode 100644 (file)
index 0000000..0cdcfed
--- /dev/null
@@ -0,0 +1,121 @@
+/*
+** Copyright (C) 2014 Cisco and/or its affiliates. All rights reserved.
+ * Copyright (C) 2002-2013 Sourcefire, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License Version 2 as
+ * published by the Free Software Foundation.  You may not use, modify or
+ * distribute this program under any other version of the GNU General
+ * Public License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+// config_ipv6_frag.cc author Josh Rosenbaum <jorosenba@cisco.com>
+
+#include <sstream>
+#include <vector>
+
+#include "conversion_state.h"
+#include "util/converter.h"
+#include "util/util.h"
+
+namespace config
+{
+
+namespace {
+
+class Ipv6Frag : public ConversionState
+{
+public:
+    Ipv6Frag(Converter* cv, LuaData* ld) : ConversionState(cv, ld) {};
+    virtual ~Ipv6Frag() {};
+    virtual bool convert(std::istringstream& data_stream);
+
+private:
+    void add_deleted_option(std::string opt);
+};
+
+} // namespace
+
+void Ipv6Frag::add_deleted_option(std::string dlt_opt)
+{
+    // see comment in Ipv6Frag::convert
+    if (!ld->is_quiet_mode())
+        ld->add_deprecated_comment("config ipv6_frag: " + dlt_opt);
+}
+
+bool Ipv6Frag::convert(std::istringstream& data_stream)
+{
+    bool retval = true;
+    std::string arg;
+
+    // I'm checking here because I do not want to create this
+    // table in quiet mode
+    if (!ld->is_quiet_mode())
+        ld->open_table("deleted_snort_config_options");
+
+    while (util::get_string(data_stream, arg, ","))
+    {
+        bool tmpval = true;
+        std::string keyword;
+        std::istringstream arg_stream(arg);
+
+        if (!(arg_stream >> keyword))
+            tmpval = false;
+
+        else if (!keyword.compare("max_frag_sessions"))
+            add_deleted_option("max_frag_sessions");
+
+        else if (!keyword.compare("bsd_icmp_frag_alert"))
+            add_deleted_option("config ipv6_frag: bsd_icmp_frag_alert");
+
+        else if (!keyword.compare("bad_ipv6_frag_alert"))
+            add_deleted_option("bad_ipv6_frag_alert");
+
+        else if (!keyword.compare("drop_bad_ipv6_frag"))
+            add_deleted_option("drop_bad_ipv6_frag");
+
+        else if (!keyword.compare("frag_timeout"))
+        {
+            ld->open_top_level_table("ip_stream");
+            tmpval = parse_int_option("session_timeout", arg_stream);
+            ld->close_table();
+        }
+
+        else
+        {
+            tmpval = false;
+        }
+
+        if (retval && !tmpval)
+            retval = false;
+    }
+
+    return retval;
+}
+
+/**************************
+ *******  A P I ***********
+ **************************/
+
+static ConversionState* ctor(Converter* cv, LuaData* ld)
+{
+    return new Ipv6Frag(cv, ld);
+}
+
+static const ConvertMap ipv6_frag_api =
+{
+    "ipv6_frag",
+    ctor,
+};
+
+const ConvertMap* ipv6_frag_map = &ipv6_frag_api;
+
+} // namespace config
diff --git a/tools/snort2lua/config_states/config_memcaps.cc b/tools/snort2lua/config_states/config_memcaps.cc
new file mode 100644 (file)
index 0000000..65b6891
--- /dev/null
@@ -0,0 +1,125 @@
+/*
+** Copyright (C) 2014 Cisco and/or its affiliates. All rights reserved.
+ * Copyright (C) 2002-2013 Sourcefire, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License Version 2 as
+ * published by the Free Software Foundation.  You may not use, modify or
+ * distribute this program under any other version of the GNU General
+ * Public License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+// config_memcaps.cc author Josh Rosenbaum <jorosenba@cisco.com>
+
+#include <sstream>
+#include <vector>
+
+#include "conversion_state.h"
+#include "util/converter.h"
+#include "util/util.h"
+
+namespace config
+{
+
+namespace {
+
+
+template<const std::string *snort_option,
+        const std::string* lua_table,
+        const std::string* lua_option>
+class Memcap : public ConversionState
+{
+public:
+    Memcap(Converter* cv, LuaData* ld) : ConversionState(cv, ld) {};
+    virtual ~Memcap() {};
+    virtual bool convert(std::istringstream& data_stream);
+};
+
+} // namespace
+
+
+template<const std::string* snort_option,
+        const std::string* lua_table,
+        const std::string* lua_option>
+bool Memcap<snort_option, lua_table, lua_option>::convert(std::istringstream& data_stream)
+{
+    std::string memcap;
+
+
+    if ((!(data_stream >> memcap)) ||
+        (memcap.compare("memcap")))
+    {
+        return false;
+    }
+
+    ld->open_table(*lua_table);
+    bool retval1 = ld->add_diff_option_comment("config " + *snort_option + ":", "event_filter_memcap");
+    bool retval2 = parse_int_option(*lua_option, data_stream);
+    ld->close_table();
+
+    // stop parsing, even if additional options available
+    data_stream.setstate(std::ios::eofbit);
+    return retval1 && retval2;
+}
+
+template<const std::string *snort_option,
+        const std::string* lua_table,
+        const std::string* lua_option>
+static ConversionState* ctor(Converter* cv, LuaData* ld)
+{
+    return new Memcap<snort_option, lua_table, lua_option>(cv, ld);
+}
+
+/**************************
+ *******  A P I ***********
+ **************************/
+
+
+
+static const std::string alerts = "alerts";
+static const std::string detection_filter = "detection_filter";
+static const std::string detection_filter_memcap = "detection_filter_memcap";
+static const std::string event_filter = "event_filter";
+static const std::string event_filter_memcap = "event_filter_memcap";
+static const std::string rate_filter = "rate_filter";
+static const std::string rate_filter_memcap = "rate_filter_memcap";
+static const std::string threshold = "threshold";
+
+static const ConvertMap detection_filter_api =
+{
+    detection_filter,
+    ctor<&detection_filter, &alerts, &detection_filter_memcap>,
+};
+
+static const ConvertMap event_filter_api =
+{
+    event_filter,
+    ctor<&event_filter, &alerts, &event_filter_memcap>,
+};
+
+static const ConvertMap rate_filter_api =
+{
+    rate_filter,
+    ctor<&rate_filter, &alerts, &rate_filter_memcap>,
+};
+
+static const ConvertMap threshold_api =
+{
+    threshold,
+    ctor<&threshold, &alerts, &event_filter_memcap>,
+};
+
+const ConvertMap* detection_filter_map = &detection_filter_api;
+const ConvertMap* event_filter_map = &event_filter_api;
+const ConvertMap* rate_filter_map = &rate_filter_api;
+const ConvertMap* threshold_map = &threshold_api;
+
+} // namespace config
\ No newline at end of file
diff --git a/tools/snort2lua/config_states/config_mpls_payload_type.cc b/tools/snort2lua/config_states/config_mpls_payload_type.cc
new file mode 100644 (file)
index 0000000..a0d53f2
--- /dev/null
@@ -0,0 +1,98 @@
+/*
+** Copyright (C) 2014 Cisco and/or its affiliates. All rights reserved.
+ * Copyright (C) 2002-2013 Sourcefire, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License Version 2 as
+ * published by the Free Software Foundation.  You may not use, modify or
+ * distribute this program under any other version of the GNU General
+ * Public License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+// config_mpls_payload_type.cc author Josh Rosenbaum <jorosenba@cisco.com>
+
+#include <sstream>
+#include <vector>
+
+#include "conversion_state.h"
+#include "util/converter.h"
+#include "util/util.h"
+
+namespace config
+{
+
+namespace {
+
+
+class MplsPayloadType : public ConversionState
+{
+public:
+    MplsPayloadType(Converter* cv, LuaData* ld) : ConversionState(cv, ld) {};
+    virtual ~MplsPayloadType() {};
+    virtual bool convert(std::istringstream& data_stream);
+};
+
+} // namespace
+
+
+bool MplsPayloadType::convert(std::istringstream& data_stream)
+{
+    std::string type;
+    bool retval = true;
+
+    if (!(data_stream >> type))
+        return false;
+
+    ld->open_table("cd_mpls");
+
+
+    if (!type.compare("ethernet"))
+    {
+        ld->add_diff_option_comment("config mpls_payload_type: ethernet", "mpls_payload_type = eth");
+        retval = ld->add_option_to_table("mpls_payload_type", "eth");
+    }
+    else if (!type.compare("ipv4"))
+    {
+        ld->add_diff_option_comment("config mpls_payload_type: ipv4", "mpls_payload_type = ip4");
+        retval = ld->add_option_to_table("mpls_payload_type", "ip4");
+    }
+
+    else if (!type.compare("ipv6"))
+    {
+        ld->add_diff_option_comment("config mpls_payload_type: ipv6", "mpls_payload_type = ip6");
+        retval = ld->add_option_to_table("mpls_payload_type", "ip6");
+    }
+    else
+        return false;
+
+    data_stream.setstate(std::ios::eofbit); // if additional options available, stop parsing.
+    return retval;
+}
+
+/**************************
+ *******  A P I ***********
+ **************************/
+
+
+static ConversionState* ctor(Converter* cv, LuaData* ld)
+{
+    return new MplsPayloadType(cv, ld);
+}
+
+static const ConvertMap mpls_payload_type_api =
+{
+    "mpls_payload_type",
+    ctor,
+};
+
+const ConvertMap* mpls_payload_type_map = &mpls_payload_type_api;
+
+} // namespace config
\ No newline at end of file
diff --git a/tools/snort2lua/config_states/config_no_option.cc b/tools/snort2lua/config_states/config_no_option.cc
new file mode 100644 (file)
index 0000000..ebbcd15
--- /dev/null
@@ -0,0 +1,431 @@
+/*
+** Copyright (C) 2014 Cisco and/or its affiliates. All rights reserved.
+ * Copyright (C) 2002-2013 Sourcefire, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License Version 2 as
+ * published by the Free Software Foundation.  You may not use, modify or
+ * distribute this program under any other version of the GNU General
+ * Public License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+// config_no_options.cc author Josh Rosenbaum <jorosenba@cisco.com>
+
+#include <sstream>
+#include <vector>
+
+#include "conversion_state.h"
+#include "util/converter.h"
+#include "util/util.h"
+
+namespace config
+{
+namespace
+{
+
+class DeadCode : public ConversionState
+{
+public:
+    DeadCode(Converter* cv, LuaData* ld) : ConversionState(cv, ld) {}
+    virtual ~DeadCode() {}
+    virtual bool convert(std::istringstream& data_stream)
+    {
+        data_stream.setstate(std::ios::eofbit); // these deleted, not failures
+        return true;
+    }
+};
+
+} // namespace
+
+template<const std::string* snort_option, const std::string* lua_table_name, const std::string* lua_option_name = nullptr>
+static ConversionState* config_true_no_opt_ctor(Converter* cv, LuaData* ld)
+{
+    ld->open_table(*lua_table_name);
+
+    if (lua_option_name == nullptr)
+        ld->add_option_to_table(*snort_option, true);
+    else
+    {
+        ld->add_diff_option_comment("config " + *snort_option + ":", *lua_option_name);
+        ld->add_option_to_table(*lua_option_name, true);
+    }
+
+    ld->close_table();
+    return new DeadCode(cv, ld);
+}
+
+template<const std::string* snort_option, const std::string* lua_table_name, const std::string* lua_option_name = nullptr>
+static ConversionState* config_false_no_opt_ctor(Converter* cv, LuaData* ld)
+{
+    ld->open_table(*lua_table_name);
+
+    if (lua_option_name == nullptr)
+        ld->add_option_to_table(*snort_option, false);
+    else
+    {
+        ld->add_diff_option_comment("config " + *snort_option + ":", *lua_option_name);
+        ld->add_option_to_table(*lua_option_name, false);
+    }
+
+    ld->close_table();
+    return new DeadCode(cv, ld);
+}
+
+/*************************************************
+ ****************  STRUCT_NAMES  *****************
+ *************************************************/
+
+static const std::string alerts = "alerts";
+static const std::string cd_udp = "cd_udp";
+static const std::string cd_mpls = "cd_mpls";
+static const std::string daq = "daq";
+static const std::string detection = "detection";
+static const std::string ips = "ips";
+static const std::string packets = "packets";
+static const std::string process = "process";
+static const std::string output = "output";
+
+
+/*************************************************
+ **********  addressspace_agnostic  **********
+ *************************************************/
+
+static const std::string addressspace_agnostic = "addressspace_agnostic";
+static const std::string address_space_agnostic = "address_space_agnostic";
+static const ConvertMap addressspace_agnostic_api =
+{
+    addressspace_agnostic,
+    config_true_no_opt_ctor<&addressspace_agnostic, &packets, &address_space_agnostic>,
+};
+
+const ConvertMap* addressspace_agnostic_map = &addressspace_agnostic_api;
+
+/*************************************************
+ **********  alert_with_interface_name  **********
+ *************************************************/
+
+static const std::string alert_with_interface_name = "alert_with_interface_name";
+static const ConvertMap alert_with_interface_name_api =
+{
+    alert_with_interface_name,
+    config_true_no_opt_ctor<&alert_with_interface_name, &alerts>,
+};
+
+const ConvertMap* alert_with_interface_name_map = &alert_with_interface_name_api;
+
+/*************************************************
+ *********  autogenerate Decoder Rules ***********
+ *************************************************/
+
+static const std::string autogenerate_preprocessor_decoder_rules = "autogenerate_preprocessor_decoder_rules";
+static const std::string enable_builtin_rules = "enable_builtin_rules";
+static const ConvertMap autogenerate_decode_rules_api =
+{
+    autogenerate_preprocessor_decoder_rules,
+    config_true_no_opt_ctor<&autogenerate_preprocessor_decoder_rules, &ips, &enable_builtin_rules>
+};
+
+const ConvertMap* autogenerate_preprocessor_decoder_rules_map = &autogenerate_decode_rules_api;
+
+/*************************************************
+ *************  daemon  ****************
+ *************************************************/
+
+static const std::string daemon = "daemon";
+static const ConvertMap daemon_api =
+{
+    daemon,
+    config_true_no_opt_ctor<&daemon, &process>,
+};
+
+const ConvertMap* daemon_map = &daemon_api;
+
+/*************************************************
+ *************  decode_data_link  ****************
+ *************************************************/
+
+static const std::string decode_data_link = "decode_data_link";
+static const ConvertMap decode_data_link_api =
+{
+    decode_data_link,
+    config_true_no_opt_ctor<&decode_data_link, &daq>,
+};
+
+const ConvertMap* decode_data_link_map = &decode_data_link_api;
+
+/*************************************************
+ *****************  dirty_pig  *******************
+ *************************************************/
+
+static const std::string dirty_pig = "dirty_pig";
+static const ConvertMap dirty_pig_api =
+{
+    dirty_pig,
+    config_true_no_opt_ctor<&dirty_pig, &process>,
+};
+
+const ConvertMap* dirty_pig_map = &dirty_pig_api;
+
+/*************************************************
+ *****************  disable_inline_init_failopen  *******************
+ *************************************************/
+
+static const std::string disable_inline_init_failopen = "disable_inline_init_failopen";
+static const std::string enable_inline_init_failopen = "enable_inline_init_failopen";
+static const ConvertMap disable_inline_init_failopen_api =
+{
+    disable_inline_init_failopen,
+    config_false_no_opt_ctor<&disable_inline_init_failopen, &packets, &enable_inline_init_failopen>,
+};
+
+const ConvertMap* disable_inline_init_failopen_map = &disable_inline_init_failopen_api;
+
+/*************************************************
+ ***************  dump_chars_only  ***************
+ *************************************************/
+
+static const std::string dump_chars_only = "dump_chars_only";
+static const ConvertMap dump_chars_only_api =
+{
+    dump_chars_only,
+    config_true_no_opt_ctor<&dump_chars_only, &output>,
+};
+
+const ConvertMap* dump_chars_only_map = &dump_chars_only_api;
+
+/*************************************************
+ *****************  dump_payload  ****************
+ *************************************************/
+
+static const std::string dump_payload = "dump_payload";
+static const ConvertMap dump_payload_api =
+{
+    dump_payload,
+    config_true_no_opt_ctor<&dump_payload, &output>,
+};
+
+const ConvertMap* dump_payload_map = &dump_payload_api;
+
+/*************************************************
+ ************  dump_payload_verbose  *************
+ *************************************************/
+
+static const std::string dump_payload_verbose = "dump_payload_verbose";
+static const ConvertMap dump_payload_verbose_api =
+{
+    dump_payload_verbose,
+    config_true_no_opt_ctor<&dump_payload_verbose, &output>,
+};
+
+const ConvertMap* dump_payload_verbose_map = &dump_payload_verbose_api;
+
+/*************************************************
+ ************  enable_mpls_multicast  ************
+ *************************************************/
+
+static const std::string enable_mpls_multicast = "enable_mpls_multicast";
+static const ConvertMap enable_mpls_multicast_api =
+{
+    enable_mpls_multicast,
+    config_true_no_opt_ctor<&enable_mpls_multicast, &cd_mpls>
+};
+
+const ConvertMap* enable_mpls_multicast_map = &enable_mpls_multicast_api;
+
+/*************************************************
+ ********  enable_deep_teredo_inspection  ********
+ *************************************************/
+
+static const std::string enable_deep_teredo_inspection =
+    "enable_deep_teredo_inspection";
+static const std::string deep_teredo_inspection =
+    "deep_teredo_inspection";
+static const ConvertMap enable_deep_teredo_inspection_api =
+{
+    enable_deep_teredo_inspection,
+    config_true_no_opt_ctor<&enable_deep_teredo_inspection, &cd_udp, &deep_teredo_inspection>
+};
+
+const ConvertMap* enable_deep_teredo_inspection_map = &enable_deep_teredo_inspection_api;
+
+/*************************************************
+ ******************  enable_gtp ******************
+ *************************************************/
+
+static const std::string enable_gtp = "enable_gtp";
+static const ConvertMap enable_gtp_api =
+{
+    enable_gtp,
+    config_true_no_opt_ctor<&enable_gtp, &cd_udp>
+};
+
+const ConvertMap* enable_gtp_map = &enable_gtp_api;
+
+/*************************************************
+ **********  enable_mpls_overlapping_ip **********
+ *************************************************/
+
+static const std::string enable_mpls_overlapping_ip = "enable_mpls_overlapping_ip";
+static const ConvertMap enable_mpls_overlapping_ip_api =
+{
+    enable_mpls_overlapping_ip,
+    config_true_no_opt_ctor<&enable_mpls_overlapping_ip, &cd_mpls>
+};
+
+const ConvertMap* enable_mpls_overlapping_ip_map = &enable_mpls_overlapping_ip_api;
+
+
+/*************************************************
+ *************  log_ipv6_extra_data  *************
+ *************************************************/
+
+static const std::string log_ipv6_extra_data = "log_ipv6_extra_data";
+static const ConvertMap log_ipv6_extra_data_api =
+{
+    log_ipv6_extra_data,
+    config_true_no_opt_ctor<&log_ipv6_extra_data, &output>
+};
+
+const ConvertMap* log_ipv6_extra_data_map = &log_ipv6_extra_data_api;
+
+/*************************************************
+ ********************  nolog  ********************
+ *************************************************/
+
+static const std::string nolog = "nolog";
+static const ConvertMap nolog_api =
+{
+    nolog,
+    config_true_no_opt_ctor<&nolog, &output>
+};
+
+const ConvertMap* nolog_map = &nolog_api;
+
+/*************************************************
+ ********************  nopcre  *******************
+ *************************************************/
+
+static const std::string nopcre = "nopcre";
+static const std::string pcre_enable = "pcre_enable";
+static const ConvertMap nopcre_api =
+{
+    nopcre,
+    config_false_no_opt_ctor<&nopcre, &detection, &pcre_enable>
+};
+
+const ConvertMap* nopcre_map = &nopcre_api;
+
+/*************************************************
+ ******************  no_promisc  *****************
+ *************************************************/
+
+static const std::string no_promisc = "no_promisc";
+static const ConvertMap no_promisc_api =
+{
+    no_promisc,
+    config_true_no_opt_ctor<&no_promisc, &daq>
+};
+
+const ConvertMap* no_promisc_map = &no_promisc_api;
+
+/*************************************************
+ ******************  obfuscate  ******************
+ *************************************************/
+
+static const std::string obfuscate = "obfuscate";
+static const ConvertMap obfuscate_api =
+{
+    obfuscate,
+    config_true_no_opt_ctor<&obfuscate, &output>
+};
+
+const ConvertMap* obfuscate_map = &obfuscate_api;
+
+/*************************************************
+ ********************  quiet  ********************
+ *************************************************/
+
+static const std::string quiet = "quiet";
+static const ConvertMap quiet_api =
+{
+    quiet,
+    config_true_no_opt_ctor<&quiet, &output>
+};
+
+const ConvertMap* quiet_map = &quiet_api;
+
+/*************************************************
+ ******************  show_year  ******************
+ *************************************************/
+
+static const std::string show_year = "show_year";
+static const ConvertMap show_year_api =
+{
+    show_year,
+    config_true_no_opt_ctor<&show_year, &output>
+};
+
+const ConvertMap* show_year_map = &show_year_api;
+
+/*************************************************
+ *******************  stateful  ******************
+ *************************************************/
+
+static const std::string stateful = "stateful";
+static const ConvertMap stateful_api =
+{
+    stateful,
+    config_true_no_opt_ctor<&stateful, &alerts>
+};
+
+const ConvertMap* stateful_map = &stateful_api;
+
+/*************************************************
+ *********************  utc  *********************
+ *************************************************/
+
+static const std::string utc = "utc";
+static const ConvertMap utc_api =
+{
+    utc,
+    config_true_no_opt_ctor<&utc, &process>,
+};
+
+const ConvertMap* utc_map = &utc_api;
+
+/*************************************************
+ ***************  verbose  ***************
+ *************************************************/
+
+static const std::string verbose = "verbose";
+static const ConvertMap verbose_api =
+{
+    verbose,
+    config_true_no_opt_ctor<&verbose, &output>,
+};
+
+const ConvertMap* verbose_map = &verbose_api;
+
+/*************************************************
+ ****************  vlan_agnostic  ****************
+ *************************************************/
+
+static const std::string vlan_agnostic = "vlan_agnostic";
+static const ConvertMap vlan_agnostic_api =
+{
+    vlan_agnostic,
+    config_true_no_opt_ctor<&vlan_agnostic, &packets>,
+};
+
+const ConvertMap* vlan_agnostic_map = &vlan_agnostic_api;
+
+
+} // namespace config
diff --git a/tools/snort2lua/config_states/config_one_int_option.cc b/tools/snort2lua/config_states/config_one_int_option.cc
new file mode 100644 (file)
index 0000000..55064d0
--- /dev/null
@@ -0,0 +1,291 @@
+/*
+** Copyright (C) 2014 Cisco and/or its affiliates. All rights reserved.
+ * Copyright (C) 2002-2013 Sourcefire, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License Version 2 as
+ * published by the Free Software Foundation.  You may not use, modify or
+ * distribute this program under any other version of the GNU General
+ * Public License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+// config_one_int_option.cc author Josh Rosenbaum <jorosenba@cisco.com>
+
+#include <sstream>
+#include <vector>
+
+#include "conversion_state.h"
+#include "util/converter.h"
+#include "util/util.h"
+
+namespace config
+{
+
+template<const std::string* snort_option,
+        const std::string* lua_table,
+        const std::string* lua_option>
+class ConfigIntOption : public ConversionState
+{
+public:
+    ConfigIntOption( Converter* cv, LuaData* ld)
+                            : ConversionState(cv, ld)
+    {
+    };
+
+    virtual ~ConfigIntOption() {};
+    virtual bool convert(std::istringstream& stream)
+    {
+        if (snort_option == nullptr ||
+            lua_table == nullptr ||
+            lua_option == nullptr)
+        {
+            return false;
+        }
+
+        ld->open_table(*lua_table);
+
+        // if the two names are not equal ...
+        if((snort_option) &&
+           (lua_option) &&
+           (*snort_option).compare(*lua_option))
+        {
+            ld->add_diff_option_comment("config " + *snort_option + ":", *lua_option);
+        }
+
+        bool retval = parse_int_option(*lua_option, stream);
+        ld->close_table();
+        return retval;
+    }
+};
+
+template<const std::string *snort_option,
+        const std::string *lua_table,
+        const std::string *lua_option = nullptr>
+static ConversionState* config_int_ctor(Converter* cv, LuaData* ld)
+{
+    if (lua_option)
+        return new ConfigIntOption<snort_option,
+                                    lua_table,
+                                    lua_option>(cv, ld);
+    else
+        return new ConfigIntOption<snort_option,
+                                    lua_table,
+                                    snort_option>(cv, ld);
+}
+
+
+/*************************************************
+ ****************  STRUCT_NAMES  *****************
+ *************************************************/
+
+static const std::string attribute_table = "attribute_table";
+static const std::string alerts = "alerts";
+static const std::string daq = "daq";
+static const std::string detection = "detection";
+static const std::string cd_mpls = "cd_mpls";
+static const std::string network = "network";
+static const std::string output = "output";
+static const std::string packets = "packets";
+static const std::string process = "process";
+static const std::string stream_tcp = "stream_tcp";
+
+/*************************************************
+ *********************  asn1  ********************
+ *************************************************/
+
+static const std::string asn1 = "asn1";
+static const ConvertMap asn1_api =
+{
+    asn1,
+    config_int_ctor<&asn1, &detection>,
+};
+
+const ConvertMap* asn1_map = &asn1_api;
+
+/*************************************************
+ ****************  flowbits_size  ****************
+ *************************************************/
+
+static const std::string flowbits_size = "flowbits_size";
+static const ConvertMap flowbits_size_api =
+{
+    flowbits_size,
+    config_int_ctor<&flowbits_size, &alerts>,
+};
+
+const ConvertMap* flowbits_size_map = &flowbits_size_api;
+
+/*************************************************
+ *************  max_attribute_hosts  *************
+ *************************************************/
+
+static const std::string max_attribute_hosts = "max_attribute_hosts";
+static const std::string max_hosts = "max_hosts";
+static const ConvertMap max_attribute_hosts_api =
+{
+    max_attribute_hosts,
+    config_int_ctor<&max_attribute_hosts, &attribute_table, &max_hosts>,
+};
+
+const ConvertMap* max_attribute_hosts_map = &max_attribute_hosts_api;
+
+/*************************************************
+ *******  max_attribute_services_per_host  *******
+ *************************************************/
+
+static const std::string max_attribute_services_per_host = "max_attribute_services_per_host";
+static const std::string max_services_per_host = "max_services_per_host";
+static const ConvertMap max_attribute_services_per_host_api =
+{
+    max_attribute_services_per_host,
+    config_int_ctor<&max_attribute_services_per_host, &attribute_table, &max_services_per_host>,
+};
+
+const ConvertMap* max_attribute_services_per_host_map = &max_attribute_services_per_host_api;
+
+/*************************************************
+ *************  max_attribute_hosts  *************
+ *************************************************/
+
+static const std::string max_metadata_services = "max_metadata_services";
+static const ConvertMap max_metadata_services_api =
+{
+    max_metadata_services,
+    config_int_ctor<&max_metadata_services, &attribute_table>,
+};
+
+const ConvertMap* max_metadata_services_map = &max_metadata_services_api;
+
+/*************************************************
+ ***********  max_mpls_labelchain_len  ***********
+ *************************************************/
+
+static const std::string max_mpls_labelchain_len = "max_mpls_labelchain_len";
+static const std::string max_mpls_stack_depth = "max_mpls_stack_depth";
+static const ConvertMap max_mpls_labelchain_len_api =
+{
+    max_mpls_labelchain_len,
+    config_int_ctor<&max_mpls_labelchain_len,
+                    &cd_mpls,
+                    &max_mpls_stack_depth>,
+};
+
+const ConvertMap* max_mpls_labelchain_len_map = &max_mpls_labelchain_len_api;
+
+/*************************************************
+ *******************  min_ttl  *******************
+ *************************************************/
+
+static const std::string min_ttl = "min_ttl";
+static const ConvertMap min_ttl_api =
+{
+    min_ttl,
+    config_int_ctor<&min_ttl, &network>,
+};
+
+const ConvertMap* min_ttl_map = &min_ttl_api;
+
+/*************************************************
+ *******************  new_ttl  *******************
+ *************************************************/
+
+static const std::string new_ttl = "new_ttl";
+static const ConvertMap new_ttl_api =
+{
+    new_ttl,
+    config_int_ctor<&new_ttl, &network>,
+};
+
+const ConvertMap* new_ttl_map = &new_ttl_api;
+
+/*************************************************
+ ******************  paf_max   *******************
+ *************************************************/
+
+static const std::string paf_max = "paf_max";
+static const ConvertMap paf_max_api =
+{
+    paf_max,
+    config_int_ctor<&paf_max, &stream_tcp>,
+};
+
+const ConvertMap* paf_max_map = &paf_max_api;
+
+/*************************************************
+ **************  pcre_match_limit   **************
+ *************************************************/
+
+static const std::string pcre_match_limit = "pcre_match_limit";
+static const ConvertMap pcre_match_limit_api =
+{
+    pcre_match_limit,
+    config_int_ctor<&pcre_match_limit, &detection>,
+};
+
+const ConvertMap* pcre_match_limit_map = &pcre_match_limit_api;
+
+/**************************************************
+ **********  pcre_match_limit_recursion  **********
+ **************************************************/
+
+static const std::string pcre_match_limit_recursion = "pcre_match_limit_recursion";
+static const ConvertMap pcre_match_limit_recursion_api =
+{
+    pcre_match_limit_recursion,
+    config_int_ctor<&pcre_match_limit_recursion, &detection>,
+};
+
+const ConvertMap* pcre_match_limit_recursion_map = &pcre_match_limit_recursion_api;
+
+/*************************************************
+ ******************  pkt_count   *****************
+ *************************************************/
+
+static const std::string pkt_count = "pkt_count";
+static const std::string limit = "limit";
+static const ConvertMap pkt_count_api =
+{
+    pkt_count,
+    config_int_ctor<&pkt_count, &packets, &limit>,
+};
+
+const ConvertMap* pkt_count_map = &pkt_count_api;
+
+
+/**************************************************
+ ******************** snaplen  ********************
+ **************************************************/
+
+static const std::string snaplen = "snaplen";
+static const ConvertMap snaplen_api =
+{
+    snaplen,
+    config_int_ctor<&snaplen, &daq>,
+};
+
+const ConvertMap* snaplen_map = &snaplen_api;
+
+
+/**************************************************
+ ************** tagged_packet_limit  **************
+ **************************************************/
+
+static const std::string tagged_packet_limit = "tagged_packet_limit";
+static const ConvertMap tagged_packet_limit_api =
+{
+    tagged_packet_limit,
+    config_int_ctor<&tagged_packet_limit, &output>,
+};
+
+const ConvertMap* tagged_packet_limit_map = &tagged_packet_limit_api;
+
+
+} // namespace config
diff --git a/tools/snort2lua/config_states/config_one_string_option.cc b/tools/snort2lua/config_states/config_one_string_option.cc
new file mode 100644 (file)
index 0000000..fa18bc4
--- /dev/null
@@ -0,0 +1,300 @@
+/*
+** Copyright (C) 2014 Cisco and/or its affiliates. All rights reserved.
+ * Copyright (C) 2002-2013 Sourcefire, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License Version 2 as
+ * published by the Free Software Foundation.  You may not use, modify or
+ * distribute this program under any other version of the GNU General
+ * Public License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+// config_one_string_options.cc author Josh Rosenbaum <jorosenba@cisco.com>
+
+#include <sstream>
+#include <vector>
+
+#include "conversion_state.h"
+#include "util/converter.h"
+#include "util/util.h"
+
+namespace config
+{
+
+
+
+template<const std::string* snort_option,
+        const std::string* lua_table,
+        const std::string* lua_option>
+class ConfigStringOption : public ConversionState
+{
+public:
+    ConfigStringOption( Converter* cv, LuaData* ld)
+                            : ConversionState(cv, ld)
+    {
+    };
+
+    virtual ~ConfigStringOption() {};
+    virtual bool convert(std::istringstream& stream)
+    {
+        if (snort_option == nullptr ||
+            lua_table == nullptr ||
+            lua_option == nullptr)
+        {
+            return false;
+        }
+
+        ld->open_table(*lua_table);
+
+        // if the two names are not equal ...
+        if((*snort_option).compare(*lua_option))
+            ld->add_diff_option_comment("config " + *snort_option + ":", *lua_option);
+
+        // get length (stringstream will not read spaces...which we want)
+        const int pos = stream.tellg();
+        stream.seekg(0, stream.end);
+        const int length = ((int) stream.tellg()) - pos;
+        stream.seekg(pos);
+
+        // read argument
+        char *arg_c = new char[length + 1];
+        stream.read(arg_c, length);
+        arg_c[length] = '\0';
+        std::string arg_s(arg_c);
+        delete[] arg_c;
+        util::trim(arg_s);
+
+        // finally, add to the table
+        bool retval = ld->add_option_to_table(*lua_option, arg_s);
+        ld->close_table();
+        return retval;
+    }
+};
+
+
+template<const std::string *snort_option,
+        const std::string *lua_table,
+        const std::string *lua_option = nullptr>
+static ConversionState* config_string_ctor(Converter* cv, LuaData* ld)
+{
+    if (lua_option)
+        return new ConfigStringOption<snort_option,
+                                    lua_table,
+                                    lua_option>(cv, ld);
+    else
+        return new ConfigStringOption<snort_option,
+                                    lua_table,
+                                    snort_option>(cv, ld);
+}
+
+
+/*************************************************
+ *****************  STRUCT_NAMES  ****************
+ *************************************************/
+
+static const std::string active = "active";
+static const std::string alerts = "alerts";
+static const std::string cd_mpls = "cd_mpls";
+static const std::string daq = "daq";
+static const std::string ips = "ips";
+static const std::string mode = "mode";
+static const std::string packets = "packets";
+static const std::string process = "process";
+static const std::string output = "output";
+
+
+
+/*************************************************
+ ******************  alert_file  *****************
+ *************************************************/
+
+static const std::string alertfile = "alertfile";
+static const std::string alert_file = "alert_file";
+static const ConvertMap alertfile_api =
+{
+    alertfile,
+    config_string_ctor<&alertfile, &alerts, &alert_file>,
+};
+
+const ConvertMap* alertfile_map = &alertfile_api;
+
+/*************************************************
+ *******************  bpf_file  ******************
+ *************************************************/
+
+static const std::string bpf_file = "bpf_file";
+static const ConvertMap bpf_file_api =
+{
+    bpf_file,
+    config_string_ctor<&bpf_file, &packets>,
+};
+
+const ConvertMap* bpf_file_map = &bpf_file_api;
+
+/*************************************************
+ ********************  chroot  *******************
+ *************************************************/
+
+static const std::string chroot = "chroot";
+static const ConvertMap chroot_api =
+{
+    chroot,
+    config_string_ctor<&chroot, &process>,
+};
+
+const ConvertMap* chroot_map = &chroot_api;
+
+/*************************************************
+ *********************  daq  *********************
+ *************************************************/
+
+static const std::string name = "name";
+static const ConvertMap daq_api =
+{
+    daq,
+    config_string_ctor<&daq, &daq, &name>,
+};
+
+const ConvertMap* daq_map = &daq_api;
+
+/*************************************************
+ *******************  daq_dir  *******************
+ *************************************************/
+
+static const std::string daq_dir = "daq_dir";
+static const std::string dir = "dir";
+static const ConvertMap daq_dir_api =
+{
+    daq_dir,
+    config_string_ctor<&daq_dir, &daq, &dir>,
+};
+
+const ConvertMap* daq_dir_map = &daq_dir_api;
+
+/*************************************************
+ *******************  daq_mode  *******************
+ *************************************************/
+
+static const std::string daq_mode = "daq_mode";
+static const ConvertMap daq_mode_api =
+{
+    daq_mode,
+    config_string_ctor<&daq_mode, &daq, &mode>,
+};
+
+const ConvertMap* daq_mode_map = &daq_mode_api;
+
+/*************************************************
+ *******************  daq_var  *******************
+ *************************************************/
+
+static const std::string daq_var = "daq_var";
+static const std::string var = "var";
+static const ConvertMap daq_var_api =
+{
+    daq_var,
+    config_string_ctor<&daq_var, &daq, &var>,
+};
+
+const ConvertMap* daq_var_map = &daq_var_api;
+
+/*************************************************
+ *******************  logdir  ********************
+ *************************************************/
+
+static const std::string logdir = "logdir";
+static const ConvertMap logdir_api =
+{
+    logdir,
+    config_string_ctor<&logdir, &output>,
+};
+
+const ConvertMap* logdir_map = &logdir_api;
+
+/*************************************************
+ *****************  policy_mode  *****************
+ *************************************************/
+
+static const std::string policy_mode = "policy_mode";
+static const ConvertMap policy_mode_api =
+{
+    policy_mode,
+    config_string_ctor<&policy_mode, &ips, &mode>,
+};
+
+const ConvertMap* policy_mode_map = &policy_mode_api;
+
+/*************************************************
+ ********************  react  ********************
+ *************************************************/
+
+static const std::string react = "react";
+static const ConvertMap react_api =
+{
+    react,
+    config_string_ctor<&react, &active>,
+};
+
+const ConvertMap* react_map = &react_api;
+
+/*************************************************
+ ****************  reference_net  ****************
+ *************************************************/
+
+static const std::string reference_net = "reference_net";
+static const ConvertMap reference_net_api =
+{
+    reference_net,
+    config_string_ctor<&reference_net, &alerts>,
+};
+
+const ConvertMap* reference_net_map = &reference_net_api;
+
+/*************************************************
+ *******************  set_gid  *******************
+ *************************************************/
+
+static const std::string set_gid = "set_gid";
+static const ConvertMap set_gid_api =
+{
+    set_gid,
+    config_string_ctor<&set_gid, &process>,
+};
+
+const ConvertMap* set_gid_map = &set_gid_api;
+
+/*************************************************
+ *******************  set_uid  ******************
+ *************************************************/
+
+static const std::string set_uid = "set_uid";
+static const ConvertMap set_uid_api =
+{
+    set_uid,
+    config_string_ctor<&set_uid, &process>,
+};
+
+const ConvertMap* set_uid_map = &set_uid_api;
+
+/**************************************************
+ ********************* umask  *********************
+ **************************************************/
+
+static const std::string umask = "umask";
+static const ConvertMap umask_api =
+{
+    umask,
+    config_string_ctor<&umask, &process>,
+};
+
+const ConvertMap* umask_map = &umask_api;
+
+} // namespace config
diff --git a/tools/snort2lua/config_states/config_options.cc b/tools/snort2lua/config_states/config_options.cc
deleted file mode 100644 (file)
index 0a2b262..0000000
+++ /dev/null
@@ -1,408 +0,0 @@
-/*
-** Copyright (C) 2014 Cisco and/or its affiliates. All rights reserved.
- * Copyright (C) 2002-2013 Sourcefire, Inc.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License Version 2 as
- * published by the Free Software Foundation.  You may not use, modify or
- * distribute this program under any other version of the GNU General
- * Public License.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-// config_options.cc author Josh Rosenbaum <jorosenba@cisco.com>
-
-#include <sstream>
-#include <vector>
-
-#include "conversion_state.h"
-#include "util/converter.h"
-#include "util/util.h"
-#include "config_states/config_options.h"
-
-
-namespace config
-{
-
-
-static inline void open_table_add_option(LuaData* ld,
-                                            std::string table_name, 
-                                            std::string opt_name, 
-                                            bool val)
-{
-    ld->open_table(table_name);
-    ld->add_option_to_table(opt_name, val);
-    ld->close_table();
-}
-
-/*********************************************
- ************  config paf_max ****************
- *********************************************/
-
-static const std::string paf_max = "paf_max";
-static const std::string stream_tcp = "stream_tcp";
-
-static const ConvertMap config_paf_max =
-{
-    paf_max,
-    config_int_ctor<&paf_max, &stream_tcp>,
-};
-
-const ConvertMap* paf_max_map = &config_paf_max;
-
-
-/*************************************************
- ********** PCRE_MATCH_LIMIT  ********************
- *************************************************/
-
-
-static const std::string pcre_match_limit = "pcre_match_limit";
-static const std::string detection = "detection";
-
-static const ConvertMap config_pcre_match_limit =
-{
-    pcre_match_limit,
-    config_int_ctor<&pcre_match_limit, &detection>,
-};
-
-const ConvertMap* pcre_match_limit_map = &config_pcre_match_limit;
-
-
-
-/***********************************************************
- ********** PCRE_MATCH_LIMIT_RECURSION  ********************
- ***********************************************************/
-
-static const std::string pcre_match_limit_recursion = "pcre_match_limit_recursion";
-
-
-static const ConvertMap config_pcre_match_limit_recursion =
-{
-    pcre_match_limit_recursion,
-    config_int_ctor<&pcre_match_limit_recursion, &detection>,
-};
-
-const ConvertMap* pcre_match_limit_recursion_map = &config_pcre_match_limit_recursion;
-
-
-/***********************************************************
- ****************** FLOWBIT_SIZE ***************************
- ***********************************************************/
-
-//template<const std::string *snort_option, const std::string *lua_name>
-//config_int_ctor2<snort_option, lua_name, snort_option>
-
-static const std::string alerts = "alerts";
-static const std::string flowbits_size = "flowbits_size";
-
-static const ConvertMap config_flowbit_size =
-{
-    flowbits_size,
-    config_int_ctor<&flowbits_size, &alerts>,
-};
-
-const ConvertMap* flowbit_size_map = &config_flowbit_size;
-
-
-/*********************************************
- *******  Enable GTP *************************
- *********************************************/
-
-static ConversionState* enable_gtp_ctor(Converter* cv, LuaData* ld)
-{
-    open_table_add_option(ld, "cd_udp", "enable_gtp", true);
-    return nullptr;
-}
-
-static const ConvertMap config_enable_gtp =
-{
-    "enable_gtp",
-    enable_gtp_ctor,
-};
-
-const ConvertMap* enable_gtp_map = &config_enable_gtp;
-
-
-/*********************************************
- ****************  Snaplen *******************
- *********************************************/
-
-static const std::string snaplen = "snaplen";
-static const std::string daq = "daq";
-
-static const ConvertMap config_snaplen =
-{
-    snaplen,
-    config_int_ctor<&snaplen, &daq>,
-};
-
-const ConvertMap* snaplen_map = &config_snaplen;
-
-
-/*********************************************
- ****************  set_gid *******************
- *********************************************/
-
-static const std::string set_gid = "set_gid";
-static const std::string process = "process";
-
-static const ConvertMap config_set_gid =
-{
-    set_gid,
-    config_string_ctor<&set_gid, &process>,
-};
-
-const ConvertMap* set_gid_map = &config_set_gid;
-
-/*********************************************
- ****************  set_uid *******************
- *********************************************/
-
-static const std::string set_uid = "set_uid";
-
-static const ConvertMap config_set_uid =
-{
-    set_uid,
-    config_string_ctor<&set_uid, &process>,
-};
-
-const ConvertMap* set_uid_map = &config_set_uid;
-
-
-/*********************************************
- ****************  chroot  *******************
- *********************************************/
-
-static const std::string chroot = "chroot";
-
-static const ConvertMap config_chroot =
-{
-    chroot,
-    config_string_ctor<&chroot, &process>,
-};
-
-const ConvertMap* chroot_map = &config_chroot;
-
-
-/*********************************************
- *******  Autogenerate Decoder Rules *********
- *********************************************/
-
-static ConversionState* autogenerate_preprocessor_decoder_rules_ctor(Converter* cv, LuaData* ld)
-{
-    open_table_add_option(ld, "ips", "enable_builtin_rules", true);
-    return nullptr;
-}
-
-static const ConvertMap config_autogenerate_decode_rules =
-{
-    "autogenerate_preprocessor_decoder_rules",
-    autogenerate_preprocessor_decoder_rules_ctor,
-};
-
-const ConvertMap* autogenerate_decode_rules_map = &config_autogenerate_decode_rules;
-
-
-
-#if 0
-config alert with interface name
-Appends interface name to alert (snort -I).
-config alertfile:  <filename>
-Sets the alerts output file.
-config asn1:  <max-nodes>
-Specifies the maximum number of nodes to track when doing ASN1 decoding. See Section 3.5.35 for more infor- mation and examples.
-config autogenerate preprocessor decoder rules
-
-If Snort was configured to enable decoder and preprocessor rules, this option will cause Snort to revert back to its original behavior of alerting if the decoder or preprocessor generates an event.
-config bpf file: <filename>
-Specifies BPF filters (snort -F).
-config checksum drop: <types>
-
-Types of packets to drop if invalid checksums. Values: none, noip, notcp, noicmp, noudp, ip, tcp, udp, icmp or all (only applicable in inline mode and for packets checked per checksum mode config option).
-config checksum mode: <types>
-
-
-See Table 3.2 for a list of classifications.
-config cs dir: <path>
-
-configure snort to provide a Unix socket in the path that can be used to issue commands to the running process. See Section 1.10 for more details.
-config daemon
-Forks as a daemon (snort -D).
-config decode data link
-Decodes Layer2 headers (snort -e).
-config default rule state: <state>
-
-Global configuration directive to enable or disable the load- ing of rules into the detection engine. Default (with or without directive) is enabled. Specify disabled to disable loading rules.
-config daq:  <type>
-Selects the type of DAQ to instantiate. The DAQ with the highest version of the given type is selected if there are multiple of the same type (this includes any built-in DAQs).
-config daq mode: <mode>
-
-Select the DAQ mode: passive, inline, or read-file. Not all DAQs support modes. See the DAQ distro README for possible DAQ modes or list DAQ capabilities for a brief summary.
-config daq var: <name=value>
-
-Set a DAQ specific variable. Snort just passes this infor- mation down to the DAQ. See the DAQ distro README for possible DAQ variables.
-config daq dir: <dir>
-
-Tell Snort where to look for available dynamic DAQ mod- ules. This can be repeated. The selected DAQ will be the one with the latest version.
-config daq list: [<dir>]
-
-Tell Snort to dump basic DAQ capabilities and exit. You can optionally specify a directory to include any dynamic DAQs from that directory. You can also precede this op- tion with extra DAQ directory options to look in multiple directories.
-config decode esp: [enable | disable]
-
-config disable decode alerts
-Turns off the alerts generated by the decode phase of Snort.
-config disable inline init failopen
-Disables failopen thread that allows inline traffic to pass while Snort is starting up. Only useful if Snort was configured with â€“enable-inline-init-failopen. (snort --disable-inline-init-failopen)
-config disable ipopt alerts
-Disables IP option length validation alerts.
-config disable tcpopt alerts
-Disables option length validation alerts.
-config
-disable tcpopt experimental alerts
-Turns off alerts generated by experimental TCP options.
-config disable tcpopt obsolete alerts Turns off alerts generated by obsolete TCP options.
-config disable tcpopt ttcp alerts
-Turns off alerts generated by T/TCP options.
-config disable ttcp alerts
-Turns off alerts generated by T/TCP options.
-config dump chars only
-Turns on character dumps (snort -C).
-config dump payload
-Dumps application layer (snort -d).
-config dump payload verbose
-Dumps raw packet starting at link layer (snort -X).
-config enable decode drops
-Enables the dropping of bad packets identified by decoder (only applicable in inline mode).
-config enable decode oversized alerts Enable alerting on packets that have headers containing length fields for which the value is greater than the length
-of the packet.
-37
-config enable decode oversized drops
-Enable dropping packets that have headers containing length fields for which the value is greater than the length of the packet. enable decode oversized alerts must also be enabled for this to be effective (only applicable in inline mode).
-config enable deep teredo inspection
-Snort’s packet decoder only decodes Teredo (IPv6 over UDP over IPv4) traffic on UDP port 3544. This option makes Snort decode Teredo traffic on all UDP ports.
-config enable ipopt drops
-Enables the dropping of bad packets with bad/truncated IP options (only applicable in inline mode).
-config enable mpls multicast
-Enables support for MPLS multicast. This option is needed when the network allows MPLS multicast traffic. When this option is off and MPLS multicast traffic is de- tected, Snort will generate an alert. By default, it is off.
-config enable mpls overlapping ip
-Enables support for overlapping IP addresses in an MPLS network. In a normal situation, where there are no over- lapping IP addresses, this configuration option should not be turned on. However, there could be situations where two private networks share the same IP space and differ- ent MPLS labels are used to differentiate traffic from the two VPNs. In such a situation, this configuration option should be turned on. By default, it is off.
-config enable tcpopt drops
-Enables the dropping of bad packets with bad/truncated TCP option (only applicable in inline mode).
-config
-enable tcpopt experimental drops
-Enables the dropping of bad packets with experimental TCP option. (only applicable in inline mode).
-config enable tcpopt obsolete drops
-Enables the dropping of bad packets with obsolete TCP option. (only applicable in inline mode).
-config enable tcpopt ttcp drops
-Enables the dropping of bad packets with T/TCP option. (only applicable in inline mode).
-config enable ttcp drops
-Enables the dropping of bad packets with T/TCP option. (only applicable in inline mode).
-config event filter: memcap <bytes>
-Set global memcap in bytes for thresholding. Default is 1048576 bytes (1 megabyte).
-config event queue: [max queue <num>] [log <num>] [order events <order>]
-Specifies conditions about Snort’s event queue. You can use the following options:
-• max queue <integer> (max events supported)
-• log <integer> (number of events to log)
-• order events [priority|content length] (how to order events within the queue)
-See Section 2.4.4 for more information and examples.
-config flowbits size: <num-bits>
-Specifies the maximum number of flowbit tags that can be used within a rule set. The default is 1024 bits and maximum is 2048.
-config ignore ports: <proto> <port-list>
-Specifies ports to ignore (useful for ignoring noisy NFS traffic). Specify the protocol (TCP, UDP, IP, or ICMP), followed by a list of ports. Port ranges are supported.
-config interface:  <iface>
-Sets the network interface (snort -i).
-38
-config ipv6 frag:
-[bsd icmp frag alert on|off] [, bad ipv6 frag alert on|off] [, frag timeout <secs>] [,
-max frag sessions <max-track>]
-The following options can be used:
-• bsd icmp frag alert on|off (Specify whether or not to alert. Default is on)
-• bad ipv6 frag alert on|off (Specify whether or not to alert. Default is on)
-• frag timeout <integer> (Specify amount of time in seconds to timeout first frag in hash table)
-• max frag sessions <integer> (Specify the num- ber of fragments to track in the hash table)
-config logdir:  <dir>
-Sets the logdir (snort -l).
-config log ipv6 extra data
-Set Snort to log IPv6 source and destination addresses as unified2 extra data events.
-config max attribute hosts: <hosts>
-Sets a limit on the maximum number of hosts to read from the attribute table. Minimum value is 32 and the maxi- mum is 524288 (512k). The default is 10000. If the number of hosts in the attribute table exceeds this value, an error is logged and the remainder of the hosts are ignored. This option is only supported with a Host Attribute Table (see section 2.7).
-config max attribute services per hostS:ets a per host limit on the maximum number of services to <hosts> read from the attribute table. Minimum value is 1 and the maximum is 65535. The default is 100. For a given host, if the number of services in the attribute table exceeds this value, an error is logged and the remainder of the services for that host are ignored. This option is only supported
-with a Host Attribute Table (see section 2.7).
-config max mpls labelchain len: <num-hdrs>
-Sets a Snort-wide limit on the number of MPLS headers a packet can have. Its default value is -1, which means that there is no limit on label chain length.
-config min ttl: <ttl>
-Sets a Snort-wide minimum ttl to ignore all traffic.
-config mpls payload type: ipv4|ipv6|ethernet
-Sets a Snort-wide MPLS payload type. In addition to ipv4, ipv6 and ethernet are also valid options. The default MPLS payload type is ipv4
-config no promisc
-Disables promiscuous mode (snort -p).
-config nolog
-Disables logging. Note: Alerts will still occur. (snort -N).
-config nopcre
-Disables pcre pattern matching.
-config obfuscate
-Obfuscates IP Addresses (snort -O).
-config order:  <order>
-Changes the order that rules are evaluated, e.g.: pass alert log activation.
-config pcre match limit: <integer>
-Restricts the amount of backtracking a given PCRE op- tion. For example, it will limit the number of nested re- peats within a pattern. A value of -1 allows for unlimited PCRE, up to the PCRE library compiled limit (around 10 million). A value of 0 results in no PCRE evaluation. The snort default value is 1500.
-config pcre match limit recursion: <integer>
-Restricts the amount of stack used by a given PCRE op- tion. A value of -1 allows for unlimited PCRE, up to the PCRE library compiled limit (around 10 million). A value of 0 results in no PCRE evaluation. The snort default value is 1500. This option is only useful if the value is less than the pcre match limit
-config pkt count: <N>
-Exits after N packets (snort -n).
-39
-config policy version: <base-version-string> [<binding-version-string>]
-Supply versioning information to configuration files. Base version should be a string in all configuration files including included ones. In addition, binding version must be in any file configured with config binding. This option is used to avoid race conditions when modifying and loading a configuration within a short time span - before Snort has had a chance to load a previous configuration.
-config profile preprocs
-Print statistics on preprocessor performance. See Section 2.5.2 for more details.
-config profile rules
-Print statistics on rule performance. See Section 2.5.1 for more details.
-config protected content: md5|sha256|sha512
-Specifies a default algorithm to use for protected content rules.
-config quiet
-Disables banner and status reports (snort -q). NOTE: The command line switch -q takes effect immediately af- ter processing the command line parameters, whereas us- ing config quiet in snort.conf takes effect when the con- figuration line in snort.conf is parsed. That may occur after other configuration settings that result in output to console or syslog.
-config reference:  <ref>
-Adds a new reference system to Snort, e.g.: myref http://myurl.com/?id=
-config reference net <cidr>
-For IP obfuscation, the obfuscated net will be used if the packet contains an IP address in the reference net. Also used to determine how to set up the logging directory structure for the session post detection rule option and ASCII output plugin - an attempt is made to name the log directories after the IP address that is not in the reference net.
-config response:  [attempts
-<count>] [, device <dev>]
-Set the number of strafing attempts per injected response and/or the device, such as eth0, from which to send re- sponses. These options may appear in any order but must be comma separated. The are intended for passive mode.
-config show year
-Shows year in timestamps (snort -y).
-config so rule memcap: <bytes>
-Set global memcap in bytes for so rules that dynamically allocate memory for storing session data in the stream pre- processor. A value of 0 disables the memcap. Default is 0. Maximum value is the maximum value an unsigned 32 bit integer can hold which is 4294967295 or 4GB.
-config stateful
-Sets assurance mode for stream (stream is established).
-config tagged packet limit: <max-tag>
-When a metric other than packets is used in a tag option in a rule, this option sets the maximum number of packets to be tagged regardless of the amount defined by the other metric. See Section 3.7.5 on using the tag option when writing rules for more details. The default value when this option is not configured is 256 packets. Setting this option to a value of 0 will disable the packet limit.
-config threshold:  memcap <bytes>
-Set global memcap in bytes for thresholding. Default is 1048576 bytes (1 megabyte). (This is deprecated. Use config event filter instead.)
-config umask:  <umask>
-Sets umask when running (snort -m).
-40
-config utc
-Uses UTC instead of local time for timestamps (snort -U).
-config verbose
-Uses verbose logging to STDOUT (snort -v).
-config vlan agnostic
-
-Causes Snort to ignore vlan headers for the purposes of connection and frag tracking. This option is only valid in the base configuration when using multiple configurations, and the default is off.
-config address space agnostic
-
-Causes Snort to ignore DAQ address space ID for the pur- poses of connection and frag tracking. This option is only valid in the base configuration when using multiple config- urations, and the default is off.
-config policy mode: tap|inline|inline test
-
-Sets the policy mode to either passive, inline or inline test.
-config tunnel verdicts: gtp|teredo|6in4|4in6
-
-#endif
-
-} // namespace config
\ No newline at end of file
diff --git a/tools/snort2lua/config_states/config_options.h b/tools/snort2lua/config_states/config_options.h
deleted file mode 100644 (file)
index 858ed0b..0000000
+++ /dev/null
@@ -1,113 +0,0 @@
-/*
-** Copyright (C) 2014 Cisco and/or its affiliates. All rights reserved.
- * Copyright (C) 2002-2013 Sourcefire, Inc.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License Version 2 as
- * published by the Free Software Foundation.  You may not use, modify or
- * distribute this program under any other version of the GNU General
- * Public License.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-// config_options.h author Josh Rosenbaum <jorosenba@cisco.com>
-
-#ifndef CONFIG_OPTIONS_H
-#define CONFIG_OPTIONS_H
-
-
-#include <string>
-#include <sstream>
-#include "conversion_state.h"
-#include "util/converter.h"
-
-
-namespace config
-{
-
-/**********************************
- ********  TEMPLATES!!   **********
- **********************************/
-
-
-// int template
-
-template<const std::string *snort_option,
-        const std::string *lua_table_name,
-        const std::string* lua_option_name>
-class ConfigIntOption : public ConversionState
-{
-public:
-    ConfigIntOption( Converter* cv, LuaData* ld)
-                            : ConversionState(cv, ld)
-    {
-    };
-
-    virtual ~ConfigIntOption() {};
-    virtual bool convert(std::istringstream& stream)
-    {
-        // if the two names are not equal ...
-        if((*snort_option).compare((*lua_option_name)))
-            ld->add_diff_option_comment(*snort_option, *lua_option_name);
-
-        ld->open_table((*lua_table_name));
-        return parse_int_option(*lua_option_name, stream);
-    }
-};
-
-
-template<const std::string *snort_option, const std::string *lua_name, const std::string *lua_option_name = nullptr>
-static ConversionState* config_int_ctor(Converter* cv, LuaData* ld)
-{
-    if (lua_option_name)
-        return new ConfigIntOption<snort_option, lua_name, lua_option_name>(cv, ld);
-    else
-        return new ConfigIntOption<snort_option, lua_name, snort_option>(cv, ld);
-}
-
-// string template
-
-template<const std::string *snort_option,
-        const std::string *lua_table_name,
-        const std::string* lua_option_name>
-class ConfigStringOption : public ConversionState
-{
-public:
-    ConfigStringOption( Converter* cv, LuaData* ld)
-                            : ConversionState(cv, ld)
-    {
-    };
-
-    virtual ~ConfigStringOption() {};
-    virtual bool convert(std::istringstream& stream)
-    {
-        // if the two names are not equal ...
-        if((*snort_option).compare((*lua_option_name)))
-            ld->add_diff_option_comment(*snort_option, *lua_option_name);
-
-        ld->open_table((*lua_table_name));
-        return parse_string_option(*lua_option_name, stream);
-    }
-};
-
-
-template<const std::string *snort_option, const std::string *lua_name, const std::string *lua_option_name = nullptr>
-static ConversionState* config_string_ctor(Converter* cv, LuaData* ld)
-{
-    if (lua_option_name)
-        return new ConfigStringOption<snort_option, lua_name, lua_option_name>(cv, ld);
-    else
-        return new ConfigStringOption<snort_option, lua_name, snort_option>(cv, ld);
-}
-
-} // namespace config
-
-
-#endif
diff --git a/tools/snort2lua/config_states/config_order.cc b/tools/snort2lua/config_states/config_order.cc
new file mode 100644 (file)
index 0000000..256350f
--- /dev/null
@@ -0,0 +1,80 @@
+/*
+** Copyright (C) 2014 Cisco and/or its affiliates. All rights reserved.
+ * Copyright (C) 2002-2013 Sourcefire, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License Version 2 as
+ * published by the Free Software Foundation.  You may not use, modify or
+ * distribute this program under any other version of the GNU General
+ * Public License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+// config_order.cc author Josh Rosenbaum <jorosenba@cisco.com>
+
+#include <sstream>
+#include <vector>
+
+#include "conversion_state.h"
+#include "util/converter.h"
+#include "util/util.h"
+
+namespace config
+{
+
+namespace {
+
+class Order : public ConversionState
+{
+public:
+    Order(Converter* cv, LuaData* ld) : ConversionState(cv, ld) {};
+    virtual ~Order() {};
+    virtual bool convert(std::istringstream& data_stream);
+};
+
+} // namespace
+
+bool Order::convert(std::istringstream& data_stream)
+{
+    bool retval = true;
+    std::string val;
+
+    ld->open_table("alerts");
+
+    while (data_stream >> val)
+    {
+        bool tmpval = ld->add_list_to_table("order", val);
+
+        if (retval && !tmpval)
+            retval = false;
+    }
+
+    ld->close_table();
+    return retval;
+}
+
+/**************************
+ *******  A P I ***********
+ **************************/
+
+static ConversionState* ctor(Converter* cv, LuaData* ld)
+{
+    return new Order(cv, ld);
+}
+
+static const ConvertMap order_api =
+{
+    "order",
+    ctor,
+};
+
+const ConvertMap* order_map = &order_api;
+
+} // namespace config
diff --git a/tools/snort2lua/config_states/config_profile.cc b/tools/snort2lua/config_states/config_profile.cc
new file mode 100644 (file)
index 0000000..fac8c06
--- /dev/null
@@ -0,0 +1,160 @@
+/*
+** Copyright (C) 2014 Cisco and/or its affiliates. All rights reserved.
+ * Copyright (C) 2002-2013 Sourcefire, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License Version 2 as
+ * published by the Free Software Foundation.  You may not use, modify or
+ * distribute this program under any other version of the GNU General
+ * Public License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+// config_profile.cc author Josh Rosenbaum <jorosenba@cisco.com>
+
+#include <sstream>
+#include <vector>
+
+#include "conversion_state.h"
+#include "util/converter.h"
+#include "util/util.h"
+
+namespace config
+{
+
+namespace {
+
+
+template<const std::string* table_name>
+class Profilers : public ConversionState
+{
+public:
+    Profilers(Converter* cv, LuaData* ld) : ConversionState(cv, ld) {};
+    virtual ~Profilers() {};
+    virtual bool convert(std::istringstream& data_stream);
+};
+
+} // namespace
+
+
+template<const std::string* table_name>
+bool Profilers<table_name>::convert(std::istringstream& data_stream)
+{
+    std::string args;
+    bool retval = true;
+
+    ld->open_table("profile");
+    ld->open_table(*table_name);
+
+    while (util::get_string(data_stream, args, ","))
+    {
+        bool tmpval = true;
+        std::istringstream arg_stream (args);
+        std::string keyword;
+
+        if (!(arg_stream >> keyword))
+            tmpval = false;
+
+        else if (!keyword.compare("print"))
+        {
+            ld->add_diff_option_comment("print", "count");
+
+            std::string tmp_string;
+            if (!(arg_stream >> tmp_string))
+                tmpval = false;
+
+            else if (!tmp_string.compare("all"))
+                tmpval = ld->add_option_to_table("count", -1);
+
+            else if (isdigit(tmp_string[0]) ||
+                     (tmp_string[0] == '-') ||
+                     (tmp_string[0] == '+'))
+                tmpval = ld->add_option_to_table("count", std::stoi(tmp_string));
+
+            else
+                tmpval = false;
+        }
+
+        else if (!keyword.compare("sort"))
+        {
+            std::string val;
+
+            if (!(arg_stream >> val))
+                tmpval = false;
+
+            else if (!val.compare("avg_ticks_per_nomatch"))
+            {
+                ld->add_diff_option_comment("sort avg_ticks_per_nomatch", "sort = avg_ticks_per_no_match");
+                tmpval = ld->add_option_to_table("sort", "avg_ticks_per_no_match");
+            }
+
+            else
+                tmpval = ld->add_option_to_table("sort", val);
+        }
+
+        else if (!keyword.compare("filename"))
+        {
+            ld->open_table("file");
+            tmpval = parse_string_option("name", arg_stream);
+
+            std::string append;
+            if ((arg_stream >> append) &&
+                (!append.compare("append")))
+            {
+                if (!ld->add_option_to_table("append", true))
+                    tmpval = false;
+            }
+
+            ld->close_table();
+        }
+
+        else
+        {
+            tmpval = false;
+        }
+
+        if (retval && !tmpval)
+            retval = false;
+    }
+
+    ld->close_table();
+    return retval;
+}
+
+template<const std::string* table_name>
+static ConversionState* ctor(Converter* cv, LuaData* ld)
+{
+    return new Profilers<table_name>(cv, ld);
+}
+
+/**************************
+ *******  A P I ***********
+ **************************/
+
+static const std::string rules = "rules";
+static const std::string preprocs = "preprocs";
+
+
+static const ConvertMap profile_rules_api =
+{
+    "profile_rules",
+    ctor<&rules>,
+};
+
+static const ConvertMap profile_preprocs_api =
+{
+    "profile_preprocs",
+    ctor<&preprocs>,
+};
+
+const ConvertMap* profile_rules_map = &profile_rules_api;
+const ConvertMap* profile_preprocs_map = &profile_preprocs_api;
+
+} // namespace config
\ No newline at end of file
diff --git a/tools/snort2lua/config_states/config_response.cc b/tools/snort2lua/config_states/config_response.cc
new file mode 100644 (file)
index 0000000..1460e3e
--- /dev/null
@@ -0,0 +1,96 @@
+/*
+** Copyright (C) 2014 Cisco and/or its affiliates. All rights reserved.
+ * Copyright (C) 2002-2013 Sourcefire, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License Version 2 as
+ * published by the Free Software Foundation.  You may not use, modify or
+ * distribute this program under any other version of the GNU General
+ * Public License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+// config_response.cc author Josh Rosenbaum <jorosenba@cisco.com>
+
+#include <sstream>
+#include <vector>
+
+#include "conversion_state.h"
+#include "util/converter.h"
+#include "util/util.h"
+
+namespace config
+{
+
+namespace {
+
+class Response : public ConversionState
+{
+public:
+    Response(Converter* cv, LuaData* ld) : ConversionState(cv, ld) {};
+    virtual ~Response() {};
+    virtual bool convert(std::istringstream& data_stream);
+};
+
+} // namespace
+
+bool Response::convert(std::istringstream& data_stream)
+{
+    std::string keyword;
+    bool retval = true;
+
+    ld->open_table("active");
+
+    while (util::get_string(data_stream, keyword, ", "))
+    {
+        bool tmpval = true;
+        std::string val;
+
+        if (!util::get_string(data_stream, val, ", "))
+            tmpval = false;
+
+        else if (!keyword.compare("attempts"))
+            tmpval = ld->add_option_to_table("attempts", std::stoi(val));
+
+        else if (!keyword.compare("device"))
+            tmpval = ld->add_option_to_table("device", val);
+
+        else if (!keyword.compare("dst_mac"))
+            tmpval = ld->add_option_to_table("dst_mac", val);
+
+        else
+            tmpval = false;
+
+
+        if (retval && !tmpval)
+            retval = false;
+    }
+
+    return retval;
+}
+
+/**************************
+ *******  A P I ***********
+ **************************/
+
+static ConversionState* ctor(Converter* cv, LuaData* ld)
+{
+    return new Response(cv, ld);
+}
+
+static const ConvertMap response_api =
+{
+    "response",
+    ctor,
+};
+
+const ConvertMap* response_map = &response_api;
+
+} // namespace config
\ No newline at end of file
diff --git a/tools/snort2lua/config_states/config_tunnel_verdicts.cc b/tools/snort2lua/config_states/config_tunnel_verdicts.cc
new file mode 100644 (file)
index 0000000..e8e41cc
--- /dev/null
@@ -0,0 +1,79 @@
+/*
+** Copyright (C) 2014 Cisco and/or its affiliates. All rights reserved.
+ * Copyright (C) 2002-2013 Sourcefire, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License Version 2 as
+ * published by the Free Software Foundation.  You may not use, modify or
+ * distribute this program under any other version of the GNU General
+ * Public License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+// config_tunnel_verdicts.cc author Josh Rosenbaum <jorosenba@cisco.com>
+
+#include <sstream>
+#include <vector>
+
+#include "conversion_state.h"
+#include "util/converter.h"
+#include "util/util.h"
+
+namespace config
+{
+
+namespace {
+
+class TunnelVerdicts : public ConversionState
+{
+public:
+    TunnelVerdicts(Converter* cv, LuaData* ld) : ConversionState(cv, ld) {};
+    virtual ~TunnelVerdicts() {};
+    virtual bool convert(std::istringstream& data_stream);
+};
+
+} // namespace
+
+bool TunnelVerdicts::convert(std::istringstream& data_stream)
+{
+    bool retval = true;
+    std::string val;
+
+    ld->open_table("alerts");
+
+    while (util::get_string(data_stream, val, ", "))
+    {
+        bool tmpval = ld->add_list_to_table("tunnel_verdicts", val);
+
+        if (retval && !tmpval)
+            retval = false;
+    }
+
+    return retval;
+}
+
+/**************************
+ *******  A P I ***********
+ **************************/
+
+static ConversionState* ctor(Converter* cv, LuaData* ld)
+{
+    return new TunnelVerdicts(cv, ld);
+}
+
+static const ConvertMap tunnel_verdicts_api =
+{
+    "tunnel_verdicts",
+    ctor,
+};
+
+const ConvertMap* tunnel_verdicts_map = &tunnel_verdicts_api;
+
+} // namespace config
index fc3448118d88b273390eda87b30eb2ee5a992aa4..08fd43a9acb7b0108808d430873eaeda5fad5af6 100644 (file)
@@ -258,7 +258,6 @@ protected:
     inline bool set_next_rule_state(std::istringstream& stream)
     {
         std::string keyword;
-
         int pos = stream.tellg();
 
 //        std::getline(stream, keyword, ':');
@@ -267,12 +266,14 @@ protected:
 
         while(std::getline(stream, keyword, ':'))
         {
-            int semi_colon_pos = keyword.find(';');
+            std::size_t semi_colon_pos = keyword.find(';');
             if (semi_colon_pos != std::string::npos)
             {
-                // found a nested option without a colon
-                // 2 == last charachter of option + semi_colon
-                stream.seekg(pos + semi_colon_pos + 1);
+                // found an option without a colon, so set stream
+                // to semi-colon
+                std::streamoff off = 1 + (std::streamoff)(pos) +
+                                     (std::streamoff)(semi_colon_pos);
+                stream.seekg(off);
                 keyword = keyword.substr(0, semi_colon_pos);
             }
 
index 7466209b32bbf0b4f70044aba0ea600f831a0474..74e32c90640e376bc47b2fc468bd125707a1124e 100644 (file)
@@ -1,5 +1,4 @@
 
-add_subdirectory(rule)
 
 add_library( conversion_data
     dt_comment.h
@@ -14,10 +13,10 @@ add_library( conversion_data
     dt_table.cc
     dt_rule.h
     dt_rule.cc
+    dt_rule_option.h
+    dt_rule_option.cc
+    dt_rule_suboption.h
+    dt_rule_suboption.cc
     dt_var.h
     dt_var.cc
 )
-
-target_link_libraries( conversion_data
-    rule_data
-)
index 3fc8cbbdb6550c2b702780eaea3ceab268d97e57..1d58edb38571d68e347fbd10fb8ddc3a996c21c4 100644 (file)
@@ -79,8 +79,8 @@ void Comments::add_sorted_text(std::string new_text)
 
 bool Comments::empty()
 {
-    int cnt = header ? -1 : 0;
-    return ((comment.size() + cnt) == 0);
+    return ((comment.size() == 0) ||
+            (comment.size() == 1 && header));
 }
 
 std::ostream &operator<<( std::ostream& out, const Comments &c)
@@ -108,14 +108,14 @@ std::ostream &operator<<( std::ostream& out, const Comments &c)
     }
 
 
-    const int pre_str_length = pre_str.size();
+    const std::size_t pre_str_length = pre_str.size();
 
 
     for (std::string str : c.comment)
     {
         bool first_line = true;
         std::string curr_pre_str = pre_str;
-        int max_line_length = c.max_line_length - pre_str_length - 1;
+        std::size_t max_line_length = c.max_line_length - pre_str_length - 1;
 
         // print a newline betweens strings, but not before the first line.
         if (first_str)
@@ -132,7 +132,7 @@ std::ostream &operator<<( std::ostream& out, const Comments &c)
 
         while(!str.empty())
         {
-            int substr_len = max_line_length;
+            std::size_t substr_len = max_line_length;
 
             // determine the first space before 80 charachters
             // if there are no spaces, print the entire string
@@ -140,7 +140,7 @@ std::ostream &operator<<( std::ostream& out, const Comments &c)
             {
                 substr_len = str.rfind(" ", max_line_length);
 
-                if (substr_len == -1)
+                if (substr_len == std::string::npos)
                 {
                     substr_len = str.find(" ");
 
index f57e9171b8144a05caae48acf126cb1517cf4ad6..5f591a8ec5047d3c2dd4048fb3047d89834cc474 100644 (file)
@@ -71,7 +71,7 @@ private:
     bool prev_empty;
     bool header;  // true if a string was passed into constructor
     enum CommentType type;
-    const int max_line_length = 80;
+    const std::size_t max_line_length = 80;
     const std::string comment_line = "--";
     const std::string start_multi_com = "--[[";
     const std::string end_multi_com = "--]]";
index defc5fec39137455bfcf07eea495315e68c760cf..43c4b120ba89aa99c8b136fbc49bc5a427150a86 100644 (file)
@@ -25,7 +25,7 @@
 #include <sstream>
 
 
-LuaData::PrintMode LuaData::mode = LuaData::PrintMode::DEFAULT;
+LuaData::PrintMode LuaData::mode = LuaData::PrintMode::QUIET;
 
 static inline Table* find_table(std::vector<Table*> vec, std::string name)
 {
@@ -349,11 +349,12 @@ void LuaData::bad_rule(std::string bad_option, std::istringstream& stream)
     // we only need to go through this once.
     if (!curr_rule_bad)
     {
-        bad_rules->add_text("Failed to convert rule: first_unkown_option=" + bad_option);
-        bad_rules->add_text("bad_rule: " + stream.str() + ")");
+        bad_rules->add_text(std::string());
+        bad_rules->add_text("Failed to convert rule: " + stream.str() + ")");
         curr_rule->bad_rule();
         curr_rule_bad = true;
     }
+    bad_rules->add_text("^^^^ unkown_option=" + bad_option);
 }
 
 bool LuaData::add_hdr_data(std::string data)
index 5349739b7f564e38cefbefa48a88ca0d02fc43ac..2100f0bdea679409c63c07f711f1f1b889015dd5 100644 (file)
@@ -123,7 +123,7 @@ std::ostream &operator<<( std::ostream& out, const Rule &rule)
     if (rule.is_bad_rule || rule.is_comment)
         out << "#";
 
-    for(int i = 0; i < rule.num_hdr_data; i++)
+    for(std::size_t i = 0; i < rule.num_hdr_data; i++)
     {
         if (first_line)
             first_line = false;
index a95167c6f4148c9acf730052897c8bf9ca2bc3c8..3f13ff4b497fede969e3822969b7ba8353d6097c 100644 (file)
@@ -28,7 +28,7 @@
 #include <iostream>
 #include <array>
 
-#include "data/rule/rd_option.h"
+#include "data/dt_rule_option.h"
 
 class Rule
 {
@@ -53,7 +53,7 @@ private:
     std::vector<std::string> comments;
     std::array<std::string, 7> hdr_data;
     std::vector<RuleOption*> options;
-    int num_hdr_data;
+    std::size_t num_hdr_data;
     bool is_bad_rule;
     bool is_comment;
 };
similarity index 98%
rename from tools/snort2lua/data/rule/rd_option.cc
rename to tools/snort2lua/data/dt_rule_option.cc
index 80177a56c19bee71f87f2ad8af20a1332658d332..52b179ea87a6d8bcf1bf13e06b7a6f1ac90baaaf 100644 (file)
@@ -19,7 +19,7 @@
  */
 // rd_option.cc author Josh Rosenbaum <jorosenba@cisco.com>
 
-#include "data/rule/rd_option.h"
+#include "data/dt_rule_option.h"
 
 
 
similarity index 94%
rename from tools/snort2lua/data/rule/rd_option.h
rename to tools/snort2lua/data/dt_rule_option.h
index 76e8ddac1616e1447b0edd35c91ac93f3c4bc262..996d77b37659fc6b8970a3ed99075598f2343219 100644 (file)
  */
 // dt_option.h author Josh Rosenbaum <jorosenba@cisco.com>
 
-#ifndef RD_OPTION_H
-#define RD_OPTION_H
+#ifndef DT_RULE_OPTION_H
+#define DT_RULE_OPTION_H
 
 #include <string>
 #include <vector>
 #include <iostream>
 
-#include "data/rule/rd_suboption.h"
+#include "data/dt_rule_suboption.h"
 
 class RuleOption
 {
similarity index 93%
rename from tools/snort2lua/data/rule/rd_suboption.cc
rename to tools/snort2lua/data/dt_rule_suboption.cc
index 600b8cc64bbf34aa0417cc26bc801078de029157..99a3ae8b516fb0d00c409b43d6bfce98fae44370 100644 (file)
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  */
-// rd_suboption.cc author Josh Rosenbaum <jorosenba@cisco.com>
+// dt_rule_suboptions.cc author Josh Rosenbaum <jorosenba@cisco.com>
 
 #include <string>
-
-#include "data/rule/rd_suboption.h"
+#include "data/dt_rule_suboption.h"
 
 
 RuleSubOption::RuleSubOption(std::string name)
similarity index 91%
rename from tools/snort2lua/data/rule/rd_suboption.h
rename to tools/snort2lua/data/dt_rule_suboption.h
index d111ef25465aa21576775b77b485e0632a2d9842..6df2c23e48255edd667e4581da4c7b5c810220d2 100644 (file)
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  */
-// dt_option.h author Josh Rosenbaum <jorosenba@cisco.com>
+// dt_rule_suboptions.h author Josh Rosenbaum <jorosenba@cisco.com>
 
-#ifndef RD_SUBOPTION_H
-#define RD_SUBOPTION_H
+#ifndef DT_RULE_SUBOPTIONS_H
+#define DT_RULE_SUBOPTIONS_H
 
 #include <string>
 #include <vector>
index ca5f027fd80442655f8b719d6c508f0496db688a..bd3940a53101b9af6c2f0a056276d033395cccab 100644 (file)
@@ -80,7 +80,9 @@ bool Variable::add_value(std::string elem)
     return true;
 }
 
-static inline void print_newline(std::ostream& out, int& count, std::string whitespace)
+static inline void print_newline(std::ostream& out,
+                                 std::size_t& count,
+                                 std::string whitespace)
 {
     out << "\n" << whitespace;
     count = whitespace.size();
@@ -90,7 +92,7 @@ std::ostream& operator<<( std::ostream& out, const Variable &var)
 {
     std::string whitespace;
     bool first_var = true;
-    int count = 0;
+    std::size_t count = 0;
 
     for(int i = 0; i < var.depth; i++)
         whitespace += "    ";
@@ -142,8 +144,8 @@ std::ostream& operator<<( std::ostream& out, const Variable &var)
             count += 3;
 
 
-            int printed_length = 0;
-            int str_size = v->data.size();
+            std::size_t printed_length = 0;
+            std::size_t str_size = v->data.size();
             bool first_loop = true;
 
             while (printed_length < str_size)
@@ -159,12 +161,21 @@ std::ostream& operator<<( std::ostream& out, const Variable &var)
 
 
                 std::string tmp = v->data.substr(printed_length);
-                int remaining_space = var.max_line_length - count;
-                int str_len = util::get_substr_length(tmp, remaining_space);
-                out << tmp.substr(0, str_len);
 
-                count += str_len;
-                printed_length += str_len;
+                if (var.max_line_length < count)
+                {
+                    out << "FATAL ERROR: dt_var.cc - underflow! was "
+                            "not reset" << std::endl;
+                }
+                else
+                {
+                    std::size_t remaining_space = var.max_line_length - count;
+                    std::size_t str_len = util::get_substr_length(tmp, remaining_space);
+                    out << tmp.substr(0, str_len);
+
+                    count += str_len;
+                    printed_length += str_len;
+                }
             }
 
             out << " ]]";
index 41657dbfefe2e215a4a69f7522535fa3db837c03..92a16c31c3efeb9dfab5640e5b44d0da26cefe29 100644 (file)
@@ -50,7 +50,7 @@ private:
     std::vector<VarData*> vars;
     std::string name;
     int depth;
-    const int max_line_length = 77; // leave room for additional text
+    const std::size_t max_line_length = 77; // leave room for additional text
 
 };
 
diff --git a/tools/snort2lua/data/rule/CMakeLists.txt b/tools/snort2lua/data/rule/CMakeLists.txt
deleted file mode 100644 (file)
index e38b197..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-
-add_library( rule_data
-    rd_option.h
-    rd_option.cc
-    rd_suboption.h
-    rd_suboption.cc
-)
diff --git a/tools/snort2lua/data/rule/rd_string.cc b/tools/snort2lua/data/rule/rd_string.cc
deleted file mode 100644 (file)
index e69de29..0000000
index bbdd85704c6c297e3263910c139441f1cf600f4d..ed651b324a433b15fa8a4790afe1968f33b14b4f 100644 (file)
@@ -47,7 +47,7 @@ bool Config::convert(std::istringstream& data_stream)
 {
     std::string keyword;
 
-    if(data_stream >> keyword)
+    if (util::get_string(data_stream, keyword, ":"))
     {
 
         if(keyword.back() == ':')
index 202ba6468923739471245c065dc233ff614b01ae..c4d09ed626b54878209068a71bdc98d1506cfbc8 100644 (file)
@@ -64,8 +64,9 @@ bool RuleHeader::convert(std::istringstream& data_stream)
     // add that part back when printing each rule.
     int curr_pos = data_stream.tellg();
     std::string rule_string = data_stream.str();
-    int end_pos = rule_string.rfind(')');
+    std::size_t end_pos = rule_string.rfind(')');
     rule_string = rule_string.substr(0, end_pos);
+    util::rtrim(rule_string); // gaurantee last char is a rule opt/subopt
     data_stream.str(rule_string);
     data_stream.seekg(curr_pos);  // position was reset. so find curr position
 
index 445ebc16f0ab7800cf2180fecefd05532e07abdb..622b16b2d4ce937e3bfd79a4926baf27040969c7 100644 (file)
@@ -43,76 +43,56 @@ public:
 
 bool RuleState::convert(std::istringstream& data_stream)
 {
-    std::string keyword;
+    std::string arg;
     bool retval = true;
     int count = 0;
 
     ld->open_new_top_level_table("rule_state");
 
-    while (data_stream >> keyword)
+    while (util::get_string(data_stream, arg, ", "))
     {
-        int prev = 0;
+        bool tmpval = true;
 
-        // Snort delineates by either a space or a comma
-        while (prev < keyword.size())
+        switch (count)
         {
-            std::string arg;
-            bool tmpval = true;
-            int pos = keyword.find_first_of(",", prev);
-
-            if (pos == std::string::npos)
-            {
-                arg = keyword.substr(prev);
-                prev = pos;
-            }
-            else
-            {
-                arg = keyword.substr(prev, pos - prev);
-                prev = pos + 1;
-            }
-
-
-            switch (count)
-            {
-                case 0:
-                    tmpval = ld->add_option_to_table("sid", std::stoi(arg));
-                    count++;
-                    break;
-                case 1:
-                    tmpval = ld->add_option_to_table("gid", std::stoi(arg));
-                    count++;
-                    break;
-                case 2:
-                    if (!arg.compare("enabled"))
-                    {
-                        ld->add_diff_option_comment("enabled", "enable");
-                        tmpval = ld->add_option_to_table("enable", true);
-                    }
-                    else if (!arg.compare("disabled"))
-                    {
-                        ld->add_diff_option_comment("disabled", "enable");
-                        tmpval = ld->add_option_to_table("enable", false);
-                    }
-                    else
-                    {
-                        ld->add_error_comment("unkown option!");
-                        retval = false;
-                    }
-
-                    count++;
-                    break;
-                case 3:
-                    ld->add_deprecated_comment("action");
-                    count++;
-                    break;
-                default:
-                    ld->add_error_comment("rule_state has too many option!!");
-
-            }
-
-            if (retval)
-                retval = tmpval;
+            case 0:
+                tmpval = ld->add_option_to_table("sid", std::stoi(arg));
+                count++;
+                break;
+            case 1:
+                tmpval = ld->add_option_to_table("gid", std::stoi(arg));
+                count++;
+                break;
+            case 2:
+                if (!arg.compare("enabled"))
+                {
+                    ld->add_diff_option_comment("enabled", "enable");
+                    tmpval = ld->add_option_to_table("enable", true);
+                }
+                else if (!arg.compare("disabled"))
+                {
+                    ld->add_diff_option_comment("disabled", "enable");
+                    tmpval = ld->add_option_to_table("enable", false);
+                }
+                else
+                {
+                    ld->add_error_comment("unkown option!");
+                    retval = false;
+                }
+
+                count++;
+                break;
+            case 3:
+                ld->add_deprecated_comment("action");
+                count++;
+                break;
+            default:
+                ld->add_error_comment("rule_state has too many option!!");
+
         }
+
+        if (retval && !tmpval)
+            retval = false;
     }
 
     return retval;
index 6fa783b2b9a517c8519210b664c960dfa04fafa2..a5d0f25c67dae60ae4c7bdc740a3d4eacb2361d8 100644 (file)
@@ -29,7 +29,7 @@
 namespace output
 {
 
-static ConversionState* ctor(Converter* cv, LuaData* ld)
+static ConversionState* ctor(Converter* /*cv*/, LuaData* ld)
 {
     ld->open_table("alert_null"); // in case there are no arguments
     ld->close_table();
index 69d20f526dc194ed618d2d5a491f3559acd6288a..89ce62086638ad34f6f80d199a4e5506b85fc1ab 100644 (file)
@@ -29,7 +29,7 @@
 namespace output
 {
 
-static ConversionState* ctor(Converter* cv, LuaData* ld)
+static ConversionState* ctor(Converter* /*cv*/, LuaData* ld)
 {
     ld->open_table("alert_unixsock"); // in case there are no arguments
     ld->close_table();
index b0ca98239924b0c323cb0c649dab3fd70b2520f7..3ea81aca39f067df47a506ca755a4cc30ceb7880 100644 (file)
@@ -13,7 +13,6 @@ add_library(preprocessor_states
     pps_perfmonitor.cc
     pps_rpc_decode.cc
     pps_sfportscan.cc
-    pps_smtp.cc
     pps_stream_ip.cc
     pps_stream_global.cc
     pps_stream_tcp.cc
index dcd68f753aaa825f7d25c3c9bf1cc21573b8fb4d..2dcc222cf127194fcda3d107da5f63271417efd1 100644 (file)
@@ -31,7 +31,7 @@
 namespace preprocessors
 {
 
-static ConversionState* bo_ctor(Converter* cv, LuaData* ld)
+static ConversionState* bo_ctor(Converter* /*cv*/, LuaData* ld)
 {
     ld->open_table("bo");
     ld->close_table();
index 1aed8ba81962b2bbb27378957e412914d15b39ce..e012664a373ec6de04f08788d0229a616e655cb5 100644 (file)
@@ -70,7 +70,7 @@ bool Frag3Global::convert(std::istringstream& data_stream)
 
         else if(!keyword.compare("prealloc_memcap"))
             tmpval = parse_deleted_option("prealloc_memcap", args_stream);
-        
+
         else if(!keyword.compare("prealloc_frags"))
             tmpval = parse_deleted_option("prealloc_frags", args_stream);
 
index 06de19e1261c6a364d1b6913200422e3a4ae341b..580af8807e58f01e1a25e8f5b6d7074cdb8a71d4 100644 (file)
@@ -32,7 +32,7 @@ namespace preprocessors
 
 
 template<const std::string *norm_option>
-static ConversionState* norm_sans_options_ctor(Converter* cv, LuaData* ld)
+static ConversionState* norm_sans_options_ctor(Converter* /*cv*/, LuaData* ld)
 {
     ld->open_table("normalize");
     ld->add_diff_option_comment("preprocessor normalize_" + *norm_option, *norm_option + " = <bool>");
@@ -238,19 +238,19 @@ bool TcpNormalizer::convert(std::istringstream& data_stream)
         
         else if(!keyword.compare("trim_rst"))
         {
-            tmpval = ld->add_diff_option_comment("trim_rst", "trim");
+            ld->add_diff_option_comment("trim_rst", "trim");
             tmpval = ld->add_option_to_table("trim", true);
         }
         
         else if(!keyword.compare("trim_win"))
         {
-            tmpval = ld->add_diff_option_comment("trim_win", "trim");
+            ld->add_diff_option_comment("trim_win", "trim");
             tmpval = ld->add_option_to_table("trim", true);
         }
         
         else if(!keyword.compare("trim_mss"))
         {
-            tmpval = ld->add_diff_option_comment("trim_mss", "trim");
+            ld->add_diff_option_comment("trim_mss", "trim");
             tmpval = ld->add_option_to_table("trim", true);
         }
 
diff --git a/tools/snort2lua/preprocessor_states/pps_smtp.cc b/tools/snort2lua/preprocessor_states/pps_smtp.cc
deleted file mode 100644 (file)
index bf69633..0000000
+++ /dev/null
@@ -1,115 +0,0 @@
-/*
-** Copyright (C) 2014 Cisco and/or its affiliates. All rights reserved.
- * Copyright (C) 2002-2013 Sourcefire, Inc.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License Version 2 as
- * published by the Free Software Foundation.  You may not use, modify or
- * distribute this program under any other version of the GNU General
- * Public License.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-// smtp.cc author Josh Rosenbaum <jorosenba@cisco.com>
-
-#include <sstream>
-#include <vector>
-
-#include "conversion_state.h"
-#include "util/converter.h"
-#include "util/util.h"
-
-namespace preprocessors
-{
-
-namespace {
-
-class Smtp : public ConversionState
-{
-public:
-    Smtp(Converter* cv, LuaData* ld) : ConversionState(cv, ld) {};
-    virtual ~Smtp() {};
-    virtual bool convert(std::istringstream& data_stream);
-};
-
-} // namespace
-
-
-bool Smtp::convert(std::istringstream& data_stream)
-{
-
-#if 0
-    std::string keyword;
-    if(data_stream >> keyword)
-    {
-        const ConvertMap* map = util::find_map(output_api, keyword);
-        if (map)
-        {
-            cv->set_state(map->ctor(converter));
-            return true;
-        }
-    }
-
-ports
-inspection_type stateful|stateless
-normalize all|none|cmds *
-ignore_data
-ignore_tls_data
-max_command_line_len <int> 
-max_header_line_len <int> *
-max_response_line_len <int>
-alt_max_command_line_len <int> { <cmd> [<cmd>] }
-no_alerts
-invalid_cmds { <Space-delimited list of commands> } 
-valid_cmds { <Space-delimited list of commands> } 
-data_cmds { <Space-delimited list of commands> } 
-binary_data_cmds { <Space-delimited list of commands> }
-auth_cmds { <Space-delimited list of commands> } 
-alert_unknown_cmds
-normalize_cmds { <Space-delimited list of commands> } 
-xlink2state { enable/disable [drop] }
-print_cmds
-disabled
-b64_decode_depth
-qp_decode_depth
-bitenc_decode_depth
-uu_decode_depth
-enable_mime_decoding
-max_mime_depth <int> 
-max_mime_mem <int> 
-log_mailfrom
-log_rcptto
-log_filename
-log_email_hdrs
-email_hdrs_log_depth <int> 
-memcap <int>
-#endif
-
-    return false;    
-}
-
-/**************************
- *******  A P I ***********
- **************************/
-
-static ConversionState* ctor(Converter* cv, LuaData* ld)
-{
-    return new Smtp(cv, ld);
-}
-
-static const ConvertMap preprocessor_smtp = 
-{
-    "smtp",
-    ctor,
-};
-
-const ConvertMap* smtp_map = &preprocessor_smtp;
-
-} // namespace preprocessors
index 2769036eb91da65b58a3e3d160d5626a860d981a..137f480a4bf5efe21171a67a11aa4200cc6b827a 100644 (file)
@@ -162,7 +162,6 @@ bool StreamTcp::convert(std::istringstream& data_stream)
 {
     std::string keyword;
     bool retval = true;
-    bool blahhablha;
 
     ld->open_table("stream_tcp");
 
index 3b98e2e45418ef636e736b5458ea34f3ee8bb0a5..cdc9cf558f49272369491e7198328a10617c5f3b 100644 (file)
@@ -42,7 +42,6 @@ extern const ConvertMap *normalizer_tcp_map;
 extern const ConvertMap *perfmonitor_map;
 extern const ConvertMap *rpc_decode_map;
 extern const ConvertMap *sfportscan_map;
-extern const ConvertMap *smtp_map;
 extern const ConvertMap *stream_ip_map;
 extern const ConvertMap *stream_global_map;
 extern const ConvertMap *stream_tcp_map;
@@ -68,7 +67,6 @@ const std::vector<const ConvertMap*> preprocessor_api =
     perfmonitor_map,
     rpc_decode_map,
     sfportscan_map,
-    smtp_map,
     stream_ip_map,
     stream_global_map,
     stream_tcp_map,
index 68e664c35e27e5768ab44213077ffbb8e8765a54..f5a3db11fbdf53b974ea21ad143054b7d3375497 100644 (file)
@@ -68,14 +68,13 @@ bool Content<option_name>::convert(std::istringstream& data_stream)
     {
         bool tmpval = true;
         util::trim(val);
-        int keyword_pos = val.find_first_of(':');
+        std::size_t keyword_pos = val.find_first_of(':');
         std::string keyword;
 
         if (keyword_pos != std::string::npos)
         {
             keyword = val.substr(0, keyword_pos);
             val = val.substr(keyword_pos + 1, std::string::npos);
-//            subopts.str(val);  // reset the subopts buffer for someone else
         }
         else
         {
index 724fc0ecc6c3c74a663417fb688d20cf0d8d93de..2a04c97d9179ed2c10553476243f7156eeb68cce 100644 (file)
@@ -52,7 +52,7 @@ bool Pcre::convert(std::istringstream& data_stream)
 
     std::string pcre_str = util::get_rule_option_args(data_stream);
 
-    int pattern_end = pcre_str.rfind("/");
+    std::size_t pattern_end = pcre_str.rfind("/");
     std::string pattern = pcre_str.substr(0, pattern_end + 1);
     std::string options = pcre_str.substr(pattern_end + 1, std::string::npos);
     std::string new_opts = std::string();
index e1bf6b47e8dac6119adf64924c1ea61aa5bb44f0..1ef2b83b622825b48821634659d6aa22313add50 100644 (file)
@@ -40,7 +40,7 @@ struct Arg: public option::Arg
   static void printError(const char* msg1, const option::Option& opt, const char* msg2)
   {
     fprintf(stderr, "%s", msg1);
-    fwrite(opt.name, opt.namelen, 1, stderr);
+      fwrite(opt.name, (std::size_t)opt.namelen, 1, stderr);
     fprintf(stderr, "%s", msg2);
   }
 
@@ -231,7 +231,11 @@ int main (int argc, char* argv[])
             print_line("Multiple print modes provided. "
                 "Running in " + mode + " mode");
     }
-
+    else
+    {
+        quiet_mode = true;
+        ld.set_quiet_print();
+    }
 
     // Get the output file.  Warn the user if they provided multiple
     // files
index b080657d4565c569b9d371192802bff8c650965a..6ddd77e125472561f0e85e771b8abd52962e590f 100644 (file)
@@ -158,7 +158,7 @@ int Converter::convert_file(std::string input_file)
         std::getline(in, tmp);
         util::rtrim(tmp);
 
-        int first_non_white_char = tmp.find_first_not_of(' ');
+        std::size_t first_non_white_char = tmp.find_first_not_of(' ');
         if ((first_non_white_char == std::string::npos) ||
                  (tmp[first_non_white_char] == '#') ||
                  (tmp[first_non_white_char] == ';')) // no, i did not know that semicolons made a line a comment
@@ -184,7 +184,7 @@ int Converter::convert_file(std::string input_file)
         {
             orig_text += tmp;
             std::istringstream data_stream(orig_text);
-            while(data_stream.tellg() != -1)
+            while(data_stream.peek() != std::char_traits<wchar_t>::eof())
             {
                 if ((state == nullptr) || !state->convert(data_stream))
                 {
index 0ae65faf96d13380e8a33f9affa690cbdaf10e6b..1f344c4cb292e75786b714a9d21b886a3fd06301 100644 (file)
@@ -25,6 +25,8 @@
 #include <cctype>
 #include <locale>
 #include <sys/stat.h>
+#include <iostream>
+#include <string>
 #include "util/util.h"
 #include "conversion_state.h"
 
@@ -58,7 +60,7 @@ const ConvertMap* find_map(const std::vector<const ConvertMap*> map, std::string
 std::string &sanitize_multi_line_string(std::string &s)
 {
 
-    int found = s.find("]]");
+    std::size_t found = s.find("]]");
     while (found != std::string::npos)
     {
         s.insert(found + 1, " ");
@@ -76,9 +78,9 @@ std::string &sanitize_multi_line_string(std::string &s)
 }
 
 
-int get_substr_length(std::string str, int max_length)
+std::size_t get_substr_length(std::string str, std::size_t max_length)
 {
-    int str_len;
+    std::size_t str_len;
 
     if (str.size() < max_length)
         return str.size();
@@ -112,26 +114,33 @@ bool get_string(std::istringstream& stream,
     }
     else
     {
-        int pos;
+        int pos = 0;
         option = std::string();
 
+        // we don't want an empty string
         while (stream.good() && option.empty())
         {
             pos = stream.tellg();
             std::getline(stream, option, delimeters[0]);
         }
 
-        // check to ensure we got some data (and not a whitespace string)
-        if(option.find_first_not_of(' ') == std::string::npos)
+        // find the first non-delimeter charachter
+        const std::size_t first_char = option.find_first_not_of(delimeters);
+
+        // if there are no charachters between a delimeter, empty string. return false
+        if (first_char == std::string::npos)
             return false;
 
-        int first_delim = option.find_first_of(delimeters);
-        if (first_delim != std::string::npos)
-        {
-            option = option.substr(0, first_delim);
-            stream.seekg(pos + first_delim + 1); // + 1 to eat delimeter
-        }
+        // find the first delimeter after the first non-delimeter
+        std::size_t first_delim = option.find_first_of(delimeters, first_char);
+
+        if (first_delim == std::string::npos)
+            first_delim = option.size();    // set value to take proper substr
+        else
+            stream.seekg((std::streamoff)(pos) + (std::streamoff)(first_delim) + 1);
+
 
+        option = option.substr(first_char, first_delim - first_char);
         trim(option);
         return true;
     }
@@ -160,6 +169,16 @@ bool file_exists (const std::string& name) {
   return (stat (name.c_str(), &buffer) == 0);
 }
 
+bool case_compare(std::string arg1, std::string arg2)
+{
+    std::transform(arg1.begin(), arg1.end(), arg1.begin(), ::tolower);
+    std::transform(arg2.begin(), arg2.end(), arg2.begin(), ::tolower);
+
+    if (!arg1.compare(arg2))
+        return true;
+    return false;
+}
+
 #if 0
 bool is_textfile_empty( const char* filename )
 {
index abfd7ae76ff49f7f4219c802cef19d8570a8aafc..ff449a1fa2be9e297554c65d4b952259f8678c1d 100644 (file)
@@ -93,7 +93,9 @@ std::string &sanitize_multi_line_string(std::string &s);
 // find the location of the first space before max_str_lenght.
 // if no space exists before max_str_length, return the first space
 // after max_length. Otherwise, return std::string::npos
-int get_substr_length(std::string s, int max_length);
+std::size_t  get_substr_length(std::string s, std::size_t max_length);
+
+bool case_compare(std::string, std::string);
 
 }  // namespace util