Skip to content

Commit

Permalink
feat: Delete of CLIENT conditional directives.
Browse files Browse the repository at this point in the history
The use of the CLIENT directive is deleted and all manager logic is removed.
  • Loading branch information
sdvendramini committed Aug 12, 2024
1 parent 604667d commit d949d67
Show file tree
Hide file tree
Showing 11 changed files with 3 additions and 117 deletions.
4 changes: 0 additions & 4 deletions src/modules/active_response/src/execd.c
Original file line number Diff line number Diff line change
Expand Up @@ -217,11 +217,7 @@ void ExecdRun(char *exec_msg, int *childcount)

os_strdup("active-response/bin/restart.sh", cmd_api[0]);

#ifdef CLIENT
os_strdup("agent", cmd_api[1]);
#else
os_strdup("manager", cmd_api[1]);
#endif

ExecCmd(cmd_api);
return;
Expand Down
4 changes: 0 additions & 4 deletions src/modules/active_response/src/wcom.c
Original file line number Diff line number Diff line change
Expand Up @@ -193,11 +193,7 @@ size_t wcom_restart(char ** output) {

if (access("active-response/bin/restart.sh", F_OK) == 0) {
exec_cmd[0] = "active-response/bin/restart.sh";
#ifdef CLIENT
exec_cmd[1] = "agent";
#else
exec_cmd[1] = "manager";
#endif
} else {
exec_cmd[0] = "bin/wazuh-control";
exec_cmd[1] = "restart";
Expand Down
2 changes: 0 additions & 2 deletions src/modules/command/src/wm_command.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,10 @@ void * wm_command_main(wm_command_t * command) {
pthread_exit(0);
}

#ifdef CLIENT
if (!getDefine_Int("wazuh_command", "remote_commands", 0, 1) && command->agent_cfg) {
mtwarn(WM_COMMAND_LOGTAG, "Remote commands are disabled. Ignoring '%s'.", command->tag);
pthread_exit(0);
}
#endif

// Verify command
if (command->md5_hash || command->sha1_hash || command->sha256_hash) {
Expand Down
2 changes: 0 additions & 2 deletions src/modules/fim/src/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,11 @@ int Read_Syscheck_Config(const char *cfgfile)
return (OS_INVALID);
}

#ifdef CLIENT
mdebug1(FIM_CLIENT_CONFIGURATION, cfgfile);

/* Read shared config */
modules |= CAGENT_CONFIG;
ReadConfig(modules, AGENTCONFIG, &syscheck, NULL);
#endif

OSList_foreach(node_it, syscheck.directories) {
dir_it = node_it->data;
Expand Down
72 changes: 1 addition & 71 deletions src/modules/inventory/src/wm_syscollector.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,6 @@
#include "headers/logging_helper.h"
#include "commonDefs.h"

#ifndef CLIENT
#include "router.h"
#include "utils/flatbuffers/include/syscollector_synchronization_schema.h"
#include "utils/flatbuffers/include/syscollector_deltas_schema.h"
#include "agent_messages_adapter.h"
#endif // CLIENT

#ifdef WIN32
static DWORD WINAPI wm_sys_main(void *arg); // Module main function. It won't return
#else
Expand Down Expand Up @@ -57,15 +50,6 @@ syscollector_start_func syscollector_start_ptr = NULL;
syscollector_stop_func syscollector_stop_ptr = NULL;
syscollector_sync_message_func syscollector_sync_message_ptr = NULL;

#ifndef CLIENT
void *router_module_ptr = NULL;
router_provider_create_func router_provider_create_func_ptr = NULL;
router_provider_send_fb_func router_provider_send_fb_func_ptr = NULL;
ROUTER_PROVIDER_HANDLE rsync_handle = NULL;
ROUTER_PROVIDER_HANDLE syscollector_handle = NULL;
int disable_manager_scan = 1;
#endif // CLIENT

long syscollector_sync_max_eps = 10; // Database synchronization number of events per second (default value)
int queue_fd = 0; // Output queue file descriptor

Expand All @@ -78,11 +62,8 @@ static void wm_sys_send_message(const void* data, const char queue_id) {
if (!is_shutdown_process_started()) {
const int eps = 1000000/syscollector_sync_max_eps;
if (wm_sendmsg_ex(eps, queue_fd, data, WM_SYS_LOCATION, queue_id, &is_shutdown_process_started) < 0) {
#ifdef CLIENT
mterror(WM_SYS_LOGTAG, "Unable to send message to '%s' (wazuh-agentd might be down). Attempting to reconnect.", DEFAULTQUEUE);
#else
mterror(WM_SYS_LOGTAG, "Unable to send message to '%s' (wazuh-analysisd might be down). Attempting to reconnect.", DEFAULTQUEUE);
#endif

// Since this method is beign called by multiple threads it's necessary this particular portion of code
// to be mutually exclusive. When one thread is successfully reconnected, the other ones will make use of it.
w_mutex_lock(&sys_reconnect_mutex);
Expand All @@ -101,30 +82,10 @@ static void wm_sys_send_message(const void* data, const char queue_id) {

static void wm_sys_send_diff_message(const void* data) {
wm_sys_send_message(data, SYSCOLLECTOR_MQ);
#ifndef CLIENT
if(!disable_manager_scan)
{
char* msg_to_send = adapt_delta_message(data, "localhost", "000", "127.0.0.1", NULL);
if (msg_to_send && router_provider_send_fb_func_ptr) {
router_provider_send_fb_func_ptr(syscollector_handle, msg_to_send, syscollector_deltas_SCHEMA);
}
cJSON_free(msg_to_send);
}
#endif // CLIENT
}

static void wm_sys_send_dbsync_message(const void* data) {
wm_sys_send_message(data, DBSYNC_MQ);
#ifndef CLIENT
if(!disable_manager_scan)
{
char* msg_to_send = adapt_sync_message(data, "localhost", "000", "127.0.0.1", NULL);
if (msg_to_send && router_provider_send_fb_func_ptr) {
router_provider_send_fb_func_ptr(rsync_handle, msg_to_send, syscollector_synchronization_SCHEMA);
}
cJSON_free(msg_to_send);
}
#endif // CLIENT
}

static void wm_sys_log_config(wm_sys_t *sys)
Expand Down Expand Up @@ -182,21 +143,6 @@ void* wm_sys_main(wm_sys_t *sys) {
so_free_library(rsync_module);
#endif
}
#ifndef CLIENT
// Load router module only for manager if is enabled
disable_manager_scan = getDefine_Int("vulnerability-detection", "disable_scan_manager", 0, 1);
if (router_module_ptr = so_get_module_handle("router"), router_module_ptr) {
router_provider_create_func_ptr = so_get_function_sym(router_module_ptr, "router_provider_create");
router_provider_send_fb_func_ptr = so_get_function_sym(router_module_ptr, "router_provider_send_fb");
if (router_provider_create_func_ptr && router_provider_send_fb_func_ptr) {
mtdebug1(WM_SYS_LOGTAG, "Router module loaded.");
} else {
mwarn("Failed to load methods from router module.");
}
} else {
mwarn("Failed to load router module.");
}
#endif // CLIENT
} else {
#ifdef __hpux
mtinfo(WM_SYS_LOGTAG, "Not supported in HP-UX.");
Expand All @@ -216,18 +162,6 @@ void* wm_sys_main(wm_sys_t *sys) {
}
// else: if max_eps is 0 (from configuration) let's use the default max_eps value (10)
wm_sys_log_config(sys);
#ifndef CLIENT
// Router providers initialization
if (router_provider_create_func_ptr){
if(syscollector_handle = router_provider_create_func_ptr("deltas-syscollector", true), !syscollector_handle) {
mdebug2("Failed to create router handle for 'syscollector'.");
}

if (rsync_handle = router_provider_create_func_ptr("rsync-syscollector", true), !rsync_handle) {
mdebug2("Failed to create router handle for 'rsync'.");
}
}
#endif // CLIENT
syscollector_start_ptr(sys->interval,
wm_sys_send_diff_message,
wm_sys_send_dbsync_message,
Expand Down Expand Up @@ -257,10 +191,6 @@ void* wm_sys_main(wm_sys_t *sys) {
queue_fd = 0;
}
so_free_library(syscollector_module);
#ifndef CLIENT
so_free_library(router_module_ptr);
router_module_ptr = NULL;
#endif // CLIENT
syscollector_module = NULL;
mtinfo(WM_SYS_LOGTAG, "Module finished.");
w_mutex_lock(&sys_stop_mutex);
Expand Down
2 changes: 0 additions & 2 deletions src/modules/logcollector/src/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,10 @@ int LogCollectorConfig(const char *cfgfile)
return (OS_INVALID);
}

#ifdef CLIENT
modules |= CAGENT_CONFIG;
log_config.agent_cfg = 1;
ReadConfig(modules, AGENTCONFIG, &log_config, NULL);
log_config.agent_cfg = 0;
#endif

logff = log_config.config;
globs = log_config.globs;
Expand Down
4 changes: 0 additions & 4 deletions src/modules/logcollector/src/logcollector.c
Original file line number Diff line number Diff line change
Expand Up @@ -1951,11 +1951,7 @@ void * w_output_thread(void * args){
message->queue_mq, message->log_target);
if (result != 0) {
if (result != 1) {
#ifdef CLIENT
merror("Unable to send message to '%s' (wazuh-agentd might be down). Attempting to reconnect.", DEFAULTQUEUE);
#else
merror("Unable to send message to '%s' (wazuh-analysisd might be down). Attempting to reconnect.", DEFAULTQUEUE);
#endif
}
// Retry to connect infinitely.
logr_queue = StartMQ(DEFAULTQUEUE, WRITE, INFINITE_OPENQ_ATTEMPTS);
Expand Down
2 changes: 0 additions & 2 deletions src/modules/osquery/src/wm_osquery_monitor.c
Original file line number Diff line number Diff line change
Expand Up @@ -462,9 +462,7 @@ int wm_osquery_decorators(wm_osquery_monitor_t * osquery)
if (ReadConfig(CLABELS, OSSECCONF, &labels, NULL) < 0)
goto end;

#ifdef CLIENT
ReadConfig(CLABELS | CAGENT_CONFIG, AGENTCONFIG, &labels, NULL);
#endif

// Do we have labels defined?

Expand Down
2 changes: 0 additions & 2 deletions src/modules/rootcheck/src/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,9 @@ int Read_Rootcheck_Config(const char *cfgfile)
return (OS_INVALID);
}

#ifdef CLIENT
/* Read shared config */
modules |= CAGENT_CONFIG;
ReadConfig(modules, AGENTCONFIG, &rootcheck, NULL);
#endif

switch (rootcheck.disabled) {
case RK_CONF_UNPARSED:
Expand Down
4 changes: 0 additions & 4 deletions src/modules/sca/src/wm_sca.c
Original file line number Diff line number Diff line change
Expand Up @@ -173,11 +173,7 @@ void * wm_sca_main(wm_sca_t * data) {

data->request_db_interval = getDefine_Int("sca","request_db_interval", 1, 60) * 60;
data->commands_timeout = getDefine_Int("sca", "commands_timeout", 1, 300);
#ifdef CLIENT
data->remote_commands = getDefine_Int("sca", "remote_commands", 0, 1);
#else
data->remote_commands = 1; // Only for agents
#endif

/* Maximum request interval is the scan interval */
if(data->request_db_interval > data->scan_config.interval) {
Expand Down
22 changes: 2 additions & 20 deletions src/modules/upgrade/src/wm_agent_upgrade.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,7 @@
#include "wazuh_modules/wmodules.h"
#include "os_net/os_net.h"

#ifdef CLIENT
#include "agent/wm_agent_upgrade_agent.h"
#else
#include "manager/wm_agent_upgrade_manager.h"
#endif

/**
* Module main function. It won't return
Expand Down Expand Up @@ -53,11 +49,8 @@ STATIC DWORD WINAPI wm_agent_upgrade_main(void *arg) {
#else
STATIC void *wm_agent_upgrade_main(wm_agent_upgrade* upgrade_config) {
#endif
#ifdef CLIENT
wm_agent_upgrade_start_agent_module(&upgrade_config->agent_config, upgrade_config->enabled);
#else
wm_agent_upgrade_start_manager_module(&upgrade_config->manager_config, upgrade_config->enabled);
#endif
wm_agent_upgrade_start_agent_module(&upgrade_config->agent_config, upgrade_config->enabled);


#ifdef WIN32
return 0;
Expand All @@ -68,9 +61,6 @@ STATIC void *wm_agent_upgrade_main(wm_agent_upgrade* upgrade_config) {

STATIC void wm_agent_upgrade_destroy(wm_agent_upgrade* upgrade_config) {
mtinfo(WM_AGENT_UPGRADE_LOGTAG, WM_UPGRADE_MODULE_FINISHED);
#ifndef CLIENT
os_free(upgrade_config->manager_config.wpk_repository);
#endif
os_free(upgrade_config);
}

Expand All @@ -83,13 +73,6 @@ STATIC cJSON *wm_agent_upgrade_dump(const wm_agent_upgrade* upgrade_config){
} else {
cJSON_AddStringToObject(wm_info,"enabled","no");
}
#ifndef CLIENT
cJSON_AddNumberToObject(wm_info, "max_threads", upgrade_config->manager_config.max_threads);
cJSON_AddNumberToObject(wm_info, "chunk_size", upgrade_config->manager_config.chunk_size);
if (upgrade_config->manager_config.wpk_repository) {
cJSON_AddStringToObject(wm_info, "wpk_repository", upgrade_config->manager_config.wpk_repository);
}
#else
if (upgrade_config->agent_config.enable_ca_verification) {
cJSON_AddStringToObject(wm_info,"ca_verification","yes");
} else {
Expand All @@ -102,7 +85,6 @@ STATIC cJSON *wm_agent_upgrade_dump(const wm_agent_upgrade* upgrade_config){
}
cJSON_AddItemToObject(wm_info,"ca_store",calist);
}
#endif
cJSON_AddItemToObject(root,"agent-upgrade",wm_info);
return root;
}

0 comments on commit d949d67

Please sign in to comment.