projects
/
ossec-hids.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
new upstream release (3.3.0); modify package compatibility for Stretch
[ossec-hids.git]
/
src
/
client-agent
/
receiver-win.c
diff --git
a/src/client-agent/receiver-win.c
b/src/client-agent/receiver-win.c
old mode 100755
(executable)
new mode 100644
(file)
index
73456df
..
859bdf7
--- a/
src/client-agent/receiver-win.c
+++ b/
src/client-agent/receiver-win.c
@@
-1,5
+1,3
@@
-/* @(#) $Id$ */
-
/* Copyright (C) 2009 Trend Micro Inc.
* All right reserved.
*
/* Copyright (C) 2009 Trend Micro Inc.
* All right reserved.
*
@@
-9,8
+7,8
@@
* Foundation
*/
* Foundation
*/
-
#ifdef WIN32
#ifdef WIN32
+
#include "shared.h"
#include "os_execd/execd.h"
#include "os_crypto/md5/md5_op.h"
#include "shared.h"
#include "os_execd/execd.h"
#include "os_crypto/md5/md5_op.h"
@@
-18,226
+16,181
@@
#include "agentd.h"
#include "agentd.h"
-
-/* receiver_thread:
- * Receive events from the server.
- */
-void *receiver_thread(void *none)
+/* Receive events from the server */
+void *receiver_thread(__attribute__((unused)) void *none)
{
int recv_b;
{
int recv_b;
-
- char file[OS_SIZE_1024 +1];
- char buffer[OS_MAXSTR +1];
-
+
+ char file[OS_SIZE_1024 + 1];
+ char buffer[OS_MAXSTR + 1];
+
char cleartext[OS_MAXSTR + 1];
char *tmp_msg;
char cleartext[OS_MAXSTR + 1];
char *tmp_msg;
-
+
char file_sum[34];
fd_set fdset;
struct timeval selecttime;
char file_sum[34];
fd_set fdset;
struct timeval selecttime;
-
- FILE *fp;
+ FILE *fp;
- /* Setting FP to null, before starting */
+ /* Set FP to null before starting */
fp = NULL;
fp = NULL;
-
- memset(cleartext, '\0', OS_MAXSTR +1);
- memset(buffer, '\0', OS_MAXSTR +1);
- memset(file, '\0', OS_SIZE_1024 +1);
+
+ memset(cleartext, '\0', OS_MAXSTR + 1);
+ memset(buffer, '\0', OS_MAXSTR + 1);
+ memset(file, '\0', OS_SIZE_1024 + 1);
memset(file_sum, '\0', 34);
memset(file_sum, '\0', 34);
-
-
- while(1)
- {
- /* sock must be set. */
- if(logr->sock == -1)
- {
+
+ while (1) {
+ /* sock must be set */
+ if (agt->sock == -1) {
sleep(5);
continue;
}
FD_ZERO(&fdset);
sleep(5);
continue;
}
FD_ZERO(&fdset);
- FD_SET(logr->sock, &fdset);
-
+ FD_SET(agt->sock, &fdset);
- /* Wait for 30 seconds. */
+ /* Wait for 30 seconds */
selecttime.tv_sec = 30;
selecttime.tv_usec = 0;
selecttime.tv_sec = 30;
selecttime.tv_usec = 0;
-
- /* Wait for 120 seconds at a maximum for any descriptor */
+ /* Wait with a timeout for any descriptor */
recv_b = select(0, &fdset, NULL, NULL, &selecttime);
recv_b = select(0, &fdset, NULL, NULL, &selecttime);
- if(recv_b == -1)
- {
- merror(SELECT_ERROR, ARGV0);
+ if (recv_b == -1) {
+ merror(SELECT_ERROR, ARGV0, errno, strerror(errno));
sleep(30);
continue;
sleep(30);
continue;
- }
- else if(recv_b == 0)
- {
+ } else if (recv_b == 0) {
continue;
}
continue;
}
- /* Read until no more messages are available */
- while((recv_b = recv(logr->sock,buffer,OS_SIZE_1024, 0))>0)
- {
+ /* Read until no more messages are available */
+ while ((recv_b = recv(agt->sock, buffer, OS_SIZE_1024, 0)) > 0) {
/* Id of zero -- only one key allowed */
/* Id of zero -- only one key allowed */
- tmp_msg = ReadSecMSG(&keys, buffer, cleartext, 0, recv_b -1);
- if(tmp_msg == NULL)
- {
- merror(MSG_ERROR,ARGV0,logr->rip[logr->rip_id]);
+ tmp_msg = ReadSecMSG(&keys, buffer, cleartext, 0, recv_b - 1);
+ if (tmp_msg == NULL) {
+ merror(MSG_ERROR, ARGV0, agt->rip[agt->rip_id]);
continue;
}
continue;
}
-
/* Check for commands */
/* Check for commands */
- if(IsValidHeader(tmp_msg))
- {
+ if (IsValidHeader(tmp_msg)) {
/* This is the only thread that modifies it */
available_server = (int)time(NULL);
/* This is the only thread that modifies it */
available_server = (int)time(NULL);
-
- /* Run timeout commands. */
- if(logr->execdq >= 0)
+ /* Run timeout commands */
+ if (agt->execdq >= 0) {
WinTimeoutRun(available_server);
WinTimeoutRun(available_server);
-
+ }
+
/* If it is an active response message */
/* If it is an active response message */
- if(strncmp(tmp_msg, EXECD_HEADER, strlen(EXECD_HEADER)) == 0)
- {
- tmp_msg+=strlen(EXECD_HEADER);
-
-
- /* Run on windows. */
- if(logr->execdq >= 0)
- {
+ if (strncmp(tmp_msg, EXECD_HEADER, strlen(EXECD_HEADER)) == 0) {
+ tmp_msg += strlen(EXECD_HEADER);
+
+ /* Run on Windows */
+ if (agt->execdq >= 0) {
WinExecdRun(tmp_msg);
}
WinExecdRun(tmp_msg);
}
-
-
- continue;
- }
+ continue;
+ }
- /* Restart syscheck. */
- else if(strcmp(tmp_msg, HC_SK_RESTART) == 0)
- {
+ /* Restart syscheck */
+ else if (strcmp(tmp_msg, HC_SK_RESTART) == 0) {
os_set_restart_syscheck();
continue;
}
os_set_restart_syscheck();
continue;
}
-
/* Ack from server */
/* Ack from server */
- else if(strcmp(tmp_msg, HC_ACK) == 0)
- {
+ else if (strcmp(tmp_msg, HC_ACK) == 0) {
continue;
}
/* Close any open file pointer if it was being written to */
continue;
}
/* Close any open file pointer if it was being written to */
- if(fp)
- {
+ if (fp) {
fclose(fp);
fp = NULL;
}
/* File update message */
fclose(fp);
fp = NULL;
}
/* File update message */
- if(strncmp(tmp_msg, FILE_UPDATE_HEADER,
- strlen(FILE_UPDATE_HEADER)) == 0)
- {
+ if (strncmp(tmp_msg, FILE_UPDATE_HEADER,
+ strlen(FILE_UPDATE_HEADER)) == 0) {
char *validate_file;
char *validate_file;
- tmp_msg+=strlen(FILE_UPDATE_HEADER);
+ tmp_msg += strlen(FILE_UPDATE_HEADER);
/* Going to after the file sum */
validate_file = strchr(tmp_msg, ' ');
/* Going to after the file sum */
validate_file = strchr(tmp_msg, ' ');
- if(!validate_file)
- {
+ if (!validate_file) {
continue;
}
*validate_file = '\0';
continue;
}
*validate_file = '\0';
- /* copying the file sum */
+ /* Copy the file sum */
strncpy(file_sum, tmp_msg, 33);
strncpy(file_sum, tmp_msg, 33);
-
- /* Setting tmp_msg to the beginning of the file name */
+ /* Set tmp_msg to the beginning of the file name */
validate_file++;
tmp_msg = validate_file;
validate_file++;
tmp_msg = validate_file;
-
- if((validate_file = strchr(tmp_msg, '\n')) != NULL)
- {
+ if ((validate_file = strchr(tmp_msg, '\n')) != NULL) {
*validate_file = '\0';
}
*validate_file = '\0';
}
- while((validate_file = strchr(tmp_msg, '/')) != NULL)
- {
+ while ((validate_file = strchr(tmp_msg, '/')) != NULL) {
*validate_file = '-';
}
*validate_file = '-';
}
- if(tmp_msg[0] == '.')
- tmp_msg[0] = '-';
+ if (tmp_msg[0] == '.') {
+ tmp_msg[0] = '-';
+ }
-
- snprintf(file, OS_SIZE_1024, "%s/%s",
- SHAREDCFG_DIR,
- tmp_msg);
+ snprintf(file, OS_SIZE_1024, "%s/%s",
+ SHAREDCFG_DIR,
+ tmp_msg);
- fp = fopen(file, "w");
- if(!fp)
- {
- merror(FOPEN_ERROR, ARGV0, file);
+ fp = fopen(file, "wb");
+ if (!fp) {
+ merror(FOPEN_ERROR, ARGV0, file, errno, strerror(errno));
}
}
}
}
- else if(strncmp(tmp_msg, FILE_CLOSE_HEADER,
- strlen(FILE_CLOSE_HEADER)) == 0)
- {
- /* no error */
+ else if (strncmp(tmp_msg, FILE_CLOSE_HEADER,
+ strlen(FILE_CLOSE_HEADER)) == 0) {
+ /* No error */
os_md5 currently_md5;
os_md5 currently_md5;
- /* Making sure to close for the rename to work */
- if(fp)
- {
+ /* Close for the rename to work */
+ if (fp) {
fclose(fp);
fp = NULL;
}
fclose(fp);
fp = NULL;
}
-
- if(file[0] == '\0')
- {
- /* nada */
+
+ if (file[0] == '\0') {
+ /* Nothing to be done */
}
}
- else if(OS_MD5_File(file, currently_md5) < 0)
- {
- /* Removing file */
+ else if (OS_MD5_File(file, currently_md5, OS_TEXT) < 0) {
+ /* Remove file */
unlink(file);
file[0] = '\0';
unlink(file);
file[0] = '\0';
- }
- else
- {
- if(strcmp(currently_md5, file_sum) != 0)
- {
+ } else {
+ if (strcmp(currently_md5, file_sum) != 0) {
debug1("%s: Failed md5 for: %s -- deleting.",
debug1("%s: Failed md5 for: %s -- deleting.",
- ARGV0, file);
+ ARGV0, file);
unlink(file);
unlink(file);
- }
- else
- {
+ } else {
char *final_file;
char *final_file;
- /* Renaming the file to its orignal name */
+ /* Rename the file to its original name */
final_file = strrchr(file, '/');
final_file = strrchr(file, '/');
- if(final_file)
- {
- if(strcmp(final_file + 1, SHAREDCFG_FILENAME) == 0)
- {
+ if (final_file) {
+ if (strcmp(final_file + 1, SHAREDCFG_FILENAME) == 0) {
UnmergeFiles(file, SHAREDCFG_DIR);
}
UnmergeFiles(file, SHAREDCFG_DIR);
}
- }
- else
- {
+ } else {
unlink(file);
}
}
unlink(file);
}
}
@@
-246,40
+199,33
@@
void *receiver_thread(void *none)
}
}
}
}
- else
- {
+ else {
merror("%s: WARN: Unknown message received from server.", ARGV0);
}
}
merror("%s: WARN: Unknown message received from server.", ARGV0);
}
}
- else if(fp)
- {
+ else if (fp) {
available_server = (int)time(NULL);
fprintf(fp, "%s", tmp_msg);
}
available_server = (int)time(NULL);
fprintf(fp, "%s", tmp_msg);
}
- else
- {
+ else {
merror("%s: WARN: Unknown message received. No action defined.",
ARGV0);
}
merror("%s: WARN: Unknown message received. No action defined.",
ARGV0);
}
- }
+ }
}
}
-
- /* Cleaning up */
- if(fp)
- {
+ /* Clean up */
+ if (fp) {
fclose(fp);
fclose(fp);
- if(file[0] != '\0')
+ if (file[0] != '\0') {
unlink(file);
unlink(file);
+ }
}
}
-
- return(NULL);
+ return (NULL);
}
}
+#endif /* WIN32 */
-#endif
-
-/* EOF */