Skip to content

Commit

Permalink
Merge pull request #76 from wazuh/enhancement/71-remove-client-condit…
Browse files Browse the repository at this point in the history
…ional-directives-from-the-code

Enhancement/71 remove client conditional directives from the code
  • Loading branch information
TomasTurina authored Aug 13, 2024
2 parents edf34a0 + 22004cd commit 5fa3e5b
Show file tree
Hide file tree
Showing 24 changed files with 10 additions and 2,522 deletions.
11 changes: 0 additions & 11 deletions src/common/file_op/include/file_op.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
21 changes: 0 additions & 21 deletions src/common/file_op/src/file_op.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
193 changes: 0 additions & 193 deletions src/common/file_op/tests/unit/tests/test_file_op.c
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Expand Down Expand Up @@ -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),
Expand Down
48 changes: 0 additions & 48 deletions src/common/syscheck_op/include/syscheck_op.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand All @@ -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
*
Expand All @@ -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

Expand Down
Loading

0 comments on commit 5fa3e5b

Please sign in to comment.