1 /* @(#) $Id: ./src/client-agent/main.c, 2011/09/08 dcid Exp $
4 /* Copyright (C) 2009 Trend Micro Inc.
7 * This program is a free software; you can redistribute it
8 * and/or modify it under the terms of the GNU General Public
9 * License (version 2) as published by the FSF - Free Software
13 /* Part of the OSSEC HIDS
14 * Available at http://www.ossec.net
26 #define ARGV0 "ossec-agentd"
33 /* main, v0.2, 2005/11/09
35 int main(int argc, char **argv)
41 char *dir = DEFAULTDIR;
43 char *group = GROUPGLOBAL;
50 /* Setting the name */
54 while((c = getopt(argc, argv, "Vtdfhu:g:D:")) != -1){
71 ErrorExit("%s: -u needs an argument",ARGV0);
76 ErrorExit("%s: -g needs an argument",ARGV0);
84 ErrorExit("%s: -D needs an argument",ARGV0);
91 debug1(STARTED_MSG, ARGV0);
93 agt = (agent *)calloc(1, sizeof(agent));
96 ErrorExit(MEM_ERROR, ARGV0);
100 /* Check current debug_level
101 * Command line setting takes precedence
103 if (debug_level == 0)
105 /* Getting debug level */
106 debug_level = getDefine_Int("agent","debug", 0, 2);
107 while(debug_level != 0)
116 if(ClientConf(DEFAULTCPATH) < 0)
118 ErrorExit(CLIENT_ERROR,ARGV0);
123 merror(AG_INV_IP, ARGV0);
124 ErrorExit(CLIENT_ERROR,ARGV0);
127 if(agt->notify_time == 0)
129 agt->notify_time = NOTIFY_TIME;
131 if(agt->max_time_reconnect_try == 0 )
133 agt->max_time_reconnect_try = NOTIFY_TIME * 3;
135 if(agt->max_time_reconnect_try <= agt->notify_time)
137 agt->max_time_reconnect_try = (agt->notify_time * 3);
138 verbose("%s: INFO: Max time to reconnect can't be less than notify_time(%d), using notify_time*3 (%d)",ARGV0,agt->notify_time,agt->max_time_reconnect_try);
140 verbose("%s: INFO: Using notify time: %d and max time to reconnect: %d",ARGV0,agt->notify_time,agt->max_time_reconnect_try);
143 /* Checking auth keys */
146 ErrorExit(AG_NOKEYS_EXIT, ARGV0);
150 /* Check if the user/group given are valid */
151 uid = Privsep_GetUser(user);
152 gid = Privsep_GetGroup(group);
153 if((uid < 0)||(gid < 0))
155 ErrorExit(USER_ERROR,ARGV0,user,group);
160 /* Exit if test config */
165 /* Starting the signal manipulation */
170 AgentdStart(dir, uid, gid, user, group);