Skip to content
This repository has been archived by the owner on Jan 2, 2024. It is now read-only.

Commit

Permalink
Add support for a custom Zeek scripts directory.
Browse files Browse the repository at this point in the history
This is where scripts accompanying installed Zeek analyzers go. The path
can be printed through `spicyz --print-scripts-dir`, it'll be
`<libdir>/spicy/zeek/scripts`. If ZEEKPATH is not set explicitly, the
plugin will add this to Zeek's search path.

We are also relocating the module directory to
`<libdir>/spicy/zeek/modules`.

This is in preparation for zeek/spicy-analyzers#31.
  • Loading branch information
rsmmr committed Mar 25, 2021
1 parent 98420c2 commit d68cea0
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ message(
"\n"
"\nVersion: ${SPICY_ZEEK_PLUGIN_VERSION} (${SPICY_ZEEK_PLUGIN_VERSION_NUMBER})"
"\nBuild type: ${CMAKE_BUILD_TYPE}"
"\nModules directory: ${SPICY_ZEEK_MODULE_DIR}"
"\nScripts directory: ${SPICY_ZEEK_SCRIPTS_DIR}"
"\nZeek debug build: ${ZEEK_DEBUG_BUILD}"
"\nspicy-config: ${SPICY_CONFIG}"
"\nzeek-config: ${ZEEK_CONFIG}"
Expand Down
6 changes: 5 additions & 1 deletion compiler/bin/spicyz.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ static struct option long_driver_options[] = {{"abort-on-exceptions", required_a
{"print-zeek-config", no_argument, nullptr, 'z'},
{"print-module-path", no_argument, nullptr, 'M'},
{"report-times", required_argument, nullptr, 'R'},
{"print-scripts-path", no_argument, nullptr, 'S'},
{"version", no_argument, nullptr, 'v'},
{"version-number", no_argument, nullptr, 'V'},
{nullptr, 0, nullptr, 0}};
Expand All @@ -50,6 +51,7 @@ static void usage() {
" -M | --print-module-path Print the Zeek plugin's default module search path.\n"
" -O | --optimize Build optimized release version of generated code.\n"
" -R | --report-times Report a break-down of compiler's execution time.\n"
" -S | --print-scripts-path Print the path to Zeek scripts accompanying Spicy modules.\n"
" -T | --keep-tmps Do not delete any temporary files created.\n"
" -X | --debug-addl <addl> Implies -d and adds selected additional instrumentation "
"(comma-separated; see 'help' for list).\n"
Expand All @@ -63,7 +65,7 @@ using hilti::Nothing;
static hilti::Result<Nothing> parseOptions(int argc, char** argv, hilti::driver::Options* driver_options,
hilti::Options* compiler_options) {
while ( true ) {
int c = getopt_long(argc, argv, "ABc:CdX:D:L:Mo:ORTvhz", long_driver_options, nullptr);
int c = getopt_long(argc, argv, "ABc:CdX:D:L:Mo:ORSTvhz", long_driver_options, nullptr);

if ( c == -1 )
break;
Expand Down Expand Up @@ -141,6 +143,8 @@ static hilti::Result<Nothing> parseOptions(int argc, char** argv, hilti::driver:

case 'R': driver_options->report_times = true; break;

case 'S': std::cout << spicy::zeek::configuration::PluginScriptsDirectory << std::endl; return Nothing();

case 'T': driver_options->keep_tmps = true; break;

case 'v': std::cout << spicy::zeek::configuration::PluginVersion << std::endl; return Nothing();
Expand Down
5 changes: 4 additions & 1 deletion plugin/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,12 @@ foreach(i bin include lib scripts spicy)
install(DIRECTORY ${ZEEK_SPICY_PLUGIN_BUILD_DIR}/${i} DESTINATION "${PLUGIN_INSTALL_DIR}" USE_SOURCE_PERMISSIONS)
endforeach ()

set(SPICY_ZEEK_MODULE_DIR "${CMAKE_INSTALL_FULL_LIBDIR}/spicy/zeek")
set(SPICY_ZEEK_MODULE_DIR "${CMAKE_INSTALL_FULL_LIBDIR}/spicy/zeek/modules" CACHE PATH "")
install(DIRECTORY DESTINATION "${SPICY_ZEEK_MODULE_DIR}")

set(SPICY_ZEEK_SCRIPTS_DIR "${CMAKE_INSTALL_FULL_LIBDIR}/spicy/zeek/scripts" CACHE PATH "")
install(DIRECTORY DESTINATION "${SPICY_ZEEK_SCRIPTS_DIR}")

install(DIRECTORY DESTINATION ${CMAKE_INSTALL_FULL_BINDIR})
install_symlink("${PLUGIN_INSTALL_DIR}/bin/spicyz" ${CMAKE_INSTALL_FULL_BINDIR}/spicyz)

Expand Down
1 change: 1 addition & 0 deletions plugin/include/config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,6 @@ inline const auto CxxBrokerIncludeDirectory = "${BROKER_INCLUDE_DIR}";
inline const auto PluginLibraryDirectoryBuild = "${CMAKE_CURRENT_SOURCE_DIR}/spicy";
inline const auto PluginLibraryDirectoryInstallation = "${PLUGIN_INSTALL_DIR}/spicy";
inline const auto PluginModuleDirectory = "${SPICY_ZEEK_MODULE_DIR}";
inline const auto PluginScriptsDirectory = "${SPICY_ZEEK_SCRIPTS_DIR}";

}
5 changes: 5 additions & 0 deletions plugin/src/plugin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,11 @@ void plugin::Zeek_Spicy::Plugin::InitPreScript() {
addLibraryPaths(hilti::rt::normalizePath(OurPlugin->PluginDirectory()).string() + "/spicy");
autoDiscoverModules();

if ( ! getenv("ZEEKPATH") ) { // similar to Zeek: don't touch ZEEKPATH if set to anything (including empty)
ZEEK_DEBUG(hilti::rt::fmt("Adding %s to ZEEKPATH", spicy::zeek::configuration::PluginScriptsDirectory));
::zeek::util::detail::add_to_zeek_path(spicy::zeek::configuration::PluginScriptsDirectory);
}

ZEEK_DEBUG("Done with pre-script initialization");
}

Expand Down
2 changes: 1 addition & 1 deletion tests/Scripts/get-path
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ elif [ "$1" = "--plugin-path-for-installation" ]; then
# 3. If we have spicyz in path, derive from module path.
# TODO: Could add seperate --print-plugin-dir to spicyz.
spicyz=$(which spicyz 2>/dev/null)
test -n "${spicyz}" && echo $(cd $(${spicyz} --print-module-path)/../_Zeek_Spicy && pwd) && exit 0
test -n "${spicyz}" && echo $(cd $(${spicyz} --print-module-path)/../../_Zeek_Spicy && pwd) && exit 0

exit 1

Expand Down

0 comments on commit d68cea0

Please sign in to comment.