Imported Upstream version 2.7
[ossec-hids.git] / src / os_dbd / main.c
index 613ef50..6e0b2a2 100755 (executable)
@@ -1,4 +1,5 @@
-/* @(#) $Id$ */
+/* @(#) $Id: ./src/os_dbd/main.c, 2011/09/08 dcid Exp $
+ */
 
 /* Copyright (C) 2009 Trend Micro Inc.
  * All rights reserved.
@@ -8,7 +9,7 @@
  * License (version 2) as published by the FSF - Free Software
  * Foundation.
  *
- * License details at the LICENSE file included with OSSEC or 
+ * License details at the LICENSE file included with OSSEC or
  * online at: http://www.ossec.net/en/licensing.html
  */
 
@@ -30,7 +31,7 @@ void db_info()
 {
     print_out(" ");
     print_out("%s %s - %s", __name, __version, __author);
-    
+
     #ifdef UMYSQL
     print_out("Compiled with MySQL support.");
     #endif
@@ -42,7 +43,7 @@ void db_info()
     #if !defined(UMYSQL) && !defined(UPOSTGRES)
     print_out("Compiled without any Database support.");
     #endif
-    
+
     print_out(" ");
     print_out("%s",__license);
 
@@ -70,7 +71,7 @@ int main(int argc, char **argv)
 
     /* Setting the name */
     OS_SetName(ARGV0);
-        
+
 
     while((c = getopt(argc, argv, "vVdhtfu:g:D:c:")) != -1){
         switch(c){
@@ -79,7 +80,7 @@ int main(int argc, char **argv)
                 break;
             case 'v':
                 db_info();
-                break;    
+                break;
             case 'h':
                 help(ARGV0);
                 break;
@@ -103,13 +104,14 @@ int main(int argc, char **argv)
                 if(!optarg)
                     ErrorExit("%s: -D needs an argument",ARGV0);
                 dir=optarg;
+                break;
             case 'c':
                 if(!optarg)
                     ErrorExit("%s: -c needs an argument",ARGV0);
                 cfg = optarg;
                 break;
             case 't':
-                test_config = 1;    
+                test_config = 1;
                 break;
             default:
                 help(ARGV0);
@@ -142,9 +144,9 @@ int main(int argc, char **argv)
     /* Exit here if test config is set */
     if(test_config)
         exit(0);
-        
-        
-    if(!run_foreground) 
+
+
+    if(!run_foreground)
     {
         /* Going on daemon mode */
         nowDaemon();
@@ -152,7 +154,7 @@ int main(int argc, char **argv)
     }
 
 
-    
+
     /* Not configured */
     if(c == 0)
     {
@@ -160,10 +162,10 @@ int main(int argc, char **argv)
         exit(0);
     }
 
-    
+
     /* Maybe disable this debug? */
     debug1("%s: DEBUG: Connecting to '%s', using '%s', '%s', '%s', %d,'%s'.",
-           ARGV0, db_config.host, db_config.user, 
+           ARGV0, db_config.host, db_config.user,
            db_config.pass, db_config.db,db_config.port,db_config.sock);
 
 
@@ -174,13 +176,13 @@ int main(int argc, char **argv)
     /* Getting maximum reconned attempts */
     db_config.maxreconnect = getDefine_Int("dbd",
                                            "reconnect_attempts", 1, 9999);
-    
-    
+
+
     /* Connecting to the database */
     c = 0;
     while(c <= (db_config.maxreconnect * 10))
     {
-        db_config.conn = osdb_connect(db_config.host, db_config.user, 
+        db_config.conn = osdb_connect(db_config.host, db_config.user,
                                       db_config.pass, db_config.db,
                                       db_config.port,db_config.sock);
 
@@ -192,7 +194,7 @@ int main(int argc, char **argv)
 
         c++;
         sleep(c * 60);
-        
+
     }
 
 
@@ -202,18 +204,18 @@ int main(int argc, char **argv)
         merror(DB_CONFIGERR, ARGV0);
         ErrorExit(CONFIG_ERROR, ARGV0, cfg);
     }
-    
+
 
     /* We must notify that we connected -- easy debugging */
-    verbose("%s: Connected to database '%s' at '%s'.", 
+    verbose("%s: Connected to database '%s' at '%s'.",
             ARGV0, db_config.db, db_config.host);
 
-    
+
     /* Privilege separation */ 
     if(Privsep_SetGroup(gid) < 0)
         ErrorExit(SETGID_ERROR,ARGV0,group);
 
-    
+
     /* chrooting */
     if(Privsep_Chroot(dir) < 0)
         ErrorExit(CHROOT_ERROR,ARGV0,dir);
@@ -237,8 +239,8 @@ int main(int argc, char **argv)
         ErrorExit(CONFIG_ERROR, ARGV0, cfg);
     }
 
-    
-    /* Changing user */        
+
+    /* Changing user */
     if(Privsep_SetUser(uid) < 0)
         ErrorExit(SETUID_ERROR,ARGV0,user);
 
@@ -250,15 +252,15 @@ int main(int argc, char **argv)
     /* Signal manipulation */
     StartSIG(ARGV0);
 
-    
+
     /* Creating PID files */
     if(CreatePID(ARGV0, getpid()) < 0)
         ErrorExit(PID_ERROR,ARGV0);
 
-    
+
     /* Start up message */
     verbose(STARTUP_MSG, ARGV0, (int)getpid());
-    
+
 
     /* the real daemon now */  
     OS_DBD(&db_config);