From d949d677bbcd499904ea6db9a5b909a104a05032 Mon Sep 17 00:00:00 2001 From: Santiago Vendramini Date: Wed, 7 Aug 2024 06:36:47 -0300 Subject: [PATCH] feat: Delete of CLIENT conditional directives. The use of the CLIENT directive is deleted and all manager logic is removed. --- src/modules/active_response/src/execd.c | 4 -- src/modules/active_response/src/wcom.c | 4 -- src/modules/command/src/wm_command.c | 2 - src/modules/fim/src/config.c | 2 - src/modules/inventory/src/wm_syscollector.c | 72 +------------------- src/modules/logcollector/src/config.c | 2 - src/modules/logcollector/src/logcollector.c | 4 -- src/modules/osquery/src/wm_osquery_monitor.c | 2 - src/modules/rootcheck/src/config.c | 2 - src/modules/sca/src/wm_sca.c | 4 -- src/modules/upgrade/src/wm_agent_upgrade.c | 22 +----- 11 files changed, 3 insertions(+), 117 deletions(-) diff --git a/src/modules/active_response/src/execd.c b/src/modules/active_response/src/execd.c index 6e07023b02..308486badd 100644 --- a/src/modules/active_response/src/execd.c +++ b/src/modules/active_response/src/execd.c @@ -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; diff --git a/src/modules/active_response/src/wcom.c b/src/modules/active_response/src/wcom.c index fa1b6f875b..99e8d519be 100644 --- a/src/modules/active_response/src/wcom.c +++ b/src/modules/active_response/src/wcom.c @@ -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"; diff --git a/src/modules/command/src/wm_command.c b/src/modules/command/src/wm_command.c index d14c2c2123..3932701614 100644 --- a/src/modules/command/src/wm_command.c +++ b/src/modules/command/src/wm_command.c @@ -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) { diff --git a/src/modules/fim/src/config.c b/src/modules/fim/src/config.c index 2a2f1f92b7..eb145ea6da 100644 --- a/src/modules/fim/src/config.c +++ b/src/modules/fim/src/config.c @@ -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; diff --git a/src/modules/inventory/src/wm_syscollector.c b/src/modules/inventory/src/wm_syscollector.c index b2f8fcfec3..d7895b6dc2 100644 --- a/src/modules/inventory/src/wm_syscollector.c +++ b/src/modules/inventory/src/wm_syscollector.c @@ -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 @@ -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 @@ -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); @@ -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) @@ -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."); @@ -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, @@ -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); diff --git a/src/modules/logcollector/src/config.c b/src/modules/logcollector/src/config.c index 6c5c4c94b8..acfffd26ba 100644 --- a/src/modules/logcollector/src/config.c +++ b/src/modules/logcollector/src/config.c @@ -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; diff --git a/src/modules/logcollector/src/logcollector.c b/src/modules/logcollector/src/logcollector.c index 564c181cf9..3775e4ccbe 100644 --- a/src/modules/logcollector/src/logcollector.c +++ b/src/modules/logcollector/src/logcollector.c @@ -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); diff --git a/src/modules/osquery/src/wm_osquery_monitor.c b/src/modules/osquery/src/wm_osquery_monitor.c index 7c9bdce8ff..cffdd5a7ac 100644 --- a/src/modules/osquery/src/wm_osquery_monitor.c +++ b/src/modules/osquery/src/wm_osquery_monitor.c @@ -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? diff --git a/src/modules/rootcheck/src/config.c b/src/modules/rootcheck/src/config.c index 26b672330b..63ed93c651 100644 --- a/src/modules/rootcheck/src/config.c +++ b/src/modules/rootcheck/src/config.c @@ -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: diff --git a/src/modules/sca/src/wm_sca.c b/src/modules/sca/src/wm_sca.c index 5933127d14..f81c5dcf18 100644 --- a/src/modules/sca/src/wm_sca.c +++ b/src/modules/sca/src/wm_sca.c @@ -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) { diff --git a/src/modules/upgrade/src/wm_agent_upgrade.c b/src/modules/upgrade/src/wm_agent_upgrade.c index 7f67853245..e298d6e982 100644 --- a/src/modules/upgrade/src/wm_agent_upgrade.c +++ b/src/modules/upgrade/src/wm_agent_upgrade.c @@ -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 @@ -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; @@ -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); } @@ -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 { @@ -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; }