From: Josh Date: Fri, 10 Oct 2014 21:54:35 +0000 (-0500) Subject: minor documentation fixes X-Git-Tag: 3.0.0-233~1383^2~5 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bfd0091ef978edfe840d37fb5ef169698a9959b2;p=thirdparty%2Fsnort3.git minor documentation fixes --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 0302f5d00..4b12495c2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 diff --git a/tools/snort2lua/config_states/config_binding.cc b/tools/snort2lua/config_states/config_binding.cc index b4513c84a..3a31c351e 100644 --- a/tools/snort2lua/config_states/config_binding.cc +++ b/tools/snort2lua/config_states/config_binding.cc @@ -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; + } } diff --git a/tools/snort2lua/config_states/config_ignore_ports.cc b/tools/snort2lua/config_states/config_ignore_ports.cc index 4206802d2..34d516dfa 100644 --- a/tools/snort2lua/config_states/config_ignore_ports.cc +++ b/tools/snort2lua/config_states/config_ignore_ports.cc @@ -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 = diff --git a/tools/snort2lua/utils/parse_cmd_line.cc b/tools/snort2lua/utils/parse_cmd_line.cc index a7ff51dfd..5dfbf393d 100644 --- a/tools/snort2lua/utils/parse_cmd_line.cc +++ b/tools/snort2lua/utils/parse_cmd_line.cc @@ -25,17 +25,30 @@ #include #include #include -#include +#include #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 ...\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, " = %s\n", out_default.c_str() ); + fprintf(stdout, " = . Rules will be written to the \n"); + fprintf(stdout, " = %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 file to convert"}, + { "c", parse_config_file, "", + "The Snort 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, "", "output all errors to "}, - { "o", parse_output_file, - "output the new Snort++ lua configuration to "}, - - { "p", dont_parse_includes, - "if file contains any or " + { "i", dont_parse_includes, "", + "if file contains any or " "(i.e. 'include path/to/conf/other_conf'), do NOT parse those files"}, - { "q", print_quiet, + { "o", parse_output_file, "", + "output the new Snort++ lua configuration to "}, + + { "q", print_quiet, "", "quiet mode. Only output valid confiration information"}, - { "r", parse_rule_file, + { "r", parse_rule_file, "", "output any converted rule to "}, - { "s", sing_rule_files, - "when parsing , write 's rules to . Meaningles if '-p' provided"}, - - { "t", sing_conf_files, - "when parsing , write 's information, excluding rules, to . Meaningles if '-p' provided"}, - - { "conf-file", parse_config_file, - "A Snort file which will be converted"}, - - { "dont-parse-includes", dont_parse_includes, - "if file contains any or " - "(i.e. 'include path/to/conf/other_conf'), do NOT parse those files"}, + { "s", sing_rule_files, "", + "when parsing , write 's rules to . Meaningles if '-i' provided"}, - { "error-file", parse_error_file, - "output all errors to "}, + { "t", sing_conf_files, "", + "when parsing , write 's information, excluding rules, to . 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 , write 's information, excluding rules, to . Use with '-p'"}, + { "conf-file", parse_config_file, "", + "Same as '-c'. A Snort file which will be converted"}, - { "single-rule-files", sing_rule_files, - "when parsing , write 's rules to . Use with '-p'"}, - - { "output-file", parse_output_file, - "output the new Snort++ lua configuration to "}, + { "dont-parse-includes", dont_parse_includes, "", + "Same as '-p'. if file contains any or " + "(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, "", + "Same as '-e'. output all errors to "}, - { "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 , write 's information, excluding rules, to "}, - { "rule-file", parse_rule_file, - "output any converted rule to "}, + { "single-rule-file", sing_rule_files, "", + "Same as '-s'. when parsing , write 's rules to ."}, - { nullptr, nullptr, nullptr } -}; + { "output-file", parse_output_file, "", + "Same as '-o'. output the new Snort++ lua configuration to "}, -#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, "", + "Same as '-r'. output any converted rule to "}, - 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;