1 /* @(#) $Id: ./src/remoted/sendmsg.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"
21 /* pthread send_msg mutex */
22 pthread_mutex_t sendmsg_mutex;
24 /* pthread key update mutex */
25 pthread_mutex_t keyupdate_mutex;
28 /* void keyupdate_init()
33 /* Initializing mutex */
34 pthread_mutex_init(&keyupdate_mutex, NULL);
38 /* void void key_lock()
40 * Locks/unlocks the update mutex.
44 if(pthread_mutex_lock(&keyupdate_mutex) != 0)
46 merror(MUTEX_ERROR, ARGV0);
51 if(pthread_mutex_unlock(&keyupdate_mutex) != 0)
53 merror(MUTEX_ERROR, ARGV0);
59 * Check for key updates.
63 /* Checking key for updates. */
64 if(!OS_CheckUpdateKeys(&keys))
71 /* Locking before using */
72 if(pthread_mutex_lock(&sendmsg_mutex) != 0)
75 merror(MUTEX_ERROR, ARGV0);
79 if(OS_UpdateKeys(&keys))
81 if(pthread_mutex_unlock(&sendmsg_mutex) != 0)
83 merror(MUTEX_ERROR, ARGV0);
89 if(pthread_mutex_unlock(&sendmsg_mutex) != 0)
91 merror(MUTEX_ERROR, ARGV0);
100 * Initializes send_msg.
104 /* Initializing mutex */
105 pthread_mutex_init(&sendmsg_mutex, NULL);
110 * Send message to an agent.
111 * Returns -1 on error
113 int send_msg(int agentid, char *msg)
116 char crypt_msg[OS_MAXSTR +1];
119 /* If we don't have the agent id, ignore it */
120 if(keys.keyentries[agentid]->rcvd < (time(0) - (2*NOTIFY_TIME)))
126 msg_size = CreateSecMSG(&keys, msg, crypt_msg, agentid);
129 merror(SEC_ERROR,ARGV0);
134 /* Locking before using */
135 if(pthread_mutex_lock(&sendmsg_mutex) != 0)
137 merror(MUTEX_ERROR, ARGV0);
142 /* Sending initial message */
143 if(sendto(logr.sock, crypt_msg, msg_size, 0,
144 (struct sockaddr *)&keys.keyentries[agentid]->peer_info,
147 merror(SEND_ERROR,ARGV0, keys.keyentries[agentid]->id);
151 /* Unlocking mutex */
152 if(pthread_mutex_unlock(&sendmsg_mutex) != 0)
154 merror(MUTEX_ERROR, ARGV0);