Skip to content

Commit

Permalink
Rename all BRO-prefixed environment variables
Browse files Browse the repository at this point in the history
For backward compatibility when reading values, we first check
the ZEEK-prefixed value, and if not set, then check the corresponding
BRO-prefixed value.
  • Loading branch information
dnthayer committed May 22, 2019
1 parent d6096b1 commit 1a74516
Show file tree
Hide file tree
Showing 105 changed files with 330 additions and 274 deletions.
8 changes: 4 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ set(BRO_PLUGIN_INSTALL_PATH ${ZEEK_ROOT_DIR}/lib/bro/plugins CACHE STRING "Insta
configure_file(zeek-path-dev.in ${CMAKE_CURRENT_BINARY_DIR}/zeek-path-dev)

file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/zeek-path-dev.sh
"export BROPATH=`${CMAKE_CURRENT_BINARY_DIR}/zeek-path-dev`\n"
"export BRO_PLUGIN_PATH=\"${CMAKE_CURRENT_BINARY_DIR}/src\":${BRO_PLUGIN_PATH}\n"
"export ZEEKPATH=`${CMAKE_CURRENT_BINARY_DIR}/zeek-path-dev`\n"
"export ZEEK_PLUGIN_PATH=\"${CMAKE_CURRENT_BINARY_DIR}/src\":${ZEEK_PLUGIN_PATH}\n"
"export PATH=\"${CMAKE_CURRENT_BINARY_DIR}/src\":$PATH\n")

file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/zeek-path-dev.csh
"setenv BROPATH `${CMAKE_CURRENT_BINARY_DIR}/zeek-path-dev`\n"
"setenv BRO_PLUGIN_PATH \"${CMAKE_CURRENT_BINARY_DIR}/src\":${BRO_PLUGIN_PATH}\n"
"setenv ZEEKPATH `${CMAKE_CURRENT_BINARY_DIR}/zeek-path-dev`\n"
"setenv ZEEK_PLUGIN_PATH \"${CMAKE_CURRENT_BINARY_DIR}/src\":${ZEEK_PLUGIN_PATH}\n"
"setenv PATH \"${CMAKE_CURRENT_BINARY_DIR}/src\":$PATH\n")

file(STRINGS "${CMAKE_CURRENT_SOURCE_DIR}/VERSION" VERSION LIMIT_COUNT 1)
Expand Down
18 changes: 9 additions & 9 deletions man/zeek.8
Original file line number Diff line number Diff line change
Expand Up @@ -122,31 +122,31 @@ show leaks
record heap
.SH ENVIRONMENT
.TP
.B BROPATH
.B ZEEKPATH
file search path
.TP
.B BRO_PLUGIN_PATH
.B ZEEK_PLUGIN_PATH
plugin search path
.TP
.B BRO_PLUGIN_ACTIVATE
.B ZEEK_PLUGIN_ACTIVATE
plugins to always activate
.TP
.B BRO_PREFIXES
.B ZEEK_PREFIXES
prefix list
.TP
.B BRO_DNS_FAKE
.B ZEEK_DNS_FAKE
disable DNS lookups
.TP
.B BRO_SEED_FILE
.B ZEEK_SEED_FILE
file to load seeds from
.TP
.B BRO_LOG_SUFFIX
.B ZEEK_LOG_SUFFIX
ASCII log file extension
.TP
.B BRO_PROFILER_FILE
.B ZEEK_PROFILER_FILE
Output file for script execution statistics
.TP
.B BRO_DISABLE_BROXYGEN
.B ZEEK_DISABLE_ZEEKYGEN
Disable Zeekygen (Broxygen) documentation support
.SH AUTHOR
.B zeek
Expand Down
16 changes: 9 additions & 7 deletions scripts/base/frameworks/broker/main.zeek
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@ export {
const default_port = 9999/tcp &redef;

## Default interval to retry listening on a port if it's currently in
## use already. Use of the BRO_DEFAULT_LISTEN_RETRY environment variable
## use already. Use of the ZEEK_DEFAULT_LISTEN_RETRY environment variable
## (set as a number of seconds) will override this option and also
## any values given to :zeek:see:`Broker::listen`.
const default_listen_retry = 30sec &redef;

## Default address on which to listen.
##
## .. zeek:see:: Broker::listen
const default_listen_address = getenv("BRO_DEFAULT_LISTEN_ADDRESS") &redef;
const default_listen_address = getenv("ZEEK_DEFAULT_LISTEN_ADDRESS") != "" ? getenv("ZEEK_DEFAULT_LISTEN_ADDRESS") : getenv("BRO_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
## BRO_DEFAULT_CONNECT_RETRY environment variable (set as number of
## ZEEK_DEFAULT_CONNECT_RETRY environment variable (set as number of
## seconds) will override this option and also any values given to
## :zeek:see:`Broker::peer`.
const default_connect_retry = 30sec &redef;
Expand Down Expand Up @@ -70,7 +70,7 @@ export {
const log_batch_interval = 1sec &redef;

## Max number of threads to use for Broker/CAF functionality. The
## BRO_BROKER_MAX_THREADS environment variable overrides this setting.
## ZEEK_BROKER_MAX_THREADS environment variable overrides this setting.
const max_threads = 1 &redef;

## Interval of time for under-utilized Broker/CAF threads to sleep
Expand Down Expand Up @@ -235,7 +235,7 @@ export {
##
## retry: If non-zero, retries listening in regular intervals if the port cannot be
## acquired immediately. 0 disables retries. If the
## BRO_DEFAULT_LISTEN_RETRY environment variable is set (as number
## ZEEK_DEFAULT_LISTEN_RETRY environment variable is set (as number
## of seconds), it overrides any value given here.
##
## Returns: the bound port or 0/? on failure.
Expand All @@ -253,7 +253,7 @@ export {
## retry: an interval at which to retry establishing the
## connection with the remote peer if it cannot be made initially, or
## if it ever becomes disconnected. If the
## BRO_DEFAULT_CONNECT_RETRY environment variable is set (as number
## ZEEK_DEFAULT_CONNECT_RETRY environment variable is set (as number
## of seconds), it overrides any value given here.
##
## Returns: true if it's possible to try connecting with the peer and
Expand Down Expand Up @@ -379,7 +379,9 @@ function listen(a: string, p: port, retry: interval): port

if ( bound == 0/tcp )
{
local e = getenv("BRO_DEFAULT_LISTEN_RETRY");
local e = getenv("ZEEK_DEFAULT_LISTEN_RETRY");
if ( e == "" )
e = getenv("BRO_DEFAULT_LISTEN_RETRY");

if ( e != "" )
retry = double_to_interval(to_double(e));
Expand Down
2 changes: 1 addition & 1 deletion scripts/base/frameworks/cluster/__load__.zeek
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ redef Broker::log_topic = Cluster::rr_log_topic;

# If this script isn't found anywhere, the cluster bombs out.
# Loading the cluster framework requires that a script by this name exists
# somewhere in the BROPATH. The only thing in the file should be the
# somewhere in the ZEEKPATH. The only thing in the file should be the
# cluster definition in the :zeek:id:`Cluster::nodes` variable.
@load cluster-layout

Expand Down
6 changes: 3 additions & 3 deletions scripts/base/frameworks/cluster/main.zeek
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ export {
global worker_count: count = 0;

## The cluster layout definition. This should be placed into a filter
## named cluster-layout.zeek somewhere in the BROPATH. It will be
## named cluster-layout.zeek somewhere in the ZEEKPATH. It will be
## automatically loaded if the CLUSTER_NODE environment variable is set.
## Note that ZeekControl handles all of this automatically.
## The table is typically indexed by node names/labels (e.g. "manager"
Expand All @@ -210,8 +210,8 @@ export {
const node = getenv("CLUSTER_NODE") &redef;

## Interval for retrying failed connections between cluster nodes.
## If set, the BRO_DEFAULT_CONNECT_RETRY (given in number of seconds)
## overrides this option.
## If set, the ZEEK_DEFAULT_CONNECT_RETRY (given in number of seconds)
## environment variable overrides this option.
const retry_interval = 1min &redef;

## When using broker-enabled cluster framework, nodes broadcast this event
Expand Down
8 changes: 6 additions & 2 deletions scripts/base/frameworks/logging/writers/ascii.zeek
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,14 @@ function default_rotation_postprocessor_func(info: Log::RotationInfo) : bool
{
# If the filename has a ".gz" extension, then keep it.
local gz = info$fname[-3:] == ".gz" ? ".gz" : "";
local bls = getenv("BRO_LOG_SUFFIX");
local bls = getenv("ZEEK_LOG_SUFFIX");

if ( bls == "" )
bls = "log";
{
bls = getenv("BRO_LOG_SUFFIX");
if ( bls == "" )
bls = "log";
}

# Move file to name including both opening and closing time.
local dst = fmt("%s.%s.%s%s", info$path,
Expand Down
2 changes: 1 addition & 1 deletion scripts/base/frameworks/notice/main.zeek
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@ function is_being_suppressed(n: Notice::Info): bool
}

# Executes a script with all of the notice fields put into the
# new process' environment as "BRO_ARG_<field>" variables.
# new process' environment as "ZEEK_ARG_<field>" variables.
function execute_with_notice(cmd: string, n: Notice::Info)
{
# TODO: fix system calls
Expand Down
13 changes: 10 additions & 3 deletions scripts/base/init-bare.zeek
Original file line number Diff line number Diff line change
Expand Up @@ -1806,7 +1806,14 @@ event net_done(t: time) { done_with_network = T; }

function log_file_name(tag: string): string
{
local suffix = getenv("BRO_LOG_SUFFIX") == "" ? "log" : getenv("BRO_LOG_SUFFIX");
local suffix = getenv("ZEEK_LOG_SUFFIX");
if ( suffix == "" )
{
suffix = getenv("BRO_LOG_SUFFIX");
if ( suffix == "" )
suffix = "log";
}

return fmt("%s.%s", tag, suffix);
}

Expand Down Expand Up @@ -1839,11 +1846,11 @@ function add_signature_file(sold: string, snew: string): string

## Signature files to read. Use ``redef signature_files += "foo.sig"`` to
## extend. Signature files added this way will be searched relative to
## ``BROPATH``. Using the ``@load-sigs`` directive instead is preferred
## ``ZEEKPATH``. Using the ``@load-sigs`` directive instead is preferred
## since that can search paths relative to the current script.
global signature_files = "" &add_func = add_signature_file;

## ``p0f`` fingerprint file to use. Will be searched relative to ``BROPATH``.
## ``p0f`` fingerprint file to use. Will be searched relative to ``ZEEKPATH``.
const passive_fingerprint_file = "base/misc/p0f.fp" &redef;

## Definition of "secondary filters". A secondary filter is a BPF filter given
Expand Down
23 changes: 16 additions & 7 deletions src/Brofiler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,13 @@ Brofiler::~Brofiler()

bool Brofiler::ReadStats()
{
char* bf = getenv("BRO_PROFILER_FILE");
char* bf = getenv("ZEEK_PROFILER_FILE");
if ( ! bf )
return false;
{
bf = getenv("BRO_PROFILER_FILE");
if ( ! bf )
return false;
}

FILE* f = fopen(bf, "r");
if ( ! f )
Expand Down Expand Up @@ -47,14 +51,19 @@ bool Brofiler::ReadStats()

bool Brofiler::WriteStats()
{
char* bf = getenv("BRO_PROFILER_FILE");
if ( ! bf ) return false;
char* bf = getenv("ZEEK_PROFILER_FILE");
if ( ! bf )
{
bf = getenv("BRO_PROFILER_FILE");
if ( ! bf )
return false;
}

SafeDirname dirname{bf};

if ( ! ensure_intermediate_dirs(dirname.result.data()) )
{
reporter->Error("Failed to open BRO_PROFILER_FILE destination '%s' for writing", bf);
reporter->Error("Failed to open ZEEK_PROFILER_FILE destination '%s' for writing", bf);
return false;
}

Expand All @@ -69,7 +78,7 @@ bool Brofiler::WriteStats()

if ( fd == -1 )
{
reporter->Error("Failed to generate unique file name from BRO_PROFILER_FILE: %s", bf);
reporter->Error("Failed to generate unique file name from ZEEK_PROFILER_FILE: %s", bf);
return false;
}
f = fdopen(fd, "w");
Expand All @@ -81,7 +90,7 @@ bool Brofiler::WriteStats()

if ( ! f )
{
reporter->Error("Failed to open BRO_PROFILER_FILE destination '%s' for writing", bf);
reporter->Error("Failed to open ZEEK_PROFILER_FILE destination '%s' for writing", bf);
return false;
}

Expand Down
4 changes: 2 additions & 2 deletions src/Brofiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Brofiler {

/**
* Imports Bro script Stmt usage information from file pointed to by
* environment variable BRO_PROFILER_FILE.
* environment variable ZEEK_PROFILER_FILE.
*
* @return: true if usage info was read, otherwise false.
*/
Expand All @@ -26,7 +26,7 @@ class Brofiler {
/**
* Combines usage stats from current run with any read from ReadStats(),
* then writes information to file pointed to by environment variable
* BRO_PROFILER_FILE. If the value of that env. variable ends with
* ZEEK_PROFILER_FILE. If the value of that env. variable ends with
* ".XXXXXX" (exactly 6 X's), then it is first passed through mkstemp
* to get a unique file.
*
Expand Down
4 changes: 2 additions & 2 deletions src/bro.bif
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ static bool prepare_environment(TableVal* tbl, bool set)

char* tmp = copy_string(key->AsString()->CheckString());
to_upper(tmp);
const char* var = fmt("BRO_ARG_%s", tmp);
const char* var = fmt("ZEEK_ARG_%s", tmp);
delete [] tmp;

if ( set )
Expand Down Expand Up @@ -468,7 +468,7 @@ function system%(str: string%): int
##
## env: A :zeek:type:`table` with the environment variables in the form
## of key-value pairs. Each specified environment variable name
## will be automatically prepended with ``BRO_ARG_``.
## will be automatically prepended with ``ZEEK_ARG_``.
##
## Returns: The return value from the OS ``system`` function.
##
Expand Down
8 changes: 6 additions & 2 deletions src/broker/Manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,9 @@ void Manager::InitPostScript()

BrokerConfig config{std::move(options)};

auto max_threads_env = getenv("BRO_BROKER_MAX_THREADS");
auto max_threads_env = getenv("ZEEK_BROKER_MAX_THREADS");
if ( ! max_threads_env )
max_threads_env = getenv("BRO_BROKER_MAX_THREADS");

if ( max_threads_env )
config.set("scheduler.max-threads", atoi(max_threads_env));
Expand Down Expand Up @@ -303,7 +305,9 @@ 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("BRO_DEFAULT_CONNECT_RETRY");
auto e = getenv("ZEEK_DEFAULT_CONNECT_RETRY");
if ( ! e )
e = getenv("BRO_DEFAULT_CONNECT_RETRY");

if ( e )
retry = atoi(e);
Expand Down
2 changes: 1 addition & 1 deletion src/broker/Manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ class Manager : public iosource::IOSource {
* @param addr an address to connect to, e.g. "localhost" or "127.0.0.1".
* @param port the TCP port on which the remote side is listening.
* @param retry If non-zero, the time after which to retry if
* connection cannot be established, or breaks. BRO_DEFAULT_CONNECT_RETRY
* connection cannot be established, or breaks. ZEEK_DEFAULT_CONNECT_RETRY
* environment variable overrides this value.
*/
void Peer(const std::string& addr, uint16_t port, double retry = 10.0);
Expand Down
8 changes: 6 additions & 2 deletions src/logging/writers/ascii/Ascii.cc
Original file line number Diff line number Diff line change
Expand Up @@ -444,9 +444,13 @@ bool Ascii::DoHeartbeat(double network_time, double current_time)

string Ascii::LogExt()
{
const char* ext = getenv("BRO_LOG_SUFFIX");
const char* ext = getenv("ZEEK_LOG_SUFFIX");
if ( ! ext )
ext = "log";
{
ext = getenv("BRO_LOG_SUFFIX");
if ( ! ext )
ext = "log";
}

return ext;
}
Expand Down
Loading

0 comments on commit 1a74516

Please sign in to comment.