-/* @(#) $Id: agent_control.c,v 1.11 2009/06/24 18:53:09 dcid Exp $ */
+/* @(#) $Id: ./src/util/agent_control.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
*/
int gid = 0;
int uid = 0;
int c = 0, restart_syscheck = 0, restart_all_agents = 0, list_agents = 0;
- int info_agent = 0, agt_id = 0, active_only = 0, csv_output = 0;
+ int info_agent = 0, agt_id = 0, active_only = 0, csv_output = 0;
int list_responses = 0, end_time = 0, restart_agent = 0;
char shost[512];
-
+
keystore keys;
-
-
+
+
/* Setting the name */
OS_SetName(ARGV0);
-
-
+
+
/* user arguments */
if(argc < 2)
{
break;
case 'L':
list_responses = 1;
- break;
+ break;
case 'e':
end_time = 1;
- break;
+ break;
case 'r':
restart_syscheck = 1;
break;
list_agents++;
break;
case 's':
- csv_output = 1;
- break;
+ csv_output = 1;
+ break;
case 'c':
active_only++;
- break;
+ break;
case 'i':
info_agent++;
case 'u':
helpmsg();
}
agent_id = optarg;
- restart_agent = 1;
+ restart_agent = 1;
case 'a':
restart_all_agents = 1;
break;
}
}
-
-
+
+
/* Getting the group name */
gid = Privsep_GetGroup(group);
uid = Privsep_GetUser(user);
ErrorExit(USER_ERROR, ARGV0, user, group);
}
-
+
/* Setting the group */
if(Privsep_SetGroup(gid) < 0)
{
ErrorExit(SETGID_ERROR,ARGV0, group);
}
-
-
+
+
/* Chrooting to the default directory */
if(Privsep_Chroot(dir) < 0)
{
/* Inside chroot now */
nowChroot();
-
+
/* Setting the user */
if(Privsep_SetUser(uid) < 0)
{
printf("\nOSSEC HIDS %s. Available active responses:\n", ARGV0);
}
-
+
fp = fopen(DEFAULTAR, "r");
if(fp)
{
r_cmd = strchr(buffer, ' ');
if(!r_cmd)
continue;
-
+
*r_cmd = '\0';
r_cmd++;
if(*r_cmd == '-')
r_timeout = strchr(r_cmd, ' ');
if(!r_timeout)
continue;
- *r_timeout = '\0';
-
+ *r_timeout = '\0';
+
if(strcmp(r_name, "restart-ossec0") == 0)
{
continue;
exit(0);
}
-
+
/* Listing available agents. */
if(list_agents)
{
if(!csv_output)
{
- printf("\nOSSEC HIDS %s. List of available agents:",
+ printf("\nOSSEC HIDS %s. List of available agents:",
ARGV0);
printf("\n ID: 000, Name: %s (server), IP: 127.0.0.1, Active/Local\n",
shost);
printf("\n");
exit(0);
}
-
+
/* Checking if the provided ID is valid. */
- if(agent_id != NULL)
+ if(agent_id != NULL)
{
if(strcmp(agent_id, "000") != 0)
{
agt_id = -1;
}
}
-
+
/* Printing information from an agent. */
char final_ip[128 +1];
char final_mask[128 +1];
agent_info *agt_info;
-
+
final_ip[128] = '\0';
final_mask[128] = '\0';
-
+
if(!csv_output)
printf("\nOSSEC HIDS %s. Agent information:", ARGV0);
/* Getting netmask from ip. */
getNetmask(keys.keyentries[agt_id]->ip->netmask, final_mask, 128);
- snprintf(final_ip, 128, "%s%s",keys.keyentries[agt_id]->ip->ip,
+ snprintf(final_ip, 128, "%s%s",keys.keyentries[agt_id]->ip->ip,
final_mask);
}
else
{
- printf("%s,%s,%s,%s,",
+ printf("%s,%s,%s,%s,",
keys.keyentries[agt_id]->id,
keys.keyentries[agt_id]->name,
final_ip,
- print_agent_status(agt_status));
+ print_agent_status(agt_status));
}
}
else
{
- agt_status = get_agent_status(NULL, NULL);
+ agt_status = get_agent_status(NULL, NULL);
agt_info = get_agent_info(NULL, "127.0.0.1");
if(!csv_output)
printf("000,%s,127.0.0.1,%s/Local,",
shost,
print_agent_status(agt_status));
-
+
}
}
-
+
if(!csv_output)
{
printf(" Operating system: %s\n", agt_info->os);
printf(" Client version: %s\n", agt_info->version);
printf(" Last keep alive: %s\n\n", agt_info->last_keepalive);
-
+
if(end_time)
{
}
else
{
- printf("%s,%s,%s,%s,%s,\n",
+ printf("%s,%s,%s,%s,%s,\n",
agt_info->os,
agt_info->version,
agt_info->last_keepalive,
agt_info->syscheck_time,
agt_info->rootcheck_time);
}
-
+
exit(0);
}
exit(0);
}
-
+
if(restart_syscheck && agent_id)
exit(0);
}
-
-
+
+
if(restart_agent && agent_id)
{
/* Connecting to remoted. */
exit(0);
}
-
+
printf("\n** Invalid argument combination.\n");
helpmsg();