Remove support for .bro script extension and BRO_ environment variables

This commit is contained in:
Tim Wojtulewicz 2021-01-25 14:46:47 -07:00
parent 44ad614094
commit 725e759560
11 changed files with 33 additions and 171 deletions

View file

@ -257,44 +257,29 @@ bool Manager::ActivateDynamicPluginInternal(const std::string& name, bool ok_if_
string init;
// First load {scripts}/__preload__.zeek automatically.
for (const string& ext : util::detail::script_extensions)
{
init = dir + "scripts/__preload__" + ext;
init = dir + "scripts/__preload__.zeek";
if ( util::is_file(init) )
{
DBG_LOG(DBG_PLUGINS, " Loading %s", init.c_str());
util::detail::warn_if_legacy_script(init);
scripts_to_load.push_back(init);
break;
}
}
// Load {bif,scripts}/__load__.zeek automatically.
for (const string& ext : util::detail::script_extensions)
{
init = dir + "lib/bif/__load__" + ext;
init = dir + "lib/bif/__load__.zeek";
if ( util::is_file(init) )
{
DBG_LOG(DBG_PLUGINS, " Loading %s", init.c_str());
util::detail::warn_if_legacy_script(init);
scripts_to_load.push_back(init);
break;
}
}
for (const string& ext : util::detail::script_extensions)
{
init = dir + "scripts/__load__" + ext;
init = dir + "scripts/__load__.zeek";
if ( util::is_file(init) )
{
DBG_LOG(DBG_PLUGINS, " Loading %s", init.c_str());
util::detail::warn_if_legacy_script(init);
scripts_to_load.push_back(init);
break;
}
}
// Mark this plugin as activated by clearing the path.

View file

@ -581,17 +581,6 @@ uint64_t rand64bit()
return base;
}
const array<string, 2> script_extensions = {".zeek", ".bro"};
void warn_if_legacy_script(std::string_view filename)
{
if ( ends_with(filename, ".bro") )
{
std::string x(filename);
reporter->Warning("Loading script '%s' with legacy extension, support for '.bro' will be removed in Zeek v4.1", x.c_str());
}
}
TEST_CASE("util is_package_loader")
{
CHECK(is_package_loader("/some/path/__load__.zeek") == true);
@ -601,17 +590,7 @@ TEST_CASE("util is_package_loader")
bool is_package_loader(const string& path)
{
string filename(std::move(SafeBasename(path).result));
for ( const string& ext : script_extensions )
{
if ( filename == "__load__" + ext )
{
warn_if_legacy_script(filename);
return true;
}
}
return false;
return ( filename == "__load__.zeek" );
}
void add_to_zeek_path(const string& dir)
@ -627,19 +606,15 @@ FILE* open_package(string& path, const string& mode)
string arg_path = path;
path.append("/__load__");
for ( const string& ext : script_extensions )
{
string p = path + ext;
string p = path + ".zeek";
if ( can_read(p) )
{
warn_if_legacy_script(path);
path.append(ext);
path.append(".zeek");
return open_file(path, mode);
}
}
path.append(script_extensions[0]);
string package_loader = "__load__" + script_extensions[0];
path.append(".zeek");
string package_loader = "__load__.zeek";
reporter->Error("Failed to open package '%s': missing '%s' file",
arg_path.c_str(), package_loader.c_str());
return nullptr;
@ -2008,28 +1983,15 @@ string find_script_file(const string& filename, const string& path_set)
vector<string> paths;
tokenize_string(path_set, ":", &paths);
vector<string> ext(detail::script_extensions.begin(), detail::script_extensions.end());
vector<string> ext = {".zeek"};
for ( size_t n = 0; n < paths.size(); ++n )
{
string f = find_file_in_path(filename, paths[n], ext);
if ( ! f.empty() )
{
detail::warn_if_legacy_script(f);
return f;
}
}
if ( ends_with(filename, ".bro") )
{
detail::warn_if_legacy_script(filename);
// We were looking for a file explicitly ending in .bro and didn't
// find it, so fall back to one ending in .zeek, if it exists.
auto fallback = string(filename.data(), filename.size() - 4) + ".zeek";
return find_script_file(fallback, path_set);
}
return string();
}
@ -2404,17 +2366,7 @@ char* zeekenv(const char* name)
if ( it == legacy_vars.end() )
return rval;
auto val = getenv(it->second);
if ( val && starts_with(it->second, "BRO_") )
{
if ( reporter )
reporter->Warning("Using legacy environment variable %s, support will be removed in Zeek v4.1; use %s instead", it->second, name);
else
fprintf(stderr, "Using legacy environment variable %s, support will be removed in Zeek v4.1; use %s instead\n", it->second, name);
}
return val;
return getenv(it->second);
}
static string json_escape_byte(char c)

View file

@ -174,11 +174,6 @@ constexpr SourceID SOURCE_LOCAL = 0;
// indicating whether it's a local or remote event.
constexpr SourceID SOURCE_BROKER = 0xffffffff;
extern const std::array<std::string, 2> script_extensions;
/** Prints a warning if the filename ends in .bro. */
void warn_if_legacy_script(std::string_view filename);
bool is_package_loader(const std::string& path);
extern void add_to_zeek_path(const std::string& dir);

View file

@ -468,13 +468,8 @@ time_t ScriptInfo::DoGetModificationTime() const
if ( ! info )
{
for (const string& ext : util::detail::script_extensions)
{
string pkg_name = *it + "/__load__" + ext;
string pkg_name = *it + "/__load__.zeek";
info = zeek::detail::zeekygen_mgr->GetScriptInfo(pkg_name);
if ( info )
break;
}
if ( ! info )
reporter->InternalWarning("Zeekygen failed to get mtime of %s",

View file

@ -1,5 +1,4 @@
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
loaded lcl2.base.utils.site.zeek
loaded lcl.base.utils.site.zeek
loaded lcl2.base.protocols.http.bro
loaded lcl.base.protocols.http.zeek

View file

@ -1,2 +1 @@
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
Loaded: dontloadme.bro

View file

@ -1,12 +0,0 @@
# @TEST-EXEC: zeek -b %INPUT >out 2>&1
# @TEST-EXEC: TEST_DIFF_CANONIFIER=$SCRIPTS/diff-remove-abspath btest-diff out
# We don't have a foo.bro, but we'll accept foo.zeek.
@load foo.bro
@TEST-START-FILE foo.zeek
event zeek_init()
{
print "loaded foo.zeek";
}
@TEST-END-FILE

View file

@ -1,34 +1,11 @@
# Test loading scripts with different file extensions.
#
# Test that either ".zeek" or ".bro" can be loaded without specifying extension
# @TEST-EXEC: cp x/foo.bro .
# @TEST-EXEC: zeek -b load_foo > bro_only
# @TEST-EXEC: btest-diff bro_only
# @TEST-EXEC: rm foo.bro
#
# Test that ".zeek" can be loaded without specifying extension
# @TEST-EXEC: cp x/foo.zeek .
# @TEST-EXEC: zeek -b load_foo > zeek_only
# @TEST-EXEC: btest-diff zeek_only
# @TEST-EXEC: rm foo.zeek
#
# Test that ".zeek" is the preferred file extension, unless ".bro" is specified
# @TEST-EXEC: cp x/foo.* .
# @TEST-EXEC: cp x2/foo .
# @TEST-EXEC: zeek -b load_foo > zeek_preferred
# @TEST-EXEC: btest-diff zeek_preferred
#
# @TEST-EXEC: zeek -b load_foo_bro > bro_preferred
# @TEST-EXEC: btest-diff bro_preferred
# @TEST-EXEC: rm foo*
#
# Test that ".bro" is preferred over a script with no file extension (when
# there is no ".zeek" script)
# @TEST-EXEC: cp x/foo.bro .
# @TEST-EXEC: cp x2/foo .
# @TEST-EXEC: zeek -b load_foo > bro_preferred_2
# @TEST-EXEC: btest-diff bro_preferred_2
# @TEST-EXEC: rm foo*
#
# Test that a script with no file extension can be loaded
# @TEST-EXEC: cp x2/foo .
# @TEST-EXEC: zeek -b load_foo > no_extension
@ -55,19 +32,11 @@
@load foo
@TEST-END-FILE
@TEST-START-FILE load_foo_bro
@load foo.bro
@TEST-END-FILE
@TEST-START-FILE load_foo_xyz
@load foo.xyz
@TEST-END-FILE
@TEST-START-FILE x/foo.bro
print "Bro script loaded";
@TEST-END-FILE
@TEST-START-FILE x/foo.zeek
print "Zeek script loaded";
@TEST-END-FILE

View file

@ -1,23 +1,13 @@
# Test that package loading works when a package loader script is present.
#
# Test that ".zeek" is loaded when there is also a ".bro"
# Test that ".zeek" is loaded
# @TEST-EXEC: zeek -b foo >output
# @TEST-EXEC: btest-diff output
#
# Test that ".bro" is loaded when there is no ".zeek"
# @TEST-EXEC: rm foo/__load__.zeek
# @TEST-EXEC: zeek -b foo >output2
# @TEST-EXEC: btest-diff output2
#
# Test that package cannot be loaded when no package loader script exists.
# @TEST-EXEC: rm foo/__load__.bro
# @TEST-EXEC: rm foo/__load__.zeek
# @TEST-EXEC-FAIL: zeek -b foo
@TEST-START-FILE foo/__load__.bro
@load ./test
print "__load__.bro loaded";
@TEST-END-FILE
@TEST-START-FILE foo/__load__.zeek
@load ./test
print "__load__.zeek loaded";

View file

@ -18,12 +18,7 @@ print "loaded lcl.base.utils.site.zeek";
print "loaded lcl2.base.utils.site.zeek";
@TEST-END-FILE
# For a script package like base/protocols/http/, either of the recognized
# file extensions can be loaded here.
# For a script package like base/protocols/http/, verify the package can be loaded.
@TEST-START-FILE lcl.base.protocols.http.zeek
print "loaded lcl.base.protocols.http.zeek";
@TEST-END-FILE
@TEST-START-FILE lcl2.base.protocols.http.bro
print "loaded lcl2.base.protocols.http.bro";
@TEST-END-FILE

View file

@ -1,15 +1,9 @@
# This tests the @unload directive
#
# Test that @unload works with ".bro" when there is no ".zeek" script
# @TEST-EXEC: zeek -b unloadbro misc/loaded-scripts dontloadmebro > output
# @TEST-EXEC: zeek -b unload misc/loaded-scripts dontloadme > output
# @TEST-EXEC: btest-diff output
# @TEST-EXEC: grep dontloadmebro loaded_scripts.log && exit 1 || exit 0
#
# Test that @unload looks for ".zeek" first (assuming no file extension is
# specified in the @unload)
# @TEST-EXEC: zeek -b unload misc/loaded-scripts dontloadme.zeek dontloadme.bro > output2
# @TEST-EXEC: btest-diff output2
# @TEST-EXEC: grep dontloadme.bro loaded_scripts.log
# @TEST-EXEC: grep dontloadme loaded_scripts.log && exit 1 || exit 0
@TEST-START-FILE unloadbro.bro
@unload dontloadmebro
@ -30,3 +24,4 @@ print "Loaded: dontloadme.zeek";
@TEST-START-FILE dontloadme.bro
print "Loaded: dontloadme.bro";
@TEST-END-FILE
z