1 /* Copyright (C) 2009 Trend Micro Inc.
4 * This program is a free software; you can redistribute it
5 * and/or modify it under the terms of the GNU General Public
6 * License (version 2) as published by the FSF - Free Software
16 #define ARGV0 "ossec-agentd"
20 static void help_agentd(void) __attribute((noreturn));
23 /* Print help statement */
24 static void help_agentd()
27 print_out(" %s: -[Vhdtf] [-u user] [-g group] [-c config] [-D dir]", ARGV0);
28 print_out(" -V Version and license message");
29 print_out(" -h This help message");
30 print_out(" -d Execute in debug mode. This parameter");
31 print_out(" can be specified multiple times");
32 print_out(" to increase the debug level.");
33 print_out(" -t Test configuration");
34 print_out(" -f Run in foreground");
35 print_out(" -u <user> User to run as (default: %s)", USER);
36 print_out(" -g <group> Group to run as (default: %s)", GROUPGLOBAL);
37 print_out(" -c <config> Configuration file to use (default: %s)", DEFAULTCPATH);
38 print_out(" -D <dir> Directory to chroot into (default: %s)", DEFAULTDIR);
43 int main(int argc, char **argv)
49 const char *dir = DEFAULTDIR;
50 const char *user = USER;
51 const char *group = GROUPGLOBAL;
52 const char *cfg = DEFAULTCPATH;
62 while ((c = getopt(argc, argv, "Vtdfhu:g:D:c:")) != -1) {
79 ErrorExit("%s: -u needs an argument", ARGV0);
85 ErrorExit("%s: -g needs an argument", ARGV0);
94 ErrorExit("%s: -D needs an argument", ARGV0);
100 ErrorExit("%s: -c needs an argument.", ARGV0);
110 debug1(STARTED_MSG, ARGV0);
112 agt = (agent *)calloc(1, sizeof(agent));
114 ErrorExit(MEM_ERROR, ARGV0, errno, strerror(errno));
117 /* Check current debug_level
118 * Command line setting takes precedence
120 if (debug_level == 0) {
121 /* Get debug level */
122 debug_level = getDefine_Int("agent", "debug", 0, 2);
123 while (debug_level != 0) {
130 if (ClientConf(cfg) < 0) {
131 ErrorExit(CLIENT_ERROR, ARGV0);
135 merror(AG_INV_IP, ARGV0);
136 ErrorExit(CLIENT_ERROR, ARGV0);
139 if (agt->notify_time == 0) {
140 agt->notify_time = NOTIFY_TIME;
142 if (agt->max_time_reconnect_try == 0 ) {
143 agt->max_time_reconnect_try = NOTIFY_TIME * 3;
145 if (agt->max_time_reconnect_try <= agt->notify_time) {
146 agt->max_time_reconnect_try = (agt->notify_time * 3);
147 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);
149 verbose("%s: INFO: Using notify time: %d and max time to reconnect: %d", ARGV0, agt->notify_time, agt->max_time_reconnect_try);
151 /* Check auth keys */
152 if (!OS_CheckKeys()) {
153 ErrorExit(AG_NOKEYS_EXIT, ARGV0);
156 /* Check if the user/group given are valid */
157 uid = Privsep_GetUser(user);
158 gid = Privsep_GetGroup(group);
159 if (uid == (uid_t) - 1 || gid == (gid_t) - 1) {
160 ErrorExit(USER_ERROR, ARGV0, user, group);
163 /* Exit if test config */
168 /* Start the signal manipulation */
172 AgentdStart(dir, uid, gid, user, group);