X-Git-Url: http://ftp.carnet.hr/carnet-debian/scm?a=blobdiff_plain;f=src%2Fclient-agent%2Fnotify.c;h=e698380e6e3b6d88af426b88b2ece8cfb7e2d61d;hb=6ef2f786c6c8ead94841b5f93baf9f43421f08c8;hp=373dd664eac671a3db32f387c5545e5db83483a2;hpb=914feba5d54f979cd5d7e69c349c3d01f630042a;p=ossec-hids.git diff --git a/src/client-agent/notify.c b/src/client-agent/notify.c index 373dd66..e698380 100755 --- a/src/client-agent/notify.c +++ b/src/client-agent/notify.c @@ -1,11 +1,12 @@ -/* @(#) $Id: notify.c,v 1.23 2009/06/26 13:50:02 dcid Exp $ */ +/* @(#) $Id: ./src/client-agent/notify.c, 2011/09/08 dcid Exp $ + */ /* Copyright (C) 2009 Trend Micro Inc. * All right reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ @@ -19,6 +20,20 @@ time_t g_saved_time = 0; +char *rand_keepalive_str2(char *dst, int size) +{ + static const char text[] = "abcdefghijklmnopqrstuvwxyz" + "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + "0123456789" + "!@#$%^&*()_+-=;'[],./?"; + int i, len = rand() % (size - 1); + for ( i = 0; i < len; ++i ) + { + dst[i] = text[rand() % (sizeof text - 1)]; + } + dst[i] = '\0'; + return dst; +} /* getfiles: Return the name of the files in a directory */ @@ -27,9 +42,9 @@ char *getsharedfiles() int m_size = 512; char *ret; - + os_md5 md5sum; - + if(OS_MD5_File(SHAREDCFG_FILE, md5sum) != 0) { @@ -49,7 +64,7 @@ char *getsharedfiles() snprintf(ret, m_size, "%s merged.mg\n", md5sum); - + return(ret); } @@ -59,15 +74,21 @@ char *getsharedfiles() /* run_notify: Send periodically notification to server */ void run_notify() { + char keep_alive_random[1024]; char tmp_msg[OS_SIZE_1024 +1]; char *uname; char *shared_files; + os_md5 md5sum; + + + keep_alive_random[0] = '\0'; time_t curr_time; curr_time = time(0); + #ifndef ONEWAY /* Check if the server has responded */ if((curr_time - available_server) > (3*NOTIFY_TIME)) { @@ -83,6 +104,7 @@ void run_notify() verbose(SERVER_UP, ARGV0); os_delwait(); } + #endif /* Check if time has elapsed */ @@ -91,14 +113,14 @@ void run_notify() return; } g_saved_time = curr_time; - + debug1("%s: DEBUG: Sending agent notification.", ARGV0); /* Send the message. - * Message is going to be the - * uname\n checksum file\n checksum file\n - */ + * Message is going to be the + * uname\n checksum file\n checksum file\n + */ /* Getting uname */ uname = getuname(); @@ -122,23 +144,20 @@ void run_notify() } } + rand_keepalive_str2(keep_alive_random, 700); + /* creating message */ - if(File_DateofChange(AGENTCONFIGINT) > 0) + if((File_DateofChange(AGENTCONFIGINT) > 0 ) && + (OS_MD5_File(AGENTCONFIGINT, md5sum) == 0)) { - os_md5 md5sum; - if(OS_MD5_File(AGENTCONFIGINT, md5sum) != 0) - { - snprintf(tmp_msg, OS_SIZE_1024, "#!-%s\n%s",uname, shared_files); - } - else - { - snprintf(tmp_msg, OS_SIZE_1024, "#!-%s / %s\n%s",uname, md5sum, shared_files); - } + snprintf(tmp_msg, OS_SIZE_1024, "#!-%s / %s\n%s\n%s", + uname, md5sum, shared_files, keep_alive_random); } else { - snprintf(tmp_msg, OS_SIZE_1024, "#!-%s\n%s",uname, shared_files); + snprintf(tmp_msg, OS_SIZE_1024, "#!-%s\n%s\n%s", + uname, shared_files, keep_alive_random); }