-/* @(#) $Id: agentd.c,v 1.44 2009/06/24 17:06:24 dcid Exp $ */
+/* @(#) $Id: ./src/client-agent/agentd.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 rc = 0;
int pid = 0;
- int maxfd = 0;
+ int maxfd = 0;
fd_set fdset;
-
+
struct timeval fdtimeout;
-
+
/* Going daemon */
pid = getpid();
available_server = 0;
nowDaemon();
goDaemon();
-
+
/* Setting group ID */
if(Privsep_SetGroup(gid) < 0)
ErrorExit(SETGID_ERROR, ARGV0, group);
-
+
/* chrooting */
if(Privsep_Chroot(dir) < 0)
ErrorExit(CHROOT_ERROR, ARGV0, dir);
-
+
nowChroot();
maxfd = logr->m_queue;
logr->sock = -1;
-
+
/* Creating PID file */
/* Reading the private keys */
verbose(ENC_READ, ARGV0);
-
+
OS_ReadKeys(&keys);
OS_StartCounter(&keys);
+
+ /* cmoraes : changed the following call to
os_write_agent_info(keys.keyentries[0]->name, NULL, keys.keyentries[0]->id);
+ */
+ os_write_agent_info(keys.keyentries[0]->name, NULL, keys.keyentries[0]->id,
+ logr->profile);
/* Start up message */
verbose(STARTUP_MSG, ARGV0, (int)getpid());
-
+
/* Initial random numbers */
#ifdef __OpenBSD__
srandomdev();
#else
srandom( time(0) + getpid()+ pid + getppid());
#endif
-
+
random();
{
ErrorExit(UNABLE_CONN, ARGV0);
}
-
+
/* Setting max fd for select */
if(logr->sock > maxfd)
os_setwait();
start_agent(1);
-
+
os_delwait();
intcheck_file(OSSECCONF, dir);
intcheck_file(OSSEC_DEFINES, dir);
-
+
/* Sending first notification */
run_notify();
-
-
+
+
/* Maxfd must be higher socket +1 */
maxfd++;
-
-
+
+
/* monitor loop */
while(1)
{
fdtimeout.tv_sec = 120;
fdtimeout.tv_usec = 0;
-
+
/* Wait for 120 seconds at a maximum for any descriptor */
rc = select(maxfd, &fdset, NULL, NULL, &fdtimeout);
if(rc == -1)
{
ErrorExit(SELECT_ERROR, ARGV0);
}
-
-
+
+
else if(rc == 0)
{
continue;
- }
+ }
+
-
/* For the receiver */
if(FD_ISSET(logr->sock, &fdset))
{
receive_msg();
}
-
+
/* For the forwarder */
if(FD_ISSET(logr->m_queue, &fdset))
{