-/* @(#) $Id$ */
+/* @(#) $Id: ./src/agentlessd/agentlessd.c, 2011/09/08 dcid Exp $
+ */
/* Copyright (C) 2009 Trend Micro Inc.
* All rights reserved.
char sys_location[1024 +1];
sys_location[1024] = '\0';
- snprintf(sys_location, 1024, "%s/(%s) %s",
+ snprintf(sys_location, 1024, "%s/(%s) %s",
AGENTLESS_ENTRYDIRPATH, script, host);
fp = fopen(sys_location, "w");
sys_location[1024] = '\0';
snprintf(sys_location, 1024, "(%s) %s->%s", script, host, SYSCHECK);
-
+
if(SendMSG(lessdc.queue, msg, sys_location, SYSCHECK_MQ) < 0)
{
merror(QUEUE_SEND, ARGV0);
sys_location[1024] = '\0';
snprintf(sys_location, 1024, "(%s) %s->%s", script, host, SYSCHECK);
-
+
if(SendMSG(lessdc.queue, msg, sys_location, LOCALFILE_MQ) < 0)
{
merror(QUEUE_SEND, ARGV0);
snprintf(buf, 2048, "%s/%s->%s/diff.%d",
DIFF_DIR_PATH, host, script, alert_diff_time);
-
+
fp = fopen(buf, "r");
if(!fp)
{
else
{
/* Weird diff with only one large line. */
- buf[256] = '\0';
+ buf[256] = '\0';
}
}
else
/* Getting up to 8 line changes. */
tmp_str = buf;
-
+
while(tmp_str && (*tmp_str != '\0'))
{
tmp_str = strchr(tmp_str, '\n');
if(!tmp_str)
- break;
+ break;
else if(n >= 7)
{
- *tmp_str = '\0';
+ *tmp_str = '\0';
break;
}
n++;
- tmp_str++;
+ tmp_str++;
}
buf, n>=7?
"\nMore changes..":
"");
-
-
+
+
snprintf(buf, 1024, "(%s) %s->agentless", script, host);
-
+
if(SendMSG(lessdc.queue, diff_alert, buf, LOCALFILE_MQ) < 0)
{
merror(QUEUE_SEND, ARGV0);
os_md5 md5sum_old;
os_md5 md5sum_new;
-
+
old_location[1024] = '\0';
new_location[1024] = '\0';
tmp_location[1024] = '\0';
if(OS_MD5_File(new_location, md5sum_new) != 0)
{
merror("%s: ERROR: Invalid internal state (missing '%s').",
- ARGV0, new_location);
+ ARGV0, new_location);
return(0);
}
/* Run diff. */
date_of_change = File_DateofChange(old_location);
- snprintf(diff_cmd, 2048, "diff \"%s\" \"%s\" > \"%s/%s->%s/diff.%d\" "
+ snprintf(diff_cmd, 2048, "diff \"%s\" \"%s\" > \"%s/%s->%s/diff.%d\" "
"2>/dev/null",
- tmp_location, old_location,
+ tmp_location, old_location,
DIFF_DIR_PATH, host, script, date_of_change);
if(system(diff_cmd) != 256)
{
merror("%s: ERROR: Unable to run diff for %s->%s",
ARGV0, host, script);
- return(0);
+ return(0);
}
{
FILE *fp = NULL;
char sys_location[1024 +1];
-
+
sys_location[1024] = '\0';
snprintf(sys_location, 1024, "%s/%s->%s/%s", DIFF_DIR_PATH, host, script,
DIFF_NEW_FILE);
}
}
- snprintf(sys_location, 1024, "%s/%s->%s/%s", DIFF_DIR_PATH, host,
+ snprintf(sys_location, 1024, "%s/%s->%s/%s", DIFF_DIR_PATH, host,
script, DIFF_NEW_FILE);
fp = fopen(sys_location, "w");
if(!fp)
char command[OS_SIZE_1024 +1];
FILE *fp;
FILE *fp_store = NULL;
-
-
+
+
buf[0] = '\0';
command[0] = '\0';
- command[OS_SIZE_1024] = '\0';
-
-
+ command[OS_SIZE_1024] = '\0';
+
+
while(entry->server[i])
{
/* Ignored entry. */
i++;
continue;
}
-
-
- /* We only test for the first server entry. */
+
+
+ /* We only test for the first server entry. */
else if(test_it)
{
int ret_code = 0;
- snprintf(command, OS_SIZE_1024,
- "%s/%s test test >/dev/null 2>&1",
+ snprintf(command, OS_SIZE_1024,
+ "%s/%s test test >/dev/null 2>&1",
AGENTLESSDIRPATH, entry->type);
ret_code = system(command);
{
merror("%s: ERROR: Expect command not found (or bad "
"arguments) for '%s'.",
- ARGV0, entry->type);
+ ARGV0, entry->type);
}
merror("%s: ERROR: Test failed for '%s' (%d). Ignoring.",
ARGV0, entry->type, ret_code/256);
verbose("%s: INFO: Test passed for '%s'.", ARGV0, entry->type);
return(0);
}
-
+
if(entry->server[i][0] == 's')
{
- snprintf(command, OS_SIZE_1024, "%s/%s \"use_su\" \"%s\" %s 2>&1",
- AGENTLESSDIRPATH, entry->type, entry->server[i] +1,
+ snprintf(command, OS_SIZE_1024, "%s/%s \"use_su\" \"%s\" %s 2>&1",
+ AGENTLESSDIRPATH, entry->type, entry->server[i] +1,
entry->options);
}
else if(entry->server[i][0] == 'o')
{
- snprintf(command, OS_SIZE_1024, "%s/%s \"use_sudo\" \"%s\" %s 2>&1",
- AGENTLESSDIRPATH, entry->type, entry->server[i] +1,
+ snprintf(command, OS_SIZE_1024, "%s/%s \"use_sudo\" \"%s\" %s 2>&1",
+ AGENTLESSDIRPATH, entry->type, entry->server[i] +1,
entry->options);
}
else
{
- snprintf(command, OS_SIZE_1024, "%s/%s \"%s\" %s 2>&1",
- AGENTLESSDIRPATH, entry->type, entry->server[i] +1,
+ snprintf(command, OS_SIZE_1024, "%s/%s \"%s\" %s 2>&1",
+ AGENTLESSDIRPATH, entry->type, entry->server[i] +1,
entry->options);
}
tmp_str = strchr(buf, '\n');
if(tmp_str)
*tmp_str = '\0';
-
+
if(strncmp(buf, "ERROR: ", 7) == 0)
{
- merror("%s: ERROR: %s: %s: %s", ARGV0,
+ merror("%s: ERROR: %s: %s: %s", ARGV0,
entry->type, entry->server[i] +1, buf +7);
entry->error_flag++;
break;
}
else if(strncmp(buf, "INFO: ", 6) == 0)
{
- verbose("%s: INFO: %s: %s: %s", ARGV0,
+ verbose("%s: INFO: %s: %s: %s", ARGV0,
entry->type, entry->server[i] +1, buf +6);
}
else if(strncmp(buf, "FWD: ", 4) == 0)
{
tmp_str = buf + 5;
- send_intcheck_msg(entry->type, entry->server[i]+1,
+ send_intcheck_msg(entry->type, entry->server[i]+1,
tmp_str);
}
else if(strncmp(buf, "LOG: ", 4) == 0)
else if((entry->state & LESSD_STATE_DIFF) &&
(strncmp(buf, "STORE: ", 7) == 0))
{
- fp_store = open_diff_file(entry->server[i]+1,
+ fp_store = open_diff_file(entry->server[i]+1,
entry->type);
}
else if(fp_store)
}
else
{
- save_agentless_entry(entry->server[i] +1,
+ save_agentless_entry(entry->server[i] +1,
entry->type, "syscheck");
}
pclose(fp);
}
else
{
- merror("%s: ERROR: popen failed on '%s' for '%s'.", ARGV0,
+ merror("%s: ERROR: popen failed on '%s' for '%s'.", ARGV0,
entry->type, entry->server[i] +1);
entry->error_flag++;
}
{
fclose(fp_store);
}
-
+
return(0);
}
/* Main agentlessd */
void Agentlessd()
{
- time_t tm;
- struct tm *p;
+ time_t tm;
+ struct tm *p;
- int today = 0;
+ int today = 0;
int thismonth = 0;
int thisyear = 0;
int test_it = 1;
/* Waiting a few seconds to settle */
sleep(2);
memset(str, '\0', OS_SIZE_1024 +1);
-
-
+
+
/* Getting currently time before starting */
tm = time(NULL);
p = localtime(&tm);
-
+
today = p->tm_mday;
thismonth = p->tm_mon;
thisyear = p->tm_year+1900;
-
+
/* Connecting to the message queue
* Exit if it fails.
if(lessdc.entries[i]->error_flag != 99)
{
merror("%s: ERROR: Too many failures for '%s'. Ignoring it.",
- ARGV0, lessdc.entries[i]->type);
+ ARGV0, lessdc.entries[i]->type);
lessdc.entries[i]->error_flag = 99;
}
continue;
}
-
+
/* Run the check again if the frequency has elapsed. */
if((lessdc.entries[i]->state & LESSD_STATE_PERIODIC) &&
- ((lessdc.entries[i]->current_state +
+ ((lessdc.entries[i]->current_state +
lessdc.entries[i]->frequency) < tm))
{
run_periodic_cmd(lessdc.entries[i], test_it);
if(!test_it)
lessdc.entries[i]->current_state = tm;
}
-
+
i++;
sleep(i);
}
-
+
/* We only check every minute */
test_it = 0;
sleep(60);