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)
24 int test_config = 0,run_foreground = 0;
26 char *cfg = DEFAULTCPATH;
27 char *dir = DEFAULTDIR;
29 char *group = GROUPGLOBAL;
32 /* Setting the name -- must be done ASAP */
36 while((c = getopt(argc, argv, "Vdthfu:g:c:D:")) != -1){
53 ErrorExit("%s: -u needs an argument",ARGV0);
58 ErrorExit("%s: -g needs an argument",ARGV0);
66 ErrorExit("%s: -c need an argument", ARGV0);
71 ErrorExit("%s: -D needs an argument",ARGV0);
77 /* Check current debug_level
78 * Command line setting takes precedence
82 /* Getting debug level */
83 debug_level = getDefine_Int("remoted", "debug", 0, 2);
84 while(debug_level != 0)
92 debug1(STARTED_MSG,ARGV0);
95 /* Return 0 if not configured */
96 if(RemotedConfig(cfg, &logr) < 0)
98 ErrorExit(CONFIG_ERROR, ARGV0, cfg);
102 /* Exit if test_config is set */
106 if(logr.conn == NULL)
108 /* Not configured. */
112 /* Check if the user and group given are valid */
113 uid = Privsep_GetUser(user);
114 gid = Privsep_GetGroup(group);
115 if((uid < 0)||(gid < 0))
116 ErrorExit(USER_ERROR, ARGV0, user, group);
119 /* pid before going daemon */
130 /* Setting new group */
131 if(Privsep_SetGroup(gid) < 0)
132 ErrorExit(SETGID_ERROR, ARGV0, group);
134 /* Going on chroot */
135 if(Privsep_Chroot(dir) < 0)
136 ErrorExit(CHROOT_ERROR,ARGV0,dir);
142 /* Starting the signal manipulation */
146 /* Creating some randoness */
150 srandom( time(0) + getpid()+ i);
156 /* Start up message */
157 verbose(STARTUP_MSG, ARGV0, (int)getpid());
160 /* Really starting the program. */
162 while(logr.conn[i] != 0)
164 /* Forking for each connection handler */
168 debug1("%s: DEBUG: Forking remoted: '%d'.",ARGV0, i);
169 HandleRemote(i, uid);