1 /* Copyright (C) 2009 Trend Micro Inc.
4 * This program is a free software; you can redistribute it
5 * and/or modify it under the terms of the GNU General Public
6 * License (version 2) as published by the FSF - Free Software
14 #include "os_net/os_net.h"
17 /* Start of a new thread. Only returns on unrecoverable errors. */
18 void *AR_Forward(__attribute__((unused)) void *arg)
24 char msg_to_send[OS_SIZE_1024 + 1];
26 char msg[OS_SIZE_1024 + 1];
27 char *location = NULL;
28 char *ar_location_str = NULL;
29 char *ar_agent_id = NULL;
32 /* Create the unix queue */
33 if ((arq = StartMQ(ARQUEUE, READ)) < 0) {
34 ErrorExit(QUEUE_ERROR, ARGV0, ARQUEUE, strerror(errno));
37 memset(msg, '\0', OS_SIZE_1024 + 1);
41 if (OS_RecvUnix(arq, OS_SIZE_1024, msg)) {
42 /* Always zero the location */
45 /* Get the location */
48 /* Location is going to be the agent name */
49 tmp_str = strchr(msg, ')');
51 merror(EXECD_INV_MSG, ARGV0, msg);
56 /* Going after the ')' and space */
59 /* Extract the source IP */
60 tmp_str = strchr(tmp_str, ' ');
62 merror(EXECD_INV_MSG, ARGV0, msg);
69 ar_location_str = tmp_str;
70 if (*tmp_str == ALL_AGENTS_C) {
71 ar_location |= ALL_AGENTS;
74 if (*tmp_str == REMOTE_AGENT_C) {
75 ar_location |= REMOTE_AGENT;
76 } else if (*tmp_str == NO_AR_C) {
77 ar_location |= NO_AR_MSG;
80 if (*tmp_str == SPECIFIC_AGENT_C) {
81 ar_location |= SPECIFIC_AGENT;
84 /* Extract the active response location */
85 tmp_str = strchr(ar_location_str, ' ');
87 merror(EXECD_INV_MSG, ARGV0, msg);
93 /* Extract the agent id */
94 ar_agent_id = tmp_str;
95 tmp_str = strchr(tmp_str, ' ');
97 merror(EXECD_INV_MSG, ARGV0, msg);
103 /* Create the new message */
104 if (ar_location & NO_AR_MSG) {
105 snprintf(msg_to_send, OS_SIZE_1024, "%s%s",
109 snprintf(msg_to_send, OS_SIZE_1024, "%s%s%s",
115 /* Lock use of keys */
118 /* Send to ALL agents */
119 if (ar_location & ALL_AGENTS) {
121 for (i = 0; i < keys.keysize; i++) {
122 send_msg(i, msg_to_send);
126 /* Send to the remote agent that generated the event */
127 else if ((ar_location & REMOTE_AGENT) && (location != NULL)) {
128 agent_id = OS_IsAllowedName(&keys, location);
131 merror(AR_NOAGENT_ERROR, ARGV0, location);
135 send_msg((unsigned)agent_id, msg_to_send);
138 /* Send to a pre-defined agent */
139 else if (ar_location & SPECIFIC_AGENT) {
142 agent_id = OS_IsAllowedID(&keys, ar_agent_id);
146 merror(AR_NOAGENT_ERROR, ARGV0, ar_agent_id);
150 send_msg((unsigned)agent_id, msg_to_send);
153 /* Lock use of keys */