From: Josh Date: Wed, 15 Oct 2014 20:37:21 +0000 (-0500) Subject: Adding environment variable PLUGIN_PATH to snort documentation builds X-Git-Tag: 3.0.0-233~1370^2~7 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3b2d290d8f92f6ffcc5fbc65f91270c6063ba4af;p=thirdparty%2Fsnort3.git Adding environment variable PLUGIN_PATH to snort documentation builds --- diff --git a/cmake/FindAsciidoc.cmake b/cmake/FindAsciidoc.cmake index 15929015d..1a1eb584e 100644 --- a/cmake/FindAsciidoc.cmake +++ b/cmake/FindAsciidoc.cmake @@ -2,25 +2,28 @@ # this module looks for asciidoc # # ASCIIDOC_A2X_EXE - the full path to asciidoc's a2x +# ASCIIDOC_EXE - the full path to asciidoc's asciidoc command # Asciidoc_FOUND - If false, don't attempt to use asciidoc. +# set(ERROR_MESSAGE "Unable to find Asciidoc. Dowbnload and install AsciiDoc to create custom documentation" ) +FIND_PROGRAM(ASCIIDOC_EXE asciidoc) find_program(ASCIIDOC_A2X_EXE a2x) include(FindPackageHandleStandardArgs) find_package_handle_standard_args(Asciidoc - REQUIRED_VARS ASCIIDOC_A2X_EXE + REQUIRED_VARS ASCIIDOC_A2X_EXE ASCIIDOC_EXE FAIL_MESSAGE "${ERROR_MESSAGE}" ) mark_as_advanced( + ASCIIDOC_EXE ASCIIDOC_A2X_EXE ) - diff --git a/doc/CMakeLists.txt b/doc/CMakeLists.txt index 92bc124fd..1ba415cfc 100644 --- a/doc/CMakeLists.txt +++ b/doc/CMakeLists.txt @@ -14,22 +14,39 @@ # # ############################################################################## +# snort --help-${type} set(HELP_SOURCES commands.txt config.txt - options.txt + modules.txt plugins.txt + options.txt + signals.txt + help.txt +# snort2lua_cmds.txt Get Snort2Lua command line options ) +# snort --list-${type} set(LIST_SOURCES builtin.txt gids.txt -# modules.txt Requires Special formatting. manually added below. +) + +# snort --help-module ${module} +set (MODULE_SOURCES + basic.txt + codec.txt + data.txt + inspector.txt + ips_action.txt + ips_option.txt + logger.txt ) set(BUILT_SOURCES ${HELP_SOURCES} ${LIST_SOURCES} + ${MODULE_SOURCES} # version.txt Requires special formatting. manually added below. # config_changes.txt If ruby executable found ) @@ -90,8 +107,12 @@ if (MAKE_PDF_DOC OR MAKE_HTML_DOC) add_custom_command( OUTPUT ${output} - COMMAND $ --markup --help-${file_name} | sort > ${output} - DEPENDS snort + COMMAND ${CMAKE_COMMAND} + -DOUT_FILE=${output} + -DSNORT_EXECUTABLE=$ + -DHELP_TYPE=${file_name} + -P ${CMAKE_CURRENT_LIST_DIR}/cmake_scripts.cmake + DEPENDS snort cmake_scripts.cmake COMMENT "Documents: building ${file}" ) list(APPEND ALL_SOURCES ${output}) @@ -103,13 +124,34 @@ if (MAKE_PDF_DOC OR MAKE_HTML_DOC) add_custom_command( OUTPUT ${output} - COMMAND $ --markup --list-${file_name} | sort > ${output} - DEPENDS snort + COMMAND ${CMAKE_COMMAND} + -DOUT_FILE=${output} + -DSNORT_EXECUTABLE=$ + -DLIST_TYPE=${file_name} + -P ${CMAKE_CURRENT_LIST_DIR}/cmake_scripts.cmake + DEPENDS snort cmake_scripts.cmake COMMENT "Documents: building ${file}" ) list(APPEND ALL_SOURCES ${output}) endforeach(file) + foreach (module ${MODULE_SOURCES}) + set (output "${CMAKE_CURRENT_BINARY_DIR}/${module}") + get_filename_component(module_name "${module}" NAME_WE) + + add_custom_command( + OUTPUT ${output} + COMMAND ${CMAKE_COMMAND} + -DOUT_FILE=${output} + -DSNORT_EXECUTABLE=$ + -DMODULE_TYPE=${module_name} + -P ${CMAKE_CURRENT_LIST_DIR}/cmake_scripts.cmake + DEPENDS snort cmake_scripts.cmake + COMMENT "Documents: building ${module}" + ) + list(APPEND ALL_SOURCES ${output}) + endforeach(module) + # build version.txt seperately set (output ${CMAKE_CURRENT_BINARY_DIR}/version.txt) add_custom_command( @@ -120,20 +162,6 @@ if (MAKE_PDF_DOC OR MAKE_HTML_DOC) ) list(APPEND ALL_SOURCES ${output}) - # build modules.txt seperately - set (output ${CMAKE_CURRENT_BINARY_DIR}/modules.txt) - add_custom_command( - OUTPUT ${output} - COMMAND ${CMAKE_COMMAND} - -DOUT_FILE=${output} - -DSNORT_EXECUTABLE=$ - -P ${CMAKE_CURRENT_LIST_DIR}/module_output.cmake - DEPENDS snort ${CMAKE_CURRENT_LIST_DIR}/module_output.cmake - COMMENT "Documents: building modules.txt" - ) - list (APPEND ALL_SOURCES ${output}) - - # If ruby is present, built the configuration differences if (RUBY_EXECUTABLE) set (input ${CMAKE_CURRENT_LIST_DIR}/config_changes.txt) @@ -184,13 +212,14 @@ set (PDF_ARGUMENTS --icons --icons-dir=./images/icons --resource=${CMAKE_CURRENT set (HTML_ARGUMENTS --copy --attribute linkcss --attribute stylesdir --attribute disable-javascript --attribute quirks! ${PDF_ARGUMENTS}) add_custom_command(OUTPUT snort_manual.html - COMMAND ${ASCIIDOC_A2X_EXE} - -f xhtml - ${HTML_ARGUMENTS} - --resource=${CMAKE_CURRENT_BINARY_DIR} - --destination-dir=${CMAKE_CURRENT_BINARY_DIR} + COMMAND ${ASCIIDOC_EXE} + -b xhtml11 + -a toc2 + -a icons + -a imagesdir=${CMAKE_CURRENT_SOURCE_DIR}/images ${CMAKE_CURRENT_BINARY_DIR}/snort_manual.txt - DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/snort_manual.txt ${ALL_SOURCES} + DEPENDS ${ALL_SOURCES} + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} COMMENT "Documents: building snort_manual.html" ) @@ -199,7 +228,7 @@ add_custom_command(OUTPUT snort_manual.pdf -f pdf ${PDF_ARGUMENTS} ${CMAKE_CURRENT_BINARY_DIR}/snort_manual.txt - DEPENDS ${ALL_SOURCES} snort_manual.html + DEPENDS ${ALL_SOURCES} ${CMAKE_CURRENT_BINARY_DIR}/snort_manual.html COMMENT "Documents: building snort_manual.pdf" ) @@ -219,14 +248,12 @@ add_custom_command(OUTPUT snort_manual.tgz ) add_custom_command(OUTPUT images.tgz - COMMAND tar - zcf images.tgz - --exclude callouts - --exclude README - -C ${CMAKE_CURRENT_SOURCE_DIR}/images - . + COMMAND + ${CMAKE_COMMAND} + -E tar zcf ${CMAKE_CURRENT_BINARY_DIR}/images.tgz . DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/images ${ALL_SOURCES} COMMENT "Documents: building images.tgz" + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/images ) diff --git a/doc/Makefile.am b/doc/Makefile.am index e6a195e33..8ccf930ba 100644 --- a/doc/Makefile.am +++ b/doc/Makefile.am @@ -61,82 +61,83 @@ endif dist_doc_DATA += $(EXTRA_DIST) snort = $(top_builddir)/src/snort +plugin_path = $(if $(shell echo $$PLUGIN_PATH), --plugin-path=$$PLUGIN_PATH ) $(unbuilt_sources): $(snort) mkdir -p images [ -a $(builddir)/$@ ] || cp $(srcdir)/$@ $(builddir)/$@ builtin.txt: $(snort) - $(snort) --markup --list-builtin | sort -n -t : -k 1.4 -k 2 > $@ + $(snort) $(plugin_path) --markup --list-builtin | sort -n -t : -k 1.4 -k 2 > $@ commands.txt: $(snort) - $(snort) --markup --help-commands | sort > $@ + $(snort) $(plugin_path) --markup --help-commands | sort > $@ config.txt: $(snort) - $(snort) --markup --help-config | sort -k 3 > $@ + $(snort) $(plugin_path) --markup --help-config | sort -k 3 > $@ gids.txt: $(snort) - $(snort) --markup --list-gids | sort -n -k 1.4 > $@ + $(snort) $(plugin_path) --markup --list-gids | sort -n -k 1.4 > $@ modules.txt: $(snort) - $(snort) --markup --help-modules > $@ + $(snort) $(plugin_path) --markup --help-modules > $@ plugins.txt: $(snort) - $(snort) --markup --help-plugins > $@ + $(snort) $(plugin_path) --markup --help-plugins > $@ help.txt: $(snort) $(snort) --help > $@ basic.txt: $(snort) for m in `$(snort) --list-modules basic` ; do \ - $(snort) --markup --help-module $$m ; \ + $(snort) $(plugin_path) --markup --help-module $$m ; \ done > $@ codec.txt: $(snort) for m in `$(snort) --list-modules codec` ; do \ - $(snort) --markup --help-module $$m ; \ + $(snort) $(plugin_path) --markup --help-module $$m ; \ done > $@ data.txt: $(snort) for m in `$(snort) --list-modules data` ; do \ - $(snort) --markup --help-module $$m ; \ + $(snort) $(plugin_path) --markup --help-module $$m ; \ done > $@ inspector.txt: $(snort) for m in `$(snort) --list-modules inspector` ; do \ - $(snort) --markup --help-module $$m ; \ + $(snort) $(plugin_path) --markup --help-module $$m ; \ done > $@ ips_action.txt: $(snort) for m in `$(snort) --list-modules ips_action` ; do \ - $(snort) --markup --help-module $$m ; \ + $(snort) $(plugin_path) --markup --help-module $$m ; \ done > $@ ips_option.txt: $(snort) for m in `$(snort) --list-modules ips_action` ; do \ - $(snort) --markup --help-module $$m ; \ + $(snort) $(plugin_path) --markup --help-module $$m ; \ done > $@ logger.txt: $(snort) for m in `$(snort) --list-modules logger` ; do \ - $(snort) --markup --help-module $$m ; \ + $(snort) $(plugin_path) --markup --help-module $$m ; \ done > $@ #search_engine.txt: $(snort) # for m in `$(snort) --list-modules search_engine` ; do \ -# $(snort) --markup --help-module $$m ; \ +# $(snort) $(plugin_path) --markup --help-module $$m ; \ # done > $@ #so_rule.txt: $(snort) # for m in `$(snort) --list-modules so_rule` ; do \ -# $(snort) --markup --help-module $$m ; \ +# $(snort) $(plugin_path) --markup --help-module $$m ; \ # done > $@ options.txt: $(snort) - $(snort) --markup --help-options | sort > $@ + $(snort) $(plugin_path) --markup --help-options | sort > $@ signals.txt: $(snort) - $(snort) --markup --help-signals > $@ + $(snort) $(plugin_path) --markup --help-signals > $@ version.txt: $(snort) $(snort) -V 2>&1 | grep -v Using > $@ diff --git a/doc/cmake_scripts.cmake b/doc/cmake_scripts.cmake new file mode 100644 index 000000000..97efcd7d8 --- /dev/null +++ b/doc/cmake_scripts.cmake @@ -0,0 +1,98 @@ + + +if (SNORT_EXECUTABLE AND OUT_FILE) + + # unsure why the extra level of indirection is needed, but it is + set (PLUG_PATH $ENV{PLUGIN_PATH}) + if (PLUG_PATH) + set (PLUGIN "--plugin-path=$ENV{PLUGIN_PATH}") + endif () + + + if (MODULE_TYPE) + + # clear any previous data in the file + execute_process ( + COMMAND ${CMAKE_COMMAND} -E echo "" + OUTPUT_FILE ${OUT_FILE} + ) + + # get the list of modules from Snort + execute_process ( + COMMAND ${SNORT_EXECUTABLE} --list-modules ${MODULE_TYPE} + OUTPUT_FILE ${OUT_FILE}.list + ) + + file (STRINGS "${OUT_FILE}.list" MODULE_TYPE) + file (REMOVE "${OUT_FILE}.list") + + + foreach (m ${MODULE_TYPE}) + execute_process ( + COMMAND + ${SNORT_EXECUTABLE} + ${PLUGIN} + --markup + --help-module + ${m} + OUTPUT_VARIABLE CONTENTS + ) + + file (APPEND ${OUT_FILE} "${CONTENTS}") + endforeach(m ${MODULE_TYPE}) + + elseif (HELP_TYPE) + + + if (${HELP_TYPE} MATCHES "help") + execute_process ( + COMMAND + ${SNORT_EXECUTABLE} + ${PLUGIN} + --markup + --help + OUTPUT_FILE ${OUT_FILE} + ) + else() + execute_process ( + COMMAND + ${SNORT_EXECUTABLE} + ${PLUGIN} + --markup + --help-${HELP_TYPE} + COMMAND sort + OUTPUT_FILE ${OUT_FILE} + ) + endif() + + elseif (LIST_TYPE) + + execute_process ( + COMMAND + ${SNORT_EXECUTABLE} + ${PLUGIN} + --markup + --list-${LIST_TYPE} + COMMAND sort + OUTPUT_FILE ${OUT_FILE} + ) + + else() + message (FATAL_ERROR "either MODULE_TYPE, ASCIIDOC_CMD, LIST_TYPE must be defined!") + endif() + + +else() + set (HELP_STR "help") + + if (HELP_STR MATCHES "help") + message(STATUS "${HELP_STR} MATCHES help") + else () + message(STATUS "${HELP_STR} does NOT match help") + endif() + + message (FATAL_ERROR "The command \${SNORT_EXECUTABLE} --markup --help-module \${module}" + " requires a valid options 'SNORT_EXECUTABLE' and 'OUT_FILE'\n" + " \tSNORT_EXECUTABLE == ${SNORT_EXECUTABLE}\n" + " \tOUT_FILE == ${OUT_FILE}") +endif() diff --git a/doc/module_output.cmake b/doc/module_output.cmake deleted file mode 100644 index a50c6eed0..000000000 --- a/doc/module_output.cmake +++ /dev/null @@ -1,34 +0,0 @@ - - -if (SNORT_EXECUTABLE AND OUT_FILE) - - # clear any previous data in the file - execute_process ( - COMMAND ${CMAKE_COMMAND} -E echo "" - OUTPUT_FILE ${OUT_FILE} - ) - - # get the list of modules from Snort - execute_process ( - COMMAND ${SNORT_EXECUTABLE} --list-modules - OUTPUT_FILE ${OUT_FILE}.list - ) - - file (STRINGS "${OUT_FILE}.list" MODULES) - file (REMOVE "${OUT_FILE}.list") - - - foreach (m ${MODULES}) - execute_process ( - COMMAND ${SNORT_EXECUTABLE} --markup --help-module ${m} - OUTPUT_VARIABLE CONTENTS - ) - - file (APPEND ${OUT_FILE} "${CONTENTS}") - endforeach(m ${MODULES}) - -else () - message (FATAL_ERROR "The options 'SNORT_EXECUTABLE' and 'OUT_FILE' must be provided to this script!!!") - -endif() - diff --git a/doc/snort2lua.txt b/doc/snort2lua.txt index 7a46ab615..029512319 100644 --- a/doc/snort2lua.txt +++ b/doc/snort2lua.txt @@ -7,7 +7,7 @@ Those errors can occur for a multitude of reasons and are not necessarily bad. There are a also few peculiarities of Snort2Lua that may be confusing to a first time user. Specifically, aside from an initial configuration file (which is specified from the command line or as the file in ‘config binding’), every file that is included into Snort++ must be either a Lua file or a rule file; the file cannot contain both rules and Lua syntax. Therefore, when parsing a file specified with the ‘include’ command, Snort2Lua will output both a Lua file and a rule file. Additionally, any line that is a comment in a configuration file will be added in to a comments section at the bottom of the main configuration file. Finally, rules that contain unsupported options will be converted to the best of Snort2Lua’s capability and then printed as a comment in the rule file. -=== Snort2Lua command line options +=== Snort2Lua command line By default, Snort2Lua will attempt to parse every ‘include’ file and every ‘binding’ file. There is an option to change this functionality. @@ -16,6 +16,7 @@ When specifying a rule file with one of the command line options, Snort2Lua will There are currently three output modes: default, quiet, and differences. As expected, quiet mode produces a Snort\++ configuration. All errors (aside from Fatal Snort2Lua erros), differences, and comments will ommited from the final output file. Default mode will print everything. That mean you will be able to see exactly what changes have occured between Snort and Snort\++ in addition to the new syntax, the original file's comments, and all errors that have occured. Finally, differences mode will not actually ouput a valid Snort++ configuration. Instead, you can see the exact options from the input configuration that have changed. +// FIXIT-J L include Snort2Lua commands === Known Problems: - Any Snort ‘string’ which is dependent on a variable will no longer have that variable in the Lua string. diff --git a/src/parser/parser.cc b/src/parser/parser.cc index a4f06436a..b8ec94fc5 100644 --- a/src/parser/parser.cc +++ b/src/parser/parser.cc @@ -1118,9 +1118,9 @@ void ParseError(const char *format, ...) get_parse_location(file_name, file_line); if (file_line ) - ErrorMessage("ERROR: %s:%d %s\n", file_name, file_line, buf); + LogMessage("ERROR: %s:%d %s\n", file_name, file_line, buf); else - ErrorMessage("ERROR: %s\n", buf); + LogMessage("ERROR: %s\n", buf); parse_errors++; } diff --git a/src/protocols/packet_manager.h b/src/protocols/packet_manager.h index d42f288d1..16254ab2d 100644 --- a/src/protocols/packet_manager.h +++ b/src/protocols/packet_manager.h @@ -51,9 +51,8 @@ enum class UnreachResponse FWD, }; -/* - * PacketManager class - */ +// FIXIT-M J -- Roll the PacketManager and 'layer' namespace into +// the Packet struct class SO_PUBLIC PacketManager { public: diff --git a/tools/snort2lua/data/data_types/dt_var.cc b/tools/snort2lua/data/data_types/dt_var.cc index 7b8591ba6..6b334f948 100644 --- a/tools/snort2lua/data/data_types/dt_var.cc +++ b/tools/snort2lua/data/data_types/dt_var.cc @@ -55,7 +55,6 @@ std::string Variable::get_value(DataApi* ld) variable.append(std::string(ld->translate_variable(v->data))); } - std::cout << "VARIABLE: value == " << variable << "END" << std::endl; return variable; } diff --git a/tools/snort2lua/data/dt_data.cc b/tools/snort2lua/data/dt_data.cc index 4b623cdd3..cb804bf83 100644 --- a/tools/snort2lua/data/dt_data.cc +++ b/tools/snort2lua/data/dt_data.cc @@ -92,7 +92,6 @@ std::string DataApi::expand_vars(const std::string &string) i = j = 0; l_string = string.size(); - std::cout << "ExpandVars, Before: " << string << std::endl; while(i < l_string && j < std::string::npos) { @@ -225,8 +224,6 @@ std::string DataApi::expand_vars(const std::string &string) estring.resize(j); estring[j] = '\0'; - std::cout << "ExpandVars, After: " << estring << std::endl; - return estring; } diff --git a/tools/snort2lua/utils/converter.cc b/tools/snort2lua/utils/converter.cc index 66732de9d..98e32e692 100644 --- a/tools/snort2lua/utils/converter.cc +++ b/tools/snort2lua/utils/converter.cc @@ -244,14 +244,9 @@ int Converter::convert(std::string input, } - // Snort++ requires a binder table to be instantiated, - // although not necessarily filled. So, just add this table. - // If its already added, these lines won't have any effect - table_api.open_top_level_table("binder"); - table_api.close_table(); - // finally, lets print the converter to file std::ofstream out; + out.open(output_file, std::ifstream::out); out << "require(\"snort_config\") -- for loading\n\n"; @@ -271,6 +266,7 @@ int Converter::convert(std::string input, } + table_api.print_tables(out); data_api.print_comments(out); diff --git a/tools/snort2lua/utils/parse_cmd_line.cc b/tools/snort2lua/utils/parse_cmd_line.cc index 016c86594..325d41d4f 100644 --- a/tools/snort2lua/utils/parse_cmd_line.cc +++ b/tools/snort2lua/utils/parse_cmd_line.cc @@ -76,6 +76,7 @@ const std::string get_rule_file() static void help_args(const char* pfx, const char* /*val*/); +static void print_args(const char* pfx, const char* /*val*/); //------------------------------------------------------------------------- // arg foo @@ -181,7 +182,7 @@ static void help_usage() fprintf(stdout, " -?: list options\n"); fprintf(stdout, " -V: output version\n"); fprintf(stdout, " --help: help summary\n"); - exit(1); + exit(0); } static void help_usage(const char* key, const char* /*val*/) { help_usage(); } @@ -317,10 +318,15 @@ static void help(const char* key, const char* val) exit(0); } +static void print_args(const char* key, const char* val) +{ + help_args(key, val); + exit(0); +} static ConfigFunc basic_opts[] = { - { "?", help_args, "", + { "?", print_args, "", "show usage" }, { "h", help, "",