Skip to content
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

Shuffle some variables around #1875

Merged
merged 6 commits into from
Feb 21, 2021
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
1 change: 1 addition & 0 deletions src/addagent/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ static void print_banner(void);
static void manage_shutdown(int sig) __attribute__((noreturn));
#endif

int willchroot;

#if defined(__MINGW32__)
static int setenv(const char *name, const char *val, __attribute__((unused)) int overwrite)
Expand Down
2 changes: 2 additions & 0 deletions src/addagent/manage_agents.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ int add_agent(int json_output)

char authfile[257];

extern int willchroot;

if(willchroot > 0) {
snprintf(authfile, 256, "%s", AUTH_FILE); //XXX
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/addagent/manage_agents.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,4 +147,4 @@ extern fpos_t fp_pos;
#define GMF_UNKN_ERROR ARGV0 ": Could not run GetModuleFileName which returned (%ld).\n"


int willchroot;
//int willchroot;
2 changes: 2 additions & 0 deletions src/addagent/manage_keys.c
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,8 @@ int k_bulkload(const char *cmdbulk)
char delims[] = ",";
char *token = NULL;

extern int willchroot;

/* Check if we can open the input file */
printf("Opening: [%s]\n", cmdbulk);
infp = fopen(cmdbulk, "r");
Expand Down
7 changes: 6 additions & 1 deletion src/analysisd/analysisd.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,12 @@
#endif

#ifdef SQLITE_ENABLED
#include "syscheck-sqlite.h"
#include <sqlite3.h>
sqlite3 *conn;
#endif

#ifdef LIBGEOIP_ENABLED
GeoIP *geoipdb;
#endif

/** Prototypes **/
Expand Down
3 changes: 3 additions & 0 deletions src/analysisd/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

#include "config/config.h"
#include "config/global-config.h"

#ifdef LIBGEOIP_ENABLED
#include "GeoIP.h"
#endif
Expand All @@ -20,9 +21,11 @@
extern long int __crt_ftell; /* Global ftell pointer */
extern _Config Config; /* Global Config structure */

/*
#ifdef LIBGEOIP_ENABLED
GeoIP *geoipdb;
#endif
*/

int GlobalConf(const char *cfgfile);

Expand Down
1 change: 1 addition & 0 deletions src/analysisd/decoders/geoip.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ char *GetGeoInfobyIP(char *ip_addr)
GeoIPRecord *geoiprecord;
char *geodata = NULL;
char geobuffer[256 +1];
extern GeoIP *geoipdb;

if(!geoipdb)
{
Expand Down
2 changes: 1 addition & 1 deletion src/analysisd/decoders/syscheck.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#include "decoder.h"

#ifdef SQLITE_ENABLED
#include "syscheck-sqlite.h"
#include <sqlite3.h>
#endif

typedef struct __sdb {
Expand Down
4 changes: 4 additions & 0 deletions src/analysisd/makelists.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ time_t c_time;
char __shost[512];
OSDecoderInfo *NULL_Decoder;

#ifdef LIBGEOIP_ENABLED
GeoIP *geoipdb;
#endif

/* print help statement */
__attribute__((noreturn))
static void help_makelists(void)
Expand Down
5 changes: 0 additions & 5 deletions src/analysisd/syscheck-sqlite.h

This file was deleted.

1 change: 1 addition & 0 deletions src/analysisd/testrule.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ int main(int argc, char **argv)
memset(prev_month, '\0', 4);

#ifdef LIBGEOIP_ENABLED
extern GeoIP *geoipdb;
geoipdb = NULL;
#endif

Expand Down
2 changes: 2 additions & 0 deletions src/client-agent/agentd.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ void AgentdStart(const char *dir, int uid, int gid, const char *user, const char
fd_set fdset;
struct timeval fdtimeout;

extern agent *agt;

available_server = 0;

/* Initial random numbers must happen before chroot */
Expand Down
3 changes: 3 additions & 0 deletions src/client-agent/event-forward.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
/* Receive a message locally on the agent and forward it to the manager */
void *EventForward()
{

extern agent *agt;

ssize_t recv_b;
char msg[OS_MAXSTR + 1];

Expand Down
2 changes: 2 additions & 0 deletions src/client-agent/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ int main(int argc, char **argv)

debug1(STARTED_MSG, ARGV0);

extern agent *agt;

agt = (agent *)calloc(1, sizeof(agent));
if (!agt) {
ErrorExit(MEM_ERROR, ARGV0, errno, strerror(errno));
Expand Down
2 changes: 2 additions & 0 deletions src/client-agent/notify.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ void run_notify()
os_md5 md5sum;
time_t curr_time;

extern agent *agt;

keep_alive_random[0] = '\0';
curr_time = time(0);

Expand Down
1 change: 1 addition & 0 deletions src/client-agent/receiver-win.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
/* Receive events from the server */
void *receiver_thread(__attribute__((unused)) void *none)
{
extern agent *agt;
int recv_b;

char file[OS_SIZE_1024 + 1];
Expand Down
2 changes: 2 additions & 0 deletions src/client-agent/receiver.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ void *receive_msg()
char cleartext[OS_MAXSTR + 1];
char *tmp_msg;

extern agent *agt;

memset(cleartext, '\0', OS_MAXSTR + 1);
memset(buffer, '\0', OS_MAXSTR + 1);

Expand Down
3 changes: 3 additions & 0 deletions src/client-agent/sendmsg.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
/* Send a message to the server */
int send_msg(int agentid, const char *msg)
{

extern agent *agt;

size_t msg_size;
char crypt_msg[OS_MAXSTR + 1];

Expand Down
5 changes: 5 additions & 0 deletions src/client-agent/start_agent.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
int connect_server(int initial_id)
{
unsigned int attempts = 2;

extern agent *agt;

int rc = initial_id;

/* Checking if the initial is zero, meaning we have to
Expand Down Expand Up @@ -98,6 +101,8 @@ void start_agent(int is_startup)
char cleartext[OS_MAXSTR + 1];
char fmsg[OS_MAXSTR + 1];

extern agent *agt;

memset(msg, '\0', OS_MAXSTR + 2);
memset(buffer, '\0', OS_MAXSTR + 1);
memset(cleartext, '\0', OS_MAXSTR + 1);
Expand Down
20 changes: 10 additions & 10 deletions src/os_net/os_net.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#include <errno.h>
#include "shared.h"
#include "os_net.h"
agent *agt;
agent *os_net_agt;

/* Prototypes */
static OSNetInfo *OS_Bindport(char *_port, unsigned int _proto, const char *_ip);
Expand Down Expand Up @@ -346,11 +346,11 @@ int OS_Connect(char *_port, unsigned int protocol, const char *_ip)
return(OS_INVALID);
}

if (agt) {
if (agt->lip) {
if (os_net_agt) {
if (os_net_agt->lip) {
memset(&hints, 0, sizeof(struct addrinfo));
hints.ai_flags = AI_NUMERICHOST;
s = getaddrinfo(agt->lip, NULL, &hints, &result);
s = getaddrinfo(os_net_agt->lip, NULL, &hints, &result);
if (s != 0) {
verbose("getaddrinfo: %s", gai_strerror(s));
}
Expand All @@ -363,8 +363,8 @@ int OS_Connect(char *_port, unsigned int protocol, const char *_ip)
memset(&hints, 0, sizeof(struct addrinfo));
/* Allow IPv4 or IPv6 if local_ip isn't specified */
hints.ai_family = AF_UNSPEC;
if (agt) {
if (agt->lip) {
if (os_net_agt) {
if (os_net_agt->lip) {
hints.ai_family = local_ai->ai_family;
}
}
Expand Down Expand Up @@ -398,13 +398,13 @@ int OS_Connect(char *_port, unsigned int protocol, const char *_ip)
continue;
}

if (agt) {
if (agt->lip) {
if (os_net_agt) {
if (os_net_agt->lip) {
if (bind(ossock, local_ai->ai_addr, local_ai->ai_addrlen)) {
verbose("Unable to bind to local address %s. Ignoring. (%s)",
agt->lip, strerror(errno));
os_net_agt->lip, strerror(errno));
}
else verbose("Connecting from local address %s", agt->lip);
else verbose("Connecting from local address %s", os_net_agt->lip);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/os_net/os_net.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

#include "headers/shared.h"
#include "config/client-config.h"
extern agent *agt;
extern agent *os_net_agt;
#ifdef WIN32
#ifndef AI_ADDRCONFIG
#define AI_ADDRCONFIG 0x0400
Expand Down
4 changes: 4 additions & 0 deletions src/win32/win_agent.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ int local_start()
WSADATA wsaData;
DWORD threadID;
DWORD threadID2;
extern agent *agt;

/* Start agent */
agt = (agent *)calloc(1, sizeof(agent));
Expand Down Expand Up @@ -271,6 +272,7 @@ int SendMSG(__attribute__((unused)) int queue, const char *message, const char *
char tmpstr[OS_MAXSTR + 2];
char crypt_msg[OS_MAXSTR + 2];
DWORD dwWaitResult;
extern agent *agt;

tmpstr[OS_MAXSTR + 1] = '\0';
crypt_msg[OS_MAXSTR + 1] = '\0';
Expand Down Expand Up @@ -468,6 +470,8 @@ void send_win32_info(time_t curr_time)
tmp_msg[OS_MAXSTR + 1] = '\0';
crypt_msg[OS_MAXSTR + 1] = '\0';

extern agent *agt;

debug1("%s: DEBUG: Sending keep alive message.", ARGV0);

/* Fix time */
Expand Down