mirror of
https://github.com/zeek/zeek.git
synced 2025-10-04 23:58:20 +00:00
Merge branch 'master' of git.bro.org:bro
This commit is contained in:
commit
8479298e04
4 changed files with 79 additions and 17 deletions
24
CHANGES
24
CHANGES
|
@ -4,20 +4,30 @@
|
||||||
* Fixing documentation piece on the interesting-hostname script.
|
* Fixing documentation piece on the interesting-hostname script.
|
||||||
(Robin Sommer)
|
(Robin Sommer)
|
||||||
|
|
||||||
* Use the deterministic bro_random() in a test, instead of os
|
* Improve the SMB documentation. (Vlad Grigorescu)
|
||||||
random(). (Johanna Amann)
|
|
||||||
|
|
||||||
* Adapt a test to an output change on FreeBSD 11.0. (Johanna Amann)
|
2.5-beta-46 | 2016-10-06 14:11:03 -0700
|
||||||
|
|
||||||
* Prevent loading version.bro during plugins.hooks test. (Johanna Amann)
|
* Fixing Broxygen indexing confusion for plugins. Scripts in plugins now
|
||||||
|
get an artificial index prefix: "plugin_name/", followed by the script's
|
||||||
|
relative path inside the plugin's top-level directory. For example,
|
||||||
|
"/opt/bro/lib/bro/plugins/Bro_Netmap/scripts/init.bro" now turns into
|
||||||
|
"Bro_Netmap/scripts/init.bro" for Broxygen purposes (whereas it used to
|
||||||
|
be just "init.bro"). (Robin Sommer)
|
||||||
|
|
||||||
* Add missing path canonifier to version test. (Johanna Amann)
|
* Fix a couple of tests, addressing issues of the newly introduced version.bro
|
||||||
|
as well as small FreeBSD 11.0 issues. (Johanna Amann)
|
||||||
|
|
||||||
* Update documentation license. (Johanna Amann)
|
* Update documentation license. (Johanna Amann)
|
||||||
|
|
||||||
* Improve the SMB documentation. (Vlad Grigorescu)
|
* Add a convenient way to access version information to Bro.
|
||||||
|
|
||||||
* Add script API to access Bro version information. (Johanna Amann)
|
@if ( Version::number >= 20500 )
|
||||||
|
or
|
||||||
|
@if ( Version::at_least("2.5") )
|
||||||
|
|
||||||
|
Version::info contains detailed information about the running version of
|
||||||
|
Bro, including beta flags, etc. (Johanna Amann)
|
||||||
|
|
||||||
2.5-beta-35 | 2016-10-02 17:38:31 -0400
|
2.5-beta-35 | 2016-10-02 17:38:31 -0400
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
// See the file "COPYING" in the main distribution directory for copyright.
|
// See the file "COPYING" in the main distribution directory for copyright.
|
||||||
|
|
||||||
#include "Manager.h"
|
#include "Manager.h"
|
||||||
|
#include "plugin/Manager.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
@ -38,6 +39,20 @@ static string RemoveLeadingSpace(const string& s)
|
||||||
return rval;
|
return rval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Turns a script's full path into a shortened, normalized version that we
|
||||||
|
// use for indexing.
|
||||||
|
static string NormalizeScriptPath(const string& path)
|
||||||
|
{
|
||||||
|
if ( auto p = plugin_mgr->LookupPluginByPath(path) )
|
||||||
|
{
|
||||||
|
auto rval = normalize_path(path);
|
||||||
|
auto prefix = SafeBasename(p->PluginDirectory()).result;
|
||||||
|
return prefix + "/" + rval.substr(p->PluginDirectory().size() + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
return without_bropath_component(path);
|
||||||
|
}
|
||||||
|
|
||||||
Manager::Manager(const string& arg_config, const string& bro_command)
|
Manager::Manager(const string& arg_config, const string& bro_command)
|
||||||
: disabled(), comment_buffer(), comment_buffer_map(), packages(), scripts(),
|
: disabled(), comment_buffer(), comment_buffer_map(), packages(), scripts(),
|
||||||
identifiers(), all_info(), last_identifier_seen(), incomplete_type(),
|
identifiers(), all_info(), last_identifier_seen(), incomplete_type(),
|
||||||
|
@ -108,7 +123,7 @@ void Manager::Script(const string& path)
|
||||||
if ( disabled )
|
if ( disabled )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
string name = without_bropath_component(path);
|
string name = NormalizeScriptPath(path);
|
||||||
|
|
||||||
if ( scripts.GetInfo(name) )
|
if ( scripts.GetInfo(name) )
|
||||||
{
|
{
|
||||||
|
@ -149,8 +164,8 @@ void Manager::ScriptDependency(const string& path, const string& dep)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
string name = without_bropath_component(path);
|
string name = NormalizeScriptPath(path);
|
||||||
string depname = without_bropath_component(dep);
|
string depname = NormalizeScriptPath(dep);
|
||||||
ScriptInfo* script_info = scripts.GetInfo(name);
|
ScriptInfo* script_info = scripts.GetInfo(name);
|
||||||
|
|
||||||
if ( ! script_info )
|
if ( ! script_info )
|
||||||
|
@ -174,7 +189,7 @@ void Manager::ModuleUsage(const string& path, const string& module)
|
||||||
if ( disabled )
|
if ( disabled )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
string name = without_bropath_component(path);
|
string name = NormalizeScriptPath(path);
|
||||||
ScriptInfo* script_info = scripts.GetInfo(name);
|
ScriptInfo* script_info = scripts.GetInfo(name);
|
||||||
|
|
||||||
if ( ! script_info )
|
if ( ! script_info )
|
||||||
|
@ -225,7 +240,7 @@ void Manager::StartType(ID* id)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
string script = without_bropath_component(id->GetLocationInfo()->filename);
|
string script = NormalizeScriptPath(id->GetLocationInfo()->filename);
|
||||||
ScriptInfo* script_info = scripts.GetInfo(script);
|
ScriptInfo* script_info = scripts.GetInfo(script);
|
||||||
|
|
||||||
if ( ! script_info )
|
if ( ! script_info )
|
||||||
|
@ -289,7 +304,7 @@ void Manager::Identifier(ID* id)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
string script = without_bropath_component(id->GetLocationInfo()->filename);
|
string script = NormalizeScriptPath(id->GetLocationInfo()->filename);
|
||||||
ScriptInfo* script_info = scripts.GetInfo(script);
|
ScriptInfo* script_info = scripts.GetInfo(script);
|
||||||
|
|
||||||
if ( ! script_info )
|
if ( ! script_info )
|
||||||
|
@ -318,7 +333,7 @@ void Manager::RecordField(const ID* id, const TypeDecl* field,
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
string script = without_bropath_component(path);
|
string script = NormalizeScriptPath(path);
|
||||||
idd->AddRecordField(field, script, comment_buffer);
|
idd->AddRecordField(field, script, comment_buffer);
|
||||||
comment_buffer.clear();
|
comment_buffer.clear();
|
||||||
DBG_LOG(DBG_BROXYGEN, "Document record field %s, identifier %s, script %s",
|
DBG_LOG(DBG_BROXYGEN, "Document record field %s, identifier %s, script %s",
|
||||||
|
@ -343,7 +358,7 @@ void Manager::Redef(const ID* id, const string& path)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
string from_script = without_bropath_component(path);
|
string from_script = NormalizeScriptPath(path);
|
||||||
ScriptInfo* script_info = scripts.GetInfo(from_script);
|
ScriptInfo* script_info = scripts.GetInfo(from_script);
|
||||||
|
|
||||||
if ( ! script_info )
|
if ( ! script_info )
|
||||||
|
@ -365,7 +380,7 @@ void Manager::SummaryComment(const string& script, const string& comment)
|
||||||
if ( disabled )
|
if ( disabled )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
string name = without_bropath_component(script);
|
string name = NormalizeScriptPath(script);
|
||||||
ScriptInfo* info = scripts.GetInfo(name);
|
ScriptInfo* info = scripts.GetInfo(name);
|
||||||
|
|
||||||
if ( info )
|
if ( info )
|
||||||
|
|
|
@ -241,6 +241,8 @@ bool Manager::ActivateDynamicPluginInternal(const std::string& name, bool ok_if_
|
||||||
DBG_LOG(DBG_PLUGINS, " InitialzingComponents");
|
DBG_LOG(DBG_PLUGINS, " InitialzingComponents");
|
||||||
current_plugin->InitializeComponents();
|
current_plugin->InitializeComponents();
|
||||||
|
|
||||||
|
plugins_by_path.insert(std::make_pair(normalize_path(dir), current_plugin));
|
||||||
|
|
||||||
if ( current_plugin->APIVersion() != BRO_PLUGIN_API_VERSION )
|
if ( current_plugin->APIVersion() != BRO_PLUGIN_API_VERSION )
|
||||||
reporter->FatalError("plugin's API version does not match Bro (expected %d, got %d in %s)",
|
reporter->FatalError("plugin's API version does not match Bro (expected %d, got %d in %s)",
|
||||||
BRO_PLUGIN_API_VERSION, current_plugin->APIVersion(), path);
|
BRO_PLUGIN_API_VERSION, current_plugin->APIVersion(), path);
|
||||||
|
@ -328,7 +330,7 @@ void Manager::RegisterPlugin(Plugin *plugin)
|
||||||
|
|
||||||
if ( current_dir && current_sopath )
|
if ( current_dir && current_sopath )
|
||||||
// A dynamic plugin, record its location.
|
// A dynamic plugin, record its location.
|
||||||
plugin->SetPluginLocation(current_dir, current_sopath);
|
plugin->SetPluginLocation(normalize_path(current_dir), current_sopath);
|
||||||
|
|
||||||
current_plugin = plugin;
|
current_plugin = plugin;
|
||||||
}
|
}
|
||||||
|
@ -463,6 +465,31 @@ Manager::bif_init_func_map* Manager::BifFilesInternal()
|
||||||
return bifs;
|
return bifs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Plugin* Manager::LookupPluginByPath(std::string path)
|
||||||
|
{
|
||||||
|
path = normalize_path(path);
|
||||||
|
|
||||||
|
if ( is_file(path) )
|
||||||
|
path = SafeDirname(path).result;
|
||||||
|
|
||||||
|
while ( path.size() )
|
||||||
|
{
|
||||||
|
auto i = plugins_by_path.find(path);
|
||||||
|
|
||||||
|
if ( i != plugins_by_path.end() )
|
||||||
|
return i->second;
|
||||||
|
|
||||||
|
auto j = path.rfind("/");
|
||||||
|
|
||||||
|
if ( j == std::string::npos )
|
||||||
|
break;
|
||||||
|
|
||||||
|
path.erase(j);
|
||||||
|
}
|
||||||
|
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
static bool hook_cmp(std::pair<int, Plugin*> a, std::pair<int, Plugin*> b)
|
static bool hook_cmp(std::pair<int, Plugin*> a, std::pair<int, Plugin*> b)
|
||||||
{
|
{
|
||||||
if ( a.first == b.first )
|
if ( a.first == b.first )
|
||||||
|
|
|
@ -149,6 +149,13 @@ public:
|
||||||
*/
|
*/
|
||||||
template<class T> std::list<T *> Components() const;
|
template<class T> std::list<T *> Components() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the (dynamic) plugin associated with a given filesytem
|
||||||
|
* path. The path can be the plugin directory itself, or any path
|
||||||
|
* inside it.
|
||||||
|
*/
|
||||||
|
Plugin* LookupPluginByPath(std::string path);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if there's at least one plugin interested in a given
|
* Returns true if there's at least one plugin interested in a given
|
||||||
* hook.
|
* hook.
|
||||||
|
@ -329,6 +336,9 @@ private:
|
||||||
// of that type enabled.
|
// of that type enabled.
|
||||||
hook_list** hooks;
|
hook_list** hooks;
|
||||||
|
|
||||||
|
// A map of all the top-level plugin directories.
|
||||||
|
std::map<std::string, Plugin*> plugins_by_path;
|
||||||
|
|
||||||
// Helpers providing access to current state during dlopen().
|
// Helpers providing access to current state during dlopen().
|
||||||
static Plugin* current_plugin;
|
static Plugin* current_plugin;
|
||||||
static const char* current_dir;
|
static const char* current_dir;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue