zeek-setup: Validate plugin debug streams during startup

Providing an unknown plugin debug stream with -B was previously silently
accepted. This caused user confusing as the behavior is "no output, but
seems to work".

Check the enabled debug streams once all plugins have been loaded and
exit early on for invalid streams.

    $ ZEEK_PLUGIN_PATH=./build zeek -B plugin-zeek-myplugin -e 'print zeek_version();'
    error in <command line>, line 3: No plugin debug stream 'plugin-zeek-myplugin' found

Closes #913.
This commit is contained in:
Arne Welzel 2022-07-06 18:45:40 +02:00
parent 8ba44c656a
commit d703033ae6
5 changed files with 58 additions and 3 deletions

View file

@ -11,6 +11,8 @@
#include <set>
#include <string>
#include "zeek/util.h"
#define DBG_LOG(stream, args...) \
if ( ::zeek::detail::debug_logger.IsEnabled(stream) ) \
::zeek::detail::debug_logger.Log(stream, args)
@ -84,6 +86,9 @@ public:
// Takes comma-seperated list of stream prefixes.
void EnableStreams(const char* streams);
// Check the enabled streams for invalid ones.
bool CheckStreams(const std::set<std::string>& plugin_names);
bool IsEnabled(DebugStream stream) const { return streams[int(stream)].enabled; }
void SetVerbose(bool arg_verbose) { verbose = arg_verbose; }
@ -105,6 +110,11 @@ private:
std::set<std::string> enabled_streams;
static Stream streams[NUM_DBGS];
const std::string PluginStreamName(const std::string& plugin_name)
{
return "plugin-" + util::strreplace(plugin_name, "::", "-");
}
};
extern DebugLogger debug_logger;