mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 06:38:20 +00:00
Add an internal getenv wrapper function: zeekenv
It maps newer environment variable names starting with ZEEK to the legacy names starting with BRO.
This commit is contained in:
parent
580822a32c
commit
7f0fb49612
14 changed files with 82 additions and 81 deletions
13
CHANGES
13
CHANGES
|
@ -1,4 +1,17 @@
|
|||
|
||||
2.6-334 | 2019-05-23 20:40:03 -0700
|
||||
|
||||
* Add an internal getenv wrapper function: zeekenv (Jon Siwek, Corelight)
|
||||
|
||||
It maps newer environment variable names starting with ZEEK to the
|
||||
legacy names starting with BRO.
|
||||
|
||||
* Rename all BRO-prefixed environment variables (Daniel Thayer)
|
||||
|
||||
For backward compatibility when reading values, we first check
|
||||
the ZEEK-prefixed value, and if not set, then check the corresponding
|
||||
BRO-prefixed value.
|
||||
|
||||
2.6-331 | 2019-05-23 18:03:42 -0700
|
||||
|
||||
* Update broker unit test output. (Jon Siwek, Corelight)
|
||||
|
|
2
VERSION
2
VERSION
|
@ -1 +1 @@
|
|||
2.6-331
|
||||
2.6-334
|
||||
|
|
|
@ -16,7 +16,7 @@ export {
|
|||
## Default address on which to listen.
|
||||
##
|
||||
## .. zeek:see:: Broker::listen
|
||||
const default_listen_address = getenv("ZEEK_DEFAULT_LISTEN_ADDRESS") != "" ? getenv("ZEEK_DEFAULT_LISTEN_ADDRESS") : getenv("BRO_DEFAULT_LISTEN_ADDRESS") &redef;
|
||||
const default_listen_address = getenv("ZEEK_DEFAULT_LISTEN_ADDRESS") &redef;
|
||||
|
||||
## Default interval to retry connecting to a peer if it cannot be made to
|
||||
## work initially, or if it ever becomes disconnected. Use of the
|
||||
|
@ -380,8 +380,6 @@ function listen(a: string, p: port, retry: interval): port
|
|||
if ( bound == 0/tcp )
|
||||
{
|
||||
local e = getenv("ZEEK_DEFAULT_LISTEN_RETRY");
|
||||
if ( e == "" )
|
||||
e = getenv("BRO_DEFAULT_LISTEN_RETRY");
|
||||
|
||||
if ( e != "" )
|
||||
retry = double_to_interval(to_double(e));
|
||||
|
|
|
@ -84,11 +84,7 @@ function default_rotation_postprocessor_func(info: Log::RotationInfo) : bool
|
|||
local bls = getenv("ZEEK_LOG_SUFFIX");
|
||||
|
||||
if ( bls == "" )
|
||||
{
|
||||
bls = getenv("BRO_LOG_SUFFIX");
|
||||
if ( bls == "" )
|
||||
bls = "log";
|
||||
}
|
||||
bls = "log";
|
||||
|
||||
# Move file to name including both opening and closing time.
|
||||
local dst = fmt("%s.%s.%s%s", info$path,
|
||||
|
|
|
@ -1807,12 +1807,9 @@ event net_done(t: time) { done_with_network = T; }
|
|||
function log_file_name(tag: string): string
|
||||
{
|
||||
local suffix = getenv("ZEEK_LOG_SUFFIX");
|
||||
|
||||
if ( suffix == "" )
|
||||
{
|
||||
suffix = getenv("BRO_LOG_SUFFIX");
|
||||
if ( suffix == "" )
|
||||
suffix = "log";
|
||||
}
|
||||
suffix = "log";
|
||||
|
||||
return fmt("%s.%s", tag, suffix);
|
||||
}
|
||||
|
|
|
@ -17,13 +17,10 @@ Brofiler::~Brofiler()
|
|||
|
||||
bool Brofiler::ReadStats()
|
||||
{
|
||||
char* bf = getenv("ZEEK_PROFILER_FILE");
|
||||
char* bf = zeekenv("ZEEK_PROFILER_FILE");
|
||||
|
||||
if ( ! bf )
|
||||
{
|
||||
bf = getenv("BRO_PROFILER_FILE");
|
||||
if ( ! bf )
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
|
||||
FILE* f = fopen(bf, "r");
|
||||
if ( ! f )
|
||||
|
@ -51,13 +48,10 @@ bool Brofiler::ReadStats()
|
|||
|
||||
bool Brofiler::WriteStats()
|
||||
{
|
||||
char* bf = getenv("ZEEK_PROFILER_FILE");
|
||||
char* bf = zeekenv("ZEEK_PROFILER_FILE");
|
||||
|
||||
if ( ! bf )
|
||||
{
|
||||
bf = getenv("BRO_PROFILER_FILE");
|
||||
if ( ! bf )
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
|
||||
SafeDirname dirname{bf};
|
||||
|
||||
|
|
|
@ -414,7 +414,7 @@ void DNS_Mgr::Init()
|
|||
// script-layer option to configure the DNS resolver as it may not be
|
||||
// configured to the user's desired address at the time when we need to to
|
||||
// the lookup.
|
||||
auto dns_resolver = getenv("ZEEK_DNS_RESOLVER");
|
||||
auto dns_resolver = zeekenv("ZEEK_DNS_RESOLVER");
|
||||
auto dns_resolver_addr = dns_resolver ? IPAddr(dns_resolver) : IPAddr();
|
||||
char err[NB_DNS_ERRSIZE];
|
||||
|
||||
|
|
|
@ -339,7 +339,7 @@ function network_time%(%): time
|
|||
## .. zeek:see:: setenv
|
||||
function getenv%(var: string%): string
|
||||
%{
|
||||
const char* env_val = getenv(var->CheckString());
|
||||
const char* env_val = zeekenv(var->CheckString());
|
||||
if ( ! env_val )
|
||||
env_val = ""; // ###
|
||||
return new StringVal(env_val);
|
||||
|
|
|
@ -177,9 +177,7 @@ void Manager::InitPostScript()
|
|||
|
||||
BrokerConfig config{std::move(options)};
|
||||
|
||||
auto max_threads_env = getenv("ZEEK_BROKER_MAX_THREADS");
|
||||
if ( ! max_threads_env )
|
||||
max_threads_env = getenv("BRO_BROKER_MAX_THREADS");
|
||||
auto max_threads_env = zeekenv("ZEEK_BROKER_MAX_THREADS");
|
||||
|
||||
if ( max_threads_env )
|
||||
config.set("scheduler.max-threads", atoi(max_threads_env));
|
||||
|
@ -305,9 +303,7 @@ void Manager::Peer(const string& addr, uint16_t port, double retry)
|
|||
DBG_LOG(DBG_BROKER, "Starting to peer with %s:%" PRIu16,
|
||||
addr.c_str(), port);
|
||||
|
||||
auto e = getenv("ZEEK_DEFAULT_CONNECT_RETRY");
|
||||
if ( ! e )
|
||||
e = getenv("BRO_DEFAULT_CONNECT_RETRY");
|
||||
auto e = zeekenv("ZEEK_DEFAULT_CONNECT_RETRY");
|
||||
|
||||
if ( e )
|
||||
retry = atoi(e);
|
||||
|
|
|
@ -444,13 +444,10 @@ bool Ascii::DoHeartbeat(double network_time, double current_time)
|
|||
|
||||
string Ascii::LogExt()
|
||||
{
|
||||
const char* ext = getenv("ZEEK_LOG_SUFFIX");
|
||||
const char* ext = zeekenv("ZEEK_LOG_SUFFIX");
|
||||
|
||||
if ( ! ext )
|
||||
{
|
||||
ext = getenv("BRO_LOG_SUFFIX");
|
||||
if ( ! ext )
|
||||
ext = "log";
|
||||
}
|
||||
ext = "log";
|
||||
|
||||
return ext;
|
||||
}
|
||||
|
|
20
src/main.cc
20
src/main.cc
|
@ -147,10 +147,7 @@ const char* bro_version()
|
|||
|
||||
bool bro_dns_fake()
|
||||
{
|
||||
if ( getenv("ZEEK_DNS_FAKE") || getenv("BRO_DNS_FAKE") )
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
return zeekenv("ZEEK_DNS_FAKE");
|
||||
}
|
||||
|
||||
void usage(int code = 1)
|
||||
|
@ -208,8 +205,8 @@ void usage(int code = 1)
|
|||
fprintf(stderr, " $ZEEK_SEED_FILE | file to load seeds from (not set)\n");
|
||||
fprintf(stderr, " $ZEEK_LOG_SUFFIX | ASCII log file extension (.%s)\n", logging::writer::Ascii::LogExt().c_str());
|
||||
fprintf(stderr, " $ZEEK_PROFILER_FILE | Output file for script execution statistics (not set)\n");
|
||||
fprintf(stderr, " $ZEEK_DISABLE_ZEEKYGEN | Disable Zeekygen documentation support (%s)\n", getenv("ZEEK_DISABLE_ZEEKYGEN") || getenv("BRO_DISABLE_BROXYGEN") ? "set" : "not set");
|
||||
fprintf(stderr, " $ZEEK_DNS_RESOLVER | IPv4/IPv6 address of DNS resolver to use (%s)\n", getenv("ZEEK_DNS_RESOLVER") ? getenv("ZEEK_DNS_RESOLVER") : "not set, will use first IPv4 address from /etc/resolv.conf");
|
||||
fprintf(stderr, " $ZEEK_DISABLE_ZEEKYGEN | Disable Zeekygen documentation support (%s)\n", zeekenv("ZEEK_DISABLE_ZEEKYGEN") ? "set" : "not set");
|
||||
fprintf(stderr, " $ZEEK_DNS_RESOLVER | IPv4/IPv6 address of DNS resolver to use (%s)\n", zeekenv("ZEEK_DNS_RESOLVER") ? zeekenv("ZEEK_DNS_RESOLVER") : "not set, will use first IPv4 address from /etc/resolv.conf");
|
||||
|
||||
fprintf(stderr, "\n");
|
||||
|
||||
|
@ -428,10 +425,7 @@ int main(int argc, char** argv)
|
|||
char* id_name = 0;
|
||||
char* events_file = 0;
|
||||
|
||||
char* seed_load_file = getenv("ZEEK_SEED_FILE");
|
||||
if ( ! seed_load_file )
|
||||
seed_load_file = getenv("BRO_SEED_FILE");
|
||||
|
||||
char* seed_load_file = zeekenv("ZEEK_SEED_FILE");
|
||||
char* seed_save_file = 0;
|
||||
char* user_pcap_filter = 0;
|
||||
char* debug_streams = 0;
|
||||
|
@ -500,9 +494,7 @@ int main(int argc, char** argv)
|
|||
|
||||
prefixes.append(strdup("")); // "" = "no prefix"
|
||||
|
||||
char* p = getenv("ZEEK_PREFIXES");
|
||||
if ( ! p )
|
||||
p = getenv("BRO_PREFIXES");
|
||||
char* p = zeekenv("ZEEK_PREFIXES");
|
||||
|
||||
if ( p )
|
||||
add_to_name_list(p, ':', prefixes);
|
||||
|
@ -1088,7 +1080,7 @@ int main(int argc, char** argv)
|
|||
// Drain the event queue here to support the protocols framework configuring DPM
|
||||
mgr.Drain();
|
||||
|
||||
if ( reporter->Errors() > 0 && ! getenv("ZEEK_ALLOW_INIT_ERRORS") )
|
||||
if ( reporter->Errors() > 0 && ! zeekenv("ZEEK_ALLOW_INIT_ERRORS") )
|
||||
reporter->FatalError("errors occurred while initializing");
|
||||
|
||||
broker_mgr->ZeekInitDone();
|
||||
|
|
64
src/util.cc
64
src/util.cc
|
@ -958,15 +958,10 @@ const std::string& bro_path()
|
|||
{
|
||||
if ( bro_path_value.empty() )
|
||||
{
|
||||
const char* path = getenv("ZEEKPATH");
|
||||
const char* path = zeekenv("ZEEKPATH");
|
||||
|
||||
if ( ! path )
|
||||
{
|
||||
path = getenv("BROPATH");
|
||||
|
||||
if ( ! path )
|
||||
path = DEFAULT_ZEEKPATH;
|
||||
}
|
||||
path = DEFAULT_ZEEKPATH;
|
||||
|
||||
bro_path_value = path;
|
||||
}
|
||||
|
@ -984,30 +979,20 @@ extern void add_to_bro_path(const string& dir)
|
|||
|
||||
const char* bro_plugin_path()
|
||||
{
|
||||
const char* path = getenv("ZEEK_PLUGIN_PATH");
|
||||
const char* path = zeekenv("ZEEK_PLUGIN_PATH");
|
||||
|
||||
if ( ! path )
|
||||
{
|
||||
path = getenv("BRO_PLUGIN_PATH");
|
||||
|
||||
if ( ! path )
|
||||
path = BRO_PLUGIN_INSTALL_PATH;
|
||||
}
|
||||
path = BRO_PLUGIN_INSTALL_PATH;
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
const char* bro_plugin_activate()
|
||||
{
|
||||
const char* names = getenv("ZEEK_PLUGIN_ACTIVATE");
|
||||
const char* names = zeekenv("ZEEK_PLUGIN_ACTIVATE");
|
||||
|
||||
if ( ! names )
|
||||
{
|
||||
names = getenv("BRO_PLUGIN_ACTIVATE");
|
||||
|
||||
if ( ! names )
|
||||
names = "";
|
||||
}
|
||||
names = "";
|
||||
|
||||
return names;
|
||||
}
|
||||
|
@ -1403,11 +1388,7 @@ FILE* rotate_file(const char* name, RecordVal* rotate_info)
|
|||
|
||||
const char* log_file_name(const char* tag)
|
||||
{
|
||||
const char* env = getenv("ZEEK_LOG_SUFFIX");
|
||||
|
||||
if ( ! env )
|
||||
env = getenv("BRO_LOG_SUFFIX");
|
||||
|
||||
const char* env = zeekenv("ZEEK_LOG_SUFFIX");
|
||||
return fmt("%s.%s", tag, (env ? env : "log"));
|
||||
}
|
||||
|
||||
|
@ -1862,3 +1843,34 @@ void bro_strerror_r(int bro_errno, char* buf, size_t buflen)
|
|||
// GNU vs. XSI flavors make it harder to use strerror_r.
|
||||
strerror_r_helper(res, buf, buflen);
|
||||
}
|
||||
|
||||
char* zeekenv(const char* name)
|
||||
{
|
||||
static std::map<const char*, const char*, CompareString> legacy_vars = {
|
||||
{ "ZEEKPATH", "BROPATH" },
|
||||
{ "ZEEK_PLUGIN_PATH", "BRO_PLUGIN_PATH" },
|
||||
{ "ZEEK_PLUGIN_ACTIVATE", "BRO_PLUGIN_ACTIVATE" },
|
||||
{ "ZEEK_PREFIXES", "BRO_PREFIXES" },
|
||||
{ "ZEEK_DNS_FAKE", "BRO_DNS_FAKE" },
|
||||
{ "ZEEK_SEED_FILE", "BRO_SEED_FILE" },
|
||||
{ "ZEEK_LOG_SUFFIX", "BRO_LOG_SUFFIX" },
|
||||
{ "ZEEK_PROFILER_FILE", "BRO_PROFILER_FILE" },
|
||||
{ "ZEEK_DISABLE_ZEEKYGEN", "BRO_DISABLE_BROXYGEN" },
|
||||
{ "ZEEK_DEFAULT_CONNECT_RETRY", "BRO_DEFAULT_CONNECT_RETRY" },
|
||||
{ "ZEEK_BROKER_MAX_THREADS", "BRO_BROKER_MAX_THREADS" },
|
||||
{ "ZEEK_DEFAULT_LISTEN_ADDRESS", "BRO_DEFAULT_LISTEN_ADDRESS" },
|
||||
{ "ZEEK_DEFAULT_LISTEN_RETRY", "BRO_DEFAULT_LISTEN_RETRY" },
|
||||
};
|
||||
|
||||
auto rval = getenv(name);
|
||||
|
||||
if ( rval )
|
||||
return rval;
|
||||
|
||||
auto it = legacy_vars.find(name);
|
||||
|
||||
if ( it == legacy_vars.end() )
|
||||
return rval;
|
||||
|
||||
return getenv(it->second);
|
||||
}
|
||||
|
|
|
@ -549,4 +549,10 @@ std::string canonify_name(const std::string& name);
|
|||
*/
|
||||
void bro_strerror_r(int bro_errno, char* buf, size_t buflen);
|
||||
|
||||
/**
|
||||
* A wrapper function for getenv(). Helps check for existence of
|
||||
* legacy environment variable names that map to the latest \a name.
|
||||
*/
|
||||
char* zeekenv(const char* name);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -64,7 +64,7 @@ Manager::Manager(const string& arg_config, const string& bro_command)
|
|||
identifiers(), all_info(), last_identifier_seen(), incomplete_type(),
|
||||
enum_mappings(), config(arg_config), bro_mtime()
|
||||
{
|
||||
if ( getenv("ZEEK_DISABLE_ZEEKYGEN") || getenv("BRO_DISABLE_BROXYGEN") )
|
||||
if ( zeekenv("ZEEK_DISABLE_ZEEKYGEN") )
|
||||
disabled = true;
|
||||
|
||||
// If running bro without the "-X" option, then we don't need bro_mtime.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue