1 /* @(#) $Id: ./src/remoted/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
19 int main(int argc, char **argv)
23 int test_config = 0,run_foreground = 0;
25 char *cfg = DEFAULTCPATH;
26 char *dir = DEFAULTDIR;
28 char *group = GROUPGLOBAL;
31 /* Setting the name -- must be done ASAP */
35 while((c = getopt(argc, argv, "Vdthfu:g:c:D:")) != -1){
51 ErrorExit("%s: -u needs an argument",ARGV0);
56 ErrorExit("%s: -g needs an argument",ARGV0);
64 ErrorExit("%s: -c need an argument", ARGV0);
69 ErrorExit("%s: -D needs an argument",ARGV0);
74 debug1(STARTED_MSG,ARGV0);
77 /* Return 0 if not configured */
78 if(RemotedConfig(cfg, &logr) < 0)
80 ErrorExit(CONFIG_ERROR, ARGV0, cfg);
84 /* Exit if test_config is set */
94 /* Check if the user and group given are valid */
95 uid = Privsep_GetUser(user);
96 gid = Privsep_GetGroup(group);
97 if((uid < 0)||(gid < 0))
98 ErrorExit(USER_ERROR, ARGV0, user, group);
101 /* pid before going daemon */
112 /* Setting new group */
113 if(Privsep_SetGroup(gid) < 0)
114 ErrorExit(SETGID_ERROR, ARGV0, group);
116 /* Going on chroot */
117 if(Privsep_Chroot(dir) < 0)
118 ErrorExit(CHROOT_ERROR,ARGV0,dir);
124 /* Starting the signal manipulation */
128 /* Creating some randoness */
132 srandom( time(0) + getpid()+ i);
138 /* Start up message */
139 verbose(STARTUP_MSG, ARGV0, (int)getpid());
142 /* Really starting the program. */
144 while(logr.conn[i] != 0)
146 /* Forking for each connection handler */
150 debug1("%s: DEBUG: Forking remoted: '%d'.",ARGV0, i);
151 HandleRemote(i, uid);