1 /* @(#) $Id: notify.c,v 1.23 2009/06/26 13:50:02 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
15 #include "os_crypto/md5/md5_op.h"
16 #include "os_net/os_net.h"
19 time_t g_saved_time = 0;
23 /* getfiles: Return the name of the files in a directory
25 char *getsharedfiles()
34 if(OS_MD5_File(SHAREDCFG_FILE, md5sum) != 0)
42 /* we control these files, max size is m_size */
43 ret = (char *)calloc(m_size +1, sizeof(char));
46 merror(MEM_ERROR, ARGV0);
51 snprintf(ret, m_size, "%s merged.mg\n", md5sum);
59 /* run_notify: Send periodically notification to server */
62 char tmp_msg[OS_SIZE_1024 +1];
71 /* Check if the server has responded */
72 if((curr_time - available_server) > (3*NOTIFY_TIME))
74 /* If response is not available, set lock and
77 verbose(SERVER_UNAV, ARGV0);
80 /* Send sync message */
83 verbose(SERVER_UP, ARGV0);
88 /* Check if time has elapsed */
89 if((curr_time - g_saved_time) < (NOTIFY_TIME - 120))
93 g_saved_time = curr_time;
95 debug1("%s: DEBUG: Sending agent notification.", ARGV0);
99 * Message is going to be the
100 * uname\n checksum file\n checksum file\n
107 merror(MEM_ERROR,ARGV0);
112 /* get shared files */
113 shared_files = getsharedfiles();
116 shared_files = strdup("\0");
120 merror(MEM_ERROR,ARGV0);
126 /* creating message */
127 if(File_DateofChange(AGENTCONFIGINT) > 0)
130 if(OS_MD5_File(AGENTCONFIGINT, md5sum) != 0)
132 snprintf(tmp_msg, OS_SIZE_1024, "#!-%s\n%s",uname, shared_files);
136 snprintf(tmp_msg, OS_SIZE_1024, "#!-%s / %s\n%s",uname, md5sum, shared_files);
141 snprintf(tmp_msg, OS_SIZE_1024, "#!-%s\n%s",uname, shared_files);
145 /* Sending status message */
146 send_msg(0, tmp_msg);