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
11 * License details at the LICENSE file included with OSSEC or
12 * online at: http://www.ossec.net/en/licensing.html
20 int main(int argc, char **argv)
22 int c, test_config = 0,run_foreground = 0;
25 /* Using MAILUSER (read only) */
26 char *dir = DEFAULTDIR;
27 char *user = MAILUSER;
28 char *group = GROUPGLOBAL;
29 char *cfg = DEFAULTCPATH;
32 /* Database Structure */
33 SyslogConfig **syslog_config = NULL;
36 /* Setting the name */
40 while((c = getopt(argc, argv, "vVdhtfu:g:D:c:")) != -1){
59 ErrorExit("%s: -u needs an argument",ARGV0);
64 ErrorExit("%s: -g needs an argument",ARGV0);
69 ErrorExit("%s: -D needs an argument",ARGV0);
73 ErrorExit("%s: -c needs an argument",ARGV0);
88 debug1(STARTED_MSG, ARGV0);
91 /* Check if the user/group given are valid */
92 uid = Privsep_GetUser(user);
93 gid = Privsep_GetGroup(group);
94 if((uid < 0)||(gid < 0))
96 ErrorExit(USER_ERROR, ARGV0, user, group);
100 /* Reading configuration */
101 syslog_config = OS_ReadSyslogConf(test_config, cfg, syslog_config);
104 /* Getting servers hostname */
105 memset(__shost, '\0', 512);
106 if(gethostname(__shost, 512 -1) != 0)
108 ErrorExit("%s: ERROR: gethostname() failed", ARGV0);
114 /* Remove domain part if available */
115 ltmp = strchr(__shost, '.');
121 /* Exit here if test config is set */
128 /* Going on daemon mode */
136 if(!syslog_config || !syslog_config[0])
138 verbose("%s: INFO: Remote syslog server not configured. "
139 "Clean exit.", ARGV0);
145 /* Privilege separation */
146 if(Privsep_SetGroup(gid) < 0)
147 ErrorExit(SETGID_ERROR,ARGV0,group);
151 if(Privsep_Chroot(dir) < 0)
152 ErrorExit(CHROOT_ERROR,ARGV0,dir);
161 if(Privsep_SetUser(uid) < 0)
162 ErrorExit(SETUID_ERROR,ARGV0,user);
165 /* Basic start up completed. */
166 debug1(PRIVSEP_MSG,ARGV0,dir,user);
169 /* Signal manipulation */
173 /* Creating PID files */
174 if(CreatePID(ARGV0, getpid()) < 0)
175 ErrorExit(PID_ERROR, ARGV0);
178 /* Start up message */
179 verbose(STARTUP_MSG, ARGV0, (int)getpid());
182 /* the real daemon now */
183 OS_CSyslogD(syslog_config);