1 /* Copyright (C) 2009 Trend Micro Inc.
4 * This program is a free software; you can redistribute it
5 * and/or modify it under the terms of the GNU General Public
6 * License (version 2) as published by the FSF - Free Software
14 static void help_remoted(void) __attribute__((noreturn));
17 /* Print help statement */
18 static void help_remoted()
21 print_out(" %s: -[Vhdtf] [-u user] [-g group] [-c config] [-D dir]", ARGV0);
22 print_out(" -V Version and license message");
23 print_out(" -h This help message");
24 print_out(" -d Execute in debug mode. This parameter");
25 print_out(" can be specified multiple times");
26 print_out(" to increase the debug level.");
27 print_out(" -t Test configuration");
28 print_out(" -f Run in foreground");
29 print_out(" -u <user> User to run as (default: %s)", REMUSER);
30 print_out(" -g <group> Group to run as (default: %s)", GROUPGLOBAL);
31 print_out(" -c <config> Configuration file to use (default: %s)", DEFAULTCPATH);
32 print_out(" -D <dir> Directory to chroot into (default: %s)", DEFAULTDIR);
37 int main(int argc, char **argv)
43 int test_config = 0, run_foreground = 0;
45 const char *cfg = DEFAULTCPATH;
46 const char *dir = DEFAULTDIR;
47 const char *user = REMUSER;
48 const char *group = GROUPGLOBAL;
53 while ((c = getopt(argc, argv, "Vdthfu:g:c:D:")) != -1) {
70 ErrorExit("%s: -u needs an argument", ARGV0);
76 ErrorExit("%s: -g needs an argument", ARGV0);
85 ErrorExit("%s: -c need an argument", ARGV0);
91 ErrorExit("%s: -D needs an argument", ARGV0);
101 /* Check current debug_level
102 * Command line setting takes precedence
104 if (debug_level == 0) {
105 /* Get debug level */
106 debug_level = getDefine_Int("remoted", "debug", 0, 2);
107 while (debug_level != 0) {
113 debug1(STARTED_MSG, ARGV0);
115 /* Return 0 if not configured */
116 if (RemotedConfig(cfg, &logr) < 0) {
117 ErrorExit(CONFIG_ERROR, ARGV0, cfg);
120 /* Exit if test_config is set */
125 if (logr.conn == NULL) {
130 /* Don't exit when client.keys empty (if set) */
131 if (getDefine_Int("remoted", "pass_empty_keyfile", 0, 1)) {
132 OS_PassEmptyKeyfile();
136 /* Check if the user and group given are valid */
137 uid = Privsep_GetUser(user);
138 gid = Privsep_GetGroup(group);
139 if (uid == (uid_t) - 1 || gid == (gid_t) - 1) {
140 ErrorExit(USER_ERROR, ARGV0, user, group);
146 /* pid before going daemon */
149 if (!run_foreground) {
155 if (Privsep_SetGroup(gid) < 0) {
156 ErrorExit(SETGID_ERROR, ARGV0, group, errno, strerror(errno));
160 if (Privsep_Chroot(dir) < 0) {
161 ErrorExit(CHROOT_ERROR, ARGV0, dir, errno, strerror(errno));
165 /* Start the signal manipulation */
170 /* Start up message */
171 verbose(STARTUP_MSG, ARGV0, (int)getpid());
173 /* Really start the program */
175 while (logr.conn[i] != 0) {
176 /* Fork for each connection handler */
179 debug1("%s: DEBUG: Forking remoted: '%d'.", ARGV0, i);
180 HandleRemote(i, uid);