]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
Adding environment variable PLUGIN_PATH to snort documentation builds
authorJosh <jrosenba@cisco.com>
Wed, 15 Oct 2014 20:37:21 +0000 (15:37 -0500)
committerJosh <jrosenba@cisco.com>
Wed, 15 Oct 2014 20:37:21 +0000 (15:37 -0500)
12 files changed:
cmake/FindAsciidoc.cmake
doc/CMakeLists.txt
doc/Makefile.am
doc/cmake_scripts.cmake [new file with mode: 0644]
doc/module_output.cmake [deleted file]
doc/snort2lua.txt
src/parser/parser.cc
src/protocols/packet_manager.h
tools/snort2lua/data/data_types/dt_var.cc
tools/snort2lua/data/dt_data.cc
tools/snort2lua/utils/converter.cc
tools/snort2lua/utils/parse_cmd_line.cc

index 15929015d3d824853ce4ca4b102a977452d8ca56..1a1eb584ed46c391d5e2ef685eb11252339764c4 100644 (file)
@@ -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
 )
-
index 92bc124fd3ec4454289a97d007e08068d92ac4fc..1ba415cfce212f7512cbcf4f7dcfaee72674d2d6 100644 (file)
 #                                                                            #
 ##############################################################################
 
+# 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 $<TARGET_FILE:snort> --markup --help-${file_name} | sort > ${output}
-            DEPENDS snort
+            COMMAND ${CMAKE_COMMAND}
+                -DOUT_FILE=${output}
+                -DSNORT_EXECUTABLE=$<TARGET_FILE:snort>
+                -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 $<TARGET_FILE:snort> --markup --list-${file_name} | sort > ${output}
-            DEPENDS snort
+            COMMAND ${CMAKE_COMMAND}
+                -DOUT_FILE=${output}
+                -DSNORT_EXECUTABLE=$<TARGET_FILE:snort>
+                -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=$<TARGET_FILE:snort>
+                -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=$<TARGET_FILE:snort>
-            -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
 )
 
 
index e6a195e333c4a7f001b920b38ccbc7faba45affa..8ccf930bad88274226629b13cf5f458eabe9af37 100644 (file)
@@ -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 (file)
index 0000000..97efcd7
--- /dev/null
@@ -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 (file)
index a50c6ee..0000000
+++ /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()
-
index 7a46ab6151cf4638e7ccd224f03f37d340e60395..02951231932d7fa188edbb4894acbf3a3f8ff933 100644 (file)
@@ -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.
index a4f06436a2ed0cae1ecd1e7dd755a25969622bfa..b8ec94fc58bab11062ec466ce1b7087061b66225 100644 (file)
@@ -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++;
 }
index d42f288d11fc818678013ffe46d964bfc2c8842b..16254ab2d7c25ed62303a697b100524f31664a58 100644 (file)
@@ -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:
index 7b8591ba6955490d4ee45d691d8598ad6c57b0f6..6b334f948d0d657fe6895b755e5656dfd5090444 100644 (file)
@@ -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;
 }
 
index 4b623cdd3e0ed2c14394104a79539f4c23b44d01..cb804bf83ba270ac8240b7cc72274ca6112b0478 100644 (file)
@@ -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;
 }
 
index 66732de9d07e9be3f72aff74a8fd9f5d054a8a49..98e32e692213a99926abb62d91c2505f72253457 100644 (file)
@@ -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);
 
index 016c86594c2559c4df4331493d6d6a95be894e84..325d41d4f9ff7cc2b4d149a366a62439b1d95a20 100644 (file)
@@ -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, "",