3 /* Copyright (C) 2009 Trend Micro Inc.
6 * This program is a free software; you can redistribute it
7 * and/or modify it under the terms of the GNU General Public
8 * License (version 2) as published by the FSF - Free Software
14 #include "config/config.h"
16 #include "os_net/os_net.h"
19 int main(int argc, char **argv)
21 int c, test_config = 0, run_foreground = 0;
23 char *dir = DEFAULTDIR;
25 char *group = GROUPGLOBAL;
26 char *cfg = DEFAULTCPATH;
28 /* Initializing global variables */
31 /* Setting the name */
35 while((c = getopt(argc, argv, "Vdhtfu:g:D:c:")) != -1){
51 ErrorExit("%s: -u needs an argument",ARGV0);
56 ErrorExit("%s: -g needs an argument",ARGV0);
61 ErrorExit("%s: -D needs an argument",ARGV0);
65 ErrorExit("%s: -c needs an argument",ARGV0);
79 debug1(STARTED_MSG,ARGV0);
81 /*Check if the user/group given are valid */
82 uid = Privsep_GetUser(user);
83 gid = Privsep_GetGroup(group);
84 if((uid < 0)||(gid < 0))
85 ErrorExit(USER_ERROR,ARGV0,user,group);
88 /* Getting config options */
89 mond.day_wait = getDefine_Int("monitord",
92 mond.compress = getDefine_Int("monitord",
95 mond.sign = getDefine_Int("monitord","sign",0,1);
97 mond.monitor_agents = getDefine_Int("monitord","monitor_agents",0,1);
100 mond.smtpserver = NULL;
101 mond.emailfrom = NULL;
106 if(ReadConfig(c, cfg, &mond, NULL) < 0)
108 ErrorExit(CONFIG_ERROR, ARGV0, cfg);
111 /* If we have any reports configured, read smtp/emailfrom */
117 char *(xml_smtp[])={"ossec_config", "global", "smtp_server", NULL};
118 char *(xml_from[])={"ossec_config", "global", "email_from", NULL};
120 if(OS_ReadXML(cfg, &xml) < 0)
122 ErrorExit(CONFIG_ERROR, ARGV0, cfg);
125 tmpsmtp = OS_GetOneContentforElement(&xml,xml_smtp);
126 mond.emailfrom = OS_GetOneContentforElement(&xml,xml_from);
128 if(tmpsmtp && mond.emailfrom)
130 mond.smtpserver = OS_GetHost(tmpsmtp, 5);
133 merror(INVALID_SMTP, ARGV0, tmpsmtp);
134 if(mond.emailfrom) free(mond.emailfrom);
135 mond.emailfrom = NULL;
136 merror("%s: Invalid SMTP server. Disabling email reports.", ARGV0);
141 if(tmpsmtp) free(tmpsmtp);
142 if(mond.emailfrom) free(mond.emailfrom);
144 mond.emailfrom = NULL;
146 merror("%s: SMTP server or 'email from' missing. Disabling email reports.", ARGV0);
153 /* Exit here if test config is set */
160 /* Going on daemon mode */
166 /* Privilege separation */
167 if(Privsep_SetGroup(gid) < 0)
168 ErrorExit(SETGID_ERROR,ARGV0,group);
172 if(Privsep_Chroot(dir) < 0)
173 ErrorExit(CHROOT_ERROR,ARGV0,dir);
180 if(Privsep_SetUser(uid) < 0)
181 ErrorExit(SETUID_ERROR,ARGV0,user);
184 debug1(PRIVSEP_MSG,ARGV0,dir,user);
188 /* Signal manipulation */
193 /* Creating PID files */
194 if(CreatePID(ARGV0, getpid()) < 0)
195 ErrorExit(PID_ERROR,ARGV0);
198 /* Start up message */
199 verbose(STARTUP_MSG, ARGV0, (int)getpid());
202 /* the real daemon now */