Skip to content

Revert os_dns stuff #1891

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions INSTALL
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,13 @@ other methods.
Before running the script, make sure your system has the necessary
libraries and tools installed:
- libssl
- libevent
- libpcre2
- libz
- make, gcc

On a Ubuntu/Debian system, these can be installed with:

apt install libz-dev libssl-dev libpcre2-dev libevent-dev build-essential
apt install libz-dev libssl-dev libpcre2-dev build-essential

Fast way steps:

Expand Down
18 changes: 4 additions & 14 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -911,26 +911,16 @@ os_crypto.a: ${crypto_o}
${OSSEC_LINK} $@ $^
${OSSEC_RANLIB} $@

#### os_dns ########

ifneq (${TARGET},winagent)
os_dns_c := $(wildcard os_dns/*.c)
os_dns_o := $(os_dns_c:.c=.o)

os_dns/os_dns.o: os_dns/os_dns.c
${OSSEC_CC} ${OSSEC_CFLAGS} -I/usr/local/include -c $^ -o $@
endif

#### os_mail #########

os_maild_c := $(wildcard os_maild/*.c) $(wildcard os_dns/*.c)
os_maild_c := $(wildcard os_maild/*.c)
os_maild_o := $(os_maild_c:.c=.o)

os_maild/%.o: os_maild/%.c
${OSSEC_CC} ${OSSEC_CFLAGS} -DARGV0=\"ossec-maild\" -c $^ -o $@

ossec-maild: ${os_maild_o} ${ossec_libs}
${OSSEC_CCBIN} ${OSSEC_CFLAGS} $^ ${OSSEC_LDFLAGS} ${DNS_CFLAGS} -levent ${COMPAT_FILES} -o $@
${OSSEC_CCBIN} ${OSSEC_CFLAGS} $^ ${OSSEC_LDFLAGS} ${DNS_CFLAGS} ${COMPAT_FILES} -o $@

#### os_dbd ##########

Expand Down Expand Up @@ -1008,7 +998,7 @@ ossec-remoted: ${remoted_o} ${ossec_libs} ${ZLIB_LIB}
#### ossec-agentd ####

ifneq (${TARGET},winagent)
client_agent_c := $(wildcard client-agent/*.c) $(wildcard os_dns/*.c)
client_agent_c := $(wildcard client-agent/*.c)
else
client_agent_c := $(wildcard client-agent/*.c)
endif
Expand All @@ -1018,7 +1008,7 @@ client-agent/%.o: client-agent/%.c
${OSSEC_CC} ${OSSEC_CFLAGS} -I./client-agent ${ZLIB_INCLUDE} -DARGV0=\"ossec-agentd\" -c $^ -o $@

ossec-agentd: ${client_agent_o} ${ossec_libs} ${ZLIB_LIB}
${OSSEC_CCBIN} ${OSSEC_CFLAGS} ${ZLIB_INCLUDE} $^ ${OSSEC_LDFLAGS} ${DNS_CFLAGS} -levent ${COMPAT_FILES} -o $@
${OSSEC_CCBIN} ${OSSEC_CFLAGS} ${ZLIB_INCLUDE} $^ ${OSSEC_LDFLAGS} ${DNS_CFLAGS} ${COMPAT_FILES} -o $@

#### addagent ######

Expand Down
53 changes: 0 additions & 53 deletions src/client-agent/agentd.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@
#include "agentd.h"
#include "os_net/os_net.h"

#ifndef WIN32
#include "os_dns/os_dns.h"
#endif //WIN32

/* Start the agent daemon */
void AgentdStart(const char *dir, int uid, int gid, const char *user, const char *group)
Expand All @@ -28,50 +25,12 @@ void AgentdStart(const char *dir, int uid, int gid, const char *user, const char
/* Initial random numbers must happen before chroot */
srandom_init();

merror("going daemon");
/* Going Daemon */
if (!run_foreground) {
nowDaemon();
goDaemon();
}

#ifndef WIN32
merror("starting imsg stuff");
/* Prepare for os_dns */
struct imsgbuf osdns_ibuf;
extern struct imsgbuf server_ibuf;
//struct imsgbuf osdns_ibuf;
int imsg_fds[2];
merror("Creating socketpair()");
if ((socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, imsg_fds)) == -1) {
ErrorExit("%s: ERROR: Could not create socket pair.", ARGV0);
}
if (setnonblock(imsg_fds[0]) < 0) {
ErrorExit("%s: ERROR: Could not set imsg_fds[0] to nonblock", ARGV0);
}
if (setnonblock(imsg_fds[1]) < 0) {
ErrorExit("%s: ERROR: Could not set imsg_fds[1] to nonblock", ARGV0);
}

/* Fork os_dns process */
switch(fork()) {
case -1:
ErrorExit("%s: ERROR: Cannot fork() os_dns process", ARGV0);
case 0:
close(imsg_fds[0]);
merror("os_dns imsg_init()");
imsg_init(&osdns_ibuf, imsg_fds[1]);
exit(osdns(&osdns_ibuf, ARGV0));
}

/* Setup imsg for the rest of agentd */
close(imsg_fds[1]);
//imsg_init(&agt->ibuf, imsg_fds[1]);
merror("agentd imsg_init()");
imsg_init(&server_ibuf, imsg_fds[0]);

#endif //WIN32

/* Set group ID */
if (Privsep_SetGroup(gid) < 0) {
ErrorExit(SETGID_ERROR, ARGV0, group, errno, strerror(errno));
Expand Down Expand Up @@ -152,11 +111,7 @@ void AgentdStart(const char *dir, int uid, int gid, const char *user, const char
intcheck_file(OSSEC_DEFINES, dir);

/* Send first notification */
#ifdef WIN32
run_notify();
#else
run_notify();
#endif //WIN32

/* Maxfd must be higher socket +1 */
maxfd++;
Expand All @@ -172,11 +127,7 @@ void AgentdStart(const char *dir, int uid, int gid, const char *user, const char
fdtimeout.tv_usec = 0;

/* Continuously send notifications */
#ifdef WIN32
run_notify();
#else
run_notify();
#endif //WIN32

/* Wait with a timeout for any descriptor */
rc = select(maxfd, &fdset, NULL, NULL, &fdtimeout);
Expand All @@ -193,11 +144,7 @@ void AgentdStart(const char *dir, int uid, int gid, const char *user, const char

/* For the forwarder */
if (FD_ISSET(agt->m_queue, &fdset)) {
#ifdef WIN32
EventForward();
#else
EventForward();
#endif
}
}
}
Expand Down
26 changes: 0 additions & 26 deletions src/client-agent/agentd.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@
#include "config/config.h"
#include "config/client-config.h"

#ifndef WIN32
#include <imsg.h>
#endif //WIN32

/*** Function Prototypes ***/

/* Client configuration */
Expand All @@ -26,11 +22,7 @@ int ClientConf(const char *cfgfile);
void AgentdStart(const char *dir, int uid, int gid, const char *user, const char *group) __attribute__((noreturn));

/* Event Forwarder */
#ifdef WIN32
void *EventForward(void);
#else
void *EventForward(void);
#endif //WIN32

/* Receiver messages */
void *receive_msg(void);
Expand All @@ -48,28 +40,13 @@ int send_msg(int agentid, const char *msg);
char *getsharedfiles(void);

/* Initialize handshake to server */
#ifdef WIN32
void start_agent(int is_startup);
#else
void start_agent(int is_startup);
#endif

/* Connect to the server */
#ifdef WIN32
int connect_server(int initial_id);
#else
int connect_server(int initial_id);
#endif

/* Notify server */
#ifdef WIN32
void run_notify(void);
#else
void run_notify(void);
#endif

/* libevent callback */
void os_agent_cb(int fd, short ev, void *arg);

/*** Global variables ***/

Expand All @@ -82,9 +59,6 @@ extern time_t available_server;
extern int run_foreground;
extern keystore keys;
extern agent *agt;
#ifndef WIN32
struct imsgbuf server_ibuf;
#endif //WIN32

#endif /* __AGENTD_H */

5 changes: 1 addition & 4 deletions src/client-agent/event-forward.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,9 @@
#include "os_net/os_net.h"
#include "sec.h"

#ifndef WIN32
#include <imsg.h>
#endif

/* Receive a message locally on the agent and forward it to the manager */
void *EventForward(void)
void *EventForward()
{
ssize_t recv_b;
char msg[OS_MAXSTR + 1];
Expand Down
3 changes: 0 additions & 3 deletions src/client-agent/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@
#define ARGV0 "ossec-agentd"
#endif

extern struct imsgbuf server_ibuf;


/* Prototypes */
static void help_agentd(void) __attribute((noreturn));

Expand Down
13 changes: 3 additions & 10 deletions src/client-agent/receiver.c
Original file line number Diff line number Diff line change
Expand Up @@ -151,18 +151,13 @@ void *receive_msg()

else if (OS_MD5_File(file, currently_md5, OS_TEXT) < 0) {
/* Remove file */
if ((unlink(file)) < 0) {
merror("%s: ERROR: Cannot unlink %s: %s", ARGV0, file, strerror(errno));
}

unlink(file);
file[0] = '\0';
} else {
if (strcmp(currently_md5, file_sum) != 0) {
debug1("%s: ERROR: Failed md5 for: %s -- deleting.",
ARGV0, file);
if ((unlink(file)) < 0) {
merror("%s: ERROR: Cannot unlink %s: %s", ARGV0, file, strerror(errno));
}
unlink(file);
} else {
char *final_file;

Expand All @@ -174,9 +169,7 @@ void *receive_msg()
}
} else {
/* Remove file */
if ((unlink(file)) < 0) {
merror("%s: ERROR: Cannot link %s: %s", ARGV0, file, strerror(errno));
}
unlink(file);
}
}

Expand Down
Loading