1 /* @(#) $Id: ./src/client-agent/notify.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
16 #include "os_crypto/md5/md5_op.h"
17 #include "os_net/os_net.h"
20 time_t g_saved_time = 0;
23 char *rand_keepalive_str2(char *dst, int size)
25 static const char text[] = "abcdefghijklmnopqrstuvwxyz"
26 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
28 "!@#$%^&*()_+-=;'[],./?";
29 int i, len = rand() % (size - 1);
30 for ( i = 0; i < len; ++i )
32 dst[i] = text[rand() % (sizeof text - 1)];
38 /* getfiles: Return the name of the files in a directory
40 char *getsharedfiles()
49 if(OS_MD5_File(SHAREDCFG_FILE, md5sum) != 0)
57 /* we control these files, max size is m_size */
58 ret = (char *)calloc(m_size +1, sizeof(char));
61 merror(MEM_ERROR, ARGV0);
66 snprintf(ret, m_size, "%s merged.mg\n", md5sum);
74 /* run_notify: Send periodically notification to server */
77 char keep_alive_random[1024];
78 char tmp_msg[OS_SIZE_1024 +1];
84 keep_alive_random[0] = '\0';
92 /* Check if the server has responded */
93 if((curr_time - available_server) > agt->max_time_reconnect_try)
95 /* If response is not available, set lock and
98 verbose(SERVER_UNAV, ARGV0);
101 /* Send sync message */
104 verbose(SERVER_UP, ARGV0);
110 /* Check if time has elapsed */
111 if((curr_time - g_saved_time) < agt->notify_time)
115 g_saved_time = curr_time;
117 debug1("%s: DEBUG: Sending agent notification.", ARGV0);
121 * Message is going to be the
122 * uname\n checksum file\n checksum file\n
129 merror(MEM_ERROR,ARGV0);
134 /* get shared files */
135 shared_files = getsharedfiles();
138 shared_files = strdup("\0");
142 merror(MEM_ERROR,ARGV0);
147 rand_keepalive_str2(keep_alive_random, 700);
150 /* creating message */
151 if((File_DateofChange(AGENTCONFIGINT) > 0 ) &&
152 (OS_MD5_File(AGENTCONFIGINT, md5sum) == 0))
154 snprintf(tmp_msg, OS_SIZE_1024, "#!-%s / %s\n%s\n%s",
155 uname, md5sum, shared_files, keep_alive_random);
159 snprintf(tmp_msg, OS_SIZE_1024, "#!-%s\n%s\n%s",
160 uname, shared_files, keep_alive_random);
164 /* Sending status message */
165 send_msg(0, tmp_msg);