1 /* @(#) $Id: ./src/agentlessd/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
15 #include "agentlessd.h"
16 #include "config/config.h"
20 int main(int argc, char **argv)
22 int c, test_config = 0, run_foreground = 0;
24 char *dir = DEFAULTDIR;
26 char *group = GROUPGLOBAL;
27 char *cfg = DEFAULTCPATH;
30 /* Setting the name */
34 while((c = getopt(argc, argv, "Vdhtfu:g:D:c:")) != -1){
50 ErrorExit("%s: -u needs an argument",ARGV0);
55 ErrorExit("%s: -g needs an argument",ARGV0);
60 ErrorExit("%s: -D needs an argument",ARGV0);
65 ErrorExit("%s: -c needs an argument",ARGV0);
80 debug1(STARTED_MSG,ARGV0);
83 /* Check if the user/group given are valid */
84 uid = Privsep_GetUser(user);
85 gid = Privsep_GetGroup(group);
86 if((uid < 0)||(gid < 0))
87 ErrorExit(USER_ERROR,ARGV0,user,group);
93 lessdc.entries = NULL;
96 if(ReadConfig(c, cfg, &lessdc, NULL) < 0)
98 ErrorExit(XML_INV_AGENTLESS, ARGV0);
102 /* Exit here if test config is set */
107 /* Going on daemon mode */
116 /* Exiting if not configured. */
119 verbose("%s: INFO: Not configured. Exiting.", ARGV0);
124 /* Privilege separation */
125 if(Privsep_SetGroup(gid) < 0)
126 ErrorExit(SETGID_ERROR,ARGV0,group);
130 if(Privsep_SetUser(uid) < 0)
131 ErrorExit(SETUID_ERROR,ARGV0,user);
134 debug1(PRIVSEP_MSG,ARGV0,dir,user);
138 /* Signal manipulation */
143 /* Creating PID files */
144 if(CreatePID(ARGV0, getpid()) < 0)
145 ErrorExit(PID_ERROR,ARGV0);
148 /* Start up message */
149 verbose(STARTUP_MSG, ARGV0, (int)getpid());
152 /* the real daemon now */