1 /* @(#) $Id: ./src/os_csyslogd/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
12 * License details at the LICENSE file included with OSSEC or
13 * online at: http://www.ossec.net/en/licensing.html
21 int main(int argc, char **argv)
23 int c, test_config = 0,run_foreground = 0;
26 /* Using MAILUSER (read only) */
27 char *dir = DEFAULTDIR;
28 char *user = MAILUSER;
29 char *group = GROUPGLOBAL;
30 char *cfg = DEFAULTCPATH;
33 /* Database Structure */
34 SyslogConfig **syslog_config = NULL;
37 /* Setting the name */
41 while((c = getopt(argc, argv, "vVdhtfu:g:D:c:")) != -1){
60 ErrorExit("%s: -u needs an argument",ARGV0);
65 ErrorExit("%s: -g needs an argument",ARGV0);
70 ErrorExit("%s: -D needs an argument",ARGV0);
75 ErrorExit("%s: -c needs an argument",ARGV0);
90 debug1(STARTED_MSG, ARGV0);
93 /* Check if the user/group given are valid */
94 uid = Privsep_GetUser(user);
95 gid = Privsep_GetGroup(group);
96 if((uid < 0)||(gid < 0))
98 ErrorExit(USER_ERROR, ARGV0, user, group);
102 /* Reading configuration */
103 syslog_config = OS_ReadSyslogConf(test_config, cfg, syslog_config);
106 /* Getting servers hostname */
107 memset(__shost, '\0', 512);
108 if(gethostname(__shost, 512 -1) != 0)
110 ErrorExit("%s: ERROR: gethostname() failed", ARGV0);
116 /* Remove domain part if available */
117 ltmp = strchr(__shost, '.');
123 /* Exit here if test config is set */
130 /* Going on daemon mode */
138 if(!syslog_config || !syslog_config[0])
140 verbose("%s: INFO: Remote syslog server not configured. "
141 "Clean exit.", ARGV0);
147 /* Privilege separation */
148 if(Privsep_SetGroup(gid) < 0)
149 ErrorExit(SETGID_ERROR,ARGV0,group);
153 if(Privsep_Chroot(dir) < 0)
154 ErrorExit(CHROOT_ERROR,ARGV0,dir);
163 if(Privsep_SetUser(uid) < 0)
164 ErrorExit(SETUID_ERROR,ARGV0,user);
167 /* Basic start up completed. */
168 debug1(PRIVSEP_MSG,ARGV0,dir,user);
171 /* Signal manipulation */
175 /* Creating PID files */
176 if(CreatePID(ARGV0, getpid()) < 0)
177 ErrorExit(PID_ERROR, ARGV0);
180 /* Start up message */
181 verbose(STARTUP_MSG, ARGV0, (int)getpid());
184 /* the real daemon now */
185 OS_CSyslogD(syslog_config);