Skip to content

Commit

Permalink
Merge pull request #163 from wazuh/poc/152-os-regex-removal
Browse files Browse the repository at this point in the history
Removal of Dependencies to Libraries Before Migration
  • Loading branch information
LucioDonda authored Sep 20, 2024
2 parents da7a0eb + 10ae0e9 commit b8fe691
Show file tree
Hide file tree
Showing 17 changed files with 54 additions and 59 deletions.
6 changes: 0 additions & 6 deletions src/common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,12 @@ add_subdirectory(time_op)
add_subdirectory(file_op)
add_subdirectory(privsep_op)
add_subdirectory(pthreads_op)
add_subdirectory(os_xml)
add_subdirectory(error_messages)
add_subdirectory(mem_op)
add_subdirectory(binaries_op)
add_subdirectory(os_net)
add_subdirectory(os_regex)
add_subdirectory(regex_op)
add_subdirectory(validate_op)
add_subdirectory(randombytes)
add_subdirectory(bzip2_op)
add_subdirectory(string_op)
add_subdirectory(expression)
add_subdirectory(debug_op)
add_subdirectory(logging_helper)
add_subdirectory(networkHelper)
Expand Down
9 changes: 2 additions & 7 deletions src/common/debug_op/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,10 @@ target_link_libraries(debug_op
mem_op
privsep_op
pthreads_op
os_xml
error_messages
os_regex
os_net
string_op
binaries_op
regex_op
validate_op
expression
randombytes
bzip2_op
cjson)
cjson)

39 changes: 24 additions & 15 deletions src/common/debug_op/src/debug_op.c
Original file line number Diff line number Diff line change
Expand Up @@ -278,47 +278,55 @@ void w_logging_init(){
}

void os_logging_config(){
OS_XML xml;
// OS_XML xml;
const char * xmlf[] = {"ossec_config", "logging", "log_format", NULL};
char * logformat;
char ** parts = NULL;
int i;

pid = (int)getpid();

if (OS_ReadXML(OSSECCONF, &xml) < 0){
flags.log_plain = 1;
flags.log_json = 0;
OS_ClearXML(&xml);
mlerror_exit(LOGLEVEL_ERROR, XML_ERROR, OSSECCONF, xml.err, xml.err_line);
}

logformat = OS_GetOneContentforElement(&xml, xmlf);
// TODO: replace function OS_ReadXML
// if (OS_ReadXML(OSSECCONF, &xml) < 0){
// flags.log_plain = 1;
// flags.log_json = 0;
// TODO: replace function OS_ClearXML
// OS_ClearXML(&xml);
// TODO: replace XML_ERROR
// mlerror_exit(LOGLEVEL_ERROR, XML_ERROR, OSSECCONF, xml.err, xml.err_line);
// }
// TODO: replace function OS_GetOneContentforElement
// logformat = OS_GetOneContentforElement(&xml, xmlf);

if (!logformat || logformat[0] == '\0'){

flags.log_plain = 1;
flags.log_json = 0;

free(logformat);
OS_ClearXML(&xml);
mdebug1(XML_NO_ELEM, "log_format");
// TODO: replace function OS_ClearXML
// OS_ClearXML(&xml);
// TODO: replace XML_NO_ELEM
// mdebug1(XML_NO_ELEM, "log_format");

}else{

parts = OS_StrBreak(',', logformat, 2);
// TODO: replace function OS_StrBreak
// parts = OS_StrBreak(',', logformat, 2);
char * part;
if (parts){
for (i=0; parts[i]; i++){
part = w_strtrim(parts[i]);
// TODO: replace function w_strtrim
// part = w_strtrim(parts[i]);
if (!strcmp(part, "plain")){
flags.log_plain = 1;
}else if(!strcmp(part, "json")){
flags.log_json = 1;
}else{
flags.log_plain = 1;
flags.log_json = 0;
mlerror_exit(LOGLEVEL_ERROR, XML_VALUEERR, "log_format", part);
// TODO: replace XML_VALUEERR
// mlerror_exit(LOGLEVEL_ERROR, XML_VALUEERR, "log_format", part);
}
}
for (i=0; parts[i]; i++){
Expand All @@ -328,7 +336,8 @@ void os_logging_config(){
}

free(logformat);
OS_ClearXML(&xml);
// TODO: replace function OS_ClearXML
// OS_ClearXML(&xml);
}
}

Expand Down
1 change: 0 additions & 1 deletion src/common/expression/include/expression.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
#define PCRE2_CODE_UNIT_WIDTH 8

#include <pcre2.h>
#include "os_regex.h"
#include "os_ip.h"

#define OSMATCH_STR "osmatch"
Expand Down
19 changes: 13 additions & 6 deletions src/common/file_op/src/file_op.c
Original file line number Diff line number Diff line change
Expand Up @@ -2202,7 +2202,9 @@ int cldir_ex_ignore(const char * name, const char ** ignore) {

while (dirent = readdir(dir), dirent) {
// Skip "." and ".."
if ((dirent->d_name[0] == '.' && (dirent->d_name[1] == '\0' || (dirent->d_name[1] == '.' && dirent->d_name[2] == '\0'))) || w_str_in_array(dirent->d_name, ignore)) {
// TODO: replace function w_str_in_array
// if ((dirent->d_name[0] == '.' && (dirent->d_name[1] == '\0' || (dirent->d_name[1] == '.' && dirent->d_name[2] == '\0'))) || w_str_in_array(dirent->d_name, ignore)) {
if (dirent->d_name[0] == '.' && (dirent->d_name[1] == '\0' || (dirent->d_name[1] == '.' && dirent->d_name[2] == '\0'))) {
continue;
}

Expand Down Expand Up @@ -3449,25 +3451,30 @@ char *w_homedir(char *arg) {
#ifdef __MACH__
pid_t pid = getpid();
if (proc_pidpath(pid, buff, PATH_MAX) > 0) {
buff = w_strtok_r_str_delim(delim, &buff);
// TODO: replace function w_strtok_r_str_delim
//buff = w_strtok_r_str_delim(delim, &buff);
}
#else
if (realpath("/proc/self/exe", buff) != NULL) {
dirname(buff);
buff = w_strtok_r_str_delim(delim, &buff);
// TODO: replace function w_strtok_r_str_delim
//buff = w_strtok_r_str_delim(delim, &buff);
}
else if (realpath("/proc/curproc/file", buff) != NULL) {
dirname(buff);
buff = w_strtok_r_str_delim(delim, &buff);
// TODO: replace function w_strtok_r_str_delim
//buff = w_strtok_r_str_delim(delim, &buff);
}
else if (realpath("/proc/self/path/a.out", buff) != NULL) {
dirname(buff);
buff = w_strtok_r_str_delim(delim, &buff);
// TODO: replace function w_strtok_r_str_delim
//buff = w_strtok_r_str_delim(delim, &buff);
}
#endif
else if (realpath(arg, buff) != NULL) {
dirname(buff);
buff = w_strtok_r_str_delim(delim, &buff);
// TODO: replace function w_strtok_r_str_delim
//buff = w_strtok_r_str_delim(delim, &buff);
} else {
// The path was not found so read WAZUH_HOME env var
char * home_env = NULL;
Expand Down
15 changes: 9 additions & 6 deletions src/common/os_net/src/os_net.c
Original file line number Diff line number Diff line change
Expand Up @@ -892,9 +892,10 @@ void resolve_hostname(char **hostname, int attempts) {
char *f_ip;

assert(hostname != NULL);
if (OS_IsValidIP(*hostname, NULL) == 1) {
return;
}
// TODO: replace function OS_IsValidIP
// if (OS_IsValidIP(*hostname, NULL) == 1) {
// return;
// }

tmp_str = strchr(*hostname, '/');
if (tmp_str) {
Expand Down Expand Up @@ -1059,9 +1060,11 @@ int get_ipv6_string(struct in6_addr addr6, char *address, size_t address_size) {
}
#endif

if ((ret == OS_SUCCESS) && !OS_GetIPv4FromIPv6(address, IPSIZE)) {
OS_ExpandIPv6(address, IPSIZE);
}
// TODO: replace function OS_GetIPv4FromIPv6
// if ((ret == OS_SUCCESS) && !OS_GetIPv4FromIPv6(address, IPSIZE)) {
// TODO: replace function OS_ExpandIPv6
// OS_ExpandIPv6(address, IPSIZE);
// }

return ret;
}
Expand Down
4 changes: 3 additions & 1 deletion src/common/pthreads_op/src/pthreads_op.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ int CreateThreadJoinable(pthread_t *lthread, void * (*function_pointer)(void *),
return -1;
}

read_size = 1024 * (size_t)getDefine_Int("wazuh", "thread_stack_size", 2048, 65536);
// TODO: replace function getDefine_Int
read_size = 1024 * (size_t) 65536;
// read_size = 1024 * (size_t)getDefine_Int("wazuh", "thread_stack_size", 2048, 65536);

/* Set the maximum stack limit to new threads */
if (pthread_attr_setstacksize(&attr, read_size)) {
Expand Down
1 change: 0 additions & 1 deletion src/common/string_op/src/string_op.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

#include "shared.h"
#include "string.h"
#include "os_regex.h"
#include "string_op.h"

#ifdef WIN32
Expand Down
6 changes: 0 additions & 6 deletions src/common/utils/include/shared.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,17 +119,11 @@
#include "mem_op.h"
#include "privsep_op.h"
#include "pthreads_op.h"
#include "os_xml.h"
#include "error_messages.h"
#include "os_regex.h"
#include "string_op.h"
#include "binaries_op.h"
#include "os_ip.h"
#include "os_net.h"
#include "expression.h"
#include "randombytes.h"
#include "bzip2_op.h"
#include "validate_op.h"


#ifndef LARGEFILE64_SOURCE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
#define PCRE2_CODE_UNIT_WIDTH 8

#include "shared.h"
#include "expression.h"

#define w_pcre2_match_data_create_from_pattern wrap_pcre2_match_data_create_from_pattern
#define w_pcre2_match wrap_pcre2_match
Expand Down
1 change: 0 additions & 1 deletion src/common/validate_op/src/validate_op.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

#include "shared.h"
#include "validate_op.h"
#include "expression.h"
#include "os_net.h"

#ifdef WAZUH_UNIT_TESTING
Expand Down
4 changes: 3 additions & 1 deletion src/common/version_op/src/version_op.c
Original file line number Diff line number Diff line change
Expand Up @@ -716,7 +716,9 @@ os_info *get_unix_version()
char *key = strtok_r(buff, ":", &save_ptr);
if (key) {
const char *expected_key = "System Version";
char *trimmed_key = w_strtrim(key);
// TODO: replace function w_strtrim
// char *trimmed_key = w_strtrim(key);
char *trimmed_key = key;
if (NULL != trimmed_key && strncmp(trimmed_key, expected_key, strlen(expected_key)) == 0) {
char *value = strtok_r(NULL, " ", &save_ptr);
if (value) {
Expand Down
1 change: 0 additions & 1 deletion src/modules/fim/src/whodata/syscheck_audit.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
#include "../os_net/os_net.h"
#include "syscheck_op.h"
#include "audit_op.h"
#include "string_op.h"

#define AUDIT_RULES_FILE "etc/audit_rules_wazuh.rules"
#define AUDIT_RULES_LINK "/etc/audit/rules.d/audit_rules_wazuh.rules"
Expand Down
3 changes: 0 additions & 3 deletions src/modules/inventory/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,9 @@ target_include_directories(inventory PUBLIC
${COMMON_FOLDER}/file_op/include
${COMMON_FOLDER}/hashHelper/include
${COMMON_FOLDER}/logging_helper/include
${COMMON_FOLDER}/os_xml/include
${COMMON_FOLDER}/privsep_op/include
${COMMON_FOLDER}/pthreads_op/include
${COMMON_FOLDER}/stringHelper/include
${COMMON_FOLDER}/string_op/include
${COMMON_FOLDER}/time_op/include
${COMMON_FOLDER}/timeHelper/include
${COMMON_FOLDER}/utils)
Expand All @@ -48,7 +46,6 @@ target_link_libraries(inventory PUBLIC
OpenSSL::SSL
OpenSSL::Crypto
utils
os_regex
logging_helper
pthreads_op
MultiTypeQueue)
Expand Down
1 change: 0 additions & 1 deletion src/modules/inventory/src/inventory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
#include <shared.h>
#include <defs.h>
#include <logging_helper.h>
#include <string_op.h>
#include <pthreads_op.h>

#include <inventory.hpp>
Expand Down
1 change: 0 additions & 1 deletion src/modules/logcollector/include/journal_log.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include "../config/localfile-config.h"

#include "cJSON.h"
#include "expression.h"

/*******************************************************************************
* NOTE: This module is not thread-safe.
Expand Down
1 change: 0 additions & 1 deletion src/modules/sca/src/wm_sca.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
#include <os_net/os_net.h>
#include <sys/stat.h>
#include "os_crypto/sha256/sha256_op.h"
#include "expression.h"
#include "shared.h"

#undef minfo
Expand Down

0 comments on commit b8fe691

Please sign in to comment.