mirror of
https://github.com/zeek/zeek.git
synced 2025-10-05 08:08:19 +00:00
Reformat the world
This commit is contained in:
parent
194cb24547
commit
b2f171ec69
714 changed files with 35149 additions and 35203 deletions
|
@ -1,84 +1,81 @@
|
|||
// See the file "COPYING" in the main distribution directory for copyright.
|
||||
|
||||
#include "zeek/zeek-config.h"
|
||||
#include "zeek/zeek-setup.h"
|
||||
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/ssl.h>
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <signal.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
#include <list>
|
||||
#include <optional>
|
||||
|
||||
#include <openssl/ssl.h>
|
||||
#include <openssl/err.h>
|
||||
|
||||
#include "zeek/3rdparty/sqlite3.h"
|
||||
#include "zeek/zeek-config.h"
|
||||
|
||||
#define DOCTEST_CONFIG_IMPLEMENT
|
||||
#include "zeek/3rdparty/doctest.h"
|
||||
|
||||
#include "zeek/Options.h"
|
||||
#include "zeek/input.h"
|
||||
#include "zeek/DNS_Mgr.h"
|
||||
#include "zeek/Frame.h"
|
||||
#include "zeek/Scope.h"
|
||||
#include "zeek/Event.h"
|
||||
#include "zeek/File.h"
|
||||
#include "zeek/Reporter.h"
|
||||
#include "zeek/RunState.h"
|
||||
#include "zeek/NetVar.h"
|
||||
#include "zeek/Var.h"
|
||||
#include "zeek/Timer.h"
|
||||
#include "zeek/Stmt.h"
|
||||
#include "zeek/Desc.h"
|
||||
#include "zeek/Debug.h"
|
||||
#include "zeek/DFA.h"
|
||||
#include "zeek/RuleMatcher.h"
|
||||
#include "zeek/Anon.h"
|
||||
#include "zeek/DFA.h"
|
||||
#include "zeek/DNS_Mgr.h"
|
||||
#include "zeek/Debug.h"
|
||||
#include "zeek/Desc.h"
|
||||
#include "zeek/Event.h"
|
||||
#include "zeek/EventRegistry.h"
|
||||
#include "zeek/Stats.h"
|
||||
#include "zeek/File.h"
|
||||
#include "zeek/Frag.h"
|
||||
#include "zeek/Frame.h"
|
||||
#include "zeek/Func.h"
|
||||
#include "zeek/Hash.h"
|
||||
#include "zeek/NetVar.h"
|
||||
#include "zeek/Options.h"
|
||||
#include "zeek/Reporter.h"
|
||||
#include "zeek/RuleMatcher.h"
|
||||
#include "zeek/RunState.h"
|
||||
#include "zeek/ScannedFile.h"
|
||||
#include "zeek/Scope.h"
|
||||
#include "zeek/ScriptCoverageManager.h"
|
||||
#include "zeek/Stats.h"
|
||||
#include "zeek/Stmt.h"
|
||||
#include "zeek/Timer.h"
|
||||
#include "zeek/Traverse.h"
|
||||
#include "zeek/Trigger.h"
|
||||
#include "zeek/Hash.h"
|
||||
#include "zeek/Func.h"
|
||||
#include "zeek/ScannedFile.h"
|
||||
#include "zeek/Frag.h"
|
||||
|
||||
#include "zeek/script_opt/ScriptOpt.h"
|
||||
|
||||
#include "zeek/supervisor/Supervisor.h"
|
||||
#include "zeek/threading/Manager.h"
|
||||
#include "zeek/input/Manager.h"
|
||||
#include "zeek/logging/Manager.h"
|
||||
#include "zeek/input/readers/raw/Raw.h"
|
||||
#include "zeek/Var.h"
|
||||
#include "zeek/analyzer/Manager.h"
|
||||
#include "zeek/analyzer/Tag.h"
|
||||
#include "zeek/binpac_zeek.h"
|
||||
#include "zeek/broker/Manager.h"
|
||||
#include "zeek/file_analysis/Manager.h"
|
||||
#include "zeek/input.h"
|
||||
#include "zeek/input/Manager.h"
|
||||
#include "zeek/input/readers/raw/Raw.h"
|
||||
#include "zeek/iosource/Manager.h"
|
||||
#include "zeek/logging/Manager.h"
|
||||
#include "zeek/module_util.h"
|
||||
#include "zeek/packet_analysis/Manager.h"
|
||||
#include "zeek/plugin/Manager.h"
|
||||
#include "zeek/file_analysis/Manager.h"
|
||||
#include "zeek/zeekygen/Manager.h"
|
||||
#include "zeek/iosource/Manager.h"
|
||||
#include "zeek/broker/Manager.h"
|
||||
#include "zeek/telemetry/Manager.h"
|
||||
#include "zeek/script_opt/ScriptOpt.h"
|
||||
#include "zeek/session/Manager.h"
|
||||
#include "zeek/supervisor/Supervisor.h"
|
||||
#include "zeek/telemetry/Manager.h"
|
||||
#include "zeek/threading/Manager.h"
|
||||
#include "zeek/zeekygen/Manager.h"
|
||||
|
||||
#include "zeek/binpac_zeek.h"
|
||||
#include "zeek/module_util.h"
|
||||
|
||||
extern "C" {
|
||||
extern "C"
|
||||
{
|
||||
#include "zeek/setsignal.h"
|
||||
};
|
||||
};
|
||||
|
||||
zeek::detail::ScriptCoverageManager zeek::detail::script_coverage_mgr;
|
||||
|
||||
#ifndef HAVE_STRSEP
|
||||
extern "C" {
|
||||
char* strsep(char**, const char*);
|
||||
};
|
||||
extern "C"
|
||||
{
|
||||
char* strsep(char**, const char*);
|
||||
};
|
||||
#endif
|
||||
|
||||
#ifdef USE_PERFTOOLS_DEBUG
|
||||
|
@ -150,7 +147,8 @@ zeek::OpaqueTypePtr dbl_histogram_metric_family_type;
|
|||
int zeek::detail::zeek_argc;
|
||||
char** zeek::detail::zeek_argv;
|
||||
|
||||
namespace zeek {
|
||||
namespace zeek
|
||||
{
|
||||
|
||||
const char* zeek_version()
|
||||
{
|
||||
|
@ -170,7 +168,8 @@ const char* zeek_version()
|
|||
#endif
|
||||
}
|
||||
|
||||
namespace detail {
|
||||
namespace detail
|
||||
{
|
||||
|
||||
static std::vector<const char*> to_cargs(const std::vector<std::string>& args)
|
||||
{
|
||||
|
@ -200,10 +199,11 @@ static bool show_plugins(int level)
|
|||
|
||||
int count = 0;
|
||||
|
||||
for ( plugin::Manager::plugin_list::const_iterator i = plugins.begin(); i != plugins.end(); i++ )
|
||||
for ( plugin::Manager::plugin_list::const_iterator i = plugins.begin(); i != plugins.end();
|
||||
i++ )
|
||||
{
|
||||
if ( requested_plugins.size()
|
||||
&& requested_plugins.find((*i)->Name()) == requested_plugins.end() )
|
||||
if ( requested_plugins.size() &&
|
||||
requested_plugins.find((*i)->Name()) == requested_plugins.end() )
|
||||
continue;
|
||||
|
||||
(*i)->Describe(&d);
|
||||
|
@ -222,7 +222,8 @@ static bool show_plugins(int level)
|
|||
{
|
||||
printf("\nInactive dynamic plugins:\n");
|
||||
|
||||
for ( plugin::Manager::inactive_plugin_list::const_iterator i = inactives.begin(); i != inactives.end(); i++ )
|
||||
for ( plugin::Manager::inactive_plugin_list::const_iterator i = inactives.begin();
|
||||
i != inactives.end(); i++ )
|
||||
{
|
||||
string name = (*i).first;
|
||||
string path = (*i).second;
|
||||
|
@ -238,15 +239,13 @@ static void done_with_network()
|
|||
util::detail::set_processing_status("TERMINATING", "done_with_network");
|
||||
|
||||
// Cancel any pending alarms (watchdog, in particular).
|
||||
(void) alarm(0);
|
||||
(void)alarm(0);
|
||||
|
||||
if ( net_done )
|
||||
{
|
||||
event_mgr.Drain();
|
||||
// Don't propagate this event to remote clients.
|
||||
event_mgr.Dispatch(
|
||||
new Event(net_done, {make_intrusive<TimeVal>(timer_mgr->Time())}),
|
||||
true);
|
||||
event_mgr.Dispatch(new Event(net_done, {make_intrusive<TimeVal>(timer_mgr->Time())}), true);
|
||||
}
|
||||
|
||||
if ( profiling_logger )
|
||||
|
@ -380,7 +379,7 @@ static std::vector<std::string> get_script_signature_files()
|
|||
if ( *s )
|
||||
rval.emplace_back(s);
|
||||
|
||||
delete [] script_signature_files;
|
||||
delete[] script_signature_files;
|
||||
return rval;
|
||||
}
|
||||
|
||||
|
@ -398,7 +397,7 @@ SetupResult setup(int argc, char** argv, Options* zopts)
|
|||
}
|
||||
|
||||
zeek_argc = argc;
|
||||
zeek_argv = new char* [argc];
|
||||
zeek_argv = new char*[argc];
|
||||
|
||||
for ( int i = 0; i < argc; i++ )
|
||||
zeek_argv[i] = util::copy_string(argv[i]);
|
||||
|
@ -505,9 +504,10 @@ SetupResult setup(int argc, char** argv, Options* zopts)
|
|||
if ( options.random_seed_input_file )
|
||||
seed_load_file = options.random_seed_input_file->data();
|
||||
|
||||
util::detail::init_random_seed((seed_load_file && *seed_load_file ? seed_load_file : nullptr),
|
||||
options.random_seed_output_file ? options.random_seed_output_file->data() : nullptr,
|
||||
options.deterministic_mode);
|
||||
util::detail::init_random_seed(
|
||||
(seed_load_file && *seed_load_file ? seed_load_file : nullptr),
|
||||
options.random_seed_output_file ? options.random_seed_output_file->data() : nullptr,
|
||||
options.deterministic_mode);
|
||||
// DEBUG_MSG("HMAC key: %s\n", md5_digest_print(shared_hmac_md5_key));
|
||||
init_hash_function();
|
||||
|
||||
|
@ -549,10 +549,8 @@ SetupResult setup(int argc, char** argv, Options* zopts)
|
|||
plugin_mgr->SearchDynamicPlugins(util::zeek_plugin_path());
|
||||
|
||||
if ( options.plugins_to_load.empty() && options.scripts_to_load.empty() &&
|
||||
options.script_options_to_set.empty() &&
|
||||
! options.pcap_file && ! options.interface &&
|
||||
! options.identifier_to_print &&
|
||||
! command_line_policy && ! options.print_plugins &&
|
||||
options.script_options_to_set.empty() && ! options.pcap_file && ! options.interface &&
|
||||
! options.identifier_to_print && ! command_line_policy && ! options.print_plugins &&
|
||||
! options.supervisor_mode && ! Supervisor::ThisNode() )
|
||||
add_input_file("-");
|
||||
|
||||
|
@ -638,300 +636,297 @@ SetupResult setup(int argc, char** argv, Options* zopts)
|
|||
// we suppress some messages here.
|
||||
|
||||
#ifdef USE_PERFTOOLS_DEBUG
|
||||
{
|
||||
HeapLeakChecker::Disabler disabler;
|
||||
{
|
||||
HeapLeakChecker::Disabler disabler;
|
||||
#endif
|
||||
|
||||
auto ipbid = install_ID("__init_primary_bifs", GLOBAL_MODULE_NAME,
|
||||
true, true);
|
||||
auto ipbft = make_intrusive<FuncType>(make_intrusive<RecordType>(nullptr),
|
||||
base_type(TYPE_BOOL),
|
||||
FUNC_FLAVOR_FUNCTION);
|
||||
ipbid->SetType(std::move(ipbft));
|
||||
auto init_bifs = [](Frame* frame, const Args* args) -> BifReturnVal
|
||||
auto ipbid = install_ID("__init_primary_bifs", GLOBAL_MODULE_NAME, true, true);
|
||||
auto ipbft = make_intrusive<FuncType>(make_intrusive<RecordType>(nullptr),
|
||||
base_type(TYPE_BOOL), FUNC_FLAVOR_FUNCTION);
|
||||
ipbid->SetType(std::move(ipbft));
|
||||
auto init_bifs = [](Frame* frame, const Args* args) -> BifReturnVal
|
||||
{
|
||||
init_primary_bifs();
|
||||
return val_mgr->True();
|
||||
init_primary_bifs();
|
||||
return val_mgr->True();
|
||||
};
|
||||
auto ipbb = make_intrusive<BuiltinFunc>(init_bifs, ipbid->Name(), false);
|
||||
auto ipbb = make_intrusive<BuiltinFunc>(init_bifs, ipbid->Name(), false);
|
||||
|
||||
run_state::is_parsing = true;
|
||||
yyparse();
|
||||
run_state::is_parsing = false;
|
||||
run_state::is_parsing = true;
|
||||
yyparse();
|
||||
run_state::is_parsing = false;
|
||||
|
||||
RecordVal::DoneParsing();
|
||||
TableVal::DoneParsing();
|
||||
RecordVal::DoneParsing();
|
||||
TableVal::DoneParsing();
|
||||
|
||||
init_general_global_var();
|
||||
init_net_var();
|
||||
run_bif_initializers();
|
||||
init_general_global_var();
|
||||
init_net_var();
|
||||
run_bif_initializers();
|
||||
|
||||
// Assign the script_args for command line processing in Zeek scripts.
|
||||
if ( ! options.script_args.empty() )
|
||||
{
|
||||
auto script_args_val = id::find_val<VectorVal>("zeek_script_args");
|
||||
for ( const string& script_arg : options.script_args )
|
||||
// Assign the script_args for command line processing in Zeek scripts.
|
||||
if ( ! options.script_args.empty() )
|
||||
{
|
||||
script_args_val->Assign(script_args_val->Size(), make_intrusive<StringVal>(script_arg));
|
||||
auto script_args_val = id::find_val<VectorVal>("zeek_script_args");
|
||||
for ( const string& script_arg : options.script_args )
|
||||
{
|
||||
script_args_val->Assign(script_args_val->Size(),
|
||||
make_intrusive<StringVal>(script_arg));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Must come after plugin activation (and also after hash
|
||||
// initialization).
|
||||
binpac::FlowBuffer::Policy flowbuffer_policy;
|
||||
flowbuffer_policy.max_capacity = global_scope()->Find(
|
||||
"BinPAC::flowbuffer_capacity_max")->GetVal()->AsCount();
|
||||
flowbuffer_policy.min_capacity = global_scope()->Find(
|
||||
"BinPAC::flowbuffer_capacity_min")->GetVal()->AsCount();
|
||||
flowbuffer_policy.contract_threshold = global_scope()->Find(
|
||||
"BinPAC::flowbuffer_contract_threshold")->GetVal()->AsCount();
|
||||
binpac::init(&flowbuffer_policy);
|
||||
// Must come after plugin activation (and also after hash
|
||||
// initialization).
|
||||
binpac::FlowBuffer::Policy flowbuffer_policy;
|
||||
flowbuffer_policy.max_capacity =
|
||||
global_scope()->Find("BinPAC::flowbuffer_capacity_max")->GetVal()->AsCount();
|
||||
flowbuffer_policy.min_capacity =
|
||||
global_scope()->Find("BinPAC::flowbuffer_capacity_min")->GetVal()->AsCount();
|
||||
flowbuffer_policy.contract_threshold =
|
||||
global_scope()->Find("BinPAC::flowbuffer_contract_threshold")->GetVal()->AsCount();
|
||||
binpac::init(&flowbuffer_policy);
|
||||
|
||||
plugin_mgr->InitBifs();
|
||||
plugin_mgr->InitBifs();
|
||||
|
||||
if ( reporter->Errors() > 0 )
|
||||
exit(1);
|
||||
if ( reporter->Errors() > 0 )
|
||||
exit(1);
|
||||
|
||||
iosource_mgr->InitPostScript();
|
||||
log_mgr->InitPostScript();
|
||||
plugin_mgr->InitPostScript();
|
||||
zeekygen_mgr->InitPostScript();
|
||||
broker_mgr->InitPostScript();
|
||||
telemetry_mgr->InitPostScript();
|
||||
timer_mgr->InitPostScript();
|
||||
event_mgr.InitPostScript();
|
||||
iosource_mgr->InitPostScript();
|
||||
log_mgr->InitPostScript();
|
||||
plugin_mgr->InitPostScript();
|
||||
zeekygen_mgr->InitPostScript();
|
||||
broker_mgr->InitPostScript();
|
||||
telemetry_mgr->InitPostScript();
|
||||
timer_mgr->InitPostScript();
|
||||
event_mgr.InitPostScript();
|
||||
|
||||
if ( supervisor_mgr )
|
||||
supervisor_mgr->InitPostScript();
|
||||
if ( supervisor_mgr )
|
||||
supervisor_mgr->InitPostScript();
|
||||
|
||||
if ( options.print_plugins )
|
||||
{
|
||||
bool success = show_plugins(options.print_plugins);
|
||||
exit(success ? 0 : 1);
|
||||
}
|
||||
if ( options.print_plugins )
|
||||
{
|
||||
bool success = show_plugins(options.print_plugins);
|
||||
exit(success ? 0 : 1);
|
||||
}
|
||||
|
||||
packet_mgr->InitPostScript();
|
||||
analyzer_mgr->InitPostScript();
|
||||
file_mgr->InitPostScript();
|
||||
dns_mgr->InitPostScript();
|
||||
packet_mgr->InitPostScript();
|
||||
analyzer_mgr->InitPostScript();
|
||||
file_mgr->InitPostScript();
|
||||
dns_mgr->InitPostScript();
|
||||
|
||||
#ifdef USE_PERFTOOLS_DEBUG
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if ( reporter->Errors() > 0 )
|
||||
{
|
||||
delete dns_mgr;
|
||||
exit(1);
|
||||
}
|
||||
|
||||
reporter->InitOptions();
|
||||
KeyedHash::InitOptions();
|
||||
zeekygen_mgr->GenerateDocs();
|
||||
|
||||
if ( options.pcap_filter )
|
||||
{
|
||||
const auto& id = global_scope()->Find("cmd_line_bpf_filter");
|
||||
|
||||
if ( ! id )
|
||||
reporter->InternalError("global cmd_line_bpf_filter not defined");
|
||||
|
||||
id->SetVal(make_intrusive<StringVal>(*options.pcap_filter));
|
||||
}
|
||||
|
||||
auto all_signature_files = options.signature_files;
|
||||
|
||||
// Append signature files defined in "signature_files" script option
|
||||
for ( auto&& sf : get_script_signature_files() )
|
||||
all_signature_files.emplace_back(std::move(sf));
|
||||
|
||||
// Append signature files defined in @load-sigs
|
||||
for ( const auto& sf : zeek::detail::sig_files )
|
||||
all_signature_files.emplace_back(sf);
|
||||
|
||||
if ( ! all_signature_files.empty() )
|
||||
{
|
||||
rule_matcher = new RuleMatcher(options.signature_re_level);
|
||||
if ( ! rule_matcher->ReadFiles(all_signature_files) )
|
||||
if ( reporter->Errors() > 0 )
|
||||
{
|
||||
delete dns_mgr;
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if ( options.print_signature_debug_info )
|
||||
rule_matcher->PrintDebug();
|
||||
reporter->InitOptions();
|
||||
KeyedHash::InitOptions();
|
||||
zeekygen_mgr->GenerateDocs();
|
||||
|
||||
file_mgr->InitMagic();
|
||||
}
|
||||
|
||||
if ( g_policy_debug )
|
||||
// ### Add support for debug command file.
|
||||
dbg_init_debugger(nullptr);
|
||||
|
||||
if ( ! options.pcap_file && ! options.interface )
|
||||
{
|
||||
const auto& interfaces_val = id::find_val("interfaces");
|
||||
if ( interfaces_val )
|
||||
if ( options.pcap_filter )
|
||||
{
|
||||
char* interfaces_str =
|
||||
interfaces_val->AsString()->Render();
|
||||
const auto& id = global_scope()->Find("cmd_line_bpf_filter");
|
||||
|
||||
if ( interfaces_str[0] != '\0' )
|
||||
options.interface = interfaces_str;
|
||||
if ( ! id )
|
||||
reporter->InternalError("global cmd_line_bpf_filter not defined");
|
||||
|
||||
delete [] interfaces_str;
|
||||
id->SetVal(make_intrusive<StringVal>(*options.pcap_filter));
|
||||
}
|
||||
}
|
||||
|
||||
if ( options.parse_only )
|
||||
{
|
||||
if ( analysis_options.usage_issues > 0 )
|
||||
analyze_scripts();
|
||||
auto all_signature_files = options.signature_files;
|
||||
|
||||
exit(reporter->Errors() != 0);
|
||||
}
|
||||
// Append signature files defined in "signature_files" script option
|
||||
for ( auto&& sf : get_script_signature_files() )
|
||||
all_signature_files.emplace_back(std::move(sf));
|
||||
|
||||
auto init_stmts = stmts ? analyze_global_stmts(stmts) : nullptr;
|
||||
// Append signature files defined in @load-sigs
|
||||
for ( const auto& sf : zeek::detail::sig_files )
|
||||
all_signature_files.emplace_back(sf);
|
||||
|
||||
analyze_scripts();
|
||||
if ( ! all_signature_files.empty() )
|
||||
{
|
||||
rule_matcher = new RuleMatcher(options.signature_re_level);
|
||||
if ( ! rule_matcher->ReadFiles(all_signature_files) )
|
||||
{
|
||||
delete dns_mgr;
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if ( analysis_options.report_recursive )
|
||||
// This option is report-and-exit.
|
||||
exit(0);
|
||||
if ( options.print_signature_debug_info )
|
||||
rule_matcher->PrintDebug();
|
||||
|
||||
if ( dns_type != DNS_PRIME )
|
||||
run_state::detail::init_run(options.interface, options.pcap_file, options.pcap_output_file, options.use_watchdog);
|
||||
file_mgr->InitMagic();
|
||||
}
|
||||
|
||||
if ( ! g_policy_debug )
|
||||
{
|
||||
(void) setsignal(SIGTERM, sig_handler);
|
||||
(void) setsignal(SIGINT, sig_handler);
|
||||
(void) setsignal(SIGPIPE, SIG_IGN);
|
||||
}
|
||||
if ( g_policy_debug )
|
||||
// ### Add support for debug command file.
|
||||
dbg_init_debugger(nullptr);
|
||||
|
||||
// Cooperate with nohup(1).
|
||||
if ( (oldhandler = setsignal(SIGHUP, sig_handler)) != SIG_DFL )
|
||||
(void) setsignal(SIGHUP, oldhandler);
|
||||
if ( ! options.pcap_file && ! options.interface )
|
||||
{
|
||||
const auto& interfaces_val = id::find_val("interfaces");
|
||||
if ( interfaces_val )
|
||||
{
|
||||
char* interfaces_str = interfaces_val->AsString()->Render();
|
||||
|
||||
if ( dns_type == DNS_PRIME )
|
||||
{
|
||||
dns_mgr->Verify();
|
||||
dns_mgr->Resolve();
|
||||
if ( interfaces_str[0] != '\0' )
|
||||
options.interface = interfaces_str;
|
||||
|
||||
if ( ! dns_mgr->Save() )
|
||||
reporter->FatalError("can't update DNS cache");
|
||||
delete[] interfaces_str;
|
||||
}
|
||||
}
|
||||
|
||||
if ( options.parse_only )
|
||||
{
|
||||
if ( analysis_options.usage_issues > 0 )
|
||||
analyze_scripts();
|
||||
|
||||
exit(reporter->Errors() != 0);
|
||||
}
|
||||
|
||||
auto init_stmts = stmts ? analyze_global_stmts(stmts) : nullptr;
|
||||
|
||||
analyze_scripts();
|
||||
|
||||
if ( analysis_options.report_recursive )
|
||||
// This option is report-and-exit.
|
||||
exit(0);
|
||||
|
||||
if ( dns_type != DNS_PRIME )
|
||||
run_state::detail::init_run(options.interface, options.pcap_file,
|
||||
options.pcap_output_file, options.use_watchdog);
|
||||
|
||||
if ( ! g_policy_debug )
|
||||
{
|
||||
(void)setsignal(SIGTERM, sig_handler);
|
||||
(void)setsignal(SIGINT, sig_handler);
|
||||
(void)setsignal(SIGPIPE, SIG_IGN);
|
||||
}
|
||||
|
||||
// Cooperate with nohup(1).
|
||||
if ( (oldhandler = setsignal(SIGHUP, sig_handler)) != SIG_DFL )
|
||||
(void)setsignal(SIGHUP, oldhandler);
|
||||
|
||||
if ( dns_type == DNS_PRIME )
|
||||
{
|
||||
dns_mgr->Verify();
|
||||
dns_mgr->Resolve();
|
||||
|
||||
if ( ! dns_mgr->Save() )
|
||||
reporter->FatalError("can't update DNS cache");
|
||||
|
||||
event_mgr.Drain();
|
||||
delete dns_mgr;
|
||||
exit(0);
|
||||
}
|
||||
|
||||
// Print the ID.
|
||||
if ( options.identifier_to_print )
|
||||
{
|
||||
const auto& id = global_scope()->Find(*options.identifier_to_print);
|
||||
if ( ! id )
|
||||
reporter->FatalError("No such ID: %s\n", options.identifier_to_print->data());
|
||||
|
||||
ODesc desc;
|
||||
desc.SetQuotes(true);
|
||||
desc.SetIncludeStats(true);
|
||||
id->DescribeExtended(&desc);
|
||||
|
||||
fprintf(stdout, "%s\n", desc.Description());
|
||||
exit(0);
|
||||
}
|
||||
|
||||
if ( profiling_interval > 0 )
|
||||
{
|
||||
const auto& profiling_file = id::find_val("profiling_file");
|
||||
profiling_logger = new ProfileLogger(profiling_file->AsFile(), profiling_interval);
|
||||
|
||||
if ( segment_profiling )
|
||||
segment_logger = profiling_logger;
|
||||
}
|
||||
|
||||
if ( ! run_state::reading_live && ! run_state::reading_traces )
|
||||
// Set up network_time to track real-time, since
|
||||
// we don't have any other source for it.
|
||||
run_state::detail::update_network_time(util::current_time());
|
||||
|
||||
if ( CPP_activation_hook )
|
||||
(*CPP_activation_hook)();
|
||||
|
||||
if ( zeek_init )
|
||||
event_mgr.Enqueue(zeek_init, Args{});
|
||||
|
||||
EventRegistry::string_list dead_handlers = event_registry->UnusedHandlers();
|
||||
|
||||
if ( ! dead_handlers.empty() && check_for_unused_event_handlers )
|
||||
{
|
||||
for ( const string& handler : dead_handlers )
|
||||
reporter->Warning("event handler never invoked: %s", handler.c_str());
|
||||
}
|
||||
|
||||
// Enable LeakSanitizer before zeek_init() and even before executing
|
||||
// top-level statements. Even though it's not bad if a leak happens only
|
||||
// once at initialization, we have to assume that script-layer code causing
|
||||
// such a leak can be placed in any arbitrary event handler and potentially
|
||||
// cause more severe problems.
|
||||
ZEEK_LSAN_ENABLE();
|
||||
|
||||
if ( init_stmts )
|
||||
{
|
||||
StmtFlowType flow;
|
||||
Frame f(init_stmts->Scope()->Length(), nullptr, nullptr);
|
||||
g_frame_stack.push_back(&f);
|
||||
|
||||
try
|
||||
{
|
||||
init_stmts->Body()->Exec(&f, flow);
|
||||
}
|
||||
catch ( InterpreterException& )
|
||||
{
|
||||
reporter->FatalError("failed to execute script statements at top-level scope");
|
||||
}
|
||||
|
||||
g_frame_stack.pop_back();
|
||||
}
|
||||
|
||||
if ( options.ignore_checksums )
|
||||
ignore_checksums = 1;
|
||||
|
||||
if ( zeek_script_loaded )
|
||||
{
|
||||
// Queue events reporting loaded scripts.
|
||||
for ( const auto& file : zeek::detail::files_scanned )
|
||||
{
|
||||
if ( file.skipped )
|
||||
continue;
|
||||
|
||||
event_mgr.Enqueue(zeek_script_loaded, make_intrusive<StringVal>(file.name.c_str()),
|
||||
val_mgr->Count(file.include_level));
|
||||
}
|
||||
}
|
||||
|
||||
reporter->ReportViaEvents(true);
|
||||
|
||||
// Drain the event queue here to support the protocols framework configuring DPM
|
||||
event_mgr.Drain();
|
||||
delete dns_mgr;
|
||||
exit(0);
|
||||
}
|
||||
|
||||
// Print the ID.
|
||||
if ( options.identifier_to_print )
|
||||
{
|
||||
const auto& id = global_scope()->Find(*options.identifier_to_print);
|
||||
if ( ! id )
|
||||
reporter->FatalError("No such ID: %s\n", options.identifier_to_print->data());
|
||||
if ( reporter->Errors() > 0 && ! getenv("ZEEK_ALLOW_INIT_ERRORS") )
|
||||
reporter->FatalError("errors occurred while initializing");
|
||||
|
||||
ODesc desc;
|
||||
desc.SetQuotes(true);
|
||||
desc.SetIncludeStats(true);
|
||||
id->DescribeExtended(&desc);
|
||||
run_state::detail::zeek_init_done = true;
|
||||
packet_mgr->DumpDebug();
|
||||
analyzer_mgr->DumpDebug();
|
||||
|
||||
fprintf(stdout, "%s\n", desc.Description());
|
||||
exit(0);
|
||||
}
|
||||
run_state::detail::have_pending_timers =
|
||||
! run_state::reading_traces && timer_mgr->Size() > 0;
|
||||
|
||||
if ( profiling_interval > 0 )
|
||||
{
|
||||
const auto& profiling_file = id::find_val("profiling_file");
|
||||
profiling_logger = new ProfileLogger(profiling_file->AsFile(),
|
||||
profiling_interval);
|
||||
|
||||
if ( segment_profiling )
|
||||
segment_logger = profiling_logger;
|
||||
}
|
||||
|
||||
if ( ! run_state::reading_live && ! run_state::reading_traces )
|
||||
// Set up network_time to track real-time, since
|
||||
// we don't have any other source for it.
|
||||
run_state::detail::update_network_time(util::current_time());
|
||||
|
||||
if ( CPP_activation_hook )
|
||||
(*CPP_activation_hook)();
|
||||
|
||||
if ( zeek_init )
|
||||
event_mgr.Enqueue(zeek_init, Args{});
|
||||
|
||||
EventRegistry::string_list dead_handlers =
|
||||
event_registry->UnusedHandlers();
|
||||
|
||||
if ( ! dead_handlers.empty() && check_for_unused_event_handlers )
|
||||
{
|
||||
for ( const string& handler : dead_handlers )
|
||||
reporter->Warning("event handler never invoked: %s", handler.c_str());
|
||||
}
|
||||
|
||||
// Enable LeakSanitizer before zeek_init() and even before executing
|
||||
// top-level statements. Even though it's not bad if a leak happens only
|
||||
// once at initialization, we have to assume that script-layer code causing
|
||||
// such a leak can be placed in any arbitrary event handler and potentially
|
||||
// cause more severe problems.
|
||||
ZEEK_LSAN_ENABLE();
|
||||
|
||||
if ( init_stmts )
|
||||
{
|
||||
StmtFlowType flow;
|
||||
Frame f(init_stmts->Scope()->Length(), nullptr, nullptr);
|
||||
g_frame_stack.push_back(&f);
|
||||
|
||||
try
|
||||
{
|
||||
init_stmts->Body()->Exec(&f, flow);
|
||||
}
|
||||
catch ( InterpreterException& )
|
||||
{
|
||||
reporter->FatalError("failed to execute script statements at top-level scope");
|
||||
}
|
||||
|
||||
g_frame_stack.pop_back();
|
||||
}
|
||||
|
||||
if ( options.ignore_checksums )
|
||||
ignore_checksums = 1;
|
||||
|
||||
if ( zeek_script_loaded )
|
||||
{
|
||||
// Queue events reporting loaded scripts.
|
||||
for ( const auto& file : zeek::detail::files_scanned )
|
||||
{
|
||||
if ( file.skipped )
|
||||
continue;
|
||||
|
||||
event_mgr.Enqueue(zeek_script_loaded,
|
||||
make_intrusive<StringVal>(file.name.c_str()),
|
||||
val_mgr->Count(file.include_level));
|
||||
}
|
||||
}
|
||||
|
||||
reporter->ReportViaEvents(true);
|
||||
|
||||
// Drain the event queue here to support the protocols framework configuring DPM
|
||||
event_mgr.Drain();
|
||||
|
||||
if ( reporter->Errors() > 0 && ! getenv("ZEEK_ALLOW_INIT_ERRORS") )
|
||||
reporter->FatalError("errors occurred while initializing");
|
||||
|
||||
run_state::detail::zeek_init_done = true;
|
||||
packet_mgr->DumpDebug();
|
||||
analyzer_mgr->DumpDebug();
|
||||
|
||||
run_state::detail::have_pending_timers = ! run_state::reading_traces && timer_mgr->Size() > 0;
|
||||
|
||||
return {0, std::move(options)};
|
||||
return {0, std::move(options)};
|
||||
}
|
||||
|
||||
int cleanup(bool did_run_loop )
|
||||
int cleanup(bool did_run_loop)
|
||||
{
|
||||
if ( did_run_loop )
|
||||
done_with_network();
|
||||
|
@ -954,9 +949,10 @@ int cleanup(bool did_run_loop )
|
|||
return 0;
|
||||
}
|
||||
|
||||
} // namespace detail
|
||||
} // namespace detail
|
||||
|
||||
namespace run_state::detail {
|
||||
namespace run_state::detail
|
||||
{
|
||||
|
||||
void zeek_terminate_loop(const char* reason)
|
||||
{
|
||||
|
@ -978,5 +974,5 @@ void zeek_terminate_loop(const char* reason)
|
|||
exit(0);
|
||||
}
|
||||
|
||||
} // namespace run_state::detail
|
||||
} // namespace zeek
|
||||
} // namespace run_state::detail
|
||||
} // namespace zeek
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue