1 /* @(#) $Id: ./src/remoted/ar-forward.c, 2011/09/08 dcid Exp $
4 /* Copyright (C) 2009 Trend Micro Inc.
7 * This program is a free software; you can redistribute it
8 * and/or modify it under the terms of the GNU General Public
9 * License (version 2) as published by the FSF - Free Software
18 #include "os_net/os_net.h"
22 /** void *AR_Forward(void *arg) v0.1
23 * Start of a new thread. Only returns
24 * on unrecoverable errors.
26 void *AR_Forward(void *arg)
33 char msg_to_send[OS_SIZE_1024 +1];
35 char msg[OS_SIZE_1024 +1];
36 char *location = NULL;
37 char *ar_location_str = NULL;
38 char *ar_agent_id = NULL;
42 /* Creating the unix queue */
43 if((arq = StartMQ(ARQUEUE, READ)) < 0)
45 ErrorExit(QUEUE_ERROR, ARGV0, ARQUEUE, strerror(errno));
48 memset(msg, '\0', OS_SIZE_1024 +1);
53 if(OS_RecvUnix(arq, OS_SIZE_1024, msg))
55 /* Always zeroing the location */
59 /* Getting the location */
63 /* Location is going to be the agent name */
64 tmp_str = strchr(msg, ')');
67 merror(EXECD_INV_MSG, ARGV0, msg);
73 /* Going after the ')' and space */
77 /* Extracting the source ip */
78 tmp_str = strchr(tmp_str, ' ');
81 merror(EXECD_INV_MSG, ARGV0, msg);
88 /* Setting ar_location */
89 ar_location_str = tmp_str;
90 if(*tmp_str == ALL_AGENTS_C)
92 ar_location|=ALL_AGENTS;
95 if(*tmp_str == REMOTE_AGENT_C)
97 ar_location|=REMOTE_AGENT;
99 else if(*tmp_str == NO_AR_C)
101 ar_location|=NO_AR_MSG;
104 if(*tmp_str == SPECIFIC_AGENT_C)
106 ar_location|=SPECIFIC_AGENT;
110 /*** Extracting the active response location ***/
111 tmp_str = strchr(ar_location_str, ' ');
114 merror(EXECD_INV_MSG, ARGV0, msg);
121 /*** Extracting the agent id */
122 ar_agent_id = tmp_str;
123 tmp_str = strchr(tmp_str, ' ');
126 merror(EXECD_INV_MSG, ARGV0, msg);
133 /*** Creating the new message ***/
134 if(ar_location & NO_AR_MSG)
136 snprintf(msg_to_send, OS_SIZE_1024, "%s%s",
142 snprintf(msg_to_send, OS_SIZE_1024, "%s%s%s",
149 /* Lock use of keys */
153 /* Sending to ALL agents */
154 if(ar_location & ALL_AGENTS)
156 for(i = 0;i< keys.keysize; i++)
158 send_msg(i, msg_to_send);
162 /* Send to the remote agent that generated the event */
163 else if((ar_location & REMOTE_AGENT) && (location != NULL))
165 agent_id = OS_IsAllowedName(&keys, location);
169 merror(AR_NOAGENT_ERROR, ARGV0, location);
173 send_msg(agent_id, msg_to_send);
176 /* Send to a pre-defined agent */
177 else if(ar_location & SPECIFIC_AGENT)
181 agent_id = OS_IsAllowedID(&keys, ar_agent_id);
186 merror(AR_NOAGENT_ERROR, ARGV0, ar_agent_id);
190 send_msg(agent_id, msg_to_send);
193 /* Lock use of keys */