From 8222193525b0b745c02c67ee7c16a8f7850bdc07 Mon Sep 17 00:00:00 2001 From: Seth Hall Date: Fri, 11 Jun 2021 17:52:27 +0000 Subject: [PATCH] Fixes for the builtin plugin functionality --- CMakeLists.txt | 2 +- cmake | 2 +- src/CMakeLists.txt | 10 ---------- src/plugin/Manager.cc | 13 ++++++++++--- src/zeek-setup.cc | 7 ++++--- 5 files changed, 16 insertions(+), 18 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 21db791f1e..2e8bea31a4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -490,7 +490,7 @@ endif() # Tell the plugin code that we're building as part of the main tree. set(ZEEK_PLUGIN_INTERNAL_BUILD true CACHE INTERNAL "" FORCE) -set(DEFAULT_ZEEKPATH .:${ZEEK_SCRIPT_INSTALL_PATH}:${ZEEK_SCRIPT_INSTALL_PATH}/policy:${ZEEK_SCRIPT_INSTALL_PATH}/site) +set(DEFAULT_ZEEKPATH .:${ZEEK_SCRIPT_INSTALL_PATH}:${ZEEK_SCRIPT_INSTALL_PATH}/policy:${ZEEK_SCRIPT_INSTALL_PATH}/site:${ZEEK_SCRIPT_INSTALL_PATH}/builtin-plugins) if ( NOT BINARY_PACKAGING_MODE ) set(ZEEK_DIST ${CMAKE_SOURCE_DIR}) diff --git a/cmake b/cmake index 74259745de..d8d09afec0 160000 --- a/cmake +++ b/cmake @@ -1 +1 @@ -Subproject commit 74259745dea5ee4889d1ac1f4ebde4e2c59c329a +Subproject commit d8d09afec01055f8258501909f6b48482a5663ed diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index b9462c5ea5..26ae9e00b9 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -194,21 +194,11 @@ foreach (plugin_dir ${BUILTIN_PLUGIN_LIST}) ${CMAKE_CURRENT_BINARY_DIR}/builtin-plugins/${plugin_name}) add_subdirectory(${plugin_dir} ${CMAKE_CURRENT_BINARY_DIR}/builtin-plugins/${plugin_name}) - - set(preload_script ${plugin_dir}/scripts/__preload__.zeek) - if (EXISTS ${plugin_dir}/scripts/__preload__.zeek) - file(APPEND ${CMAKE_BINARY_DIR}/scripts/builtin-plugins/__preload__.zeek "\n@load ${preload_script}") - endif() - set(load_script ${plugin_dir}/scripts/__load__.zeek) - if (EXISTS ${plugin_dir}/scripts/__load__.zeek) - file(APPEND ${CMAKE_BINARY_DIR}/scripts/builtin-plugins/__load__.zeek "\n@load ${load_script}") - endif() endforeach() install(FILES ${PRELOAD_SCRIPT} DESTINATION ${ZEEK_SCRIPT_INSTALL_PATH}/builtin-plugins/) install(FILES ${LOAD_SCRIPT} DESTINATION ${ZEEK_SCRIPT_INSTALL_PATH}/builtin-plugins/) - ######################################################################## ## bro target diff --git a/src/plugin/Manager.cc b/src/plugin/Manager.cc index 7880f6ea68..d9d750ebaf 100644 --- a/src/plugin/Manager.cc +++ b/src/plugin/Manager.cc @@ -415,21 +415,28 @@ void Manager::RegisterBifFile(const char* plugin, bif_init_func c) void Manager::ExtendZeekPathForPlugins() { + // Extend the path outside of the loop to avoid looking through a longer path for each plugin + vector path_additions; + for ( const auto& p : Manager::ActivePlugins() ) { if ( p->DynamicPlugin() || p->Name().empty() ) continue; string canon = std::regex_replace(p->Name(), std::regex("::"), "_"); - string dir = "plugins/" + canon + "/"; + string dir = "builtin-plugins/" + canon; + // Use find_file to find the directory in the path. string script_dir = util::find_file(dir, util::zeek_path()); - if ( ! util::is_dir(script_dir) ) + if ( script_dir.empty() || ! util::is_dir(script_dir) ) continue; DBG_LOG(DBG_PLUGINS, " Adding %s to ZEEKPATH", script_dir.c_str()); - util::detail::add_to_zeek_path(script_dir); + path_additions.push_back(script_dir); } + + for ( const auto& plugin_path : path_additions ) + util::detail::add_to_zeek_path(plugin_path); } void Manager::InitPreScript() diff --git a/src/zeek-setup.cc b/src/zeek-setup.cc index ac706ecc4b..3a66f2a350 100644 --- a/src/zeek-setup.cc +++ b/src/zeek-setup.cc @@ -601,14 +601,15 @@ SetupResult setup(int argc, char** argv, Options* zopts) // manager will be missing the plugins we want to try to add to the path. plugin_mgr->ExtendZeekPathForPlugins(); - if ( options.print_usage ) - usage(argv[0], 0); - for ( const auto& x : requested_plugins ) plugin_mgr->ActivateDynamicPlugin(std::move(x)); plugin_mgr->ActivateDynamicPlugins(! options.bare_mode); + // Print usage after plugins load so that any path extensions are properly shown. + if ( options.print_usage ) + usage(argv[0], 0); + init_event_handlers(); md5_type = make_intrusive("md5");