1 /* @(#) $Id: main.c,v 1.23 2009/11/18 19:07:41 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
18 int main(int argc, char **argv)
22 int test_config = 0,run_foreground = 0;
24 char *cfg = DEFAULTCPATH;
25 char *dir = DEFAULTDIR;
27 char *group = GROUPGLOBAL;
30 /* Setting the name -- must be done ASAP */
34 while((c = getopt(argc, argv, "Vdthfu:g:c:D:")) != -1){
50 ErrorExit("%s: -u needs an argument",ARGV0);
55 ErrorExit("%s: -g needs an argument",ARGV0);
63 ErrorExit("%s: -c need an argument", ARGV0);
68 ErrorExit("%s: -D needs an argument",ARGV0);
73 debug1(STARTED_MSG,ARGV0);
76 /* Return 0 if not configured */
77 if(RemotedConfig(cfg, &logr) < 0)
79 ErrorExit(CONFIG_ERROR, ARGV0, cfg);
83 /* Exit if test_config is set */
88 /* Check if the user and group given are valid */
89 uid = Privsep_GetUser(user);
90 gid = Privsep_GetGroup(group);
91 if((uid < 0)||(gid < 0))
92 ErrorExit(USER_ERROR, ARGV0, user, group);
95 /* pid before going daemon */
106 /* Setting new group */
107 if(Privsep_SetGroup(gid) < 0)
108 ErrorExit(SETGID_ERROR, ARGV0, group);
110 /* Going on chroot */
111 if(Privsep_Chroot(dir) < 0)
112 ErrorExit(CHROOT_ERROR,ARGV0,dir);
118 /* Starting the signal manipulation */
122 /* Creating some randoness */
126 srandom( time(0) + getpid()+ i);
132 /* Start up message */
133 verbose(STARTUP_MSG, ARGV0, (int)getpid());
136 /* Really starting the program. */
138 while(logr.conn[i] != 0)
140 /* Forking for each connection handler */
144 debug1("%s: DEBUG: Forking remoted: '%d'.",ARGV0, i);
145 HandleRemote(i, uid);