Skip to content

Commit

Permalink
Merge pull request #80 from wazuh/enhancement/72-remove-ossechids-con…
Browse files Browse the repository at this point in the history
…ditional-directives-from-the-code

Enhancement/72 remove ossechids conditional directives from the code
  • Loading branch information
TomasTurina authored Aug 16, 2024
2 parents 84b3776 + b8ed3fa commit e64ac9f
Show file tree
Hide file tree
Showing 9 changed files with 0 additions and 431 deletions.
1 change: 0 additions & 1 deletion src/modules/rootcheck/include/rootcheck.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ void check_rc_pids(void);
int check_rc_readproc(int pid);

void check_rc_ports(void);
void check_open_ports(void);
void check_rc_if(void);

/*Checks if the path or file is user-ignored */
Expand Down
122 changes: 0 additions & 122 deletions src/modules/rootcheck/src/check_open_ports.c

This file was deleted.

3 changes: 0 additions & 3 deletions src/modules/rootcheck/src/check_rc_pids.c
Original file line number Diff line number Diff line change
Expand Up @@ -168,14 +168,11 @@ static void loop_all_pids(const char *ps, pid_t max_pid, int *_errors, int *_tot
}
}

/* If we are run in the context of OSSEC-HIDS, sleep here (no rush) */
#ifdef OSSECHIDS
#ifdef WIN32
Sleep(rootcheck.tsleep);
#else
struct timeval timeout = {0, rootcheck.tsleep * 1000};
select(0, NULL, NULL, NULL, &timeout);
#endif
#endif

/* Everything fine, move on */
Expand Down
3 changes: 0 additions & 3 deletions src/modules/rootcheck/src/check_rc_ports.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,11 @@ static void test_ports(int proto, int *_errors, int *_total)
continue;
}

#ifdef OSSECHIDS
/* If we are in the context of OSSEC-HIDS, sleep here (no rush) */
#ifdef WIN32
Sleep(rootcheck.tsleep);
#else
struct timeval timeout = {0, rootcheck.tsleep * 1000};
select(0, NULL, NULL, NULL, &timeout);
#endif
#endif

if (!run_netstat(proto, i) && conn_port(proto, i)) {
Expand Down
22 changes: 0 additions & 22 deletions src/modules/rootcheck/src/check_rc_sys.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ static int read_sys_file(const char *file_name, int do_read)

if (statbuf.st_uid == 0) {
char op_msg[OS_SIZE_1024 + 1];
#ifdef OSSECHIDS
const char op_msg_fmt[] = "File '%*s' is owned by root and has written permissions to anyone.";

const int size = snprintf(NULL, 0, op_msg_fmt, (int)strlen(file_name), file_name);
Expand All @@ -161,27 +160,6 @@ static int read_sys_file(const char *file_name, int do_read)
}

_sys_errors++;

#else
const char op_msg_fmt[] = "File '%*s' is: \n - owned by root,\n - has write permissions to anyone.";

const int size = snprintf(NULL, 0, op_msg_fmt, (int)strlen(file_name), file_name);

if (size >= 0) {
if ((size_t)size < sizeof(op_msg)) {
snprintf(op_msg, sizeof(op_msg), op_msg_fmt, (int)strlen(file_name), file_name);
} else {
const unsigned int surplus = size - sizeof(op_msg) + 1;
snprintf(op_msg, sizeof(op_msg), op_msg_fmt, (int)(strlen(file_name) - surplus), file_name);
}

notify_rk(ALERT_SYSTEM_CRIT, op_msg);
} else {
mtdebug2(ARGV0, "Error %d (%s) with snprintf with file %s", errno, strerror(errno), file_name);
}

_sys_errors++;
#endif
}
} else if ((statbuf.st_mode & S_ISUID) == S_ISUID) {
if (_suid) {
Expand Down
3 changes: 0 additions & 3 deletions src/modules/rootcheck/src/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
* Foundation
*/

#ifdef OSSECHIDS
#include "shared.h"
#include "rootcheck.h"
#include "config/config.h"
Expand Down Expand Up @@ -102,5 +101,3 @@ cJSON *getRootcheckConfig(void) {

return root;
}

#endif /* OSSECHIDS */
113 changes: 0 additions & 113 deletions src/modules/rootcheck/src/rootcheck.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,50 +28,12 @@ char total_ports_tcp[65535 + 1];
#define ARGV0 "rootcheck"
#endif

#ifndef OSSECHIDS

/* Print help statement */
void help_rootcheck(char * home_path)
{
print_header();
print_out(" %s: -[Vhdtsr] [-c config] [-D dir]", ARGV0);
print_out(" -V Version and license message");
print_out(" -h Print this help message");
print_out(" -d Execute in debug mode. This parameter");
print_out(" can be specified multiple times");
print_out(" to increase the debug level.");
print_out(" -t Test configuration");
print_out(" -s Scan the whole system");
print_out(" -r Read all the files for kernel-based detection");
print_out(" -c <config> Configuration file to use");
print_out(" -D <dir> Directory to chroot into (default: %s)", home_path);
print_out(" ");
os_free(home_path);
exit(1);
}

int main(int argc, char **argv)
{
int test_config = 0;
const char *cfg = "./rootcheck.conf";
char * home_path = w_homedir(argv[0]);

#else

int rootcheck_init(int test_config)
{
const char *cfg = OSSECCONF;

#endif /* OSSECHIDS */

int c;

#ifndef OSSECHIDS
if (chdir(home_path) == -1) {
merror_exit(CHDIR_ERROR, home_path, errno, strerror(errno));
}
#endif /* OSSECHIDS */

/* Zero the structure, initialize default values */
rootcheck.workdir = NULL;
rootcheck.basedir = NULL;
Expand Down Expand Up @@ -115,58 +77,6 @@ int rootcheck_init(int test_config)
c++;
}

#ifndef OSSECHIDS
rootcheck.notify = SYSLOG_RK;
rootcheck.daemon = 0;
while ((c = getopt(argc, argv, "VstrdhD:c:")) != -1) {
switch (c) {
case 'V':
print_version();
break;
case 'h':
help_rootcheck(home_path);
break;
case 'd':
nowDebug();
break;
case 'D':
if (!optarg) {
mterror_exit(ARGV0, "-D needs an argument");
}
rootcheck.workdir = optarg;
break;
case 'c':
if (!optarg) {
mterror_exit(ARGV0, "-c needs an argument");
}
cfg = optarg;
break;
case 's':
rootcheck.scanall = 1;
break;
case 't':
test_config = 1;
break;
case 'r':
rootcheck.readall = 1;
break;
default:
help_rootcheck(home_path);
break;
}
}
#ifdef WIN32
/* Start Winsock */
{
WSADATA wsaData;
if (WSAStartup(MAKEWORD(2, 0), &wsaData) != 0) {
mterror_exit(ARGV0, "WSAStartup() failed");
}
}
#endif /* WIN32 */

#endif /* OSSECHIDS */

/* Check if the configuration is present */
if (File_DateofChange(cfg) < 0) {
mterror(ARGV0, "Configuration file '%s' not found", cfg);
Expand Down Expand Up @@ -211,22 +121,11 @@ int rootcheck_init(int test_config)
}
#endif

/* Set default values */
#ifndef OSSECHIDS
mdebug1(WAZUH_HOMEDIR, home_path);
if (rootcheck.workdir == NULL) {
rootcheck.workdir = home_path;
}
#endif

#ifdef OSSECHIDS
/* Start up message */
#ifdef WIN32
mtinfo(ARGV0, STARTUP_MSG, getpid());
#endif /* WIN32 */

#endif /* OSSECHIDS */

/* Initialize rk list */
rk_sys_name = (char **) calloc(MAX_RK_SYS + 2, sizeof(char *));
rk_sys_file = (char **) calloc(MAX_RK_SYS + 2, sizeof(char *));
Expand All @@ -236,18 +135,6 @@ int rootcheck_init(int test_config)
rk_sys_name[0] = NULL;
rk_sys_file[0] = NULL;

#ifndef OSSECHIDS
#ifndef WIN32
/* Start signal handling */
StartSIG(ARGV0);
rootcheck_connect();
#endif
mtdebug1(ARGV0, "Running run_rk_check");
run_rk_check();

mtdebug1(ARGV0, "Leaving...");
os_free(home_path);
#endif /* OSSECHIDS */
return (0);
}

Expand Down
Loading

0 comments on commit e64ac9f

Please sign in to comment.