X-Git-Url: http://ftp.carnet.hr/carnet-debian/scm?p=ossec-hids.git;a=blobdiff_plain;f=src%2Fremoted%2Far-forward.c;h=d04ecd700180c188374982099811198ce588b0c0;hp=034bcdf532ea010cd405e8b05239aa50fa4f1431;hb=3f728675941dc69d4e544d3a880a56240a6e394a;hpb=927951d1c1ad45ba9e7325f07d996154a91c911b diff --git a/src/remoted/ar-forward.c b/src/remoted/ar-forward.c old mode 100755 new mode 100644 index 034bcdf..d04ecd7 --- a/src/remoted/ar-forward.c +++ b/src/remoted/ar-forward.c @@ -1,6 +1,3 @@ -/* @(#) $Id: ./src/remoted/ar-forward.c, 2011/09/08 dcid Exp $ - */ - /* Copyright (C) 2009 Trend Micro Inc. * All right reserved. * @@ -10,194 +7,152 @@ * Foundation */ - -#include "shared.h" #include +#include "shared.h" #include "remoted.h" #include "os_net/os_net.h" - -/** void *AR_Forward(void *arg) v0.1 - * Start of a new thread. Only returns - * on unrecoverable errors. - */ -void *AR_Forward(void *arg) +/* Start of a new thread. Only returns on unrecoverable errors. */ +void *AR_Forward(__attribute__((unused)) void *arg) { - int i = 0; int arq = 0; int agent_id = 0; int ar_location = 0; - char msg_to_send[OS_SIZE_1024 +1]; + char msg_to_send[OS_SIZE_1024 + 1]; - char msg[OS_SIZE_1024 +1]; + char msg[OS_SIZE_1024 + 1]; char *location = NULL; char *ar_location_str = NULL; char *ar_agent_id = NULL; char *tmp_str = NULL; - - /* Creating the unix queue */ - if((arq = StartMQ(ARQUEUE, READ)) < 0) - { + /* Create the unix queue */ + if ((arq = StartMQ(ARQUEUE, READ)) < 0) { ErrorExit(QUEUE_ERROR, ARGV0, ARQUEUE, strerror(errno)); } - memset(msg, '\0', OS_SIZE_1024 +1); + memset(msg, '\0', OS_SIZE_1024 + 1); /* Daemon loop */ - while(1) - { - if(OS_RecvUnix(arq, OS_SIZE_1024, msg)) - { - /* Always zeroing the location */ + while (1) { + if (OS_RecvUnix(arq, OS_SIZE_1024, msg)) { + /* Always zero the location */ ar_location = 0; - - /* Getting the location */ + /* Get the location */ location = msg; - /* Location is going to be the agent name */ tmp_str = strchr(msg, ')'); - if(!tmp_str) - { + if (!tmp_str) { merror(EXECD_INV_MSG, ARGV0, msg); continue; } *tmp_str = '\0'; - /* Going after the ')' and space */ tmp_str += 2; - - /* Extracting the source ip */ + /* Extract the source IP */ tmp_str = strchr(tmp_str, ' '); - if(!tmp_str) - { + if (!tmp_str) { merror(EXECD_INV_MSG, ARGV0, msg); continue; } tmp_str++; location++; - - /* Setting ar_location */ + /* Set ar_location */ ar_location_str = tmp_str; - if(*tmp_str == ALL_AGENTS_C) - { - ar_location|=ALL_AGENTS; + if (*tmp_str == ALL_AGENTS_C) { + ar_location |= ALL_AGENTS; } tmp_str++; - if(*tmp_str == REMOTE_AGENT_C) - { - ar_location|=REMOTE_AGENT; - } - else if(*tmp_str == NO_AR_C) - { - ar_location|=NO_AR_MSG; + if (*tmp_str == REMOTE_AGENT_C) { + ar_location |= REMOTE_AGENT; + } else if (*tmp_str == NO_AR_C) { + ar_location |= NO_AR_MSG; } tmp_str++; - if(*tmp_str == SPECIFIC_AGENT_C) - { - ar_location|=SPECIFIC_AGENT; + if (*tmp_str == SPECIFIC_AGENT_C) { + ar_location |= SPECIFIC_AGENT; } - - /*** Extracting the active response location ***/ + /* Extract the active response location */ tmp_str = strchr(ar_location_str, ' '); - if(!tmp_str) - { + if (!tmp_str) { merror(EXECD_INV_MSG, ARGV0, msg); continue; } *tmp_str = '\0'; tmp_str++; - - /*** Extracting the agent id */ + /* Extract the agent id */ ar_agent_id = tmp_str; tmp_str = strchr(tmp_str, ' '); - if(!tmp_str) - { + if (!tmp_str) { merror(EXECD_INV_MSG, ARGV0, msg); continue; } *tmp_str = '\0'; tmp_str++; - - /*** Creating the new message ***/ - if(ar_location & NO_AR_MSG) - { + /* Create the new message */ + if (ar_location & NO_AR_MSG) { snprintf(msg_to_send, OS_SIZE_1024, "%s%s", - CONTROL_HEADER, - tmp_str); - } - else - { + CONTROL_HEADER, + tmp_str); + } else { snprintf(msg_to_send, OS_SIZE_1024, "%s%s%s", - CONTROL_HEADER, - EXECD_HEADER, - tmp_str); + CONTROL_HEADER, + EXECD_HEADER, + tmp_str); } - /* Lock use of keys */ key_lock(); - - /* Sending to ALL agents */ - if(ar_location & ALL_AGENTS) - { - for(i = 0;i< keys.keysize; i++) - { + /* Send to ALL agents */ + if (ar_location & ALL_AGENTS) { + unsigned int i; + for (i = 0; i < keys.keysize; i++) { send_msg(i, msg_to_send); } } /* Send to the remote agent that generated the event */ - else if((ar_location & REMOTE_AGENT) && (location != NULL)) - { + else if ((ar_location & REMOTE_AGENT) && (location != NULL)) { agent_id = OS_IsAllowedName(&keys, location); - if(agent_id < 0) - { + if (agent_id < 0) { key_unlock(); merror(AR_NOAGENT_ERROR, ARGV0, location); continue; } - send_msg(agent_id, msg_to_send); + send_msg((unsigned)agent_id, msg_to_send); } /* Send to a pre-defined agent */ - else if(ar_location & SPECIFIC_AGENT) - { + else if (ar_location & SPECIFIC_AGENT) { ar_location++; agent_id = OS_IsAllowedID(&keys, ar_agent_id); - if(agent_id < 0) - { + if (agent_id < 0) { key_unlock(); merror(AR_NOAGENT_ERROR, ARGV0, ar_agent_id); continue; } - send_msg(agent_id, msg_to_send); + send_msg((unsigned)agent_id, msg_to_send); } /* Lock use of keys */ key_unlock(); } } - - return (NULL); } - - -/* EOF */