1 /* @(#) $Id: ar-forward.c,v 1.27 2009/06/24 18:53:07 dcid Exp $ */
3 /* Copyright (C) 2009 Trend Micro Inc.
6 * This program is a free software; you can redistribute it
7 * and/or modify it under the terms of the GNU General Public
8 * License (version 3) as published by the FSF - Free Software
17 #include "os_net/os_net.h"
21 /** void *AR_Forward(void *arg) v0.1
22 * Start of a new thread. Only returns
23 * on unrecoverable errors.
25 void *AR_Forward(void *arg)
32 char msg_to_send[OS_SIZE_1024 +1];
34 char msg[OS_SIZE_1024 +1];
35 char *location = NULL;
36 char *ar_location_str = NULL;
37 char *ar_agent_id = NULL;
41 /* Creating the unix queue */
42 if((arq = StartMQ(ARQUEUE, READ)) < 0)
44 ErrorExit(QUEUE_ERROR, ARGV0, ARQUEUE, strerror(errno));
47 memset(msg, '\0', OS_SIZE_1024 +1);
52 if(OS_RecvUnix(arq, OS_SIZE_1024, msg))
54 /* Always zeroing the location */
58 /* Getting the location */
62 /* Location is going to be the agent name */
63 tmp_str = strchr(msg, ')');
66 merror(EXECD_INV_MSG, ARGV0, msg);
72 /* Going after the ')' and space */
76 /* Extracting the source ip */
77 tmp_str = strchr(tmp_str, ' ');
80 merror(EXECD_INV_MSG, ARGV0, msg);
87 /* Setting ar_location */
88 ar_location_str = tmp_str;
89 if(*tmp_str == ALL_AGENTS_C)
91 ar_location|=ALL_AGENTS;
94 if(*tmp_str == REMOTE_AGENT_C)
96 ar_location|=REMOTE_AGENT;
98 else if(*tmp_str == NO_AR_C)
100 ar_location|=NO_AR_MSG;
103 if(*tmp_str == SPECIFIC_AGENT_C)
105 ar_location|=SPECIFIC_AGENT;
109 /*** Extracting the active response location ***/
110 tmp_str = strchr(ar_location_str, ' ');
113 merror(EXECD_INV_MSG, ARGV0, msg);
120 /*** Extracting the agent id */
121 ar_agent_id = tmp_str;
122 tmp_str = strchr(tmp_str, ' ');
125 merror(EXECD_INV_MSG, ARGV0, msg);
132 /*** Creating the new message ***/
133 if(ar_location & NO_AR_MSG)
135 snprintf(msg_to_send, OS_SIZE_1024, "%s%s",
141 snprintf(msg_to_send, OS_SIZE_1024, "%s%s%s",
148 /* Lock use of keys */
152 /* Sending to ALL agents */
153 if(ar_location & ALL_AGENTS)
155 for(i = 0;i< keys.keysize; i++)
157 send_msg(i, msg_to_send);
161 /* Send to the remote agent that generated the event */
162 else if((ar_location & REMOTE_AGENT) && (location != NULL))
164 agent_id = OS_IsAllowedName(&keys, location);
168 merror(AR_NOAGENT_ERROR, ARGV0, location);
172 send_msg(agent_id, msg_to_send);
175 /* Send to a pre-defined agent */
176 else if(ar_location & SPECIFIC_AGENT)
180 agent_id = OS_IsAllowedID(&keys, ar_agent_id);
185 merror(AR_NOAGENT_ERROR, ARGV0, ar_agent_id);
189 send_msg(agent_id, msg_to_send);
192 /* Lock use of keys */