From 745384649f89a67a42894e66cdc8c2e23773b358 Mon Sep 17 00:00:00 2001 From: ddpbsd Date: Sat, 2 May 2020 12:54:36 -0400 Subject: [PATCH] Cleanup some variables. In issue #1871 @rseichter brings up that gcc 10 switches to '-fno-common' by default. This killed builds of the agent. Switch agt to os_net_agt in os_net. Shuffle around the variable in client-agent (I think gcc had issues with agt being declared in agentd.h which gets included everywhere). Shuffle around willchroot in manage_agents. --- src/addagent/main.c | 1 + src/addagent/manage_agents.c | 2 ++ src/addagent/manage_agents.h | 2 +- src/addagent/manage_keys.c | 2 ++ src/client-agent/agentd.c | 2 ++ src/client-agent/agentd.h | 4 ++-- src/client-agent/event-forward.c | 3 +++ src/client-agent/main.c | 5 ++++- src/client-agent/notify.c | 2 ++ src/client-agent/receiver-win.c | 1 + src/client-agent/receiver.c | 2 ++ src/client-agent/sendmsg.c | 3 +++ src/client-agent/start_agent.c | 7 +++++++ src/os_net/os_net.c | 20 ++++++++++---------- src/os_net/os_net.h | 2 +- 15 files changed, 43 insertions(+), 15 deletions(-) From 5d6f21e31dab30e34f1713f6cfe1b2e0108f77f5 Mon Sep 17 00:00:00 2001 From: ddpbsd Date: Mon, 25 May 2020 14:38:08 -0400 Subject: [PATCH] Shuffle around sqlite and geoip variables to make -fno-common happy --- src/analysisd/analysisd.c | 4 ++++ src/analysisd/config.h | 3 +++ src/analysisd/decoders/geoip.c | 1 + src/analysisd/makelists.c | 4 ++++ src/analysisd/testrule.c | 1 + 5 files changed, 14 insertions(+) diff --git a/src/addagent/main.c b/src/addagent/main.c index 587a8a3d..ab12f032 100644 --- a/src/addagent/main.c +++ b/src/addagent/main.c @@ -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) diff --git a/src/addagent/manage_agents.c b/src/addagent/manage_agents.c index ac39c1e6..4f9c266f 100644 --- a/src/addagent/manage_agents.c +++ b/src/addagent/manage_agents.c @@ -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 { diff --git a/src/addagent/manage_agents.h b/src/addagent/manage_agents.h index 4812dba4..f2962e80 100644 --- a/src/addagent/manage_agents.h +++ b/src/addagent/manage_agents.h @@ -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; diff --git a/src/addagent/manage_keys.c b/src/addagent/manage_keys.c index 146b4832..ffb9a1f2 100644 --- a/src/addagent/manage_keys.c +++ b/src/addagent/manage_keys.c @@ -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"); diff --git a/src/client-agent/agentd.c b/src/client-agent/agentd.c index c09cf87d..67828e79 100644 --- a/src/client-agent/agentd.c +++ b/src/client-agent/agentd.c @@ -23,6 +23,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 */ diff --git a/src/client-agent/agentd.h b/src/client-agent/agentd.h index 0246a545..a362ff9a 100644 --- a/src/client-agent/agentd.h +++ b/src/client-agent/agentd.h @@ -81,9 +81,9 @@ void os_agent_cb(int fd, short ev, void *arg); extern time_t available_server; extern int run_foreground; extern keystore keys; -extern agent *agt; +//extern agent *agt; #ifndef WIN32 -struct imsgbuf server_ibuf; +//struct imsgbuf server_ibuf; #endif //WIN32 #endif /* __AGENTD_H */ diff --git a/src/client-agent/event-forward.c b/src/client-agent/event-forward.c index 2e81f0c9..22ed0beb 100644 --- a/src/client-agent/event-forward.c +++ b/src/client-agent/event-forward.c @@ -19,6 +19,9 @@ /* Receive a message locally on the agent and forward it to the manager */ void *EventForward(void) { + + extern agent *agt; + ssize_t recv_b; char msg[OS_MAXSTR + 1]; diff --git a/src/client-agent/main.c b/src/client-agent/main.c index 5f85cfb7..01c18970 100644 --- a/src/client-agent/main.c +++ b/src/client-agent/main.c @@ -16,7 +16,8 @@ #define ARGV0 "ossec-agentd" #endif -extern struct imsgbuf server_ibuf; +//extern struct imsgbuf server_ibuf; +struct imsgbuf server_ibuf; /* Prototypes */ @@ -112,6 +113,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)); diff --git a/src/client-agent/notify.c b/src/client-agent/notify.c index 1b239f26..93fec325 100644 --- a/src/client-agent/notify.c +++ b/src/client-agent/notify.c @@ -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); diff --git a/src/client-agent/receiver-win.c b/src/client-agent/receiver-win.c index 859bdf7f..4ab62ee7 100644 --- a/src/client-agent/receiver-win.c +++ b/src/client-agent/receiver-win.c @@ -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]; diff --git a/src/client-agent/receiver.c b/src/client-agent/receiver.c index fde64c28..5286e60d 100644 --- a/src/client-agent/receiver.c +++ b/src/client-agent/receiver.c @@ -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); diff --git a/src/client-agent/sendmsg.c b/src/client-agent/sendmsg.c index 454c2e71..3076dfcf 100644 --- a/src/client-agent/sendmsg.c +++ b/src/client-agent/sendmsg.c @@ -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]; diff --git a/src/client-agent/start_agent.c b/src/client-agent/start_agent.c index 51670cee..f1df4371 100644 --- a/src/client-agent/start_agent.c +++ b/src/client-agent/start_agent.c @@ -24,6 +24,9 @@ int connect_server(int initial_id) #ifdef WIN32 unsigned int attempts = 2; #endif //WIN32 + + extern agent *agt; + int rc = initial_id; /* Checking if the initial is zero, meaning we have to @@ -139,6 +142,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); @@ -241,6 +246,8 @@ void os_agent_cb(int fd, short ev, void *arg) { struct imsg imsg; struct imsgbuf *ibuf = (struct imsgbuf *)arg; + extern agent *agt; + if (ev & EV_READ) { if ((n = imsg_read(ibuf) == -1 && errno != EAGAIN)) { ErrorExit("%s: ERROR: imsg_read() failed: %s", ARGV0, strerror(errno)); diff --git a/src/os_net/os_net.c b/src/os_net/os_net.c index f18e3be7..756e9fac 100644 --- a/src/os_net/os_net.c +++ b/src/os_net/os_net.c @@ -14,7 +14,7 @@ #include #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); @@ -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)); } @@ -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; } } @@ -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); } } diff --git a/src/os_net/os_net.h b/src/os_net/os_net.h index 9b725092..3aaf0042 100644 --- a/src/os_net/os_net.h +++ b/src/os_net/os_net.h @@ -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 diff --git a/src/analysisd/analysisd.c b/src/analysisd/analysisd.c index a220f442..2f963cd7 100644 --- a/src/analysisd/analysisd.c +++ b/src/analysisd/analysisd.c @@ -45,6 +45,10 @@ #include "syscheck-sqlite.h" #endif +#ifdef LIBGEOIP_ENABLED +GeoIP *geoipdb; +#endif + /** Prototypes **/ void OS_ReadMSG(int m_queue); RuleInfo *OS_CheckIfRuleMatch(Eventinfo *lf, RuleNode *curr_node); diff --git a/src/analysisd/config.h b/src/analysisd/config.h index 8d74c756..976d1942 100644 --- a/src/analysisd/config.h +++ b/src/analysisd/config.h @@ -12,6 +12,7 @@ #include "config/config.h" #include "config/global-config.h" + #ifdef LIBGEOIP_ENABLED #include "GeoIP.h" #endif @@ -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); diff --git a/src/analysisd/decoders/geoip.c b/src/analysisd/decoders/geoip.c index 464e4bb7..9816b4c8 100644 --- a/src/analysisd/decoders/geoip.c +++ b/src/analysisd/decoders/geoip.c @@ -30,6 +30,7 @@ char *GetGeoInfobyIP(char *ip_addr) GeoIPRecord *geoiprecord; char *geodata = NULL; char geobuffer[256 +1]; + extern GeoIP *geoipdb; if(!geoipdb) { diff --git a/src/analysisd/makelists.c b/src/analysisd/makelists.c index 06c90db7..dfbe6a4a 100644 --- a/src/analysisd/makelists.c +++ b/src/analysisd/makelists.c @@ -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) diff --git a/src/analysisd/testrule.c b/src/analysisd/testrule.c index c08fb488..b1aa928f 100644 --- a/src/analysisd/testrule.c +++ b/src/analysisd/testrule.c @@ -83,6 +83,7 @@ int main(int argc, char **argv) memset(prev_month, '\0', 4); #ifdef LIBGEOIP_ENABLED + extern GeoIP *geoipdb; geoipdb = NULL; #endif -- 2.29.3