1 /* @(#) $Id: main.c,v 1.3 2009/11/18 19:07:39 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
14 #include "agentlessd.h"
15 #include "config/config.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;
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);
78 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);
91 lessdc.entries = NULL;
94 if(ReadConfig(c, cfg, &lessdc, NULL) < 0)
96 ErrorExit(XML_INV_AGENTLESS, ARGV0);
100 /* Exit here if test config is set */
105 /* Going on daemon mode */
114 /* Exiting if not configured. */
117 verbose("%s: INFO: Not configured. Exiting.", ARGV0);
122 /* Privilege separation */
123 if(Privsep_SetGroup(gid) < 0)
124 ErrorExit(SETGID_ERROR,ARGV0,group);
128 if(Privsep_SetUser(uid) < 0)
129 ErrorExit(SETUID_ERROR,ARGV0,user);
132 debug1(PRIVSEP_MSG,ARGV0,dir,user);
136 /* Signal manipulation */
141 /* Creating PID files */
142 if(CreatePID(ARGV0, getpid()) < 0)
143 ErrorExit(PID_ERROR,ARGV0);
146 /* Start up message */
147 verbose(STARTUP_MSG, ARGV0, (int)getpid());
150 /* the real daemon now */