Skip to content

Commit

Permalink
feat: huge code clean up. removed unnecesary pals. shared simplication
Browse files Browse the repository at this point in the history
  • Loading branch information
ncvicchi committed Dec 3, 2024
1 parent 830dbb6 commit e5d0bae
Show file tree
Hide file tree
Showing 42 changed files with 131 additions and 141 deletions.
4 changes: 1 addition & 3 deletions src/common/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
add_subdirectory(binaries_op)
add_subdirectory(bzip2_op)
add_subdirectory(config)
add_subdirectory(data_provider)
add_subdirectory(dbsync)
add_subdirectory(error_messages)
add_subdirectory(file_op)
add_subdirectory(hashHelper)
add_subdirectory(logger)
add_subdirectory(mem_op)
add_subdirectory(logger)
add_subdirectory(networkHelper)
add_subdirectory(pal)
add_subdirectory(privsep_op)
Expand Down
3 changes: 3 additions & 0 deletions src/common/binaries_op/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ add_library(binaries_op STATIC src/binaries_op.c)
get_filename_component(COMMON_FOLDER ${CMAKE_CURRENT_SOURCE_DIR}/../ ABSOLUTE)
target_include_directories(binaries_op PUBLIC include)
include_directories(${COMMON_FOLDER}/pal/include)
include_directories(${COMMON_FOLDER}/error_messages/include)
include_directories(${COMMON_FOLDER}/utils/include)
include_directories(${COMMON_FOLDER}/file_op/include)

target_link_libraries(binaries_op
utils
Expand Down
19 changes: 14 additions & 5 deletions src/common/binaries_op/src/binaries_op.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,17 @@
* License (version 2) as published by the FSF - Free Software
* Foundation
*/

#include "shared.h"
#include <string.h>
#include <stdlib.h>
#include "error_messages.h"
#include "os_err.h"
#include "pal.h"
#include "logger.hpp"
#include "os_macros.h"

#ifndef WIN32
#include "file_op.h"
#endif

#ifdef WAZUH_UNIT_TESTING
#ifdef WIN32
Expand All @@ -23,7 +31,7 @@ int get_binary_path(const char *binary, char **validated_comm) {
const char sep[2] = ":";
#endif
char *path;
char *full_path;
char *full_path = NULL;
char *validated = NULL;
char *env_path = NULL;
char *env_path_copy = NULL;
Expand Down Expand Up @@ -57,9 +65,10 @@ int get_binary_path(const char *binary, char **validated_comm) {
#ifdef WIN32
snprintf(full_path, strlen(path) + strlen(binary) + 2, "%s\\%s", path, binary);
#else
snprintf(full_path, strlen(path) + strlen(binary) + 2, "%s/%s", path, binary);
if(full_path)
snprintf(full_path, strlen(path) + strlen(binary) + 2, "%s/%s", path, binary);
#endif
if (IsFile(full_path) == 0) {
if (full_path && IsFile(full_path) == 0) {
validated = strdup(full_path);
os_free(full_path);
break;
Expand Down
1 change: 1 addition & 0 deletions src/common/bzip2_op/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ add_library(bzip2_op STATIC src/bzip2_op.c)
get_filename_component(COMMON_FOLDER ${CMAKE_CURRENT_SOURCE_DIR}/../ ABSOLUTE)
target_include_directories(bzip2_op PUBLIC include)
include_directories(${COMMON_FOLDER}/pal/include)
include_directories(${COMMON_FOLDER}/error_messages/include)

target_link_libraries(bzip2_op
utils
Expand Down
7 changes: 5 additions & 2 deletions src/common/bzip2_op/src/bzip2_op.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@
* License (version 2) as published by the FSF - Free Software
* Foundation.
*/

#include "shared.h"
#include <stdio.h>
#include <errno.h>
#include "bzip2_op.h"
#include "error_messages.h"
#include "os_err.h"


int bzip2_compress(const char *file, const char *filebz2) {
Expand Down
3 changes: 1 addition & 2 deletions src/common/data_provider/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ if(NOT CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
set(CMAKE_CXX_FLAGS_DEBUG "-g -fsanitize=address,leak,undefined")
endif(FSANITIZE)
else()
set(CMAKE_CXX_FLAGS "/W4 /permissive- /MT")
set(CMAKE_CXX_FLAGS "/W4 /permissive- /MT /EHsc")
endif()

set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
Expand Down Expand Up @@ -100,7 +100,6 @@ include_directories(${SRC_FOLDER}/common/pal/include/)

if(WIN32)
include_directories(${SRC_FOLDER}/common/time_op/include/)
include_directories(${SRC_FOLDER}/common/file_op/include/)
include_directories(${SRC_FOLDER}/common/regex_op/include/)
include_directories(${SRC_FOLDER}/common/bzip2_op/include/)
include_directories(${SRC_FOLDER}/common/validate_op/include/)
Expand Down
2 changes: 1 addition & 1 deletion src/common/data_provider/src/ports/portWindowsWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include "stringHelper.h"
#include "windowsHelper.h"
#include "shared.h"
#include "cust_types.h"
#include "pal.h"

static const std::map<int32_t, std::string> STATE_TYPE =
{
Expand Down
19 changes: 0 additions & 19 deletions src/common/file_op/src/file_op.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
*/

#include "shared.h"
#include "cust_types.h"
#include "version_op.h"
#include "pal.h"

Expand All @@ -30,24 +29,6 @@
#include <regex.h>
#else
#include <aclapi.h>
typedef int DIR;
struct dirent {
unsigned short d_reclen; /* length of this record */
unsigned char d_type; /* type of file; not supported
by all file system types */
char d_name[256]; /* filename */
};
DIR * opendir(DIR *dir){ return NULL; }
int closedir(DIR *dir){ return 0; }
static char *dirname(char *s){ return NULL; }
static struct dirent *readdir(DIR *dir){ return NULL; }
static int64_t ftello64(FILE *x){ return 0; }
static int64_t fseeko64(FILE *x, int64_t pos, int mode){ return 0; }
static int64_t S_ISREG(int64_t flags){ return 0; }
static int64_t S_ISDIR(int64_t flags){ return 0; }
static char * PathFindFileNameA_(char *s){ return NULL; }
static void PathRemoveFileSpec_(char *path){}
static int wm_strcat(char **str1, const char *str2, char sep){ return 0;}
#endif

/* Vista product information */
Expand Down
1 change: 1 addition & 0 deletions src/common/mem_op/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ add_library(mem_op STATIC src/mem_op.c)
get_filename_component(COMMON_FOLDER ${CMAKE_CURRENT_SOURCE_DIR}/../ ABSOLUTE)
target_include_directories(mem_op PUBLIC include)
include_directories(${COMMON_FOLDER}/pal/include)
include_directories(${COMMON_FOLDER}/error_messages/include)

target_link_libraries(mem_op utils Logger time_op)
5 changes: 4 additions & 1 deletion src/common/mem_op/src/mem_op.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@
* Foundation
*/

#include <string.h>
#include "mem_op.h"
#include "shared.h"
#include "error_messages.h"
#include "logger.hpp"
#include "os_macros.h"

/* Add pointer to array */
void **os_AddPtArray(void *pt, void **array)
Expand Down
2 changes: 0 additions & 2 deletions src/common/pal/include/linux/priv_pal.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@

#define PRIV_PAL_H_REQUIRED

#include "priv_pal_file.h"
#include "priv_pal_thread.h"
#include "priv_pal_time.h"
#include "priv_pal_string.h"
#include "priv_pal_process.h"
Expand Down
5 changes: 0 additions & 5 deletions src/common/pal/include/linux/priv_pal_file.h

This file was deleted.

5 changes: 0 additions & 5 deletions src/common/pal/include/linux/priv_pal_thread.h

This file was deleted.

2 changes: 0 additions & 2 deletions src/common/pal/include/macos/priv_pal.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@

#define PRIV_PAL_H_REQUIRED

#include "priv_pal_file.h"
#include "priv_pal_thread.h"
#include "priv_pal_time.h"
#include "priv_pal_string.h"
#include "priv_pal_process.h"
Expand Down
5 changes: 0 additions & 5 deletions src/common/pal/include/macos/priv_pal_file.h

This file was deleted.

5 changes: 0 additions & 5 deletions src/common/pal/include/macos/priv_pal_thread.h

This file was deleted.

15 changes: 13 additions & 2 deletions src/common/pal/include/windows/priv_pal.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
#endif

#define PRIV_PAL_H_REQUIRED
#include <stdint.h>

#include "priv_pal_file.h"
#include "priv_pal_thread.h"
#include "priv_pal_time.h"
#include "priv_pal_string.h"
#include "priv_pal_process.h"
Expand All @@ -19,3 +18,15 @@
#define ATTR_RET_NONNULL
#define ATTR_UNUSED
#define UNREFERENCED_PARAMETER(P) (P)

#pragma once

typedef int uid_t;
typedef int gid_t;
typedef uint32_t u_int32_t;
typedef uint16_t u_int16_t;
typedef uint8_t u_int8_t;
typedef int pid_t;

typedef int mode_t;
#define PATH_MAX 1024*1024
34 changes: 0 additions & 34 deletions src/common/pal/include/windows/priv_pal_file.h

This file was deleted.

5 changes: 0 additions & 5 deletions src/common/pal/include/windows/priv_pal_thread.h

This file was deleted.

Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
1 change: 1 addition & 0 deletions src/common/privsep_op/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ add_library(privsep_op STATIC src/privsep_op.c)
get_filename_component(COMMON_FOLDER ${CMAKE_CURRENT_SOURCE_DIR}/../ ABSOLUTE)
target_include_directories(privsep_op PUBLIC include)
include_directories(${COMMON_FOLDER}/pal/include)
include_directories(${COMMON_FOLDER}/error_messages/include)

target_link_libraries(privsep_op utils time_op Logger)
2 changes: 1 addition & 1 deletion src/common/privsep_op/include/privsep_op.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#ifndef PRIV_H
#define PRIV_H

#include "cust_types.h"
#include "pal.h"
#include "shared.h"

#define w_ctime(x,y,z) ctime_r(x,y)
Expand Down
1 change: 1 addition & 0 deletions src/common/pthreads_op/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ add_library(pthreads_op STATIC src/pthreads_op.c)
get_filename_component(COMMON_FOLDER ${CMAKE_CURRENT_SOURCE_DIR}/../ ABSOLUTE)
target_include_directories(pthreads_op PUBLIC include)
include_directories(${COMMON_FOLDER}/pal/include)
include_directories(${COMMON_FOLDER}/error_messages/include)

target_link_libraries(pthreads_op utils time_op Logger)
1 change: 1 addition & 0 deletions src/common/pthreads_op/src/pthreads_op.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "shared.h"
#include <pthread.h>
#include <sys/resource.h>
#include "error_messages.h"

/* Create a new thread and give the argument passed to the function
* Returns 0 on success or -1 on error
Expand Down
1 change: 1 addition & 0 deletions src/common/randombytes/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ add_library(randombytes STATIC src/randombytes.c)
get_filename_component(COMMON_FOLDER ${CMAKE_CURRENT_SOURCE_DIR}/../ ABSOLUTE)
target_include_directories(randombytes PUBLIC include)
include_directories(${COMMON_FOLDER}/pal/include)
include_directories(${COMMON_FOLDER}/error_messages/include)

target_link_libraries(randombytes
utils
Expand Down
1 change: 1 addition & 0 deletions src/common/regex_op/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ add_library(regex_op STATIC src/regex_op.c)
get_filename_component(COMMON_FOLDER ${CMAKE_CURRENT_SOURCE_DIR}/../ ABSOLUTE)
target_include_directories(regex_op PUBLIC include)
include_directories(${COMMON_FOLDER}/pal/include)
include_directories(${COMMON_FOLDER}/error_messages/include)

target_link_libraries(regex_op utils Logger time_op)
3 changes: 2 additions & 1 deletion src/common/regex_op/src/regex_op.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
#ifndef WIN32

#include "shared.h"

#include <regex.h>
#include <sqlite3.h>

int OS_PRegex(const char *str, const char *regex)
{
Expand Down
5 changes: 4 additions & 1 deletion src/common/time_op/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,8 @@ add_library(time_op STATIC src/time_op.c)
get_filename_component(COMMON_FOLDER ${CMAKE_CURRENT_SOURCE_DIR}/../ ABSOLUTE)
target_include_directories(time_op PUBLIC include)
include_directories(${COMMON_FOLDER}/pal/include)
include_directories(${COMMON_FOLDER}/regex_op/include)
include_directories(${COMMON_FOLDER}/error_messages/include)
include_directories(${COMMON_FOLDER}/utils/include)

target_link_libraries(time_op utils Logger file_op)
target_link_libraries(time_op utils Logger)
20 changes: 16 additions & 4 deletions src/common/time_op/src/time_op.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,27 @@
* @brief Time operations
* @date October 4, 2017
*/

#include "shared.h"
#ifdef WIN32
#include <vcruntime.h>
#include <winsock2.h>
#include <windows.h>
#include <ws2tcpip.h>
#include <shlwapi.h>
#include <io.h>
#include <direct.h>
#endif
#include <string.h>
#include <stdbool.h>
#include "time_op.h"
#include "defs.h"
#include "os_macros.h"
#include "error_messages.h"
#include "logger.hpp"
#include "pal.h"


#ifndef WIN32
#include <sys/time.h>

#ifdef __MACH__
#include <mach/clock.h>
Expand All @@ -42,8 +56,6 @@ void gettime(struct timespec *ts) {
}

#else

#include <windows.h>
#define EPOCH_DIFFERENCE 11644473600LL

// Get the epoch time
Expand Down
Loading

0 comments on commit e5d0bae

Please sign in to comment.