1 /* @(#) $Id: main.c,v 1.9 2009/11/18 19:07:40 dcid Exp $ */
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 3) as published by the FSF - Free Software
17 int main(int argc, char **argv)
19 int c, test_config = 0, run_foreground = 0;
21 char *dir = DEFAULTDIR;
23 char *group = GROUPGLOBAL;
24 char *cfg = DEFAULTCPATH;
26 /* Initializing global variables */
29 /* Setting the name */
33 while((c = getopt(argc, argv, "Vdhtfu:g:D:c:")) != -1){
49 ErrorExit("%s: -u needs an argument",ARGV0);
54 ErrorExit("%s: -g needs an argument",ARGV0);
59 ErrorExit("%s: -D needs an argument",ARGV0);
63 ErrorExit("%s: -c needs an argument",ARGV0);
77 debug1(STARTED_MSG,ARGV0);
79 /*Check if the user/group given are valid */
80 uid = Privsep_GetUser(user);
81 gid = Privsep_GetGroup(group);
82 if((uid < 0)||(gid < 0))
83 ErrorExit(USER_ERROR,ARGV0,user,group);
86 /* Getting config options */
87 mond.day_wait = getDefine_Int("monitord",
90 mond.compress = getDefine_Int("monitord",
93 mond.sign = getDefine_Int("monitord","sign",0,1);
95 mond.monitor_agents = getDefine_Int("monitord","monitor_agents",0,1);
100 /* Exit here if test config is set */
107 /* Going on daemon mode */
113 /* Privilege separation */
114 if(Privsep_SetGroup(gid) < 0)
115 ErrorExit(SETGID_ERROR,ARGV0,group);
119 if(Privsep_Chroot(dir) < 0)
120 ErrorExit(CHROOT_ERROR,ARGV0,dir);
127 if(Privsep_SetUser(uid) < 0)
128 ErrorExit(SETUID_ERROR,ARGV0,user);
131 debug1(PRIVSEP_MSG,ARGV0,dir,user);
135 /* Signal manipulation */
140 /* Creating PID files */
141 if(CreatePID(ARGV0, getpid()) < 0)
142 ErrorExit(PID_ERROR,ARGV0);
145 /* Start up message */
146 verbose(STARTUP_MSG, ARGV0, (int)getpid());
149 /* the real daemon now */