From 7a253cc8e0f29b40b6f4489b9bb6eea06a56126f 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/common/file_op/include/file_op.h | 11 - src/common/file_op/src/file_op.c | 21 - src/common/syscheck_op/include/syscheck_op.h | 48 -- src/common/syscheck_op/src/syscheck_op.c | 438 ------------------- src/common/url/include/url.h | 4 - src/common/url/src/url.c | 54 --- src/common/utils/shared.h | 6 - 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 +- 18 files changed, 3 insertions(+), 699 deletions(-) diff --git a/src/common/file_op/include/file_op.h b/src/common/file_op/include/file_op.h index eefd0f66c9..b8eb89ec16 100644 --- a/src/common/file_op/include/file_op.h +++ b/src/common/file_op/include/file_op.h @@ -629,17 +629,6 @@ int w_is_compressed_gz_file(const char * path); */ int w_is_compressed_bz2_file(const char * path); -#ifndef CLIENT -/** - * @brief Check if a file from a path is compressed in bunzip2 or gzip and uncompressed it - * - * @param path File location - * @retval -1 The file cannot be uncompressed - * @retval 0 The file has been uncompressed (.gz or .bz2) - */ -int w_uncompress_bz2_gz_file(const char * path, const char * dest); -#endif /* CLIENT */ - /** * @brief Get the Wazuh installation directory * diff --git a/src/common/file_op/src/file_op.c b/src/common/file_op/src/file_op.c index 4a7cd9714d..24b2b7aea8 100644 --- a/src/common/file_op/src/file_op.c +++ b/src/common/file_op/src/file_op.c @@ -3432,27 +3432,6 @@ int w_is_compressed_bz2_file(const char * path) { return retval; } -#ifndef CLIENT - -int w_uncompress_bz2_gz_file(const char * path, const char * dest) { - int result = 1; - - if (w_is_compressed_bz2_file(path)) { - result = bzip2_uncompress(path, dest); - } - - if (w_is_compressed_gz_file(path)) { - result = w_uncompress_gzfile(path, dest); - } - - if (!result) { - mdebug1("The file '%s' was successfully uncompressed into '%s'", path, dest); - } - - return result; -} -#endif - #ifndef WIN32 /** * @brief Get the Wazuh installation directory diff --git a/src/common/syscheck_op/include/syscheck_op.h b/src/common/syscheck_op/include/syscheck_op.h index 6c9a0609b7..01dd670e5e 100644 --- a/src/common/syscheck_op/include/syscheck_op.h +++ b/src/common/syscheck_op/include/syscheck_op.h @@ -224,44 +224,6 @@ typedef struct sk_sum_t { long date_alert; } sk_sum_t; -/** - * @brief Parse c_sum string - * - * @param [out] sum - * @param [in] c_sum - * @param [in] w_sum - * @return 0 if success, 1 when c_sum denotes a deleted file, -1 on failure - */ -int sk_decode_sum(sk_sum_t *sum, char *c_sum, char *w_sum); - -/** - * @brief Parse fields changes and date_alert only provide for wazuh_db - * - * @param [out] sum - * @param [in] c_sum - * @return 0 if success, -1 on failure - */ -int sk_decode_extradata(sk_sum_t *sum, char *c_sum); - -/** - * @brief Fill an event with specific data - * - * @param [out] lf Event to be filled - * @param [in] f_name File name for the event - * @param [in] sum File sum used to fill the event - */ -void sk_fill_event(Eventinfo *lf, const char *f_name, const sk_sum_t *sum); - -/** - * @brief Fills a buffer with a specific file sum - * - * @param [in] sum File sum used to fill the buffer - * @param [out] output The output buffer to be written - * @param [in] size Size in bytes to be written into output - * @return 0 on success, -1 on failure - */ -int sk_build_sum(const sk_sum_t *sum, char *output, size_t size); - /** * @brief Delete from path to parent all empty folders * @@ -270,13 +232,6 @@ int sk_build_sum(const sk_sum_t *sum, char *output, size_t size); */ int remove_empty_folders(const char *path); -/** - * @brief Frees from memory a sk_sum_t structure - * - * @param [out] sum The sk_sum_t object to be freed - */ -void sk_sum_clean(sk_sum_t *sum); - /** * @brief Change in Windows paths all slashes for backslashes for compatibility * @@ -291,9 +246,6 @@ void normalize_path(char *path); * @return A string with escaped characters */ char *escape_syscheck_field(char *field); -#ifndef CLIENT -char *unescape_syscheck_field(char *sum); -#endif #ifndef WIN32 diff --git a/src/common/syscheck_op/src/syscheck_op.c b/src/common/syscheck_op/src/syscheck_op.c index 4c34472e5d..7ad3fff67a 100644 --- a/src/common/syscheck_op/src/syscheck_op.c +++ b/src/common/syscheck_op/src/syscheck_op.c @@ -115,444 +115,6 @@ int remove_empty_folders(const char *path) { } #ifndef WIN32 -#ifndef CLIENT -int sk_decode_sum(sk_sum_t *sum, char *c_sum, char *w_sum) { - assert(sum != NULL); - assert(c_sum != NULL); - - char *c_perm; - char *c_mtime; - char *c_inode; - char *attrs; - int retval = 0; - char * uname; - - if (c_sum[0] == '-' && c_sum[1] == '1') { - retval = 1; - } else { - sum->size = c_sum; - - if (!(c_perm = strchr(c_sum, ':'))) - return -1; - - *(c_perm++) = '\0'; - - if (!(sum->uid = wstr_chr(c_perm, ':'))) - return -1; - - *(sum->uid++) = '\0'; - - if (*c_perm == '|') { - // Windows permissions - char *unsc_perm = unescape_syscheck_field(c_perm); - - // We need to transform them to the new format - // before processing - sum->win_perm = decode_win_permissions(unsc_perm); - free(unsc_perm); - } else if (*c_perm == ':') { - } else if (isdigit(*c_perm)) { - sum->perm = atoi(c_perm); - } else { - os_strdup(c_perm, sum->win_perm); - } - - if (!(sum->gid = strchr(sum->uid, ':'))) - return -1; - - *(sum->gid++) = '\0'; - - if (!(sum->md5 = strchr(sum->gid, ':'))) - return -1; - - *(sum->md5++) = '\0'; - - if (!(sum->sha1 = strchr(sum->md5, ':'))) - return -1; - - *(sum->sha1++) = '\0'; - - // New fields: user name, group name, modification time and inode - - if ((uname = strchr(sum->sha1, ':'))) { - *(uname++) = '\0'; - - if (!(sum->gname = strchr(uname, ':'))) - return -1; - - *(sum->gname++) = '\0'; - - sum->uname = os_strip_char(uname, '\\'); - - if (!(c_mtime = strchr(sum->gname, ':'))) - return -1; - - *(c_mtime++) = '\0'; - - if (!(c_inode = strchr(c_mtime, ':'))) - return -1; - - *(c_inode++) = '\0'; - - sum->sha256 = NULL; - - if ((sum->sha256 = strchr(c_inode, ':'))) { - *(sum->sha256++) = '\0'; - - if (sum->sha256) { - if (attrs = strchr(sum->sha256, ':'), attrs) { - *(attrs++) = '\0'; - if (isdigit(*attrs)) { - int attributes = strtoul(attrs, NULL, 10); - os_calloc(OS_SIZE_256 + 1, sizeof(char), sum->attributes); - decode_win_attributes(sum->attributes, attributes); - } else { - os_strdup(attrs, sum->attributes); - } - } - } - - sum->mtime = atol(c_mtime); - sum->inode = atol(c_inode); - } - } - } - - // Get extra data - if (w_sum) { - char * user_name; - char * process_name; - char * symbolic_path; - - sum->wdata.user_id = w_sum; - - if ((user_name = wstr_chr(w_sum, ':'))) { - *(user_name++) = '\0'; - } else { - return -1; - } - - if ((sum->wdata.group_id = wstr_chr(user_name, ':'))) { - *(sum->wdata.group_id++) = '\0'; - } else { - return -1; - } - - if ((sum->wdata.group_name = wstr_chr(sum->wdata.group_id, ':'))) { - *(sum->wdata.group_name++) = '\0'; - } else { - return -1; - } - - if ((process_name = wstr_chr(sum->wdata.group_name, ':'))) { - *(process_name++) = '\0'; - } else { - return -1; - } - - if ((sum->wdata.audit_uid = wstr_chr(process_name, ':'))) { - *(sum->wdata.audit_uid++) = '\0'; - } else { - return -1; - } - - if ((sum->wdata.audit_name = wstr_chr(sum->wdata.audit_uid, ':'))) { - *(sum->wdata.audit_name++) = '\0'; - } else { - return -1; - } - - if ((sum->wdata.effective_uid = wstr_chr(sum->wdata.audit_name, ':'))) { - *(sum->wdata.effective_uid++) = '\0'; - } else { - return -1; - } - - if ((sum->wdata.effective_name = wstr_chr(sum->wdata.effective_uid, ':'))) { - *(sum->wdata.effective_name++) = '\0'; - } else { - return -1; - } - - if ((sum->wdata.ppid = wstr_chr(sum->wdata.effective_name, ':'))) { - *(sum->wdata.ppid++) = '\0'; - } else { - return -1; - } - - if ((sum->wdata.process_id = wstr_chr(sum->wdata.ppid, ':'))) { - *(sum->wdata.process_id++) = '\0'; - } else { - return -1; - } - - /* Look for a defined tag */ - if (sum->tag = wstr_chr(sum->wdata.process_id, ':'), sum->tag) { - *(sum->tag++) = '\0'; - } else { - sum->tag = NULL; - } - - /* Look for a symbolic path */ - if (sum->tag && (symbolic_path = wstr_chr(sum->tag, ':'))) { - *(symbolic_path++) = '\0'; - } else { - symbolic_path = NULL; - } - - /* Look if it is a silent event */ - if (symbolic_path && (c_inode = wstr_chr(symbolic_path, ':'))) { - *(c_inode++) = '\0'; - if (*c_inode == '+') { - sum->silent = 1; - } - } - - - sum->symbolic_path = unescape_syscheck_field(symbolic_path); - sum->wdata.user_name = unescape_syscheck_field(user_name); - sum->wdata.process_name = unescape_syscheck_field(process_name); - if (*sum->wdata.ppid == '-') { - sum->wdata.ppid = NULL; - } - } - - return retval; -} - -int sk_decode_extradata(sk_sum_t *sum, char *c_sum) { - char *changes; - char *date_alert; - char *sym_path; - - assert(sum != NULL); - assert(c_sum != NULL); - - if (changes = strchr(c_sum, '!'), !changes) { - return 0; - } - *changes++ = '\0'; - - if (date_alert = strchr(changes, ':'), !date_alert) { - return 0; - } - *(date_alert++) = '\0'; - - if (sym_path = strchr(date_alert, ':'), sym_path) { - *(sym_path++) = '\0'; - sum->symbolic_path = unescape_syscheck_field(sym_path); - } - - sum->changes = atoi(changes); - sum->date_alert = atol(date_alert); - - return 1; -} - -void sk_fill_event(Eventinfo *lf, const char *f_name, const sk_sum_t *sum) { - assert(lf != NULL); - assert(f_name != NULL); - assert(sum != NULL); - - os_strdup(f_name, lf->fields[FIM_FILE].value); - - if (sum->size) { - os_strdup(sum->size, lf->fields[FIM_SIZE].value); - } - - if (sum->perm) { - os_calloc(7, sizeof(char), lf->fields[FIM_PERM].value); - snprintf(lf->fields[FIM_PERM].value, 7, "%06o", sum->perm); - } else if (sum->win_perm && *sum->win_perm != '\0') { - os_strdup(sum->win_perm, lf->fields[FIM_PERM].value); - } - - if (sum->uid) { - os_strdup(sum->uid, lf->fields[FIM_UID].value); - } - - if (sum->gid) { - os_strdup(sum->gid, lf->fields[FIM_GID].value); - } - - if (sum->md5) { - os_strdup(sum->md5, lf->fields[FIM_MD5].value); - } - - if (sum->sha1) { - os_strdup(sum->sha1, lf->fields[FIM_SHA1].value); - } - - if (sum->uname) { - os_strdup(sum->uname, lf->fields[FIM_UNAME].value); - } - - if (sum->gname) { - os_strdup(sum->gname, lf->fields[FIM_GNAME].value); - } - - if (sum->mtime) { - lf->fields[FIM_MTIME].value = w_long_str(sum->mtime); - } - - if (sum->inode) { - lf->fields[FIM_INODE].value = w_long_str(sum->inode); - } - - if(sum->sha256) { - os_strdup(sum->sha256, lf->fields[FIM_SHA256].value); - } - - if(sum->attributes) { - os_strdup(sum->attributes, lf->fields[FIM_ATTRS].value); - } - - if(sum->wdata.user_id) { - os_strdup(sum->wdata.user_id, lf->fields[FIM_USER_ID].value); - } - - if(sum->wdata.user_name) { - os_strdup(sum->wdata.user_name, lf->fields[FIM_USER_NAME].value); - } - - if(sum->wdata.group_id) { - os_strdup(sum->wdata.group_id, lf->fields[FIM_GROUP_ID].value); - } - - if(sum->wdata.group_name) { - os_strdup(sum->wdata.group_name, lf->fields[FIM_GROUP_NAME].value); - } - - if(sum->wdata.process_name) { - os_strdup(sum->wdata.process_name, lf->fields[FIM_PROC_NAME].value); - } - - if(sum->wdata.parent_name) { - os_strdup(sum->wdata.parent_name, lf->fields[FIM_PROC_PNAME].value); - } - - if(sum->wdata.cwd) { - os_strdup(sum->wdata.cwd, lf->fields[FIM_AUDIT_CWD].value); - } - - if(sum->wdata.parent_cwd) { - os_strdup(sum->wdata.parent_cwd, lf->fields[FIM_AUDIT_PCWD].value); - } - - if(sum->wdata.audit_uid) { - os_strdup(sum->wdata.audit_uid, lf->fields[FIM_AUDIT_ID].value); - } - - if(sum->wdata.audit_name) { - os_strdup(sum->wdata.audit_name, lf->fields[FIM_AUDIT_NAME].value); - } - - if(sum->wdata.effective_uid) { - os_strdup(sum->wdata.effective_uid, lf->fields[FIM_EFFECTIVE_UID].value); - } - - if(sum->wdata.effective_name) { - os_strdup(sum->wdata.effective_name, lf->fields[FIM_EFFECTIVE_NAME].value); - } - - if(sum->wdata.ppid) { - os_strdup(sum->wdata.ppid, lf->fields[FIM_PPID].value); - } - - if(sum->wdata.process_id) { - os_strdup(sum->wdata.process_id, lf->fields[FIM_PROC_ID].value); - } - - if(sum->tag) { - os_strdup(sum->tag, lf->fields[FIM_TAG].value); - } - - if(sum->symbolic_path) { - os_strdup(sum->symbolic_path, lf->fields[FIM_SYM_PATH].value); - } -} - -int sk_build_sum(const sk_sum_t * sum, char * output, size_t size) { - int r; - char s_perm[16]; - char s_mtime[16]; - char s_inode[16]; - char *username; - - assert(sum != NULL); - assert(output != NULL); - - if(sum->perm) { - snprintf(s_perm, sizeof(s_perm), "%d", sum->perm); - } else { - *s_perm = '\0'; - } - snprintf(s_mtime, sizeof(s_mtime), "%ld", sum->mtime); - snprintf(s_inode, sizeof(s_inode), "%ld", sum->inode); - - username = wstr_replace((const char*)sum->uname, " ", "\\ "); - - // This string will be sent to Analysisd, who will parse it - // If it is a Windows event, we need to escape the permissions - char *win_perm = NULL; - if (sum->win_perm) { - win_perm = wstr_replace(sum->win_perm, ":", "\\:"); - } - - // size:permision:uid:gid:md5:sha1:uname:gname:mtime:inode:sha256:attrs!changes:date_alert - // ^^^^^^^^^^^^^^^^^^^^^^^^^^^checksum^^^^^^^^^^^^^^^^^^^^^^^^^^^!^^^^extradata^^^^^ - r = snprintf(output, size, "%s:%s:%s:%s:%s:%s:%s:%s:%s:%s:%s:%s!%d:%ld", - sum->size, - (!win_perm) ? s_perm : win_perm, - sum->uid, - sum->gid, - sum->md5, - sum->sha1, - sum->uname ? username : "", - sum->gname ? sum->gname : "", - sum->mtime ? s_mtime : "", - sum->inode ? s_inode : "", - sum->sha256 ? sum->sha256 : "", - sum->attributes ? sum->attributes : "", - sum->changes, - sum->date_alert - ); - - free(win_perm); - free(username); - return r < (int)size ? 0 : -1; -} - -void sk_sum_clean(sk_sum_t * sum) { - assert(sum != NULL); - - os_free(sum->symbolic_path); - os_free(sum->attributes); - os_free(sum->wdata.user_name); - os_free(sum->wdata.process_name); - os_free(sum->wdata.parent_cwd); - os_free(sum->wdata.cwd); - os_free(sum->wdata.parent_name); - os_free(sum->uname); - os_free(sum->win_perm); -} - -#endif /* #ifndef CLIENT */ - -char *unescape_syscheck_field(char *sum) { - char *esc_it; - - if (sum && *sum != '\0') { - // The parameter string is not released - sum = wstr_replace(sum, "\\ ", " "); - esc_it = wstr_replace(sum, "\\!", "!"); - free(sum); - sum = wstr_replace(esc_it, "\\:", ":"); - os_free(esc_it); - return sum; - } - return NULL; -} char *get_user(int uid) { struct passwd pwd; diff --git a/src/common/url/include/url.h b/src/common/url/include/url.h index 0f36259c11..36c05d4ab2 100644 --- a/src/common/url/include/url.h +++ b/src/common/url/include/url.h @@ -56,10 +56,6 @@ char * wurl_http_get(const char * url, size_t max_size, const long timeout); curl_response *wurl_http_request(char *method, char **headers, const char *url, const char *payload, size_t max_size, const long timeout); void wurl_free_response(curl_response* response); -#ifndef CLIENT -int wurl_request_bz2(const char * url, const char * dest, const char * header, const char * data, const long timeout, char *sha256); -int wurl_request_uncompress_bz2_gz(const char * url, const char * dest, const char * header, const char * data, const long timeout, char *sha256); -#endif /* Check download module availability */ int wurl_check_connection(); diff --git a/src/common/url/src/url.c b/src/common/url/src/url.c index dc9d05d33f..342051cea0 100644 --- a/src/common/url/src/url.c +++ b/src/common/url/src/url.c @@ -372,60 +372,6 @@ char * wurl_http_get(const char * url, size_t max_size, const long timeout) { return chunk.memory; } -#endif -#ifndef CLIENT - -// Request a download of a bzip2 file and uncompress it. -int wurl_request_bz2(const char * url, const char * dest, const char * header, const char * data, const long timeout, char *sha256) { - char compressed_file[OS_SIZE_6144 + 1]; - int retval = OS_INVALID; - - snprintf(compressed_file, OS_SIZE_6144, "tmp/req-%u", os_random()); - - if (wurl_request(url, compressed_file, header, data, timeout)) { - return retval; - - } else { - os_sha256 filehash = {0}; - if (sha256 && !OS_SHA256_File(compressed_file, filehash, 'r') && strcmp(sha256, filehash)) { - merror("Invalid file integrity for '%s'", compressed_file); - - } else if (bzip2_uncompress(compressed_file, dest)) { - merror("Could not uncompress the file downloaded from '%s'", url); - - } else { - retval = 0; - } - } - - if (remove(compressed_file) < 0) { - mdebug1("Could not remove '%s'. Error: %d.", compressed_file, errno); - } - - return retval; -} - -// Check the compression type of the file and try to download and uncompress it. -int wurl_request_uncompress_bz2_gz(const char * url, const char * dest, const char * header, const char * data, const long timeout, char *sha256) { - int res_url_request; - int compress = 0; - - if (wstr_end((char *)url, ".gz")) { - compress = 1; - res_url_request = wurl_request_gz(url, dest, header, data, timeout, sha256); - } else if (wstr_end((char *)url, ".bz2")) { - compress = 1; - res_url_request = wurl_request_bz2(url, dest, header, data, timeout, sha256); - } else { - res_url_request = wurl_request(url, dest, header, data, timeout); - } - - if (compress == 1 && !res_url_request) { - mdebug1("File from URL '%s' was successfully uncompressed into '%s'", url, dest); - } - - return res_url_request; -} #endif curl_response* wurl_http_request(char *method, char **headers, const char* url, const char *payload, size_t max_size, const long timeout) { diff --git a/src/common/utils/shared.h b/src/common/utils/shared.h index 54fe42fe2a..23b3e95ef9 100644 --- a/src/common/utils/shared.h +++ b/src/common/utils/shared.h @@ -221,12 +221,6 @@ extern const char *__local_name; // Only static arrays allowed. #define array_size(array) (sizeof(array)/sizeof(array[0])) -#ifdef CLIENT -#define isAgent 1 -#else -#define isAgent 0 -#endif - #ifndef WAZUH_UNIT_TESTING #define FOREVER() 1 #endif 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; }