From 7a253cc8e0f29b40b6f4489b9bb6eea06a56126f Mon Sep 17 00:00:00 2001 From: Santiago Vendramini Date: Wed, 7 Aug 2024 06:36:47 -0300 Subject: [PATCH 1/2] 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; } From 22004cd0675f22728a03905aa2b053338e8a83a6 Mon Sep 17 00:00:00 2001 From: Santiago Vendramini Date: Mon, 12 Aug 2024 13:55:41 -0300 Subject: [PATCH 2/2] test: UTs related to deleted functions are removed --- .../file_op/tests/unit/tests/test_file_op.c | 193 -- .../tests/unit/tests/test_syscheck_op.c | 1585 ----------------- .../fim/tests/unit/tests/test_config.c | 6 +- .../tests/unit/tests/test_fim_diff_changes.c | 3 +- .../fim/tests/unit/tests/test_run_realtime.c | 6 +- .../tests/unit/tests/test_wm_agent_upgrade.c | 37 - 6 files changed, 7 insertions(+), 1823 deletions(-) diff --git a/src/common/file_op/tests/unit/tests/test_file_op.c b/src/common/file_op/tests/unit/tests/test_file_op.c index 847a108a1a..795ea17738 100644 --- a/src/common/file_op/tests/unit/tests/test_file_op.c +++ b/src/common/file_op/tests/unit/tests/test_file_op.c @@ -239,190 +239,6 @@ void test_w_is_compressed_bz2_file_uncompressed(void **state) { assert_int_equal(ret, 0); } -// w_uncompress_bz2_gz_file - -#ifdef TEST_SERVER - -void test_w_uncompress_bz2_gz_file_bz2(void **state) { - - char * path = "/test/file.bz2"; - char * dest = "/test/file"; - int ret; - - expect_string(__wrap_fopen, path, "/test/file.bz2"); - expect_string(__wrap_fopen, mode, "rb"); - will_return(__wrap_fopen, 1); - - will_return(__wrap_fread, "BZh"); - will_return(__wrap_fread, 3); - - expect_string(__wrap_bzip2_uncompress, filebz2, "/test/file.bz2"); - expect_string(__wrap_bzip2_uncompress, file, "/test/file"); - will_return(__wrap_bzip2_uncompress, 0); - - expect_string(__wrap_fopen, path, "/test/file.bz2"); - expect_string(__wrap_fopen, mode, "rb"); - will_return(__wrap_fopen, 0); - - expect_string(__wrap__mdebug1, formatted_msg, "The file '/test/file.bz2' was successfully uncompressed into '/test/file'"); - - expect_value(__wrap_fclose, _File, 1); - will_return(__wrap_fclose, 0); - - ret = w_uncompress_bz2_gz_file(path, dest); - assert_int_equal(ret, 0); -} - -void test_MergeAppendFile_open_fail(void **state) { - - FILE * finalfp = (FILE *)5; - char * file = "test.txt"; - int path_offset = -1; - int ret; - - expect_string(__wrap_fopen, path, file); - expect_string(__wrap_fopen, mode, "r"); - will_return(__wrap_fopen, NULL); - - expect_string(__wrap__merror, formatted_msg, "Unable to open file: 'test.txt' due to [(0)-(Success)]."); - - ret = MergeAppendFile(finalfp, file, path_offset); - assert_int_equal(ret, 0); -} - -void test_MergeAppendFile_fseek_fail(void **state) { - - FILE * finalfp = (FILE *)5; - char * file = "test.txt"; - int path_offset = -1; - int ret; - - expect_string(__wrap_fopen, path, file); - expect_string(__wrap_fopen, mode, "r"); - will_return(__wrap_fopen, 6); - - will_return(__wrap_fseek, 1); - - expect_string(__wrap__merror, formatted_msg, "Unable to set EOF offset in file: 'test.txt', due to [(0)-(Success)]."); - - expect_value(__wrap_fclose, _File, 6); - will_return(__wrap_fclose, 1); - - ret = MergeAppendFile(finalfp, file, path_offset); - assert_int_equal(ret, 0); -} - -void test_MergeAppendFile_fseek2_fail(void **state) { - - FILE * finalfp = (FILE *)5; - char * file = "/test/shared/default/test.txt"; - int path_offset = -1; - int ret; - - expect_string(__wrap_fopen, path, file); - expect_string(__wrap_fopen, mode, "r"); - will_return(__wrap_fopen, 6); - - will_return(__wrap_fseek, 0); - - will_return(__wrap_ftell, 0); - expect_string(__wrap__mwarn, formatted_msg, "File '/test/shared/default/test.txt' is empty."); - - expect_value(__wrap_fprintf, __stream, finalfp); - expect_string(__wrap_fprintf, formatted_msg, "!0 test.txt\n"); - will_return(__wrap_fprintf, 0); - - will_return(__wrap_fseek, -2); - - expect_string(__wrap__merror, formatted_msg, "Unable to set the offset in file: '/test/shared/default/test.txt', due to [(0)-(Success)]."); - - expect_value(__wrap_fclose, _File, 6); - will_return(__wrap_fclose, 1); - - ret = MergeAppendFile(finalfp, file, path_offset); - assert_int_equal(ret, 0); -} - -void test_MergeAppendFile_diff_ftell(void **state) { - - FILE * finalfp = (FILE *)5; - char * file = "/test/shared/default/test.txt"; - int path_offset = 0; - int ret; - - expect_string(__wrap_fopen, path, file); - expect_string(__wrap_fopen, mode, "r"); - will_return(__wrap_fopen, 6); - - will_return(__wrap_fseek, 0); - - will_return(__wrap_ftell, 25); - - expect_value(__wrap_fprintf, __stream, finalfp); - expect_string(__wrap_fprintf, formatted_msg, "!25 /test/shared/default/test.txt\n"); - will_return(__wrap_fprintf, 0); - - will_return(__wrap_fseek, 0); - - will_return(__wrap_fread, "test.txt"); - will_return(__wrap_fread, 1); - - will_return(__wrap_fwrite, 0); - - will_return(__wrap_fread, "test.txt"); - will_return(__wrap_fread, 0); - - will_return(__wrap_ftell, 33); - - expect_value(__wrap_fclose, _File, 6); - will_return(__wrap_fclose, 1); - - expect_string(__wrap__merror, formatted_msg, "File '/test/shared/default/test.txt' was modified after getting its size."); - - ret = MergeAppendFile(finalfp, file, path_offset); - assert_int_equal(ret, 0); -} - -void test_MergeAppendFile_success(void **state) { - - FILE * finalfp = (FILE *)5; - char * file = "/test/shared/default/test.txt"; - int path_offset = 0; - int ret; - - expect_string(__wrap_fopen, path, file); - expect_string(__wrap_fopen, mode, "r"); - will_return(__wrap_fopen, 6); - - will_return(__wrap_fseek, 0); - - will_return(__wrap_ftell, 25); - - expect_value(__wrap_fprintf, __stream, finalfp); - expect_string(__wrap_fprintf, formatted_msg, "!25 /test/shared/default/test.txt\n"); - will_return(__wrap_fprintf, 0); - - will_return(__wrap_fseek, 0); - - will_return(__wrap_fread, "test.txt"); - will_return(__wrap_fread, 1); - - will_return(__wrap_fwrite, 0); - - will_return(__wrap_fread, "test.txt"); - will_return(__wrap_fread, 0); - - will_return(__wrap_ftell, 25); - - expect_value(__wrap_fclose, _File, 6); - will_return(__wrap_fclose, 1); - - ret = MergeAppendFile(finalfp, file, path_offset); - assert_int_equal(ret, 1); -} - -#endif - // w_compress_gzfile void test_w_compress_gzfile_wfopen_fail(void **state){ @@ -1120,15 +936,6 @@ int main(void) { cmocka_unit_test(test_w_is_compressed_gz_file_uncompressed), cmocka_unit_test(test_w_is_compressed_bz2_file_compressed), cmocka_unit_test(test_w_is_compressed_bz2_file_uncompressed), -#ifdef TEST_SERVER - cmocka_unit_test(test_w_uncompress_bz2_gz_file_bz2), - // MergeAppendFile - cmocka_unit_test(test_MergeAppendFile_open_fail), - cmocka_unit_test(test_MergeAppendFile_fseek_fail), - cmocka_unit_test(test_MergeAppendFile_fseek2_fail), - cmocka_unit_test(test_MergeAppendFile_diff_ftell), - cmocka_unit_test(test_MergeAppendFile_success), -#endif // w_compress_gzfile cmocka_unit_test(test_w_compress_gzfile_wfopen_fail), cmocka_unit_test(test_w_compress_gzfile_gzopen_fail), diff --git a/src/common/syscheck_op/tests/unit/tests/test_syscheck_op.c b/src/common/syscheck_op/tests/unit/tests/test_syscheck_op.c index e89223df4e..7496ad3130 100644 --- a/src/common/syscheck_op/tests/unit/tests/test_syscheck_op.c +++ b/src/common/syscheck_op/tests/unit/tests/test_syscheck_op.c @@ -47,22 +47,6 @@ typedef struct __sk_decode_data_s { char *w_sum; }sk_decode_data_t; -typedef struct __sk_fill_event_s { - sk_sum_t *sum; - Eventinfo *lf; - char *f_name; -}sk_fill_event_t; - -typedef struct __sk_build_sum_s { - sk_sum_t sum; - char *output; -}sk_build_sum_t; - -typedef struct __unescape_syscheck_field_data_s { - char *input; - char *output; -}unescape_syscheck_field_data_t; - typedef struct __registry_group_information { char *name; char *id; @@ -170,126 +154,6 @@ static int teardown_get_registry_group(void **state) { #endif -#if defined(TEST_SERVER) - -static int setup_sk_decode(void **state) { - sk_decode_data_t *data = calloc(1, sizeof(sk_decode_data_t)); - - if(!data) { - return -1; - } - - *state = data; - return 0; -} - -static int teardown_sk_decode(void **state) { - sk_decode_data_t *data = *state; - - if(data) { - sk_sum_clean(&data->sum); - - if(data->c_sum) - free(data->c_sum); - - if(data->w_sum) - free(data->w_sum); - - free(data); - } - return 0; -} - -static int setup_sk_fill_event(void **state) { - sk_fill_event_t* data = calloc(1, sizeof(sk_fill_event_t)); - - if(!data) { - return -1; - } - - if(data->lf = calloc(1, sizeof(Eventinfo)), data->lf == NULL) { - return -1; - } - - if(data->lf->fields = calloc(FIM_NFIELDS, sizeof(DynamicField)), !data->lf->fields) - return -1; - - data->lf->nfields = FIM_NFIELDS; - - if(data->sum = calloc(1, sizeof(sk_sum_t)), data->sum == NULL) { - return -1; - } - - *state = data; - return 0; -} - -static int teardown_sk_fill_event(void **state) { - sk_fill_event_t* data = *state; - - if(data){ - free(data->f_name); - - free(data->sum); - // sk_sum_clean(&data->sum); - Free_Eventinfo(data->lf); - free(data); - } - return 0; -} - -static int setup_sk_build_sum(void **state) { - sk_build_sum_t* data = calloc(1, sizeof(sk_build_sum_t)); - - if(!data) { - return -1; - } - - if(data->output = calloc(OS_MAXSTR, sizeof(char)), !data->output) - return -1; - - *state = data; - return 0; -} - -static int teardown_sk_build_sum(void **state) { - sk_build_sum_t* data = *state; - - if(data){ - free(data->output); - // sk_sum_clean(&data->sum); - - free(data); - } - return 0; -} - -#endif - -#ifndef TEST_WINAGENT - -static int setup_unescape_syscheck_field(void **state) { - *state = calloc(1, sizeof(unescape_syscheck_field_data_t)); - - if(!*state) { - return -1; - } - return 0; -} - -static int teardown_unescape_syscheck_field(void **state) { - unescape_syscheck_field_data_t *data = *state; - - if(data) { - free(data->input); - free(data->output); - free(data); - } - return 0; -} - -#endif - static int teardown_cjson(void **state) { cJSON *array = *state; @@ -566,1379 +430,7 @@ static void test_remove_empty_folders_error_removing_dir(void **state) { assert_int_equal(ret, -1); } -#if defined(TEST_SERVER) -/* sk_decode_sum tests */ -static void test_sk_decode_sum_no_decode(void **state) { - sk_decode_data_t *data = *state; - - int ret = sk_decode_sum(&data->sum, "-1", NULL); - - assert_int_equal(ret, 1); -} - -static void test_sk_decode_sum_deleted_file(void **state) { - sk_decode_data_t *data = *state; - int ret = 123456789; - - data->c_sum = strdup("-1"); - - ret = sk_decode_sum(&data->sum, data->c_sum, NULL); - - assert_int_equal(ret, 1); -} - -static void test_sk_decode_sum_no_perm(void **state) { - sk_decode_data_t *data = *state; - int ret = 123456789; - - data->c_sum = strdup("size"); - - ret = sk_decode_sum(&data->sum, data->c_sum, NULL); - - assert_int_equal(ret, -1); - assert_ptr_equal(data->sum.size, data->c_sum); -} - -static void test_sk_decode_sum_missing_separator(void **state) { - sk_decode_data_t *data = *state; - int ret = 123456789; - - data->c_sum = strdup("size:"); - - ret = sk_decode_sum(&data->sum, data->c_sum, NULL); - - assert_int_equal(ret, -1); - assert_string_equal(data->sum.size, data->c_sum); -} - -static void test_sk_decode_sum_no_uid(void **state) { - sk_decode_data_t *data = *state; - int ret = 123456789; - - data->c_sum = strdup("size::"); - - ret = sk_decode_sum(&data->sum, data->c_sum, NULL); - - assert_int_equal(ret, -1); - assert_string_equal(data->sum.size, "size"); -} - -static void test_sk_decode_sum_no_gid(void **state) { - sk_decode_data_t *data = *state; - int ret = 123456789; - - data->c_sum = strdup("size:1234:uid"); - - ret = sk_decode_sum(&data->sum, data->c_sum, NULL); - - assert_int_equal(ret, -1); - assert_string_equal(data->sum.size, "size"); - assert_int_equal(data->sum.perm, 1234); - assert_string_equal(data->sum.uid, "uid"); -} - -static void test_sk_decode_sum_no_md5(void **state) { - sk_decode_data_t *data = *state; - int ret = 123456789; - - data->c_sum = strdup("size:1234:uid:gid"); - - ret = sk_decode_sum(&data->sum, data->c_sum, NULL); - - assert_int_equal(ret, -1); - assert_string_equal(data->sum.size, "size"); - assert_int_equal(data->sum.perm, 1234); - assert_string_equal(data->sum.uid, "uid"); - assert_string_equal(data->sum.gid, "gid"); -} - -static void test_sk_decode_sum_no_sha1(void **state) { - sk_decode_data_t *data = *state; - int ret = 123456789; - - data->c_sum = strdup("size:1234:uid:gid:" - "3691689a513ace7e508297b583d7050d"); - - ret = sk_decode_sum(&data->sum, data->c_sum, NULL); - - assert_int_equal(ret, -1); - assert_string_equal(data->sum.size, "size"); - assert_int_equal(data->sum.perm, 1234); - assert_string_equal(data->sum.uid, "uid"); - assert_string_equal(data->sum.gid, "gid"); - assert_string_equal(data->sum.md5, "3691689a513ace7e508297b583d7050d"); -} - -static void test_sk_decode_sum_no_new_fields(void **state) { - sk_decode_data_t *data = *state; - int ret = 123456789; - - data->c_sum = strdup("size:1234:uid:gid:" - "3691689a513ace7e508297b583d7050d:" - "07f05add1049244e7e71ad0f54f24d8094cd8f8b"); - - ret = sk_decode_sum(&data->sum, data->c_sum, NULL); - - assert_int_equal(ret, 0); - assert_string_equal(data->sum.size, "size"); - assert_int_equal(data->sum.perm, 1234); - assert_string_equal(data->sum.uid, "uid"); - assert_string_equal(data->sum.gid, "gid"); - assert_string_equal(data->sum.md5, "3691689a513ace7e508297b583d7050d"); - assert_string_equal(data->sum.sha1, "07f05add1049244e7e71ad0f54f24d8094cd8f8b"); -} - -static void test_sk_decode_sum_win_perm_string(void **state) { - sk_decode_data_t *data = *state; - int ret = 123456789; - - data->c_sum = strdup("size:win_perm:uid:gid:" - "3691689a513ace7e508297b583d7050d:" - "07f05add1049244e7e71ad0f54f24d8094cd8f8b"); - - ret = sk_decode_sum(&data->sum, data->c_sum, NULL); - - assert_int_equal(ret, 0); - assert_string_equal(data->sum.size, "size"); - assert_string_equal(data->sum.win_perm, "win_perm"); - assert_string_equal(data->sum.uid, "uid"); - assert_string_equal(data->sum.gid, "gid"); - assert_string_equal(data->sum.md5, "3691689a513ace7e508297b583d7050d"); - assert_string_equal(data->sum.sha1, "07f05add1049244e7e71ad0f54f24d8094cd8f8b"); - -} - -static void test_sk_decode_sum_win_perm_encoded(void **state) { - sk_decode_data_t *data = *state; - int ret = 123456789; - - data->c_sum = strdup("size:|account,0,4:uid:gid:" - "3691689a513ace7e508297b583d7050d:" - "07f05add1049244e7e71ad0f54f24d8094cd8f8b"); - - ret = sk_decode_sum(&data->sum, data->c_sum, NULL); - - assert_int_equal(ret, 0); - assert_string_equal(data->sum.size, "size"); - assert_string_equal(data->sum.win_perm, "account (allowed): append_data"); - assert_string_equal(data->sum.uid, "uid"); - assert_string_equal(data->sum.gid, "gid"); - assert_string_equal(data->sum.md5, "3691689a513ace7e508297b583d7050d"); - assert_string_equal(data->sum.sha1, "07f05add1049244e7e71ad0f54f24d8094cd8f8b"); -} - -static void test_sk_decode_sum_no_gname(void **state) { - sk_decode_data_t *data = *state; - int ret = 123456789; - - data->c_sum = strdup("size:1234:uid:gid:" - "3691689a513ace7e508297b583d7050d:" - "07f05add1049244e7e71ad0f54f24d8094cd8f8b:"); - - ret = sk_decode_sum(&data->sum, data->c_sum, NULL); - - assert_int_equal(ret, -1); - assert_string_equal(data->sum.size, "size"); - assert_int_equal(data->sum.perm, 1234); - assert_string_equal(data->sum.uid, "uid"); - assert_string_equal(data->sum.gid, "gid"); - assert_string_equal(data->sum.md5, "3691689a513ace7e508297b583d7050d"); - assert_string_equal(data->sum.sha1, "07f05add1049244e7e71ad0f54f24d8094cd8f8b"); -} - -static void test_sk_decode_sum_no_uname(void **state) { - sk_decode_data_t *data = *state; - int ret = 123456789; - - data->c_sum = strdup("size:1234:uid:gid:" - "3691689a513ace7e508297b583d7050d:" - "07f05add1049244e7e71ad0f54f24d8094cd8f8b:" - ":gname"); - - ret = sk_decode_sum(&data->sum, data->c_sum, NULL); - - assert_int_equal(ret, -1); - assert_string_equal(data->sum.size, "size"); - assert_int_equal(data->sum.perm, 1234); - assert_string_equal(data->sum.uid, "uid"); - assert_string_equal(data->sum.gid, "gid"); - assert_string_equal(data->sum.md5, "3691689a513ace7e508297b583d7050d"); - assert_string_equal(data->sum.sha1, "07f05add1049244e7e71ad0f54f24d8094cd8f8b"); - assert_string_equal(data->sum.gname, "gname"); -} - -static void test_sk_decode_sum_no_mtime(void **state) { - sk_decode_data_t *data = *state; - int ret = 123456789; - - data->c_sum = strdup("size:1234:uid:gid:" - "3691689a513ace7e508297b583d7050d:" - "07f05add1049244e7e71ad0f54f24d8094cd8f8b:" - "uname:gname"); - - ret = sk_decode_sum(&data->sum, data->c_sum, NULL); - - assert_int_equal(ret, -1); - assert_string_equal(data->sum.size, "size"); - assert_int_equal(data->sum.perm, 1234); - assert_string_equal(data->sum.uid, "uid"); - assert_string_equal(data->sum.gid, "gid"); - assert_string_equal(data->sum.md5, "3691689a513ace7e508297b583d7050d"); - assert_string_equal(data->sum.sha1, "07f05add1049244e7e71ad0f54f24d8094cd8f8b"); - assert_string_equal(data->sum.gname, "gname"); - assert_string_equal(data->sum.uname, "uname"); -} - -static void test_sk_decode_sum_no_inode(void **state) { - sk_decode_data_t *data = *state; - int ret = 123456789; - - data->c_sum = strdup("size:1234:uid:gid:" - "3691689a513ace7e508297b583d7050d:" - "07f05add1049244e7e71ad0f54f24d8094cd8f8b:" - "uname:gname:2345"); - - ret = sk_decode_sum(&data->sum, data->c_sum, NULL); - - assert_int_equal(ret, -1); - assert_string_equal(data->sum.size, "size"); - assert_int_equal(data->sum.perm, 1234); - assert_string_equal(data->sum.uid, "uid"); - assert_string_equal(data->sum.gid, "gid"); - assert_string_equal(data->sum.md5, "3691689a513ace7e508297b583d7050d"); - assert_string_equal(data->sum.sha1, "07f05add1049244e7e71ad0f54f24d8094cd8f8b"); - assert_string_equal(data->sum.gname, "gname"); - assert_string_equal(data->sum.uname, "uname"); -} - -static void test_sk_decode_sum_no_sha256(void **state) { - sk_decode_data_t *data = *state; - int ret = 123456789; - - data->c_sum = strdup("size:1234:uid:gid:" - "3691689a513ace7e508297b583d7050d:" - "07f05add1049244e7e71ad0f54f24d8094cd8f8b:" - "uname:gname:2345:3456"); - - ret = sk_decode_sum(&data->sum, data->c_sum, NULL); - - assert_int_equal(ret, 0); - assert_string_equal(data->sum.size, "size"); - assert_int_equal(data->sum.perm, 1234); - assert_string_equal(data->sum.uid, "uid"); - assert_string_equal(data->sum.gid, "gid"); - assert_string_equal(data->sum.md5, "3691689a513ace7e508297b583d7050d"); - assert_string_equal(data->sum.sha1, "07f05add1049244e7e71ad0f54f24d8094cd8f8b"); - assert_string_equal(data->sum.gname, "gname"); - assert_string_equal(data->sum.uname, "uname"); - assert_null(data->sum.sha256); -} - -static void test_sk_decode_sum_empty_sha256(void **state) { - sk_decode_data_t *data = *state; - int ret = 123456789; - - data->c_sum = strdup("size:1234:uid:gid:" - "3691689a513ace7e508297b583d7050d:" - "07f05add1049244e7e71ad0f54f24d8094cd8f8b:" - "uname:gname:2345:3456::"); - - ret = sk_decode_sum(&data->sum, data->c_sum, NULL); - - assert_int_equal(ret, 0); - assert_string_equal(data->sum.size, "size"); - assert_int_equal(data->sum.perm, 1234); - assert_string_equal(data->sum.uid, "uid"); - assert_string_equal(data->sum.gid, "gid"); - assert_string_equal(data->sum.md5, "3691689a513ace7e508297b583d7050d"); - assert_string_equal(data->sum.sha1, "07f05add1049244e7e71ad0f54f24d8094cd8f8b"); - assert_string_equal(data->sum.gname, "gname"); - assert_string_equal(data->sum.uname, "uname"); - assert_string_equal(data->sum.sha256, ""); - assert_int_equal(data->sum.mtime, 2345); - assert_int_equal(data->sum.inode, 3456); -} - -static void test_sk_decode_sum_no_attributes(void **state) { - sk_decode_data_t *data = *state; - int ret = 123456789; - - data->c_sum = strdup("size:1234:uid:gid:" - "3691689a513ace7e508297b583d7050d:" - "07f05add1049244e7e71ad0f54f24d8094cd8f8b:" - "uname:gname:2345:3456:" - "672a8ceaea40a441f0268ca9bbb33e99f9643c6262667b61fbe57694df224d40"); - - ret = sk_decode_sum(&data->sum, data->c_sum, NULL); - - assert_int_equal(ret, 0); - assert_string_equal(data->sum.size, "size"); - assert_int_equal(data->sum.perm, 1234); - assert_string_equal(data->sum.uid, "uid"); - assert_string_equal(data->sum.gid, "gid"); - assert_string_equal(data->sum.md5, "3691689a513ace7e508297b583d7050d"); - assert_string_equal(data->sum.sha1, "07f05add1049244e7e71ad0f54f24d8094cd8f8b"); - assert_string_equal(data->sum.gname, "gname"); - assert_string_equal(data->sum.uname, "uname"); - assert_string_equal(data->sum.sha256, "672a8ceaea40a441f0268ca9bbb33e99f9643c6262667b61fbe57694df224d40"); - assert_int_equal(data->sum.mtime, 2345); - assert_int_equal(data->sum.inode, 3456); -} - -static void test_sk_decode_sum_non_numeric_attributes(void **state) { - sk_decode_data_t *data = *state; - int ret = 123456789; - - data->c_sum = strdup("size:1234:uid:gid:" - "3691689a513ace7e508297b583d7050d:" - "07f05add1049244e7e71ad0f54f24d8094cd8f8b:" - "uname:gname:2345:3456:" - "672a8ceaea40a441f0268ca9bbb33e99f9643c6262667b61fbe57694df224d40:" - "attributes"); - - ret = sk_decode_sum(&data->sum, data->c_sum, NULL); - - assert_int_equal(ret, 0); - assert_string_equal(data->sum.size, "size"); - assert_int_equal(data->sum.perm, 1234); - assert_string_equal(data->sum.uid, "uid"); - assert_string_equal(data->sum.gid, "gid"); - assert_string_equal(data->sum.md5, "3691689a513ace7e508297b583d7050d"); - assert_string_equal(data->sum.sha1, "07f05add1049244e7e71ad0f54f24d8094cd8f8b"); - assert_string_equal(data->sum.gname, "gname"); - assert_string_equal(data->sum.uname, "uname"); - assert_string_equal(data->sum.sha256, "672a8ceaea40a441f0268ca9bbb33e99f9643c6262667b61fbe57694df224d40"); - assert_int_equal(data->sum.mtime, 2345); - assert_int_equal(data->sum.inode, 3456); - assert_string_equal(data->sum.attributes, "attributes"); -} - -static void test_sk_decode_sum_win_encoded_attributes(void **state) { - sk_decode_data_t *data = *state; - int ret = 123456789; - - data->c_sum = strdup("size:1234:uid:gid:" - "3691689a513ace7e508297b583d7050d:" - "07f05add1049244e7e71ad0f54f24d8094cd8f8b:" - "uname:gname:2345:3456:" - "672a8ceaea40a441f0268ca9bbb33e99f9643c6262667b61fbe57694df224d40:" - "1"); - - ret = sk_decode_sum(&data->sum, data->c_sum, NULL); - - assert_int_equal(ret, 0); - assert_string_equal(data->sum.size, "size"); - assert_int_equal(data->sum.perm, 1234); - assert_string_equal(data->sum.uid, "uid"); - assert_string_equal(data->sum.gid, "gid"); - assert_string_equal(data->sum.md5, "3691689a513ace7e508297b583d7050d"); - assert_string_equal(data->sum.sha1, "07f05add1049244e7e71ad0f54f24d8094cd8f8b"); - assert_string_equal(data->sum.gname, "gname"); - assert_string_equal(data->sum.uname, "uname"); - assert_string_equal(data->sum.sha256, "672a8ceaea40a441f0268ca9bbb33e99f9643c6262667b61fbe57694df224d40"); - assert_int_equal(data->sum.mtime, 2345); - assert_int_equal(data->sum.inode, 3456); - assert_string_equal(data->sum.attributes, "READONLY"); -} - -static void test_sk_decode_sum_extra_data_empty(void **state) { - sk_decode_data_t *data = *state; - int ret = 123456789; - - data->c_sum = strdup("size:1234:uid:gid:" - "3691689a513ace7e508297b583d7050d:" - "07f05add1049244e7e71ad0f54f24d8094cd8f8b"); - data->w_sum = strdup(""); - - ret = sk_decode_sum(&data->sum, data->c_sum, data->w_sum); - - assert_int_equal(ret, -1); - assert_string_equal(data->sum.size, "size"); - assert_int_equal(data->sum.perm, 1234); - assert_string_equal(data->sum.uid, "uid"); - assert_string_equal(data->sum.gid, "gid"); - assert_string_equal(data->sum.md5, "3691689a513ace7e508297b583d7050d"); - assert_string_equal(data->sum.sha1, "07f05add1049244e7e71ad0f54f24d8094cd8f8b"); -} - -static void test_sk_decode_sum_extra_data_no_user_name(void **state) { - sk_decode_data_t *data = *state; - int ret = 123456789; - - data->c_sum = strdup("size:1234:uid:gid:" - "3691689a513ace7e508297b583d7050d:" - "07f05add1049244e7e71ad0f54f24d8094cd8f8b"); - data->w_sum = strdup("user_id"); - - ret = sk_decode_sum(&data->sum, data->c_sum, data->w_sum); - - assert_int_equal(ret, -1); - assert_string_equal(data->sum.size, "size"); - assert_int_equal(data->sum.perm, 1234); - assert_string_equal(data->sum.uid, "uid"); - assert_string_equal(data->sum.gid, "gid"); - assert_string_equal(data->sum.md5, "3691689a513ace7e508297b583d7050d"); - assert_string_equal(data->sum.sha1, "07f05add1049244e7e71ad0f54f24d8094cd8f8b"); - assert_string_equal(data->sum.wdata.user_id, "user_id"); -} - -static void test_sk_decode_sum_extra_data_no_group_id(void **state) { - sk_decode_data_t *data = *state; - int ret = 123456789; - - data->c_sum = strdup("size:1234:uid:gid:" - "3691689a513ace7e508297b583d7050d:" - "07f05add1049244e7e71ad0f54f24d8094cd8f8b"); - data->w_sum = strdup("user_id:user_name"); - - ret = sk_decode_sum(&data->sum, data->c_sum, data->w_sum); - - assert_int_equal(ret, -1); - assert_string_equal(data->sum.size, "size"); - assert_int_equal(data->sum.perm, 1234); - assert_string_equal(data->sum.uid, "uid"); - assert_string_equal(data->sum.gid, "gid"); - assert_string_equal(data->sum.md5, "3691689a513ace7e508297b583d7050d"); - assert_string_equal(data->sum.sha1, "07f05add1049244e7e71ad0f54f24d8094cd8f8b"); - assert_string_equal(data->sum.wdata.user_id, "user_id"); - assert_null(data->sum.wdata.user_name); -} - -static void test_sk_decode_sum_extra_data_no_group_name(void **state) { - sk_decode_data_t *data = *state; - int ret = 123456789; - - data->c_sum = strdup("size:1234:uid:gid:" - "3691689a513ace7e508297b583d7050d:" - "07f05add1049244e7e71ad0f54f24d8094cd8f8b"); - data->w_sum = strdup("user_id:user_name:group_id"); - - ret = sk_decode_sum(&data->sum, data->c_sum, data->w_sum); - - assert_int_equal(ret, -1); - assert_string_equal(data->sum.size, "size"); - assert_int_equal(data->sum.perm, 1234); - assert_string_equal(data->sum.uid, "uid"); - assert_string_equal(data->sum.gid, "gid"); - assert_string_equal(data->sum.md5, "3691689a513ace7e508297b583d7050d"); - assert_string_equal(data->sum.sha1, "07f05add1049244e7e71ad0f54f24d8094cd8f8b"); - assert_string_equal(data->sum.wdata.user_id, "user_id"); - assert_null(data->sum.wdata.user_name); - assert_string_equal(data->sum.wdata.group_id, "group_id"); -} - -static void test_sk_decode_sum_extra_data_no_process_name(void **state) { - sk_decode_data_t *data = *state; - int ret = 123456789; - - data->c_sum = strdup("size:1234:uid:gid:" - "3691689a513ace7e508297b583d7050d:" - "07f05add1049244e7e71ad0f54f24d8094cd8f8b"); - data->w_sum = strdup("user_id:user_name:group_id:group_name"); - - ret = sk_decode_sum(&data->sum, data->c_sum, data->w_sum); - - assert_int_equal(ret, -1); - assert_string_equal(data->sum.size, "size"); - assert_int_equal(data->sum.perm, 1234); - assert_string_equal(data->sum.uid, "uid"); - assert_string_equal(data->sum.gid, "gid"); - assert_string_equal(data->sum.md5, "3691689a513ace7e508297b583d7050d"); - assert_string_equal(data->sum.sha1, "07f05add1049244e7e71ad0f54f24d8094cd8f8b"); - assert_string_equal(data->sum.wdata.user_id, "user_id"); - assert_null(data->sum.wdata.user_name); - assert_string_equal(data->sum.wdata.group_id, "group_id"); - assert_string_equal(data->sum.wdata.group_name, "group_name"); -} - -static void test_sk_decode_sum_extra_data_no_audit_uid(void **state) { - sk_decode_data_t *data = *state; - int ret = 123456789; - - data->c_sum = strdup("size:1234:uid:gid:" - "3691689a513ace7e508297b583d7050d:" - "07f05add1049244e7e71ad0f54f24d8094cd8f8b"); - data->w_sum = strdup("user_id:user_name:group_id:group_name:process_name"); - - ret = sk_decode_sum(&data->sum, data->c_sum, data->w_sum); - - assert_int_equal(ret, -1); - assert_string_equal(data->sum.size, "size"); - assert_int_equal(data->sum.perm, 1234); - assert_string_equal(data->sum.uid, "uid"); - assert_string_equal(data->sum.gid, "gid"); - assert_string_equal(data->sum.md5, "3691689a513ace7e508297b583d7050d"); - assert_string_equal(data->sum.sha1, "07f05add1049244e7e71ad0f54f24d8094cd8f8b"); - assert_string_equal(data->sum.wdata.user_id, "user_id"); - assert_null(data->sum.wdata.user_name); - assert_string_equal(data->sum.wdata.group_id, "group_id"); - assert_string_equal(data->sum.wdata.group_name, "group_name"); - assert_null(data->sum.wdata.process_name); -} - -static void test_sk_decode_sum_extra_data_no_audit_name(void **state) { - sk_decode_data_t *data = *state; - int ret = 123456789; - - data->c_sum = strdup("size:1234:uid:gid:" - "3691689a513ace7e508297b583d7050d:" - "07f05add1049244e7e71ad0f54f24d8094cd8f8b"); - data->w_sum = strdup("user_id:user_name:group_id:group_name:process_name:" - "audit_uid"); - - ret = sk_decode_sum(&data->sum, data->c_sum, data->w_sum); - - assert_int_equal(ret, -1); - assert_string_equal(data->sum.size, "size"); - assert_int_equal(data->sum.perm, 1234); - assert_string_equal(data->sum.uid, "uid"); - assert_string_equal(data->sum.gid, "gid"); - assert_string_equal(data->sum.md5, "3691689a513ace7e508297b583d7050d"); - assert_string_equal(data->sum.sha1, "07f05add1049244e7e71ad0f54f24d8094cd8f8b"); - assert_string_equal(data->sum.wdata.user_id, "user_id"); - assert_null(data->sum.wdata.user_name); - assert_string_equal(data->sum.wdata.group_id, "group_id"); - assert_string_equal(data->sum.wdata.group_name, "group_name"); - assert_null(data->sum.wdata.process_name); - assert_string_equal(data->sum.wdata.audit_uid, "audit_uid"); -} - -static void test_sk_decode_sum_extra_data_no_effective_uid(void **state) { - sk_decode_data_t *data = *state; - int ret = 123456789; - - data->c_sum = strdup("size:1234:uid:gid:" - "3691689a513ace7e508297b583d7050d:" - "07f05add1049244e7e71ad0f54f24d8094cd8f8b"); - data->w_sum = strdup("user_id:user_name:group_id:group_name:process_name:" - "audit_uid:audit_name"); - - ret = sk_decode_sum(&data->sum, data->c_sum, data->w_sum); - - assert_int_equal(ret, -1); - assert_string_equal(data->sum.size, "size"); - assert_int_equal(data->sum.perm, 1234); - assert_string_equal(data->sum.uid, "uid"); - assert_string_equal(data->sum.gid, "gid"); - assert_string_equal(data->sum.md5, "3691689a513ace7e508297b583d7050d"); - assert_string_equal(data->sum.sha1, "07f05add1049244e7e71ad0f54f24d8094cd8f8b"); - assert_string_equal(data->sum.wdata.user_id, "user_id"); - assert_null(data->sum.wdata.user_name); - assert_string_equal(data->sum.wdata.group_id, "group_id"); - assert_string_equal(data->sum.wdata.group_name, "group_name"); - assert_null(data->sum.wdata.process_name); - assert_string_equal(data->sum.wdata.audit_uid, "audit_uid"); - assert_string_equal(data->sum.wdata.audit_name, "audit_name"); -} - -static void test_sk_decode_sum_extra_data_no_effective_name(void **state) { - sk_decode_data_t *data = *state; - int ret = 123456789; - - data->c_sum = strdup("size:1234:uid:gid:" - "3691689a513ace7e508297b583d7050d:" - "07f05add1049244e7e71ad0f54f24d8094cd8f8b"); - data->w_sum = strdup("user_id:user_name:group_id:group_name:process_name:" - "audit_uid:audit_name:effective_uid"); - - ret = sk_decode_sum(&data->sum, data->c_sum, data->w_sum); - - assert_int_equal(ret, -1); - assert_string_equal(data->sum.size, "size"); - assert_int_equal(data->sum.perm, 1234); - assert_string_equal(data->sum.uid, "uid"); - assert_string_equal(data->sum.gid, "gid"); - assert_string_equal(data->sum.md5, "3691689a513ace7e508297b583d7050d"); - assert_string_equal(data->sum.sha1, "07f05add1049244e7e71ad0f54f24d8094cd8f8b"); - assert_string_equal(data->sum.wdata.user_id, "user_id"); - assert_null(data->sum.wdata.user_name); - assert_string_equal(data->sum.wdata.group_id, "group_id"); - assert_string_equal(data->sum.wdata.group_name, "group_name"); - assert_null(data->sum.wdata.process_name); - assert_string_equal(data->sum.wdata.audit_uid, "audit_uid"); - assert_string_equal(data->sum.wdata.audit_name, "audit_name"); - assert_string_equal(data->sum.wdata.effective_uid, "effective_uid"); -} - -static void test_sk_decode_sum_extra_data_no_ppid(void **state) { - sk_decode_data_t *data = *state; - int ret = 123456789; - - data->c_sum = strdup("size:1234:uid:gid:" - "3691689a513ace7e508297b583d7050d:" - "07f05add1049244e7e71ad0f54f24d8094cd8f8b"); - data->w_sum = strdup("user_id:user_name:group_id:group_name:process_name:" - "audit_uid:audit_name:effective_uid:effective_name"); - - ret = sk_decode_sum(&data->sum, data->c_sum, data->w_sum); - - assert_int_equal(ret, -1); - assert_string_equal(data->sum.size, "size"); - assert_int_equal(data->sum.perm, 1234); - assert_string_equal(data->sum.uid, "uid"); - assert_string_equal(data->sum.gid, "gid"); - assert_string_equal(data->sum.md5, "3691689a513ace7e508297b583d7050d"); - assert_string_equal(data->sum.sha1, "07f05add1049244e7e71ad0f54f24d8094cd8f8b"); - assert_string_equal(data->sum.wdata.user_id, "user_id"); - assert_null(data->sum.wdata.user_name); - assert_string_equal(data->sum.wdata.group_id, "group_id"); - assert_string_equal(data->sum.wdata.group_name, "group_name"); - assert_null(data->sum.wdata.process_name); - assert_string_equal(data->sum.wdata.audit_uid, "audit_uid"); - assert_string_equal(data->sum.wdata.audit_name, "audit_name"); - assert_string_equal(data->sum.wdata.effective_uid, "effective_uid"); - assert_string_equal(data->sum.wdata.effective_name, "effective_name"); -} - -static void test_sk_decode_sum_extra_data_no_process_id(void **state) { - sk_decode_data_t *data = *state; - int ret = 123456789; - - data->c_sum = strdup("size:1234:uid:gid:" - "3691689a513ace7e508297b583d7050d:" - "07f05add1049244e7e71ad0f54f24d8094cd8f8b"); - data->w_sum = strdup("user_id:user_name:group_id:group_name:process_name:" - "audit_uid:audit_name:effective_uid:effective_name:ppid"); - - ret = sk_decode_sum(&data->sum, data->c_sum, data->w_sum); - - assert_int_equal(ret, -1); - assert_string_equal(data->sum.size, "size"); - assert_int_equal(data->sum.perm, 1234); - assert_string_equal(data->sum.uid, "uid"); - assert_string_equal(data->sum.gid, "gid"); - assert_string_equal(data->sum.md5, "3691689a513ace7e508297b583d7050d"); - assert_string_equal(data->sum.sha1, "07f05add1049244e7e71ad0f54f24d8094cd8f8b"); - assert_string_equal(data->sum.wdata.user_id, "user_id"); - assert_null(data->sum.wdata.user_name); - assert_string_equal(data->sum.wdata.group_id, "group_id"); - assert_string_equal(data->sum.wdata.group_name, "group_name"); - assert_null(data->sum.wdata.process_name); - assert_string_equal(data->sum.wdata.audit_uid, "audit_uid"); - assert_string_equal(data->sum.wdata.audit_name, "audit_name"); - assert_string_equal(data->sum.wdata.effective_uid, "effective_uid"); - assert_string_equal(data->sum.wdata.effective_name, "effective_name"); - assert_string_equal(data->sum.wdata.ppid, "ppid"); -} - -static void test_sk_decode_sum_extra_data_no_tag(void **state) { - sk_decode_data_t *data = *state; - int ret = 123456789; - - data->c_sum = strdup("size:1234:uid:gid:" - "3691689a513ace7e508297b583d7050d:" - "07f05add1049244e7e71ad0f54f24d8094cd8f8b"); - data->w_sum = strdup("user_id:user_name:group_id:group_name:process_name:" - "audit_uid:audit_name:effective_uid:effective_name:ppid:process_id"); - - ret = sk_decode_sum(&data->sum, data->c_sum, data->w_sum); - - assert_int_equal(ret, 0); - assert_string_equal(data->sum.size, "size"); - assert_int_equal(data->sum.perm, 1234); - assert_string_equal(data->sum.uid, "uid"); - assert_string_equal(data->sum.gid, "gid"); - assert_string_equal(data->sum.md5, "3691689a513ace7e508297b583d7050d"); - assert_string_equal(data->sum.sha1, "07f05add1049244e7e71ad0f54f24d8094cd8f8b"); - assert_string_equal(data->sum.wdata.user_id, "user_id"); - assert_string_equal(data->sum.wdata.user_name, "user_name"); - assert_string_equal(data->sum.wdata.group_id, "group_id"); - assert_string_equal(data->sum.wdata.group_name, "group_name"); - assert_string_equal(data->sum.wdata.process_name, "process_name"); - assert_string_equal(data->sum.wdata.audit_uid, "audit_uid"); - assert_string_equal(data->sum.wdata.audit_name, "audit_name"); - assert_string_equal(data->sum.wdata.effective_uid, "effective_uid"); - assert_string_equal(data->sum.wdata.effective_name, "effective_name"); - assert_string_equal(data->sum.wdata.ppid, "ppid"); - assert_string_equal(data->sum.wdata.process_id, "process_id"); - assert_null(data->sum.tag); - assert_null(data->sum.symbolic_path); -} - -static void test_sk_decode_sum_extra_data_no_symbolic_path(void **state) { - sk_decode_data_t *data = *state; - int ret = 123456789; - - data->c_sum = strdup("size:1234:uid:gid:" - "3691689a513ace7e508297b583d7050d:" - "07f05add1049244e7e71ad0f54f24d8094cd8f8b"); - data->w_sum = strdup("user_id:user_name:group_id:group_name:process_name:" - "audit_uid:audit_name:effective_uid:effective_name:" - "ppid:process_id:tag"); - - ret = sk_decode_sum(&data->sum, data->c_sum, data->w_sum); - - assert_int_equal(ret, 0); - assert_string_equal(data->sum.size, "size"); - assert_int_equal(data->sum.perm, 1234); - assert_string_equal(data->sum.uid, "uid"); - assert_string_equal(data->sum.gid, "gid"); - assert_string_equal(data->sum.md5, "3691689a513ace7e508297b583d7050d"); - assert_string_equal(data->sum.sha1, "07f05add1049244e7e71ad0f54f24d8094cd8f8b"); - assert_string_equal(data->sum.wdata.user_id, "user_id"); - assert_string_equal(data->sum.wdata.user_name, "user_name"); - assert_string_equal(data->sum.wdata.group_id, "group_id"); - assert_string_equal(data->sum.wdata.group_name, "group_name"); - assert_string_equal(data->sum.wdata.process_name, "process_name"); - assert_string_equal(data->sum.wdata.audit_uid, "audit_uid"); - assert_string_equal(data->sum.wdata.audit_name, "audit_name"); - assert_string_equal(data->sum.wdata.effective_uid, "effective_uid"); - assert_string_equal(data->sum.wdata.effective_name, "effective_name"); - assert_string_equal(data->sum.wdata.ppid, "ppid"); - assert_string_equal(data->sum.wdata.process_id, "process_id"); - assert_string_equal(data->sum.tag, "tag"); - assert_null(data->sum.symbolic_path); -} - -static void test_sk_decode_sum_extra_data_no_inode(void **state) { - sk_decode_data_t *data = *state; - int ret = 123456789; - - data->c_sum = strdup("size:1234:uid:gid:" - "3691689a513ace7e508297b583d7050d:" - "07f05add1049244e7e71ad0f54f24d8094cd8f8b"); - data->w_sum = strdup("user_id:user_name:group_id:group_name:process_name:" - "audit_uid:audit_name:effective_uid:effective_name:" - "ppid:process_id:tag:symbolic_path"); - - ret = sk_decode_sum(&data->sum, data->c_sum, data->w_sum); - - assert_int_equal(ret, 0); - assert_string_equal(data->sum.size, "size"); - assert_int_equal(data->sum.perm, 1234); - assert_string_equal(data->sum.uid, "uid"); - assert_string_equal(data->sum.gid, "gid"); - assert_string_equal(data->sum.md5, "3691689a513ace7e508297b583d7050d"); - assert_string_equal(data->sum.sha1, "07f05add1049244e7e71ad0f54f24d8094cd8f8b"); - assert_string_equal(data->sum.wdata.user_id, "user_id"); - assert_string_equal(data->sum.wdata.user_name, "user_name"); - assert_string_equal(data->sum.wdata.group_id, "group_id"); - assert_string_equal(data->sum.wdata.group_name, "group_name"); - assert_string_equal(data->sum.wdata.process_name, "process_name"); - assert_string_equal(data->sum.wdata.audit_uid, "audit_uid"); - assert_string_equal(data->sum.wdata.audit_name, "audit_name"); - assert_string_equal(data->sum.wdata.effective_uid, "effective_uid"); - assert_string_equal(data->sum.wdata.effective_name, "effective_name"); - assert_string_equal(data->sum.wdata.ppid, "ppid"); - assert_string_equal(data->sum.wdata.process_id, "process_id"); - assert_string_equal(data->sum.tag, "tag"); - assert_string_equal(data->sum.symbolic_path, "symbolic_path"); -} - -static void test_sk_decode_sum_extra_data_all_fields(void **state) { - sk_decode_data_t *data = *state; - int ret = 123456789; - - data->c_sum = strdup("size:1234:uid:gid:" - "3691689a513ace7e508297b583d7050d:" - "07f05add1049244e7e71ad0f54f24d8094cd8f8b"); - data->w_sum = strdup("user_id:user_name:group_id:group_name:process_name:" - "audit_uid:audit_name:effective_uid:effective_name:" - "ppid:process_id:tag:symbolic_path:-"); - - data->sum.silent = 0; - - ret = sk_decode_sum(&data->sum, data->c_sum, data->w_sum); - - assert_int_equal(ret, 0); - assert_string_equal(data->sum.size, "size"); - assert_int_equal(data->sum.perm, 1234); - assert_string_equal(data->sum.uid, "uid"); - assert_string_equal(data->sum.gid, "gid"); - assert_string_equal(data->sum.md5, "3691689a513ace7e508297b583d7050d"); - assert_string_equal(data->sum.sha1, "07f05add1049244e7e71ad0f54f24d8094cd8f8b"); - assert_string_equal(data->sum.wdata.user_id, "user_id"); - assert_string_equal(data->sum.wdata.user_name, "user_name"); - assert_string_equal(data->sum.wdata.group_id, "group_id"); - assert_string_equal(data->sum.wdata.group_name, "group_name"); - assert_string_equal(data->sum.wdata.process_name, "process_name"); - assert_string_equal(data->sum.wdata.audit_uid, "audit_uid"); - assert_string_equal(data->sum.wdata.audit_name, "audit_name"); - assert_string_equal(data->sum.wdata.effective_uid, "effective_uid"); - assert_string_equal(data->sum.wdata.effective_name, "effective_name"); - assert_string_equal(data->sum.wdata.ppid, "ppid"); - assert_string_equal(data->sum.wdata.process_id, "process_id"); - assert_string_equal(data->sum.tag, "tag"); - assert_string_equal(data->sum.symbolic_path, "symbolic_path"); - assert_int_equal(data->sum.silent, 0); -} - -static void test_sk_decode_sum_extra_data_all_fields_silent(void **state) { - sk_decode_data_t *data = *state; - int ret = 123456789; - - data->c_sum = strdup("size:1234:uid:gid:" - "3691689a513ace7e508297b583d7050d:" - "07f05add1049244e7e71ad0f54f24d8094cd8f8b"); - data->w_sum = strdup("user_id:user_name:group_id:group_name:process_name:" - "audit_uid:audit_name:effective_uid:effective_name:" - "ppid:process_id:tag:symbolic_path:+"); - - data->sum.silent = 0; - - ret = sk_decode_sum(&data->sum, data->c_sum, data->w_sum); - - assert_int_equal(ret, 0); - assert_string_equal(data->sum.size, "size"); - assert_int_equal(data->sum.perm, 1234); - assert_string_equal(data->sum.uid, "uid"); - assert_string_equal(data->sum.gid, "gid"); - assert_string_equal(data->sum.md5, "3691689a513ace7e508297b583d7050d"); - assert_string_equal(data->sum.sha1, "07f05add1049244e7e71ad0f54f24d8094cd8f8b"); - assert_string_equal(data->sum.wdata.user_id, "user_id"); - assert_string_equal(data->sum.wdata.user_name, "user_name"); - assert_string_equal(data->sum.wdata.group_id, "group_id"); - assert_string_equal(data->sum.wdata.group_name, "group_name"); - assert_string_equal(data->sum.wdata.process_name, "process_name"); - assert_string_equal(data->sum.wdata.audit_uid, "audit_uid"); - assert_string_equal(data->sum.wdata.audit_name, "audit_name"); - assert_string_equal(data->sum.wdata.effective_uid, "effective_uid"); - assert_string_equal(data->sum.wdata.effective_name, "effective_name"); - assert_string_equal(data->sum.wdata.ppid, "ppid"); - assert_string_equal(data->sum.wdata.process_id, "process_id"); - assert_string_equal(data->sum.tag, "tag"); - assert_string_equal(data->sum.symbolic_path, "symbolic_path"); - assert_int_equal(data->sum.silent, 1); -} - -static void test_sk_decode_sum_extra_data_null_ppid(void **state) { - sk_decode_data_t *data = *state; - int ret = 123456789; - - data->c_sum = strdup("size:1234:uid:gid:" - "3691689a513ace7e508297b583d7050d:" - "07f05add1049244e7e71ad0f54f24d8094cd8f8b"); - data->w_sum = strdup("user_id:user_name:group_id:group_name:process_name:" - "audit_uid:audit_name:effective_uid:effective_name:" - "-:process_id:tag:symbolic_path:+"); - - ret = sk_decode_sum(&data->sum, data->c_sum, data->w_sum); - - assert_int_equal(ret, 0); - assert_string_equal(data->sum.size, "size"); - assert_int_equal(data->sum.perm, 1234); - assert_string_equal(data->sum.uid, "uid"); - assert_string_equal(data->sum.gid, "gid"); - assert_string_equal(data->sum.md5, "3691689a513ace7e508297b583d7050d"); - assert_string_equal(data->sum.sha1, "07f05add1049244e7e71ad0f54f24d8094cd8f8b"); - assert_string_equal(data->sum.wdata.user_id, "user_id"); - assert_string_equal(data->sum.wdata.user_name, "user_name"); - assert_string_equal(data->sum.wdata.group_id, "group_id"); - assert_string_equal(data->sum.wdata.group_name, "group_name"); - assert_string_equal(data->sum.wdata.process_name, "process_name"); - assert_string_equal(data->sum.wdata.audit_uid, "audit_uid"); - assert_string_equal(data->sum.wdata.audit_name, "audit_name"); - assert_string_equal(data->sum.wdata.effective_uid, "effective_uid"); - assert_string_equal(data->sum.wdata.effective_name, "effective_name"); - assert_null(data->sum.wdata.ppid); - assert_string_equal(data->sum.wdata.process_id, "process_id"); - assert_string_equal(data->sum.tag, "tag"); - assert_string_equal(data->sum.symbolic_path, "symbolic_path"); - assert_int_equal(data->sum.silent, 1); -} - -// TODO: Validate this condition is required to be tested -static void test_sk_decode_sum_extra_data_null_sum(void **state) { - sk_decode_data_t *data = *state; - - data->c_sum = strdup("size:1234:uid:gid:" - "3691689a513ace7e508297b583d7050d:" - "07f05add1049244e7e71ad0f54f24d8094cd8f8b"); - - expect_assert_failure(sk_decode_sum(NULL, data->c_sum, NULL)); -} - -// TODO: Validate this condition is required to be tested -static void test_sk_decode_sum_extra_data_null_c_sum(void **state) { - sk_decode_data_t *data = *state; - - expect_assert_failure(sk_decode_sum(&data->sum, NULL, NULL)); -} - -/* sk_decode_extradata tests */ -static void test_sk_decode_extradata_null_sum(void **state) { - sk_decode_data_t *data = *state; - data->c_sum = strdup("some string"); - - expect_assert_failure(sk_decode_extradata(NULL, data->c_sum)); -} - -static void test_sk_decode_extradata_null_c_sum(void **state) { - sk_decode_data_t *data = *state; - - expect_assert_failure(sk_decode_extradata(&data->sum, NULL)); -} - -static void test_sk_decode_extradata_no_changes(void **state) { - sk_decode_data_t *data = *state; - int ret = 12345; - - data->c_sum = strdup("some string"); - - ret = sk_decode_extradata(&data->sum, data->c_sum); - - assert_int_equal(ret, 0); - assert_string_equal(data->c_sum, "some string"); -} - -static void test_sk_decode_extradata_no_date_alert(void **state) { - sk_decode_data_t *data = *state; - int ret = 12345; - - data->c_sum = strdup("some string!15"); - - ret = sk_decode_extradata(&data->sum, data->c_sum); - - assert_int_equal(ret, 0); - assert_string_equal(data->c_sum, "some string"); - assert_string_equal(data->c_sum + 12, "15"); -} - -static void test_sk_decode_extradata_no_sym_path(void **state) { - sk_decode_data_t *data = *state; - int ret = 12345; - - data->c_sum = strdup("some string!15:20"); - - data->sum.symbolic_path = NULL; - - ret = sk_decode_extradata(&data->sum, data->c_sum); - - assert_int_equal(ret, 1); - assert_string_equal(data->c_sum, "some string"); - assert_string_equal(data->c_sum + 12, "15"); - assert_string_equal(data->c_sum + 15, "20"); - assert_int_equal(data->sum.changes, 15); - assert_int_equal(data->sum.date_alert, 20); - assert_null(data->sum.symbolic_path); -} - -static void test_sk_decode_extradata_all_fields(void **state) { - sk_decode_data_t *data = *state; - int ret = 12345; - - data->c_sum = strdup("some string!15:20:a symbolic path"); - - data->sum.symbolic_path = NULL; - - ret = sk_decode_extradata(&data->sum, data->c_sum); - - assert_int_equal(ret, 1); - assert_string_equal(data->c_sum, "some string"); - assert_string_equal(data->c_sum + 12, "15"); - assert_string_equal(data->c_sum + 15, "20"); - assert_int_equal(data->sum.changes, 15); - assert_int_equal(data->sum.date_alert, 20); - assert_string_equal(data->sum.symbolic_path, "a symbolic path"); -} - -/* sk_fill_event tests */ -static void test_sk_fill_event_full_event(void **state) { - sk_fill_event_t *data = *state; - - data->f_name = strdup("f_name"); - - data->sum->size = "size"; - data->sum->perm = 123456; // 361100 in octal - data->sum->uid = "uid"; - data->sum->gid = "gid"; - data->sum->md5 = "md5"; - data->sum->sha1 = "sha1"; - data->sum->uname = "uname"; - data->sum->gname = "gname"; - data->sum->mtime = 2345678; - data->sum->inode = 3456789; - data->sum->sha256 = "sha256"; - data->sum->attributes = "attributes"; - data->sum->wdata.user_id = "user_id"; - data->sum->wdata.user_name = "user_name"; - data->sum->wdata.group_id = "group_id"; - data->sum->wdata.group_name = "group_name"; - data->sum->wdata.process_name = "process_name"; - data->sum->wdata.audit_uid = "audit_uid"; - data->sum->wdata.audit_name = "audit_name"; - data->sum->wdata.effective_uid = "effective_uid"; - data->sum->wdata.effective_name = "effective_name"; - data->sum->wdata.ppid = "ppid"; - data->sum->wdata.process_id = "process_id"; - data->sum->tag = "tag"; - data->sum->symbolic_path = "symbolic_path"; - - sk_fill_event(data->lf, data->f_name, data->sum); - - assert_string_equal(data->lf->fields[FIM_FILE].value, "f_name"); - assert_string_equal(data->lf->fields[FIM_FILE].value, "f_name"); - assert_string_equal(data->lf->fields[FIM_SIZE].value, "size"); - assert_string_equal(data->lf->fields[FIM_PERM].value, "361100"); - assert_string_equal(data->lf->fields[FIM_UID].value, "uid"); - assert_string_equal(data->lf->fields[FIM_GID].value, "gid"); - assert_string_equal(data->lf->fields[FIM_MD5].value, "md5"); - assert_string_equal(data->lf->fields[FIM_SHA1].value, "sha1"); - assert_string_equal(data->lf->fields[FIM_UNAME].value, "uname"); - assert_string_equal(data->lf->fields[FIM_GNAME].value, "gname"); - assert_string_equal(data->lf->fields[FIM_MTIME].value, "2345678"); - assert_string_equal(data->lf->fields[FIM_INODE].value, "3456789"); - assert_string_equal(data->lf->fields[FIM_SHA256].value, "sha256"); - assert_string_equal(data->lf->fields[FIM_ATTRS].value, "attributes"); - assert_string_equal(data->lf->fields[FIM_USER_ID].value, "user_id"); - assert_string_equal(data->lf->fields[FIM_USER_NAME].value, "user_name"); - assert_string_equal(data->lf->fields[FIM_GROUP_ID].value, "group_id"); - assert_string_equal(data->lf->fields[FIM_GROUP_NAME].value, "group_name"); - assert_string_equal(data->lf->fields[FIM_PROC_NAME].value, "process_name"); - assert_string_equal(data->lf->fields[FIM_AUDIT_ID].value, "audit_uid"); - assert_string_equal(data->lf->fields[FIM_AUDIT_NAME].value, "audit_name"); - assert_string_equal(data->lf->fields[FIM_EFFECTIVE_UID].value, "effective_uid"); - assert_string_equal(data->lf->fields[FIM_EFFECTIVE_NAME].value, "effective_name"); - assert_string_equal(data->lf->fields[FIM_PPID].value, "ppid"); - assert_string_equal(data->lf->fields[FIM_PROC_ID].value, "process_id"); - - assert_string_equal(data->lf->fields[FIM_TAG].value, "tag"); - - assert_string_equal(data->lf->fields[FIM_SYM_PATH].value, "symbolic_path"); -} - -static void test_sk_fill_event_empty_event(void **state) { - sk_fill_event_t *data = *state; - - data->f_name = strdup("f_name"); - - sk_fill_event(data->lf, data->f_name, data->sum); - - assert_string_equal(data->lf->fields[FIM_FILE].value, "f_name"); - assert_null(data->lf->fields[FIM_SIZE].value); - assert_null(data->lf->fields[FIM_PERM].value); - assert_null(data->lf->fields[FIM_UID].value); - assert_null(data->lf->fields[FIM_GID].value); - assert_null(data->lf->fields[FIM_MD5].value); - assert_null(data->lf->fields[FIM_SHA1].value); - assert_null(data->lf->fields[FIM_UNAME].value); - assert_null(data->lf->fields[FIM_GNAME].value); - assert_null(data->lf->fields[FIM_MTIME].value); - assert_null(data->lf->fields[FIM_INODE].value); - assert_null(data->lf->fields[FIM_SHA256].value); - assert_null(data->lf->fields[FIM_ATTRS].value); - assert_null(data->lf->fields[FIM_USER_ID].value); - assert_null(data->lf->fields[FIM_USER_NAME].value); - assert_null(data->lf->fields[FIM_GROUP_ID].value); - assert_null(data->lf->fields[FIM_GROUP_NAME].value); - assert_null(data->lf->fields[FIM_PROC_NAME].value); - assert_null(data->lf->fields[FIM_AUDIT_ID].value); - assert_null(data->lf->fields[FIM_AUDIT_NAME].value); - assert_null(data->lf->fields[FIM_EFFECTIVE_UID].value); - assert_null(data->lf->fields[FIM_EFFECTIVE_NAME].value); - assert_null(data->lf->fields[FIM_PPID].value); - assert_null(data->lf->fields[FIM_PROC_ID].value); - - assert_null(data->lf->fields[FIM_TAG].value); - - assert_null(data->lf->fields[FIM_SYM_PATH].value); -} - -static void test_sk_fill_event_win_perm(void **state) { - sk_fill_event_t *data = *state; - - data->f_name = strdup("f_name"); - - data->sum->win_perm = "win_perm"; - - sk_fill_event(data->lf, data->f_name, data->sum); - - assert_string_equal(data->lf->fields[FIM_FILE].value, "f_name"); - assert_null(data->lf->fields[FIM_SIZE].value); - assert_string_equal(data->lf->fields[FIM_PERM].value, "win_perm"); - assert_null(data->lf->fields[FIM_UID].value); - assert_null(data->lf->fields[FIM_GID].value); - assert_null(data->lf->fields[FIM_MD5].value); - assert_null(data->lf->fields[FIM_SHA1].value); - assert_null(data->lf->fields[FIM_UNAME].value); - assert_null(data->lf->fields[FIM_GNAME].value); - assert_null(data->lf->fields[FIM_MTIME].value); - assert_null(data->lf->fields[FIM_INODE].value); - assert_null(data->lf->fields[FIM_SHA256].value); - assert_null(data->lf->fields[FIM_ATTRS].value); - assert_null(data->lf->fields[FIM_USER_ID].value); - assert_null(data->lf->fields[FIM_USER_NAME].value); - assert_null(data->lf->fields[FIM_GROUP_ID].value); - assert_null(data->lf->fields[FIM_GROUP_NAME].value); - assert_null(data->lf->fields[FIM_PROC_NAME].value); - assert_null(data->lf->fields[FIM_AUDIT_ID].value); - assert_null(data->lf->fields[FIM_AUDIT_NAME].value); - assert_null(data->lf->fields[FIM_EFFECTIVE_UID].value); - assert_null(data->lf->fields[FIM_EFFECTIVE_NAME].value); - assert_null(data->lf->fields[FIM_PPID].value); - assert_null(data->lf->fields[FIM_PROC_ID].value); - - assert_null(data->lf->fields[FIM_TAG].value); - - assert_null(data->lf->fields[FIM_SYM_PATH].value); -} - -static void test_sk_fill_event_null_eventinfo(void **state) { - sk_fill_event_t *data = *state; - - data->f_name = strdup("f_name"); - - data->sum->win_perm = "win_perm"; - - expect_assert_failure(sk_fill_event(NULL, data->f_name, data->sum)); -} - -static void test_sk_fill_event_null_f_name(void **state) { - sk_fill_event_t *data = *state; - - data->sum->win_perm = "win_perm"; - - expect_assert_failure(sk_fill_event(data->lf, NULL, data->sum)); -} - -// TODO: Validate this condition is required to be tested -static void test_sk_fill_event_null_sum(void **state) { - sk_fill_event_t *data = *state; - - data->f_name = strdup("f_name"); - - expect_assert_failure(sk_fill_event(data->lf, data->f_name, NULL)); -} - -/* sk_build_sum tests */ -static void test_sk_build_sum_full_message(void **state) { - sk_build_sum_t *data = *state; - int ret; - - data->sum.size = "size"; - data->sum.perm = 123456; - data->sum.win_perm = NULL; - data->sum.uid = "uid"; - data->sum.gid = "gid"; - data->sum.md5 = "md5"; - data->sum.sha1 = "sha1"; - data->sum.uname = "username"; - data->sum.gname = "gname"; - data->sum.mtime = 234567; - data->sum.inode = 345678; - data->sum.sha256 = "sha256"; - data->sum.attributes = "attributes"; - data->sum.changes = 456789; - data->sum.date_alert = 567890; - - ret = sk_build_sum(&data->sum, data->output, OS_MAXSTR); - - assert_int_equal(ret, 0); - assert_string_equal(data->output, - "size:123456:uid:gid:md5:sha1:username:gname:234567:345678:sha256:attributes!456789:567890"); -} - -static void test_sk_build_sum_skip_fields_message(void **state) { - sk_build_sum_t *data = *state; - int ret; - - data->sum.size = "size"; - data->sum.perm = 0; - data->sum.win_perm = NULL; - data->sum.uid = "uid"; - data->sum.gid = "gid"; - data->sum.md5 = "md5"; - data->sum.sha1 = "sha1"; - data->sum.uname = NULL; - data->sum.gname = NULL; - data->sum.mtime = 0; - data->sum.inode = 0; - data->sum.sha256 = NULL; - data->sum.attributes = NULL; - data->sum.changes = 0; - data->sum.date_alert = 0; - - ret = sk_build_sum(&data->sum, data->output, OS_MAXSTR); - - assert_int_equal(ret, 0); - assert_string_equal(data->output, "size::uid:gid:md5:sha1::::::!0:0"); -} - -static void test_sk_build_sum_win_perm(void **state) { - sk_build_sum_t *data = *state; - int ret; - - data->sum.size = "size"; - data->sum.perm = 0; - data->sum.win_perm = "win_perm"; - data->sum.uid = "uid"; - data->sum.gid = "gid"; - data->sum.md5 = "md5"; - data->sum.sha1 = "sha1"; - data->sum.uname = NULL; - data->sum.gname = NULL; - data->sum.mtime = 0; - data->sum.inode = 0; - data->sum.sha256 = NULL; - data->sum.attributes = NULL; - data->sum.changes = 0; - data->sum.date_alert = 0; - - ret = sk_build_sum(&data->sum, data->output, OS_MAXSTR); - - assert_int_equal(ret, 0); - assert_string_equal(data->output, "size:win_perm:uid:gid:md5:sha1::::::!0:0"); -} - -static void test_sk_build_sum_insufficient_buffer_size(void **state) { - sk_build_sum_t *data = *state; - int ret; - - data->sum.size = "size"; - data->sum.perm = 0; - data->sum.win_perm = "win_perm"; - data->sum.uid = "uid"; - data->sum.gid = "gid"; - data->sum.md5 = "md5"; - data->sum.sha1 = "sha1"; - data->sum.uname = NULL; - data->sum.gname = NULL; - data->sum.mtime = 0; - data->sum.inode = 0; - data->sum.sha256 = NULL; - data->sum.attributes = NULL; - data->sum.changes = 0; - data->sum.date_alert = 0; - - ret = sk_build_sum(&data->sum, data->output, 10); - - assert_int_equal(ret, -1); - assert_string_equal(data->output, "size:win_"); -} - -static void test_sk_build_sum_null_sum(void **state) { - sk_build_sum_t *data = *state; - - expect_assert_failure(sk_build_sum(NULL, data->output, OS_MAXSTR)); -} - -static void test_sk_build_sum_null_output(void **state) { - sk_build_sum_t *data = *state; - - expect_assert_failure(sk_build_sum(&data->sum, NULL, OS_MAXSTR)); -} - -/* sk_sum_clean tests */ -static void test_sk_sum_clean_full_message(void **state) { - sk_decode_data_t *data = *state; - int ret; - - data->c_sum = strdup("size:1234:uid:gid:" - "3691689a513ace7e508297b583d7050d:" - "07f05add1049244e7e71ad0f54f24d8094cd8f8b:" - "uname:gname:2345:3456:" - "672a8ceaea40a441f0268ca9bbb33e99f9643c6262667b61fbe57694df224d40:" - "1"); - data->w_sum = strdup("user_id:user_name:group_id:group_name:process_name:" - "audit_uid:audit_name:effective_uid:effective_name:" - "ppid:process_id:tag:symbolic_path:-"); - - // Fill sum with as many info as possible - ret = sk_decode_sum(&data->sum, data->c_sum, data->w_sum); - assert_int_equal(ret, 0); - - // And free it - sk_sum_clean(&data->sum); - - assert_null(data->sum.symbolic_path); - assert_null(data->sum.attributes); - assert_null(data->sum.wdata.user_name); - assert_null(data->sum.wdata.process_name); - assert_null(data->sum.uname); - assert_null(data->sum.win_perm); -} - -static void test_sk_sum_clean_shortest_valid_message(void **state) { - sk_decode_data_t *data = *state; - int ret; - - data->c_sum = strdup("size:1234:uid:gid:" - "3691689a513ace7e508297b583d7050d:" - "07f05add1049244e7e71ad0f54f24d8094cd8f8b:" - "uname:gname:2345:3456"); - - // Fill sum with as many info as possible - ret = sk_decode_sum(&data->sum, data->c_sum, data->w_sum); - assert_int_equal(ret, 0); - - // And free it - sk_sum_clean(&data->sum); - - assert_null(data->sum.symbolic_path); - assert_null(data->sum.attributes); - assert_null(data->sum.wdata.user_name); - assert_null(data->sum.wdata.process_name); - assert_null(data->sum.uname); - assert_null(data->sum.win_perm); -} - -static void test_sk_sum_clean_invalid_message(void **state) { - sk_decode_data_t *data = *state; - int ret; - - data->c_sum = strdup("This is not a valid syscheck message"); - - // Fill sum with as many info as possible - ret = sk_decode_sum(&data->sum, data->c_sum, data->w_sum); - assert_int_equal(ret, -1); - - // And free it - sk_sum_clean(&data->sum); - - assert_null(data->sum.symbolic_path); - assert_null(data->sum.attributes); - assert_null(data->sum.wdata.user_name); - assert_null(data->sum.wdata.process_name); - assert_null(data->sum.uname); - assert_null(data->sum.win_perm); -} - -// TODO: Validate this condition is required to be tested -static void test_sk_sum_clean_null_sum(void **state) { - expect_assert_failure(sk_sum_clean(NULL)); -} -#endif #ifndef TEST_WINAGENT -/* unescape_syscheck_field tests */ -static void test_unescape_syscheck_field_escaped_chars(void **state) { - unescape_syscheck_field_data_t *data = *state; - - data->input = strdup("Hi\\!! This\\ is\\ a string with\\: escaped chars:"); - - data->output = unescape_syscheck_field(data->input); - - assert_string_equal(data->output, "Hi!! This is a string with: escaped chars:"); -} - -static void test_unescape_syscheck_field_no_escaped_chars(void **state) { - unescape_syscheck_field_data_t *data = *state; - - data->input = strdup("Hi!! This is a string without: escaped chars:"); - - data->output = unescape_syscheck_field(data->input); - - assert_string_equal(data->output, "Hi!! This is a string without: escaped chars:"); -} - -static void test_unescape_syscheck_null_input(void **state) { - unescape_syscheck_field_data_t *data = *state; - - data->input = NULL; - - data->output = unescape_syscheck_field(data->input); - - assert_null(data->output); -} - -static void test_unescape_syscheck_empty_string(void **state) { - unescape_syscheck_field_data_t *data = *state; - - data->input = strdup(""); - - data->output = unescape_syscheck_field(data->input); - - assert_null(data->output); -} /* get_user tests */ static void test_get_user_success(void **state) { @@ -4638,84 +3130,7 @@ int main(int argc, char *argv[]) { cmocka_unit_test(test_remove_empty_folders_non_empty_dir), cmocka_unit_test(test_remove_empty_folders_error_removing_dir), -#if defined(TEST_SERVER) - /* sk_decode_sum tests */ - cmocka_unit_test_setup_teardown(test_sk_decode_sum_no_decode, setup_sk_decode, teardown_sk_decode), - cmocka_unit_test_setup_teardown(test_sk_decode_sum_deleted_file, setup_sk_decode, teardown_sk_decode), - cmocka_unit_test_setup_teardown(test_sk_decode_sum_no_perm, setup_sk_decode, teardown_sk_decode), - cmocka_unit_test_setup_teardown(test_sk_decode_sum_missing_separator, setup_sk_decode, teardown_sk_decode), - cmocka_unit_test_setup_teardown(test_sk_decode_sum_no_uid, setup_sk_decode, teardown_sk_decode), - cmocka_unit_test_setup_teardown(test_sk_decode_sum_no_gid, setup_sk_decode, teardown_sk_decode), - cmocka_unit_test_setup_teardown(test_sk_decode_sum_no_md5, setup_sk_decode, teardown_sk_decode), - cmocka_unit_test_setup_teardown(test_sk_decode_sum_no_sha1, setup_sk_decode, teardown_sk_decode), - cmocka_unit_test_setup_teardown(test_sk_decode_sum_no_new_fields, setup_sk_decode, teardown_sk_decode), - cmocka_unit_test_setup_teardown(test_sk_decode_sum_win_perm_string, setup_sk_decode, teardown_sk_decode), - cmocka_unit_test_setup_teardown(test_sk_decode_sum_win_perm_encoded, setup_sk_decode, teardown_sk_decode), - cmocka_unit_test_setup_teardown(test_sk_decode_sum_no_gname, setup_sk_decode, teardown_sk_decode), - cmocka_unit_test_setup_teardown(test_sk_decode_sum_no_uname, setup_sk_decode, teardown_sk_decode), - cmocka_unit_test_setup_teardown(test_sk_decode_sum_no_mtime, setup_sk_decode, teardown_sk_decode), - cmocka_unit_test_setup_teardown(test_sk_decode_sum_no_inode, setup_sk_decode, teardown_sk_decode), - cmocka_unit_test_setup_teardown(test_sk_decode_sum_no_sha256, setup_sk_decode, teardown_sk_decode), - cmocka_unit_test_setup_teardown(test_sk_decode_sum_empty_sha256, setup_sk_decode, teardown_sk_decode), - cmocka_unit_test_setup_teardown(test_sk_decode_sum_no_attributes, setup_sk_decode, teardown_sk_decode), - cmocka_unit_test_setup_teardown(test_sk_decode_sum_non_numeric_attributes, setup_sk_decode, teardown_sk_decode), - cmocka_unit_test_setup_teardown(test_sk_decode_sum_win_encoded_attributes, setup_sk_decode, teardown_sk_decode), - cmocka_unit_test_setup_teardown(test_sk_decode_sum_extra_data_empty, setup_sk_decode, teardown_sk_decode), - cmocka_unit_test_setup_teardown(test_sk_decode_sum_extra_data_no_user_name, setup_sk_decode, teardown_sk_decode), - cmocka_unit_test_setup_teardown(test_sk_decode_sum_extra_data_no_group_id, setup_sk_decode, teardown_sk_decode), - cmocka_unit_test_setup_teardown(test_sk_decode_sum_extra_data_no_group_name, setup_sk_decode, teardown_sk_decode), - cmocka_unit_test_setup_teardown(test_sk_decode_sum_extra_data_no_process_name, setup_sk_decode, teardown_sk_decode), - cmocka_unit_test_setup_teardown(test_sk_decode_sum_extra_data_no_audit_uid, setup_sk_decode, teardown_sk_decode), - cmocka_unit_test_setup_teardown(test_sk_decode_sum_extra_data_no_audit_name, setup_sk_decode, teardown_sk_decode), - cmocka_unit_test_setup_teardown(test_sk_decode_sum_extra_data_no_effective_uid, setup_sk_decode, teardown_sk_decode), - cmocka_unit_test_setup_teardown(test_sk_decode_sum_extra_data_no_effective_name, setup_sk_decode, teardown_sk_decode), - cmocka_unit_test_setup_teardown(test_sk_decode_sum_extra_data_no_ppid, setup_sk_decode, teardown_sk_decode), - cmocka_unit_test_setup_teardown(test_sk_decode_sum_extra_data_no_process_id, setup_sk_decode, teardown_sk_decode), - cmocka_unit_test_setup_teardown(test_sk_decode_sum_extra_data_no_tag, setup_sk_decode, teardown_sk_decode), - cmocka_unit_test_setup_teardown(test_sk_decode_sum_extra_data_no_symbolic_path, setup_sk_decode, teardown_sk_decode), - cmocka_unit_test_setup_teardown(test_sk_decode_sum_extra_data_no_inode, setup_sk_decode, teardown_sk_decode), - cmocka_unit_test_setup_teardown(test_sk_decode_sum_extra_data_all_fields, setup_sk_decode, teardown_sk_decode), - cmocka_unit_test_setup_teardown(test_sk_decode_sum_extra_data_all_fields_silent, setup_sk_decode, teardown_sk_decode), - cmocka_unit_test_setup_teardown(test_sk_decode_sum_extra_data_null_ppid, setup_sk_decode, teardown_sk_decode), - cmocka_unit_test_setup_teardown(test_sk_decode_sum_extra_data_null_sum, setup_sk_decode, teardown_sk_decode), - cmocka_unit_test_setup_teardown(test_sk_decode_sum_extra_data_null_c_sum, setup_sk_decode, teardown_sk_decode), - - /* sk_decode_extradata tests */ - cmocka_unit_test_setup_teardown(test_sk_decode_extradata_null_sum, setup_sk_decode, teardown_sk_decode), - cmocka_unit_test_setup_teardown(test_sk_decode_extradata_null_c_sum, setup_sk_decode, teardown_sk_decode), - cmocka_unit_test_setup_teardown(test_sk_decode_extradata_no_changes, setup_sk_decode, teardown_sk_decode), - cmocka_unit_test_setup_teardown(test_sk_decode_extradata_no_date_alert, setup_sk_decode, teardown_sk_decode), - cmocka_unit_test_setup_teardown(test_sk_decode_extradata_no_sym_path, setup_sk_decode, teardown_sk_decode), - cmocka_unit_test_setup_teardown(test_sk_decode_extradata_all_fields, setup_sk_decode, teardown_sk_decode), - - /* sk_fill_event tests */ - cmocka_unit_test_setup_teardown(test_sk_fill_event_full_event, setup_sk_fill_event, teardown_sk_fill_event), - cmocka_unit_test_setup_teardown(test_sk_fill_event_empty_event, setup_sk_fill_event, teardown_sk_fill_event), - cmocka_unit_test_setup_teardown(test_sk_fill_event_win_perm, setup_sk_fill_event, teardown_sk_fill_event), - cmocka_unit_test_setup_teardown(test_sk_fill_event_null_eventinfo, setup_sk_fill_event, teardown_sk_fill_event), - cmocka_unit_test_setup_teardown(test_sk_fill_event_null_f_name, setup_sk_fill_event, teardown_sk_fill_event), - cmocka_unit_test_setup_teardown(test_sk_fill_event_null_sum, setup_sk_fill_event, teardown_sk_fill_event), - - /* sk_build_sum tests */ - cmocka_unit_test_setup_teardown(test_sk_build_sum_full_message, setup_sk_build_sum, teardown_sk_build_sum), - cmocka_unit_test_setup_teardown(test_sk_build_sum_skip_fields_message, setup_sk_build_sum, teardown_sk_build_sum), - cmocka_unit_test_setup_teardown(test_sk_build_sum_win_perm, setup_sk_build_sum, teardown_sk_build_sum), - cmocka_unit_test_setup_teardown(test_sk_build_sum_insufficient_buffer_size, setup_sk_build_sum, teardown_sk_build_sum), - cmocka_unit_test_setup_teardown(test_sk_build_sum_null_sum, setup_sk_build_sum, teardown_sk_build_sum), - cmocka_unit_test_setup_teardown(test_sk_build_sum_null_output, setup_sk_build_sum, teardown_sk_build_sum), - - /* sk_sum_clean tests */ - cmocka_unit_test_setup_teardown(test_sk_sum_clean_full_message, setup_sk_decode, teardown_sk_decode), - cmocka_unit_test_setup_teardown(test_sk_sum_clean_shortest_valid_message, setup_sk_decode, teardown_sk_decode), - cmocka_unit_test_setup_teardown(test_sk_sum_clean_invalid_message, setup_sk_decode, teardown_sk_decode), - cmocka_unit_test_setup_teardown(test_sk_sum_clean_null_sum, setup_sk_decode, teardown_sk_decode), -#endif #ifndef TEST_WINAGENT - /* unescape_syscheck_field tests */ - cmocka_unit_test_setup_teardown(test_unescape_syscheck_field_escaped_chars, setup_unescape_syscheck_field, teardown_unescape_syscheck_field), - cmocka_unit_test_setup_teardown(test_unescape_syscheck_field_no_escaped_chars, setup_unescape_syscheck_field, teardown_unescape_syscheck_field), - cmocka_unit_test_setup_teardown(test_unescape_syscheck_null_input, setup_unescape_syscheck_field, teardown_unescape_syscheck_field), - cmocka_unit_test_setup_teardown(test_unescape_syscheck_empty_string, setup_unescape_syscheck_field, teardown_unescape_syscheck_field), /* get_user tests */ cmocka_unit_test_teardown(test_get_user_success, teardown_string), diff --git a/src/modules/fim/tests/unit/tests/test_config.c b/src/modules/fim/tests/unit/tests/test_config.c index 6b73a287e2..ad68311952 100644 --- a/src/modules/fim/tests/unit/tests/test_config.c +++ b/src/modules/fim/tests/unit/tests/test_config.c @@ -306,7 +306,7 @@ void test_getSyscheckConfig(void **state) assert_int_equal(cJSON_GetArraySize(ret), 1); cJSON *sys_items = cJSON_GetObjectItem(ret, "syscheck"); - #if defined(TEST_SERVER) || defined(TEST_AGENT) + #if defined(TEST_AGENT) assert_int_equal(cJSON_GetArraySize(sys_items), 21); #elif defined(TEST_WINAGENT) assert_int_equal(cJSON_GetArraySize(sys_items), 29); @@ -350,7 +350,7 @@ void test_getSyscheckConfig(void **state) cJSON *sys_dir = cJSON_GetObjectItem(sys_items, "directories"); -#if defined(TEST_SERVER) || defined(TEST_AGENT) +#if defined(TEST_AGENT) assert_int_equal(cJSON_GetArraySize(sys_dir), 6); #elif defined(TEST_WINAGENT) assert_int_equal(cJSON_GetArraySize(sys_dir), 13); @@ -361,7 +361,7 @@ void test_getSyscheckConfig(void **state) assert_int_equal(cJSON_GetArraySize(sys_nodiff), 1); cJSON *sys_ignore = cJSON_GetObjectItem(sys_items, "ignore"); -#if defined(TEST_SERVER) || defined(TEST_AGENT) +#if defined(TEST_AGENT) assert_int_equal(cJSON_GetArraySize(sys_ignore), 12); #elif defined(TEST_WINAGENT) assert_int_equal(cJSON_GetArraySize(sys_ignore), 2); diff --git a/src/modules/fim/tests/unit/tests/test_fim_diff_changes.c b/src/modules/fim/tests/unit/tests/test_fim_diff_changes.c index d19d0e18d2..eaad77a835 100644 --- a/src/modules/fim/tests/unit/tests/test_fim_diff_changes.c +++ b/src/modules/fim/tests/unit/tests/test_fim_diff_changes.c @@ -573,8 +573,7 @@ void test_initialize_file_diff_data(void **state) { assert_string_equal(diff->diff_file, "queue/diff/tmp/diff-file"); } -#endif // END TEST_AGENT and TEST_SERVER - +#endif // END TEST_AGENT void test_initialize_file_diff_data_abspath_fail(void **state) { diff_data *diff = *state; diff --git a/src/modules/fim/tests/unit/tests/test_run_realtime.c b/src/modules/fim/tests/unit/tests/test_run_realtime.c index 44e636bbaa..5f91c92a6b 100644 --- a/src/modules/fim/tests/unit/tests/test_run_realtime.c +++ b/src/modules/fim/tests/unit/tests/test_run_realtime.c @@ -327,7 +327,7 @@ void test_realtime_start_success(void **state) { expect_function_call(__wrap_OSHash_SetFreeDataPointer); will_return(__wrap_OSHash_SetFreeDataPointer, 0); -#if defined(TEST_SERVER) || defined(TEST_AGENT) +#if defined(TEST_AGENT) will_return(__wrap_inotify_init, 0); #else expect_value(wrap_CreateEvent, lpEventAttributes, NULL); @@ -368,7 +368,7 @@ void test_realtime_start_failure_hash(void **state) { assert_int_equal(ret, -1); } -#if defined(TEST_SERVER) || defined(TEST_AGENT) +#if defined(TEST_AGENT) void test_realtime_start_failure_inotify(void **state) { OSHash *hash = *state; @@ -1934,7 +1934,7 @@ int main(void) { cmocka_unit_test_setup_teardown(test_realtime_start_success, setup_realtime_start, teardown_realtime_start), cmocka_unit_test_setup_teardown(test_realtime_start_failure_hash, setup_realtime_start, teardown_realtime_start), -#if defined(TEST_SERVER) || defined(TEST_AGENT) +#if defined(TEST_AGENT) cmocka_unit_test_setup_teardown(test_realtime_start_failure_inotify, setup_realtime_start, teardown_realtime_start), /* realtime_adddir */ diff --git a/src/modules/upgrade/tests/unit/tests/test_wm_agent_upgrade.c b/src/modules/upgrade/tests/unit/tests/test_wm_agent_upgrade.c index 4f6efb5405..36da6c85f0 100644 --- a/src/modules/upgrade/tests/unit/tests/test_wm_agent_upgrade.c +++ b/src/modules/upgrade/tests/unit/tests/test_wm_agent_upgrade.c @@ -37,16 +37,12 @@ static int setup_group(void **state) { static int teardown_group(void **state) { wm_agent_upgrade *config = *state; - #ifdef TEST_SERVER - os_free(config->manager_config.wpk_repository); - #else if (wcom_ca_store) { for (int i=0; wcom_ca_store[i]; i++) { os_free(wcom_ca_store[i]); } os_free(wcom_ca_store); } - #endif os_free(config); return 0; } @@ -67,16 +63,10 @@ void test_wm_agent_upgrade_dump_enabled(void **state) config->enabled = 1; - #ifdef TEST_SERVER - os_strdup("wazuh.com/packages", config->manager_config.wpk_repository); - config->manager_config.chunk_size = 512; - config->manager_config.max_threads = 8; - #else config->agent_config.enable_ca_verification = 1; os_calloc(2, sizeof(char*), wcom_ca_store); os_strdup(DEF_CA_STORE, wcom_ca_store[0]); wcom_ca_store[1] = NULL; - #endif cJSON *ret = wm_agent_upgrade_dump(config); @@ -87,12 +77,6 @@ void test_wm_agent_upgrade_dump_enabled(void **state) assert_non_null(conf); assert_non_null(cJSON_GetObjectItem(conf, "enabled")); assert_string_equal(cJSON_GetObjectItem(conf, "enabled")->valuestring, "yes"); - #ifdef TEST_SERVER - assert_int_equal(cJSON_GetObjectItem(conf, "max_threads")->valueint, 8); - assert_int_equal(cJSON_GetObjectItem(conf, "chunk_size")->valueint, 512); - assert_non_null(cJSON_GetObjectItem(conf, "wpk_repository")); - assert_string_equal(cJSON_GetObjectItem(conf, "wpk_repository")->valuestring, "wazuh.com/packages"); - #else assert_non_null(cJSON_GetObjectItem(conf, "ca_verification")); assert_string_equal(cJSON_GetObjectItem(conf, "ca_verification")->valuestring, "yes"); cJSON *certs = cJSON_GetObjectItem(conf, "ca_store"); @@ -100,7 +84,6 @@ void test_wm_agent_upgrade_dump_enabled(void **state) assert_int_equal(cJSON_GetArraySize(certs), 1); assert_string_equal(cJSON_GetArrayItem(certs, 0)->valuestring, DEF_CA_STORE); assert_null(cJSON_GetArrayItem(certs, 1)); - #endif } void test_wm_agent_upgrade_dump_disabled(void **state) @@ -109,9 +92,6 @@ void test_wm_agent_upgrade_dump_disabled(void **state) config->enabled = 0; - #ifdef TEST_SERVER - os_free(config->manager_config.wpk_repository); - #else config->agent_config.enable_ca_verification = 0; if (wcom_ca_store) { for (int i=0; wcom_ca_store[i]; i++) { @@ -119,7 +99,6 @@ void test_wm_agent_upgrade_dump_disabled(void **state) } os_free(wcom_ca_store); } - #endif cJSON *ret = wm_agent_upgrade_dump(config); @@ -130,12 +109,10 @@ void test_wm_agent_upgrade_dump_disabled(void **state) assert_non_null(conf); assert_non_null(cJSON_GetObjectItem(conf, "enabled")); assert_string_equal(cJSON_GetObjectItem(conf, "enabled")->valuestring, "no"); - #ifndef TEST_SERVER assert_non_null(cJSON_GetObjectItem(conf, "ca_verification")); assert_string_equal(cJSON_GetObjectItem(conf, "ca_verification")->valuestring, "no"); cJSON *certs = cJSON_GetObjectItem(conf, "ca_store"); assert_null(certs); - #endif } void test_wm_agent_upgrade_destroy(void **state) @@ -143,10 +120,6 @@ void test_wm_agent_upgrade_destroy(void **state) wm_agent_upgrade *config = NULL; os_calloc(1, sizeof(wm_agent_upgrade), config); - #ifdef TEST_SERVER - os_strdup("wazuh.com/packages", config->manager_config.wpk_repository); - #endif - expect_string(__wrap__mtinfo, tag, "wazuh-modulesd:agent-upgrade"); expect_string(__wrap__mtinfo, formatted_msg, "(8154): Module Agent Upgrade finished."); @@ -159,13 +132,8 @@ void test_wm_agent_upgrade_main_ok(void **state) config->enabled = 1; - #ifdef TEST_SERVER - expect_memory(__wrap_wm_agent_upgrade_start_manager_module, manager_configs, &config->manager_config, sizeof(&config->manager_config)); - expect_value(__wrap_wm_agent_upgrade_start_manager_module, enabled, config->enabled); - #else expect_memory(__wrap_wm_agent_upgrade_start_agent_module, agent_config, &config->agent_config, sizeof(&config->agent_config)); expect_value(__wrap_wm_agent_upgrade_start_agent_module, enabled, config->enabled); - #endif wm_agent_upgrade_main(config); } @@ -176,13 +144,8 @@ void test_wm_agent_upgrade_main_disabled(void **state) config->enabled = 0; - #ifdef TEST_SERVER - expect_memory(__wrap_wm_agent_upgrade_start_manager_module, manager_configs, &config->manager_config, sizeof(&config->manager_config)); - expect_value(__wrap_wm_agent_upgrade_start_manager_module, enabled, config->enabled); - #else expect_memory(__wrap_wm_agent_upgrade_start_agent_module, agent_config, &config->agent_config, sizeof(&config->agent_config)); expect_value(__wrap_wm_agent_upgrade_start_agent_module, enabled, config->enabled); - #endif wm_agent_upgrade_main(config); }