diff --git a/NEWS b/NEWS index 3f30b2053f..0eef411943 100644 --- a/NEWS +++ b/NEWS @@ -39,6 +39,10 @@ Deprecated Functionality compatible iterators. This enables the use of standard constructs such as ranged-for loops to iterate over those objects. +- The ``zeek::util::zeekenv()`` function is deprecated since use of all + environment variables prefixed by ``BRO_`` is now removed and calling + ``getenv()`` directly with ``ZEEK_`` environment variables can be done. + Zeek 4.0.0 ========== diff --git a/src/DNS_Mgr.cc b/src/DNS_Mgr.cc index 67c7b0e264..650312e154 100644 --- a/src/DNS_Mgr.cc +++ b/src/DNS_Mgr.cc @@ -409,7 +409,7 @@ void DNS_Mgr::InitSource() // 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 = util::zeekenv("ZEEK_DNS_RESOLVER"); + auto dns_resolver = getenv("ZEEK_DNS_RESOLVER"); auto dns_resolver_addr = dns_resolver ? IPAddr(dns_resolver) : IPAddr(); char err[NB_DNS_ERRSIZE]; diff --git a/src/Options.cc b/src/Options.cc index 6ab5b5bb0c..d1cc0cb53a 100644 --- a/src/Options.cc +++ b/src/Options.cc @@ -70,7 +70,7 @@ void Options::filter_supervised_node_options() bool fake_dns() { - return util::zeekenv("ZEEK_DNS_FAKE"); + return getenv("ZEEK_DNS_FAKE"); } extern const char* zeek_version(); @@ -135,8 +135,8 @@ void usage(const char* prog, int code) 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::detail::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", util::zeekenv("ZEEK_DISABLE_ZEEKYGEN") ? "set" : "not set"); - fprintf(stderr, " $ZEEK_DNS_RESOLVER | IPv4/IPv6 address of DNS resolver to use (%s)\n", util::zeekenv("ZEEK_DNS_RESOLVER") ? util::zeekenv("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", getenv("ZEEK_DISABLE_ZEEKYGEN") ? "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_DEBUG_LOG_STDERR | Use stderr for debug logs generated via the -B flag"); fprintf(stderr, "\n"); diff --git a/src/ScriptCoverageManager.cc b/src/ScriptCoverageManager.cc index 17f25eee83..e67dfb8c7c 100644 --- a/src/ScriptCoverageManager.cc +++ b/src/ScriptCoverageManager.cc @@ -39,7 +39,7 @@ void ScriptCoverageManager::AddStmt(Stmt* s) bool ScriptCoverageManager::ReadStats() { - char* bf = util::zeekenv("ZEEK_PROFILER_FILE"); + char* bf = getenv("ZEEK_PROFILER_FILE"); if ( ! bf ) return false; @@ -89,7 +89,7 @@ bool ScriptCoverageManager::ReadStats() bool ScriptCoverageManager::WriteStats() { - char* bf = util::zeekenv("ZEEK_PROFILER_FILE"); + char* bf = getenv("ZEEK_PROFILER_FILE"); if ( ! bf ) return false; diff --git a/src/broker/Manager.cc b/src/broker/Manager.cc index 27fb72ed53..0c265a732f 100644 --- a/src/broker/Manager.cc +++ b/src/broker/Manager.cc @@ -185,7 +185,7 @@ void Manager::InitPostScript() else reporter->FatalError("Invalid Broker::scheduler_policy: %s", scheduler_policy); - auto max_threads_env = util::zeekenv("ZEEK_BROKER_MAX_THREADS"); + auto max_threads_env = getenv("ZEEK_BROKER_MAX_THREADS"); if ( max_threads_env ) config.set("caf.scheduler.max-threads", atoi(max_threads_env)); @@ -365,7 +365,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 = util::zeekenv("ZEEK_DEFAULT_CONNECT_RETRY"); + auto e = getenv("ZEEK_DEFAULT_CONNECT_RETRY"); if ( e ) retry = atoi(e); diff --git a/src/logging/writers/ascii/Ascii.cc b/src/logging/writers/ascii/Ascii.cc index ec48bf6c85..926960faf4 100644 --- a/src/logging/writers/ascii/Ascii.cc +++ b/src/logging/writers/ascii/Ascii.cc @@ -850,7 +850,7 @@ void Ascii::RotateLeftoverLogs() string Ascii::LogExt() { - const char* ext = util::zeekenv("ZEEK_LOG_SUFFIX"); + const char* ext = getenv("ZEEK_LOG_SUFFIX"); if ( ! ext ) ext = "log"; diff --git a/src/util.cc b/src/util.cc index d045dce92c..c584678999 100644 --- a/src/util.cc +++ b/src/util.cc @@ -876,7 +876,7 @@ FILE* rotate_file(const char* name, RecordVal* rotate_info) const char* log_file_name(const char* tag) { - const char* env = zeekenv("ZEEK_LOG_SUFFIX"); + const char* env = getenv("ZEEK_LOG_SUFFIX"); return fmt("%s.%s", tag, (env ? env : "log")); } @@ -1705,7 +1705,7 @@ const std::string& zeek_path() { if ( zeek_path_value.empty() ) { - const char* path = zeekenv("ZEEKPATH"); + const char* path = getenv("ZEEKPATH"); if ( ! path ) path = DEFAULT_ZEEKPATH; @@ -1718,7 +1718,7 @@ const std::string& zeek_path() const char* zeek_plugin_path() { - const char* path = zeekenv("ZEEK_PLUGIN_PATH"); + const char* path = getenv("ZEEK_PLUGIN_PATH"); if ( ! path ) path = BRO_PLUGIN_INSTALL_PATH; @@ -1728,7 +1728,7 @@ const char* zeek_plugin_path() const char* zeek_plugin_activate() { - const char* names = zeekenv("ZEEK_PLUGIN_ACTIVATE"); + const char* names = getenv("ZEEK_PLUGIN_ACTIVATE"); if ( ! names ) names = ""; @@ -2338,35 +2338,9 @@ void zeek_strerror_r(int zeek_errno, char* buf, size_t buflen) strerror_r_helper(res, buf, buflen); } -static const std::map 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" }, -}; - char* zeekenv(const char* name) { - 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); + return getenv(name); } static string json_escape_byte(char c) diff --git a/src/util.h b/src/util.h index 6d74113fa8..27de350a1e 100644 --- a/src/util.h +++ b/src/util.h @@ -526,6 +526,7 @@ void zeek_strerror_r(int zeek_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. */ +[[deprecated("Remove in v5.1. Use getenv() directly.")]] char* zeekenv(const char* name); /** diff --git a/src/zeek-setup.cc b/src/zeek-setup.cc index 44f1dbc70e..5d0bd9bc56 100644 --- a/src/zeek-setup.cc +++ b/src/zeek-setup.cc @@ -427,7 +427,7 @@ SetupResult setup(int argc, char** argv, Options* zopts) RETSIGTYPE (*oldhandler)(int); zeek_script_prefixes = options.script_prefixes; - auto zeek_prefixes = util::zeekenv("ZEEK_PREFIXES"); + auto zeek_prefixes = getenv("ZEEK_PREFIXES"); if ( zeek_prefixes ) util::tokenize_string(zeek_prefixes, ":", &zeek_script_prefixes); @@ -488,7 +488,7 @@ SetupResult setup(int argc, char** argv, Options* zopts) supervisor_mgr = new Supervisor(std::move(cfg), std::move(*stem)); } - const char* seed_load_file = util::zeekenv("ZEEK_SEED_FILE"); + const char* seed_load_file = getenv("ZEEK_SEED_FILE"); if ( options.random_seed_input_file ) seed_load_file = options.random_seed_input_file->data(); @@ -879,7 +879,7 @@ SetupResult setup(int argc, char** argv, Options* zopts) // Drain the event queue here to support the protocols framework configuring DPM event_mgr.Drain(); - if ( reporter->Errors() > 0 && ! util::zeekenv("ZEEK_ALLOW_INIT_ERRORS") ) + if ( reporter->Errors() > 0 && ! getenv("ZEEK_ALLOW_INIT_ERRORS") ) reporter->FatalError("errors occurred while initializing"); run_state::detail::zeek_init_done = true; diff --git a/src/zeek.bif b/src/zeek.bif index 2a05ed932e..eb936c8a08 100644 --- a/src/zeek.bif +++ b/src/zeek.bif @@ -344,7 +344,7 @@ function network_time%(%): time ## .. zeek:see:: setenv function getenv%(var: string%): string %{ - const char* env_val = zeek::util::zeekenv(var->CheckString()); + const char* env_val = getenv(var->CheckString()); if ( ! env_val ) env_val = ""; // ### return zeek::make_intrusive(env_val); diff --git a/src/zeekygen/Manager.cc b/src/zeekygen/Manager.cc index 5260b7fc3f..0352bf106f 100644 --- a/src/zeekygen/Manager.cc +++ b/src/zeekygen/Manager.cc @@ -71,7 +71,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 ( util::zeekenv("ZEEK_DISABLE_ZEEKYGEN") ) + if ( getenv("ZEEK_DISABLE_ZEEKYGEN") ) disabled = true; // If running bro without the "-X" option, then we don't need bro_mtime.