X-Git-Url: http://ftp.carnet.hr/pub/carnet-debian/scm?a=blobdiff_plain;f=src%2Fremoted%2Fmain.c;h=e02f9bfd6ae604943e1a270aa0289aa656c82bd3;hb=927951d1c1ad45ba9e7325f07d996154a91c911b;hp=2f83a8d100ab54f587ecf717086c402b3429ffe2;hpb=301048b51990573e58a30dc4a5bb4ec285cad554;p=ossec-hids.git diff --git a/src/remoted/main.c b/src/remoted/main.c index 2f83a8d..e02f9bf 100755 --- a/src/remoted/main.c +++ b/src/remoted/main.c @@ -1,4 +1,5 @@ -/* @(#) $Id$ */ +/* @(#) $Id: ./src/remoted/main.c, 2011/09/08 dcid Exp $ + */ /* Copyright (C) 2009 Trend Micro Inc. * All right reserved. @@ -19,18 +20,19 @@ int main(int argc, char **argv) { int i = 0,c = 0; int uid = 0, gid = 0; + int debug_level = 0; int test_config = 0,run_foreground = 0; - + char *cfg = DEFAULTCPATH; char *dir = DEFAULTDIR; char *user = REMUSER; char *group = GROUPGLOBAL; - + /* Setting the name -- must be done ASAP */ OS_SetName(ARGV0); - + while((c = getopt(argc, argv, "Vdthfu:g:c:D:")) != -1){ switch(c){ case 'V': @@ -41,6 +43,7 @@ int main(int argc, char **argv) break; case 'd': nowDebug(); + debug_level = 1; break; case 'f': run_foreground = 1; @@ -54,9 +57,9 @@ int main(int argc, char **argv) if(!optarg) ErrorExit("%s: -g needs an argument",ARGV0); group = optarg; - break; + break; case 't': - test_config = 1; + test_config = 1; break; case 'c': if (!optarg) @@ -67,12 +70,28 @@ int main(int argc, char **argv) if(!optarg) ErrorExit("%s: -D needs an argument",ARGV0); dir = optarg; + break; + } + } + + /* Check current debug_level + * Command line setting takes precedence + */ + if (debug_level == 0) + { + /* Getting debug level */ + debug_level = getDefine_Int("remoted", "debug", 0, 2); + while(debug_level != 0) + { + nowDebug(); + debug_level--; } } + debug1(STARTED_MSG,ARGV0); - - + + /* Return 0 if not configured */ if(RemotedConfig(cfg, &logr) < 0) { @@ -84,7 +103,12 @@ int main(int argc, char **argv) if(test_config) exit(0); - + if(logr.conn == NULL) + { + /* Not configured. */ + exit(0); + } + /* Check if the user and group given are valid */ uid = Privsep_GetUser(user); gid = Privsep_GetGroup(group); @@ -96,13 +120,13 @@ int main(int argc, char **argv) i = getpid(); - if(!run_foreground) + if(!run_foreground) { nowDaemon(); goDaemon(); } - + /* Setting new group */ if(Privsep_SetGroup(gid) < 0) ErrorExit(SETGID_ERROR, ARGV0, group); @@ -116,7 +140,7 @@ int main(int argc, char **argv) /* Starting the signal manipulation */ - StartSIG(ARGV0); + StartSIG(ARGV0); /* Creating some randoness */ @@ -125,21 +149,21 @@ int main(int argc, char **argv) #else srandom( time(0) + getpid()+ i); #endif - + random(); - + /* Start up message */ verbose(STARTUP_MSG, ARGV0, (int)getpid()); /* Really starting the program. */ - i = 0; + i = 0; while(logr.conn[i] != 0) { /* Forking for each connection handler */ if(fork() == 0) - { + { /* On the child */ debug1("%s: DEBUG: Forking remoted: '%d'.",ARGV0, i); HandleRemote(i, uid);