]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
minor documentation fixes
authorJosh <jrosenba@cisco.com>
Fri, 10 Oct 2014 21:54:35 +0000 (16:54 -0500)
committerJosh <jrosenba@cisco.com>
Fri, 10 Oct 2014 21:54:35 +0000 (16:54 -0500)
CMakeLists.txt
tools/snort2lua/config_states/config_binding.cc
tools/snort2lua/config_states/config_ignore_ports.cc
tools/snort2lua/utils/parse_cmd_line.cc

index 0302f5d00c049b30323b85a8f89014d892a711b8..4b12495c297914914c9ddb446c9a0a22f4d2a7e7 100644 (file)
@@ -4,7 +4,7 @@ project (snort CXX C)
 
 set (SNORT_VERSION_MAJOR 2)
 set (SNORT_VERSION_MINOR 10)
-set (SNORT_VERSION_BUILD  120)
+set (SNORT_VERSION_BUILD  0)
 set (VERSION "${SNORT_VERSION_MAJOR}.${SNORT_VERSION_MINOR}.${SNORT_VERSION_BUILD}")
 
 # ensure cmake will look in the cmake directory for configuration files
index b4513c84af54fe74955e4814ffdb9f16becbe99b..3a31c351ec12e381b5e98b3cafed6b70a8156e42 100644 (file)
@@ -175,8 +175,7 @@ bool Binding::convert(std::istringstream& data_stream)
     } while (util::get_string(data_stream, val, ","));
 
 
-    // FIXIT-M J   This need to be refactored with converter.
-    //          Should NOT be doing all of this here.
+
     if (cv.should_convert_includes())
     {
         std::string full_name = data_api.expand_vars(file);
@@ -190,9 +189,11 @@ bool Binding::convert(std::istringstream& data_stream)
         if (util::file_exists(full_path))
         {
             Converter cv;
+            file = full_path + ".lua";
 
-            if (cv.convert(full_path, full_path + ".lua") < 0)
+            if (cv.convert(full_path, file) < 0)
                 rc = false;
+
         }
     }
 
index 4206802d2f93d6c0d44cb6680bde35957c16d77f..34d516dfa9b0c5673603236b14ffd3fac9771146 100644 (file)
@@ -37,7 +37,7 @@ constexpr uint16_t MAX_PORTS = 0xFFFF; // == 65535
 class IgnorePorts : public ConversionState
 {
 public:
-    IgnorePorts() : ConversionState() {};
+    IgnorePorts(Converter& c) : ConversionState(c) {};
     virtual ~IgnorePorts() {};
     virtual bool convert(std::istringstream& data_stream);
 };
@@ -47,7 +47,7 @@ public:
 
 bool IgnorePorts::convert(std::istringstream& data_stream)
 {
-    Binder bind;
+    Binder bind(table_api);
     bool retval = true;
     std::string keyword;
     std::string port;
@@ -137,9 +137,9 @@ bool IgnorePorts::convert(std::istringstream& data_stream)
  *******  A P I ***********
  **************************/
 
-static ConversionState* ctor()
+static ConversionState* ctor(Converter& c)
 {
-    return new IgnorePorts();
+    return new IgnorePorts(c);
 }
 
 static const ConvertMap config_ignore_ports =
index a7ff51dfd736f23400e6fdd8f90a8625eeb7cabd..5dfbf393db5ba59fb21bd9bea1261b412f868cb4 100644 (file)
 #include <iostream>
 #include <string>
 #include <string.h>
-#include <iostream>
+#include <iomanip>
 
 #include "utils/parse_cmd_line.h"
 #include "data/dt_data.h"
 #include "utils/converter.h"
+#include "utils/s2l_util.h"
 
 namespace parser
 {
 
+typedef void (*ParseConfigFunc)(const char*, const char* val);
+struct ConfigFunc
+{
+    const char *name;
+    ParseConfigFunc parse_func;
+    std::string type;
+    const char* help;
+};
+
+
+
+
 static const std::string out_default = "snort.lua";
-static const std::string error_default = "snort.lua";
+static const std::string error_default = "snort.rej";
 
 static std::string conf_file = std::string();
 static std::string conf_dir = std::string();
@@ -61,9 +74,8 @@ const std::string get_out_file()
 const std::string get_rule_file()
 { return rule_file.empty() ? get_out_file() : rule_file; }
 
-static void help_args(const char* pfx);
-static void help_usage();
 
+static void help_args(const char* pfx, const char* /*val*/);
 
 //-------------------------------------------------------------------------
 // arg foo
@@ -163,12 +175,16 @@ bool ArgList::get_arg(const char*& key, const char*& val)
     return false;
 }
 
-static void help_usage(const char* /*key*/, const char* val)
+static void help_usage()
 {
-    fprintf(stdout, "USAGE: snort2lua [-options]\n");
-    help_args(val);
+    fprintf(stdout, "usage:\n");
+    fprintf(stdout, "    -?: list options\n");
+    fprintf(stdout, "    -V: output version\n");
+    fprintf(stdout, "    --help: help summary\n");
     exit(1);
 }
+static void help_usage(const char* key, const char* /*val*/)
+{ help_usage(); }
 
 /*
  * MOST OF THIS FUNCTION IS TAKEN FROM SNORT!!
@@ -268,127 +284,122 @@ static void sing_conf_files(const char* /*key*/, const char* /*val*/)
 static void dont_parse_includes(const char* /*key*/, const char* /*val*/)
 { Converter::set_parse_includes(false); }
 
+static void print_version(const char* /*key*/, const char* /*val*/)
+{
+    fprintf(stdout, "Snort2Lua\t0.1.5");
+}
 
-typedef void (*ParseConfigFunc)(const char*, const char* val);
-struct ConfigFunc
+
+
+static void help(const char* key, const char* val)
 {
-    const char *name;
-    ParseConfigFunc parse_func;
-    const char* help;
-};
+    fprintf(stdout, "Usage: [OPTIONS]... -c <snort_conf> ...\n");
+    fprintf(stdout, "\n");
+    fprintf(stdout, "Converts the Snort configuration file specified by the -c or --conf-file\n");
+    fprintf(stdout, "options into a Snort++ configuration file\n");
+    fprintf(stdout, "\n");
+    fprintf(stdout, "\n");
+    fprintf(stdout, "\n");
+    fprintf(stdout, "Options:\n");
+    help_args(key, val);
+    fprintf(stdout, "\n");
+    fprintf(stdout, "\n");
+    fprintf(stdout, "\n");
+    fprintf(stdout, "Required option(s):\n");
+    fprintf(stdout, "\tA Snort configure file to converter. Set with either '-c' or '--conf-file'\n");
+    fprintf(stdout, "\n");
+    fprintf(stdout, "\n");
+    fprintf(stdout, "Default values:\n");
+    fprintf(stdout, "<out_file>   =  %s\n", out_default.c_str() );
+    fprintf(stdout, "<rule_file>  =  <out_file>.  Rules will be written to the <out_file>\n");
+    fprintf(stdout, "<error_file> =  %s.  Only occurs when not in Quiet mode.\n", error_default.c_str());
+    fprintf(stdout, "\n");
+    exit(0);
+}
 
 
 static ConfigFunc basic_opts[] =
 {
-    { "?", help_usage,
+    { "?", help_args, "",
       "show usage" },
 
-    { "h", help_usage,
+    { "h", help, "",
         "this overview of snort2lua"},
 
-    { "a", print_all,
+    { "a", print_all, "",
         "print all data, including errors and Snort - Snort++ configuration differences."},
 
-    { "c", parse_config_file,
-        "The Snort <conf> file to convert"},
+    { "c", parse_config_file, "<snort_conf>",
+        "The Snort <snort_conf> file to convert"},
 
-    { "d", print_differences,
-        "print Snort - Snort++ configuration differences, and only those differences"},
+    { "d", print_differences, "",
+        "print the differences, and only the differences, between the Snort and Snort++ configurations"},
 
-    { "e", parse_error_file,
+    { "e", parse_error_file, "<error_file>",
         "output all errors to <error_file>"},
 
-    { "o", parse_output_file,
-        "output the new Snort++ lua configuration to <out_file>"},
-
-    { "p", dont_parse_includes,
-        "if <conf> file contains any <include_file> or <policy_file> "
+    { "i", dont_parse_includes, "",
+        "if <snort_conf> file contains any <include_file> or <policy_file> "
         "(i.e. 'include path/to/conf/other_conf'), do NOT parse those files"},
 
-    { "q", print_quiet,
+    { "o", parse_output_file, "<out_file>",
+        "output the new Snort++ lua configuration to <out_file>"},
+
+    { "q", print_quiet, "",
         "quiet mode. Only output valid confiration information"},
 
-    { "r", parse_rule_file,
+    { "r", parse_rule_file, "<rule_file>",
         "output any converted rule to <rule_file>"},
 
-    { "s", sing_rule_files,
-        "when parsing <include_file>, write <include_file>'s rules to <out_file>. Meaningles if '-p' provided"},
-
-    { "t", sing_conf_files,
-        "when parsing <include_file>, write <include_file>'s information, excluding rules, to <out_file>. Meaningles if '-p' provided"},
-
-    { "conf-file", parse_config_file,
-        "A Snort <conf> file which will be converted"},
-
-    { "dont-parse-includes", dont_parse_includes,
-        "if <conf> file contains any <include_file> or <policy_file> "
-        "(i.e. 'include path/to/conf/other_conf'), do NOT parse those files"},
+    { "s", sing_rule_files, "",
+        "when parsing <include_file>, write <include_file>'s rules to <rule_file>. Meaningles if '-i' provided"},
 
-    { "error-file", parse_error_file,
-        "output all errors to <error_file>"},
+    { "t", sing_conf_files, "",
+        "when parsing <include_file>, write <include_file>'s information, excluding rules, to <out_file>. Meaningles if '-i' provided"},
 
-    { "help", help_usage,
-        "this overview of snort2lua"},
+    { "V", print_version, "",
+        "Print the current Snort2Lua version"},
 
-    { "single-conf-files", sing_conf_files,
-        "when parsing <include_file>, write <include_file>'s information, excluding rules, to <out_file>. Use with '-p'"},
+    { "conf-file", parse_config_file, "",
+        "Same as '-c'. A Snort <snort_conf> file which will be converted"},
 
-    { "single-rule-files", sing_rule_files,
-        "when parsing <include_file>, write <include_file>'s rules to <out_file>.  Use with '-p'"},
-
-    { "output-file", parse_output_file,
-        "output the new Snort++ lua configuration to <out_file>"},
+    { "dont-parse-includes", dont_parse_includes, "",
+        "Same as '-p'. if <snort_conf> file contains any <include_file> or <policy_file> "
+        "(i.e. 'include path/to/conf/other_conf'), do NOT parse those files"},
 
-    { "print-all", print_all,
-        "print all data, including errors, Snort - Snort++ configuration differences, and developer warnings."},
+    { "error-file", parse_error_file, "<error_file>",
+        "Same as '-e'. output all errors to <error_file>"},
 
-    { "print-differences", print_differences,
-        "print Snort - Snort++ configuration differences, and only those differences"},
+    { "help", help, "",
+        "Same as '-h'. this overview of snort2lua"},
 
-    { "print-quiet", print_quiet,
-        "quiet mode. Only output valid confiration information"},
+    { "single-conf-file", sing_conf_files, "",
+        "Same as '-t'. when parsing <include_file>, write <include_file>'s information, excluding rules, to <out_file>"},
 
-    { "rule-file", parse_rule_file,
-        "output any converted rule to <rule_file>"},
+    { "single-rule-file", sing_rule_files, "",
+        "Same as '-s'. when parsing <include_file>, write <include_file>'s rules to <rule_file>."},
 
-    { nullptr, nullptr, nullptr }
-};
+    { "output-file", parse_output_file, "<out_file>",
+        "Same as '-o'. output the new Snort++ lua configuration to <out_file>"},
 
-#if 0
-FIXIT-H J delete!!
-SnortConfig* parse_cmd_line(int argc, char* argv[])
-{
-    ArgList al(argc, argv);
-    const char* key, *val;
-    unsigned c = 0;
+    { "print-all", print_all, "",
+        "Same as '-a'. print all data, including errors, Snort - Snort++ configuration differences, and developer warnings."},
 
-    // get special options first
-    while ( al.get_arg(key, val) )
-    {
-        ::set(key, val, sc, false);
-        c++;
-    }
+    { "print-differences", print_differences, "",
+        "Same as '-d'. print the differences, and only the differences, between the Snort and Snort++ configurations"},
 
-    // now get the rest
-    al.reset();
+    { "quiet", print_quiet, "",
+        "Same as '-q'. quiet mode. Only output valid confiration information"},
 
-    while ( al.get_arg(key, val) )
-    {
-        ::set(key, val, sc, true);
-        c++;
-    }
+    { "rule-file", parse_rule_file, "<rule_file>",
+        "Same as '-r'. output any converted rule to <rule_file>"},
 
-    if ( !c )
-        help_usage(sc, argv[0]);
-    else
-        check_flags(sc);
+    { "version", print_version, "",
+        "Same as '-V'. Print the current Snort2Lua version"},
 
-    if ( int k = get_parse_errors() )
-        FatalError("see prior %d errors\n", k);
+    { nullptr, nullptr, "", nullptr, }
+};
 
-    return sc;
-}
-#endif
 
 bool parse_cmd_line(int argc, char* argv[])
 {
@@ -418,32 +429,58 @@ bool parse_cmd_line(int argc, char* argv[])
     if (!found_opt)
         help_usage();
 
-
     return true;
 }
 
-static void help_usage()
-{
-    fprintf(stdout, "usage:\n");
-    fprintf(stdout, "    -?: list options\n");
-    fprintf(stdout, "    -V: output version\n");
-    fprintf(stdout, "    --help: help summary\n");
-    exit(1);
-}
-
 
-static void help_args(const char* pfx)
+static void help_args(const char* pfx, const char* /*val*/)
 {
     ConfigFunc* p = basic_opts;
     unsigned n = pfx ? strlen(pfx) : 0;
+    const int name_field_len = 20;
+    const int data_field_len = 80 - name_field_len;
 
     while ( p->name )
     {
-        if ( p->help && (!n || !strncasecmp(p->name, pfx, n)) )
+        if ( p->help ) //&& (!n || !strncasecmp(p->name, pfx, n)) )
         {
-            const char* prefix = strlen(p->name) > 1 ? "--" : "-";
-            std::cout << prefix << p->name;
-            std::cout << " " << p->help;
+            bool two_dash = strlen(p->name) > 1;
+            std::string name = two_dash ? "--" : "-";
+            name += p->name;
+
+            if (!p->type.empty())
+            {
+                name += two_dash ? "=" : " ";
+                name += p->type;
+            }
+
+
+            std::cout << std::left << std::setw(name_field_len) << name;
+
+            if (name.size() > name_field_len)
+                std::cout << "\n" << std::left << std::setw(name_field_len) << " ";
+
+            std::string help = p->help;
+            bool first_line = true;
+
+            while(!help.empty())
+            {
+                std::size_t len = util::get_substr_length(help, data_field_len);
+
+                if (first_line)
+                    first_line = false;
+                else
+                    std::cout << "\n" << std::setw(name_field_len) << " ";
+
+                std::cout << std::left << help.substr(0, len);
+
+                if (len < help.size())
+                    help = help.substr(len + 1);
+                else
+                    break;
+            }
+
+//            std::cout << p->help;
             std::cout << std::endl;
         }
         ++p;