Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvements suggested in the review #148

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/actions/clang_format/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ runs:
shell: bash
run: |

# Print clanformat version used.
echo "Clang-format version: $(clang-format --version)"

# Don't apply changes, just check
arguments="--dry-run "

Expand Down
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,5 @@ __pycache__
### Python Virtualenv
venv

# Auto generated build files
src/**/build/*

# External dependencies
src/external/*
2 changes: 1 addition & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ configure_target(Agent)

if(BUILD_TESTS)
enable_testing()
endif()
endif()
65 changes: 3 additions & 62 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,42 +11,16 @@

uname_S := $(shell sh -c 'uname -s 2>/dev/null || echo not')
uname_P := $(shell sh -c 'uname -p 2>/dev/null || echo not')
uname_R := $(shell sh -c 'uname -r 2>/dev/null || echo not')
uname_V := $(shell sh -c 'uname -v 2>/dev/null || echo not')
uname_M := $(shell sh -c 'uname -m 2>/dev/null || echo not')

ifeq (${uname_S},Linux)
PRECOMPILED_OS:=linux
else
ifeq (${uname_S},AIX)
PRECOMPILED_OS:=aix
else
ifeq (${uname_S},SunOS)
PRECOMPILED_OS:=solaris
else
ifeq (${uname_S},Darwin)
PRECOMPILED_OS:=darwin
else
ifeq (${uname_S},FreeBSD)
PRECOMPILED_OS:=freebsd
else
ifeq (${uname_S},NetBSD)
PRECOMPILED_OS:=netbsd
else
ifeq (${uname_S},OpenBSD)
PRECOMPILED_OS:=openbsd
else
ifeq (${uname_S},HP-UX)
PRECOMPILED_OS:=hpux
else
# Unknow platform
endif # HPUX
endif # OpenBSD
endif # NetBSD
endif # FreeBSD
# Unknow platform
endif # Darwin
endif # SunOS
endif # AIX
endif # Linux

# ################################
Expand All @@ -61,62 +35,29 @@ DEPS_VERSION = 30
RESOURCES_URL_BASE := https://packages.wazuh.com/deps/
RESOURCES_URL := $(RESOURCES_URL_BASE)$(DEPS_VERSION)

ifneq (,$(filter ${uname_S},Linux Darwin HP-UX))
ifneq (,$(filter ${uname_S},Linux Darwin))
cpu_arch := ${uname_M}
ifneq (,$(filter ${cpu_arch},x86_64 amd64))
PRECOMPILED_ARCH := /amd64
else
ifneq (,$(filter ${cpu_arch},i386 i686))
PRECOMPILED_ARCH := /i386
else
ifneq (,$(filter ${cpu_arch},aarch64 arm64))
PRECOMPILED_ARCH := /aarch64
else
ifneq (,$(filter ${cpu_arch},armv8l armv7l arm32 armhf))
PRECOMPILED_ARCH := /arm32
else
ifeq (${cpu_arch},ppc64le)
PRECOMPILED_ARCH := /ppc64le
else
ifneq (,$(filter ${cpu_arch},ia64))
PRECOMPILED_ARCH := /ia64
else
PRECOMPILED_ARCH := /${uname_P}
endif
endif
endif
endif
endif
endif
else
ifneq (,$(filter ${uname_S},SunOS AIX))
cpu_arch := ${uname_P}
ifeq (${cpu_arch},powerpc)
PRECOMPILED_ARCH := /powerpc
else
ifneq (,$(filter ${cpu_arch},sparc sun4u))
PRECOMPILED_ARCH := /sparc
else
ifneq (,$(filter ${cpu_arch},i386 i86pc))
PRECOMPILED_ARCH := /i386
else
PRECOMPILED_ARCH := /${uname_M}
endif
endif
endif
else
cpu_arch := ${uname_M}
ifneq (,$(filter ${cpu_arch},unknown Unknown not))
cpu_arch := ${uname_P}
endif
PRECOMPILED_ARCH := /${cpu_arch}
endif
endif

PRECOMPILED_RES := $(PRECOMPILED_OS)$(PRECOMPILED_ARCH)

# Agent dependencies
EXTERNAL_RES := libdb procps pacman rpm
EXTERNAL_RES := libdb procps rpm

EXTERNAL_DIR := $(EXTERNAL_RES:%=external/%)
EXTERNAL_TAR := $(EXTERNAL_RES:%=external/%.tar.gz)
Expand Down
2 changes: 1 addition & 1 deletion src/agent/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ set(SOURCES

add_library(Agent ${SOURCES})
target_include_directories(Agent PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src)
target_link_libraries(Agent PUBLIC ConfigurationParser Communicator AgentInfo CommandHandler MultiTypeQueue ModuleManager PRIVATE OpenSSL::SSL OpenSSL::Crypto Boost::asio Boost::beast Logger)
target_link_libraries(Agent PUBLIC ConfigurationParser Communicator AgentInfo CommandHandler MultiTypeQueue ModuleManager PRIVATE OpenSSL::SSL OpenSSL::Crypto Boost::asio Boost::beast)

include(../cmake/ConfigureTarget.cmake)
configure_target(Agent)
Expand Down
19 changes: 17 additions & 2 deletions src/agent/configuration_parser/src/configuration_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,25 @@ namespace configuration
LogError("Using default values due to error parsing wazuh.conf file: {}", e.what());

tbl = toml::parse_str(
R"([agent]
R"(
[agent]
server_mgmt_api_port = "55000"
agent_comms_api_port = "8080"
manager_ip = "localhost")",
manager_ip = "localhost"

[inventory]
disabled = false
interval = 3600
scan_on_start = true
hardware = true
os = true
network = true
packages = true
ports = true
ports_all = true
processes = true
hotfixes = true
)",
toml::spec::v(1, 0, 0));
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/agent/include/agent.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
#include <communicator.hpp>
#include <configuration_parser.hpp>
#include <isignal_handler.hpp>
#include <moduleManager.hpp>
#include <multitype_queue.hpp>
#include <signal_handler.hpp>
#include <task_manager.hpp>
#include <moduleManager.hpp>

#include <memory>

Expand Down
14 changes: 6 additions & 8 deletions src/agent/src/agent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Agent::Agent(std::unique_ptr<ISignalHandler> signalHandler)
m_agentInfo.GetKey(),
[this](std::string table, std::string key) -> std::string
{ return m_configurationParser.GetConfig<std::string>(std::move(table), std::move(key)); })
, m_moduleManager(m_messageQueue, m_configurationParser)
{
m_taskManager.Start(std::thread::hardware_concurrency());
}
Expand All @@ -31,8 +32,6 @@ Agent::~Agent()

void Agent::Run()
{
Configuration config;

m_taskManager.EnqueueTask(m_communicator.WaitForTokenExpirationAndAuthenticate());

m_taskManager.EnqueueTask(m_communicator.GetCommandsFromManager(
Expand All @@ -52,13 +51,12 @@ void Agent::Run()
[this]() { return GetCommandFromQueue(m_messageQueue); },
[this]() { return PopCommandFromQueue(m_messageQueue); },
[](command_store::Command& cmd) { return DispatchCommand(cmd); }));

m_moduleManager.setMessageQueue(m_messageQueue);
m_moduleManager.addModule(Inventory::instance());
m_moduleManager.setup(config);
m_taskManager.EnqueueTask([this]() { m_moduleManager.start(); });

m_moduleManager.AddModule(Inventory::Instance());
m_moduleManager.Setup();
m_taskManager.EnqueueTask([this]() { m_moduleManager.Start(); });

m_signalHandler->WaitForSignal();
m_moduleManager.stop();
m_moduleManager.Stop();
m_communicator.Stop();
}
4 changes: 1 addition & 3 deletions src/agent/tests/agent_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ TEST(AgentTests, AgentStopsWhenSignalReceived)

EXPECT_CALL(*mockSignalHandlerPtr, WaitForSignal())
.Times(1)
.WillOnce([]() {
std::this_thread::sleep_for(std::chrono::seconds(1));
});
.WillOnce([]() { std::this_thread::sleep_for(std::chrono::seconds(1)); });

Agent agent(std::move(mockSignalHandler));

Expand Down
28 changes: 14 additions & 14 deletions src/common/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
add_subdirectory(logger)
add_subdirectory(utils)
add_subdirectory(version_op)
add_subdirectory(time_op)
add_subdirectory(file_op)
add_subdirectory(privsep_op)
add_subdirectory(pthreads_op)
add_subdirectory(error_messages)
add_subdirectory(mem_op)
add_subdirectory(binaries_op)
add_subdirectory(regex_op)
add_subdirectory(randombytes)
add_subdirectory(bzip2_op)
add_subdirectory(data_provider)
add_subdirectory(dbsync)
add_subdirectory(debug_op)
add_subdirectory(error_messages)
add_subdirectory(file_op)
add_subdirectory(hashHelper)
add_subdirectory(logger)
add_subdirectory(logging_helper)
add_subdirectory(mem_op)
add_subdirectory(networkHelper)
add_subdirectory(data_provider)
add_subdirectory(dbsync)
add_subdirectory(privsep_op)
add_subdirectory(pthreads_op)
add_subdirectory(randombytes)
add_subdirectory(regex_op)
add_subdirectory(sqliteWrapper)
add_subdirectory(hashHelper)
add_subdirectory(time_op)
add_subdirectory(utils)
add_subdirectory(version_op)

if(BUILD_TESTS)
enable_testing()
Expand Down
36 changes: 2 additions & 34 deletions src/common/data_provider/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ include_directories(${SRC_FOLDER}/common/stringHelper/include/)
include_directories(${SRC_FOLDER}/common/timeHelper/include/)
include_directories(${SRC_FOLDER}/shared_modules/common/)
include_directories(${SRC_FOLDER}/external/libdb/build_unix/)
if(LINUX)
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
include_directories(${SRC_FOLDER}/external/rpm/include/)
include_directories(${SRC_FOLDER}/external/rpm/builddir/output/include/)
# Avoid download externals from http-request submodule
Expand All @@ -104,14 +104,10 @@ if(LINUX)
include_directories(${SRC_FOLDER}/common/http-request/shared/)
endif()

if(CMAKE_SYSTEM_NAME STREQUAL "HP-UX")
link_directories(${INSTALL_PREFIX}/lib)
endif(CMAKE_SYSTEM_NAME STREQUAL "HP-UX")

link_directories(${SRC_FOLDER})
link_directories(${SRC_FOLDER}/external/procps/)
link_directories(${SRC_FOLDER}/external/libdb/build_unix/)
if(LINUX)
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
link_directories(${SRC_FOLDER}/external/rpm/builddir/)
link_directories(${SRC_FOLDER}/common/http-request/build)
endif()
Expand All @@ -125,14 +121,6 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
add_definitions(-DWIN32=1
-D_WIN32_WINNT=0x600
-DWIN_EXPORT)
elseif(CMAKE_CHECK_CENTOS5)
file(GLOB SYSINFO_SRC
"${CMAKE_CURRENT_SOURCE_DIR}/src/*Linux.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/network/*Linux.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/osinfo/sysOsParsers.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/packages/packageLinuxParser.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/packages/packageLinuxParserRpmLegacy.cpp")
add_definitions(-DLINUX_TYPE=LinuxType::LEGACY) # Partial compilation in legacy systems
elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux")
file(GLOB SYSINFO_SRC
"${CMAKE_CURRENT_SOURCE_DIR}/src/*Linux.cpp"
Expand All @@ -159,26 +147,6 @@ elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
"${CMAKE_CURRENT_SOURCE_DIR}/src/osinfo/sysOsParsers.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/hardware/*X86_64Mac.cpp")
endif()
elseif(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD")
file(GLOB SYSINFO_SRC
"${CMAKE_CURRENT_SOURCE_DIR}/src/*FreeBSD.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/*CommonBSD.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/network/*BSD.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/osinfo/sysOsParsers.cpp")
elseif(CMAKE_SYSTEM_NAME STREQUAL "OpenBSD")
file(GLOB SYSINFO_SRC
"${CMAKE_CURRENT_SOURCE_DIR}/src/*OpenBSD.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/*CommonBSD.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/network/*BSD.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/osinfo/sysOsParsers.cpp")
elseif(CMAKE_SYSTEM_NAME STREQUAL "SunOS")
file(GLOB SYSINFO_SRC
"${CMAKE_CURRENT_SOURCE_DIR}/src/UtilsWrapperUnix.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/*Solaris.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/packages/*Solaris.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/network/networkSolarisHelper.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/network/*Solaris.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/osinfo/sysOsParsers.cpp")
else()
file(GLOB SYSINFO_SRC
"${CMAKE_CURRENT_SOURCE_DIR}/src/*Unix.cpp"
Expand Down
11 changes: 0 additions & 11 deletions src/common/data_provider/src/network/networkFamilyDataAFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#include "networkInterfaceLinux.h"
#include "networkInterfaceBSD.h"
#include "networkInterfaceWindows.h"
#include "networkInterfaceSolaris.h"
#include "sharedDefs.h"

template <OSPlatformType osType>
Expand Down Expand Up @@ -63,14 +62,4 @@ class FactoryNetworkFamilyCreator<OSPlatformType::WINDOWS> final
}
};

template <>
class FactoryNetworkFamilyCreator<OSPlatformType::SOLARIS> final
{
public:
static std::shared_ptr<IOSNetwork> create(const std::shared_ptr<INetworkInterfaceWrapper>& interfaceWrapper)
{
return FactorySolarisNetwork::create(interfaceWrapper);
}
};

#endif // _NETWORK_FAMILY_DATA_AFACTORY_H
Loading
Loading