# 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
)
-
# #
##############################################################################
+# 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
)
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})
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(
)
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)
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"
)
-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"
)
)
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
)
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 > $@
--- /dev/null
+
+
+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()
+++ /dev/null
-
-
-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()
-
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.
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.
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++;
}
FWD,
};
-/*
- * PacketManager class
- */
+// FIXIT-M J -- Roll the PacketManager and 'layer' namespace into
+// the Packet struct
class SO_PUBLIC PacketManager
{
public:
variable.append(std::string(ld->translate_variable(v->data)));
}
- std::cout << "VARIABLE: value == " << variable << "END" << std::endl;
return variable;
}
i = j = 0;
l_string = string.size();
- std::cout << "ExpandVars, Before: " << string << std::endl;
while(i < l_string && j < std::string::npos)
{
estring.resize(j);
estring[j] = '\0';
- std::cout << "ExpandVars, After: " << estring << std::endl;
-
return estring;
}
}
- // 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";
}
+
table_api.print_tables(out);
data_api.print_comments(out);
static void help_args(const char* pfx, const char* /*val*/);
+static void print_args(const char* pfx, const char* /*val*/);
//-------------------------------------------------------------------------
// arg foo
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(); }
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, "",