Fixing some issues from rebasing

This commit is contained in:
Tim Wojtulewicz 2022-10-24 15:20:54 -07:00 committed by Tomer Lev
parent 45fa4c0dc4
commit 77c555a3a8
21 changed files with 85 additions and 158 deletions

View file

@ -16,8 +16,6 @@ list(APPEND CMAKE_PREFIX_PATH ${CMAKE_BINARY_DIR})
# Windows: Configure runtime and dependencies
if ( MSVC )
cmake_policy(SET CMP0091 NEW)
# Remove existing runtime flags
set(CompilerFlags
CMAKE_CXX_FLAGS
@ -82,12 +80,6 @@ if ( MSVC )
find_package(ZLIB)
set(ZLIB_LIBRARY ${ZLIB_LIBRARIES})
# Set Kqueue to point at the right variable.
find_package(kqueue)
set(LIBKQUEUE_ROOT_DIR "${kqueue_INCLUDES}/../")
set(LIBKQUEUE_INCLUDE_DIRS ${kqueue_INCLUDES})
set(LIBKQUEUE_LIBRARIES ${kqueue_LIBS})
# Set CAres
find_package(c-ares)
set(HAVE_CARES true) # Disable FindCAres cmake file

View file

@ -527,10 +527,10 @@ add_library(zeek_objs OBJECT ${zeek_SRCS})
if (ZEEK_STANDALONE)
add_executable(zeek main.cc
$<TARGET_OBJECTS:zeek_objs>
${zeek_HEADERS}
${bro_SUBDIR_LIBS}
${bro_PLUGIN_LIBS}
$<TARGET_OBJECTS:zeek_objs>
${zeek_HEADERS}
${bro_SUBDIR_LIBS}
${bro_PLUGIN_LIBS}
)
target_link_libraries(zeek ${bro_PLUGIN_LINK_LIBS} ${zeekdeps} ${CMAKE_THREAD_LIBS_INIT} ${CMAKE_DL_LIBS})
@ -569,10 +569,6 @@ if (NOT ZEEK_STANDALONE OR CONAN_EXPORTED)
${CMAKE_BINARY_DIR}/zeek/src
${CMAKE_BINARY_DIR}/zeek/src/include)
if ( WIN32 )
target_include_directories(libzeek PUBLIC ${CMAKE_SOURCE_DIR}/zeek/src/windows/usr.include)
endif()
install(TARGETS libzeek LIBRARY DESTINATION lib)
endif()
@ -582,13 +578,6 @@ if ( NOT WIN32 )
InstallSymlink("${CMAKE_INSTALL_PREFIX}/bin/zeek-wrapper" "${CMAKE_INSTALL_PREFIX}/bin/bro")
endif ()
if ( NOT BINARY_PACKAGING_MODE )
# Older plugins may still use `bro` in unit tests.
execute_process(COMMAND "${CMAKE_COMMAND}" -E create_symlink
"${CMAKE_CURRENT_BINARY_DIR}/../zeek-wrapper.in"
"${CMAKE_CURRENT_BINARY_DIR}/bro")
endif ()
# Target to create all the autogenerated files.
add_custom_target(generate_outputs_stage1)
add_dependencies(generate_outputs_stage1 ${bro_ALL_GENERATED_OUTPUTS})
@ -635,7 +624,6 @@ install(CODE "
# Make sure to escape a bunch of special characters in the path before trying to use it as a
# regular expression below.
string(REGEX REPLACE "([][+.*()^])" "\\\\\\1" escaped_include_path "${CMAKE_CURRENT_SOURCE_DIR}/include/*")
string(REGEX REPLACE "([][+.*()^])" "\\\\\\1" escaped_windows_path "${CMAKE_CURRENT_SOURCE_DIR}/windows/*")
if (WIN32)
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/windows/usr.include/
@ -653,8 +641,6 @@ install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/
PATTERN "3rdparty/*" EXCLUDE
# The "zeek -> ." symlink isn't needed in the install-tree
REGEX "${escaped_include_path}$" EXCLUDE
# Windows headers are already installed if needed
REGEX "${escaped_windows_path}$" EXCLUDE
# FILES_MATCHING creates empty directories:
# https://gitlab.kitware.com/cmake/cmake/-/issues/17122
@ -671,7 +657,7 @@ install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/
PATTERN "*.bif.h"
PATTERN "CMakeFiles" EXCLUDE
# The "include/zeek -> .." symlink isn't needed in the install-tree
REGEX "${escaped_path}$" EXCLUDE
REGEX "${escaped_include_path}$" EXCLUDE
)
install(FILES

View file

@ -1,7 +1,5 @@
// See the file "COPYING" in the main distribution directory for copyright.
#include <unistd.h>
#include "zeek/DNS_Mgr.h"
#include "zeek/zeek-config.h"
@ -12,6 +10,7 @@
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <algorithm>
#include <cerrno>
#include <cstdlib>

View file

@ -13,12 +13,12 @@
#include "zeek/util.h"
#define DBG_LOG(stream, ...) \
if ( ::zeek::detail::debug_logger.IsEnabled(stream) ) \
#define DBG_LOG(stream, ...) \
if ( ::zeek::detail::debug_logger.IsEnabled(stream) ) \
::zeek::detail::debug_logger.Log(stream, __VA_ARGS__)
#define DBG_LOG_VERBOSE(stream, ...) \
if ( ::zeek::detail::debug_logger.IsVerbose() && \
::zeek::detail::debug_logger.IsEnabled(stream) ) \
#define DBG_LOG_VERBOSE(stream, ...) \
if ( ::zeek::detail::debug_logger.IsVerbose() && \
::zeek::detail::debug_logger.IsEnabled(stream) ) \
::zeek::detail::debug_logger.Log(stream, __VA_ARGS__)
#define DBG_PUSH(stream) ::zeek::detail::debug_logger.PushIndent(stream)
#define DBG_POP(stream) ::zeek::detail::debug_logger.PopIndent(stream)

View file

@ -19,8 +19,8 @@
#pragma once
#include <cstdlib>
#include <unistd.h>
#include <cstdlib>
#include "zeek/util.h" // for zeek_int_t

View file

@ -27,6 +27,12 @@ struct NewRef
{
};
/**
* This has to be forward decalred and known here in order for us to be able
* cast this in the `Unref` function.
*/
class OpaqueVal;
/**
* An intrusive, reference counting smart pointer implementation. Much like
* @c std::shared_ptr, this smart pointer models shared ownership of an object
@ -113,7 +119,14 @@ public:
~IntrusivePtr()
{
if ( ptr_ )
Unref((zeek::Obj*)ptr_);
{
// Specializing `OpaqueVal` as MSVC compiler does not detect it
// inheriting from `zeek::Obj` so we have to do that manually.
if constexpr ( std::is_same_v<T, OpaqueVal> )
Unref(reinterpret_cast<zeek::Obj*>(ptr_));
else
Unref(ptr_);
}
}
void swap(IntrusivePtr& other) noexcept { std::swap(ptr_, other.ptr_); }

View file

@ -1,23 +1,21 @@
// See the file "COPYING" in the main distribution directory for copyright.
#include <unistd.h>
#include "zeek/Options.h"
#include "zeek/zeek-config.h"
#include "zeek/ScriptProfile.h"
#include "zeek/script_opt/ScriptOpt.h"
#if defined(HAVE_GETOPT_H) && ! defined(_MSC_VER)
#include <getopt.h>
#endif
#include <unistd.h>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <sstream>
#include "zeek/3rdparty/bsd-getopt-long.h"
#include "zeek/ScriptProfile.h"
#include "zeek/logging/writers/ascii/Ascii.h"
#include "zeek/script_opt/ScriptOpt.h"

View file

@ -325,13 +325,6 @@ bool BinarySerializationFormat::Write(uint32_t v, const char* tag)
return WriteData(&v, sizeof(v));
}
#if defined(_MSC_VER)
bool BinarySerializationFormat::Write(u_long v, const char* tag)
{
return Write((uint32_t) v, tag);
}
#endif
bool BinarySerializationFormat::Write(int v, const char* tag)
{
DBG_LOG(DBG_SERIAL, "Write int %d [%s]", v, tag);

View file

@ -126,9 +126,6 @@ public:
bool Write(int v, const char* tag) override;
bool Write(uint16_t v, const char* tag) override;
bool Write(uint32_t v, const char* tag) override;
#if defined(_MSC_VER)
bool Write(u_long v, const char* tag);
#endif
bool Write(int64_t v, const char* tag) override;
bool Write(uint64_t v, const char* tag) override;
bool Write(char v, const char* tag) override;

View file

@ -3973,12 +3973,11 @@ const PortValPtr& ValManager::Port(uint32_t port_num, TransportProto port_type)
port_num = 0;
}
std::pair key{port_num, port_type};
if (ports.find(key) == ports.end())
{
if ( ports.find(key) == ports.end() )
{
ports[key] = IntrusivePtr{AdoptRef{}, new PortVal(PortVal::Mask(port_num, port_type))};
}
}
return ports[key];
}

View file

@ -402,7 +402,7 @@ extern analyzer::Manager* analyzer_mgr;
DBG_LOG(zeek::DBG_ANALYZER, "%s " txt, \
fmt_conn_id(conn->OrigAddr(), ntohs(conn->OrigPort()), conn->RespAddr(), \
ntohs(conn->RespPort())));
#define DBG_ANALYZER_ARGS(conn, fmt, ...) \
#define DBG_ANALYZER_ARGS(conn, fmt, ...) \
DBG_LOG(zeek::DBG_ANALYZER, "%s " fmt, \
fmt_conn_id(conn->OrigAddr(), ntohs(conn->OrigPort()), conn->RespAddr(), \
ntohs(conn->RespPort())), \

View file

@ -823,8 +823,7 @@ bool DNS_Interpreter::ParseRR_EDNS(detail::DNS_MsgInfo* msg, const u_char*& data
case TYPE_TCP_KA:
{
EDNS_TCP_KEEPALIVE edns_tcp_keepalive{.keepalive_timeout_omitted = true,
.keepalive_timeout = 0};
EDNS_TCP_KEEPALIVE edns_tcp_keepalive{true, 0};
if ( option_len == 0 || option_len == 2 )
{
// 0 bytes is permitted by RFC 7828, showing that the timeout value is
@ -1736,11 +1735,8 @@ bool DNS_Interpreter::ParseRR_SVCB(detail::DNS_MsgInfo* msg, const u_char*& data
name_end = target_name + 1;
}
SVCB_DATA svcb_data = {
.svc_priority = svc_priority,
.target_name = make_intrusive<StringVal>(
new String(target_name, name_end - target_name, true)),
};
SVCB_DATA svcb_data = {svc_priority, make_intrusive<StringVal>(new String(
target_name, name_end - target_name, true))};
// TODO: parse svcparams
// we consume all the remaining raw data (svc params) but do nothing.

View file

@ -5,5 +5,5 @@ add_subdirectory(binary)
add_subdirectory(config)
add_subdirectory(raw)
if (USE_SQLITE)
add_subdirectory(sqlite)
add_subdirectory(sqlite)
endif()

View file

@ -107,7 +107,7 @@ bool PcapDumper::Dump(const Packet* pkt)
return false;
// Reconstitute the pcap_pkthdr.
const struct pcap_pkthdr phdr = {.ts = pkt->ts, .caplen = pkt->cap_len, .len = pkt->len};
const struct pcap_pkthdr phdr = {pkt->ts, pkt->cap_len, pkt->len};
pcap_dump((u_char*)dumper, &phdr, pkt->data);
pcap_dump_flush(dumper);

View file

@ -1,9 +1,9 @@
// See the file "COPYING" in the main distribution directory for copyright.
#include <unistd.h>
#include "zeek/zeek-config.h"
#include <unistd.h>
#include "zeek/RunState.h"
#include "zeek/iosource/Manager.h"
#include "zeek/supervisor/Supervisor.h"

View file

@ -5,6 +5,7 @@
#include <dirent.h>
#if !defined(_MSC_VER)
#include <dlfcn.h>
#include <glob.h>
#endif
#include <sys/stat.h>
#include <cerrno>
@ -163,8 +164,7 @@ bool Manager::ActivateDynamicPluginInternal(const std::string& name, bool ok_if_
{
#if defined(_MSC_VER)
return false;
#endif
#else
errors->clear(); // caller should pass it in empty, but just to be sure
dynamic_plugin_map::iterator m = dynamic_plugins.find(util::strtolower(name));
@ -218,51 +218,30 @@ bool Manager::ActivateDynamicPluginInternal(const std::string& name, bool ok_if_
}
// Load shared libraries.
string dydir = dir + "/lib";
const char *dyext = "." HOST_ARCHITECTURE DYNAMIC_PLUGIN_SUFFIX;
DBG_LOG(DBG_PLUGINS, " Searching for shared libraries in %s with extension %s", dydir.c_str(), dyext);
string dypattern = dir + "/lib/*." + HOST_ARCHITECTURE + DYNAMIC_PLUGIN_SUFFIX;
DIR* d = opendir(dydir.c_str());
DBG_LOG(DBG_PLUGINS, " Searching for shared libraries %s", dypattern.c_str());
if ( ! d )
glob_t gl;
if ( glob(dypattern.c_str(), 0, 0, &gl) == 0 )
{
DBG_LOG(DBG_PLUGINS, "Cannot open directory %s", dydir.c_str());
return true;
}
struct dirent *dp;
while ( (dp = readdir(d)) )
{
if ( strlen(dp->d_name) >= strlen(dyext)
&& zeek::util::streq(dp->d_name + strlen(dp->d_name) - strlen(dyext), dyext) )
for ( size_t i = 0; i < gl.gl_pathc; i++ )
{
string path = dydir + "/" + dp->d_name;
const char* path = gl.gl_pathv[i];
current_plugin = nullptr;
current_dir = dydir.c_str();
current_sopath = path.c_str();
#if defined(_MSC_VER)
void* hdl = LoadLibraryA(path.c_str());
#else
void* hdl = dlopen(path.c_str(), RTLD_LAZY | RTLD_GLOBAL);
#endif
current_dir = nullptr;
current_sopath = nullptr;
current_plugin = nullptr;
current_dir = dir.c_str();
current_sopath = path;
void* hdl = dlopen(path, RTLD_NOW | RTLD_GLOBAL);
current_dir = nullptr;
current_sopath = nullptr;
if ( ! hdl )
{
const char* err = nullptr;
#if defined(_MSC_VER)
char buf[65535];
const int flags = FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS;
if ( FormatMessageA(flags, nullptr, GetLastError(), 0, buf, sizeof(buf), nullptr ) )
err = buf;
#else
err = dlerror();
#endif
errors->push_back(util::fmt("cannot load plugin library %s: %s", path.c_str(),
const char* err = dlerror();
errors->push_back(util::fmt("cannot load plugin library %s: %s", path,
err ? err : "<unknown error>"));
continue;
}
@ -270,7 +249,7 @@ bool Manager::ActivateDynamicPluginInternal(const std::string& name, bool ok_if_
if ( ! current_plugin )
{
errors->push_back(
util::fmt("load plugin library %s did not instantiate a plugin", path.c_str()));
util::fmt("load plugin library %s did not instantiate a plugin", path));
continue;
}
@ -282,10 +261,10 @@ bool Manager::ActivateDynamicPluginInternal(const std::string& name, bool ok_if_
plugins_by_path.insert(
std::make_pair(util::detail::normalize_path(dir), current_plugin));
// We execute the pre-script initialization here; this in
// fact could be *during* script initialization if we got
// triggered via @load-plugin.
current_plugin->InitPreScript();
// We execute the pre-script initialization here; this in
// fact could be *during* script initialization if we got
// triggered via @load-plugin.
current_plugin->InitPreScript();
// Make sure the name the plugin reports is consistent with
// what we expect from its magic file.
@ -297,21 +276,20 @@ bool Manager::ActivateDynamicPluginInternal(const std::string& name, bool ok_if_
}
current_plugin = nullptr;
DBG_LOG(DBG_PLUGINS, " Loaded %s", path.c_str());
DBG_LOG(DBG_PLUGINS, " Loaded %s", path);
}
globfree(&gl);
if ( ! errors->empty() )
return false;
}
closedir(d);
if ( current_plugin == nullptr )
else
{
DBG_LOG(DBG_PLUGINS, " No shared library found");
}
// Add the "scripts" and "bif" directories to ZEEKPATH.
std::string scripts = dir + "scripts";
@ -353,6 +331,7 @@ bool Manager::ActivateDynamicPluginInternal(const std::string& name, bool ok_if_
m->second.clear();
return true;
#endif
}
void Manager::ActivateDynamicPlugin(const std::string& name)
@ -373,7 +352,10 @@ void Manager::ActivateDynamicPlugins(bool all)
// Activate plugins that were specifically requested.
for ( const auto& x : requested_plugins )
plugins_to_activate.emplace(x, false);
{
if ( ! x.empty() )
plugins_to_activate.emplace(x, false);
}
// Activate plugins that our environment tells us to.
vector<string> p;

View file

@ -153,7 +153,11 @@ public:
// themselves trigger deprecation warnings for accessing the
// "scripts" field. It can go when we remove that deprecation.
NodeConfig() = default;
#ifndef _MSC_VER
// MSVC throws this error when specifing this constructor:
// error C2580: multiple versions of a defaulted special member functions are not allowed
NodeConfig(NodeConfig&) = default;
#endif
NodeConfig(const NodeConfig&) = default;
NodeConfig(NodeConfig&&) = default;
~NodeConfig() = default;

View file

@ -43,7 +43,6 @@
#include <string>
#include <vector>
#include <filesystem>
#include <iostream>
#include <random>
#include "zeek/3rdparty/ConvertUTF.h"
@ -259,16 +258,6 @@ const char* fmt_access_time(double t)
time_t time = (time_t)t;
struct tm ts;
if (!time)
{
// Use wall clock.
struct timeval tv = { 0 };
if (gettimeofday(&tv, 0) < 0)
reporter->InternalError("unable to gettimeofday");
else
time = tv.tv_sec;
}
if ( ! localtime_r(&time, &ts) )
{
reporter->InternalError("unable to get time");
@ -447,7 +436,6 @@ void init_random_seed(const char* read_file, const char* write_file, bool use_em
pos += sizeof(struct timeval) / sizeof(uint32_t);
// use urandom. For reasons see e.g. http://www.2uo.de/myths-about-urandom/
#ifndef _MSC_VER
#if defined(O_NONBLOCK)
int fd = open("/dev/urandom", O_RDONLY | O_NONBLOCK);
#elif defined(O_NDELAY)
@ -470,12 +458,6 @@ void init_random_seed(const char* read_file, const char* write_file, bool use_em
errno = 0;
}
#endif
// C++ random device implementation in MSVC is sufficient for this purpose.
thread_local std::mt19937 gen(std::random_device{}());
while ( pos < zeek::detail::KeyedHash::SEED_INIT_SIZE ) {
buf[pos++] = (uint32_t)gen();
}
#endif
if ( pos < zeek::detail::KeyedHash::SEED_INIT_SIZE )
reporter->FatalError("Could not read enough random data. Wanted %d, got %zu",
@ -1638,17 +1620,16 @@ const char* vfmt(const char* format, va_list al)
va_copy(alc, al);
int n = vsnprintf(buf, buf_len, format, al);
if ( (unsigned int)n >= buf_len )
if ( n < 0 && buf_len < 1024 * 1024 )
{ // Not enough room, grow the buffer.
buf_len = n + 32;
buf_len += 32;
buf = (char*)safe_realloc(buf, buf_len);
n = vsnprintf(buf, buf_len, format, alc);
if ( (unsigned int)n >= buf_len )
reporter->InternalError("confusion reformatting in fmt()");
n = vsnprintf(buf, buf_len, format, al);
}
if ( n < 0 )
reporter->InternalError("confusion reformatting in fmt()");
va_end(alc);
return buf;
}
@ -1792,7 +1773,7 @@ string zeek_prefixes()
for ( const auto& prefix : zeek::detail::zeek_script_prefixes )
{
if ( ! rval.empty() )
rval.append(zeek_path_list_separator);
rval.append(path_list_separator);
rval.append(prefix);
}
@ -2006,7 +1987,7 @@ static string find_file_in_path(const string& filename, const string& path,
string find_file(const string& filename, const string& path_set, const string& opt_ext)
{
vector<string> paths;
tokenize_string(path_set, zeek_path_list_separator, &paths);
tokenize_string(path_set, path_list_separator, &paths);
vector<string> ext;
if ( ! opt_ext.empty() )
@ -2026,7 +2007,7 @@ string find_file(const string& filename, const string& path_set, const string& o
string find_script_file(const string& filename, const string& path_set)
{
vector<string> paths;
tokenize_string(path_set, zeek_path_list_separator, &paths);
tokenize_string(path_set, path_list_separator, &paths);
vector<string> ext = {".zeek"};

View file

@ -40,10 +40,6 @@
#endif
#endif
#ifdef _MSC_VER
#include <pthread.h>
#endif
#ifdef DEBUG
#include <cassert>

View file

@ -52,7 +52,6 @@
#include "zeek/Traverse.h"
#include "zeek/Trigger.h"
#include "zeek/Var.h"
#include "zeek/analyzer/Manager.h"
#include "zeek/binpac_zeek.h"
#include "zeek/broker/Manager.h"
@ -67,7 +66,6 @@
#include "zeek/plugin/Manager.h"
#include "zeek/script_opt/ScriptOpt.h"
#include "zeek/session/Manager.h"
#include "zeek/script_opt/ScriptOpt.h"
#include "zeek/supervisor/Supervisor.h"
#include "zeek/telemetry/Manager.h"
#include "zeek/threading/Manager.h"
@ -210,6 +208,7 @@ char version[] = VERSION;
#else
extern char version[];
#endif
const char* zeek::detail::command_line_policy = nullptr;
vector<string> zeek::detail::params;
set<string> requested_plugins;
@ -245,9 +244,6 @@ char** zeek::detail::zeek_argv;
namespace zeek
{
// Define zeek version explicitly for MSVC
const char* zeek_version()
{
#ifdef DEBUG

View file

@ -2,9 +2,7 @@
#include "zeek/zeekygen/Target.h"
#ifndef _MSC_VER
#include <fts.h>
#endif
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
@ -492,8 +490,6 @@ vector<string> dir_contents_recursive(string dir)
scan_path[0] = dir_copy;
scan_path[1] = NULL;
// Zeekygen isn't supported in Windows, due to missing FTS library.
#ifndef _MSC_VER
FTS* fts = fts_open(scan_path, FTS_NOCHDIR, 0);
if ( ! fts )
@ -520,7 +516,6 @@ vector<string> dir_contents_recursive(string dir)
delete[] scan_path;
delete[] dir_copy;
#endif
return rval;
}