-/* @(#) $Id: main.c,v 1.17 2009/11/18 19:07:40 dcid Exp $ */
+/* @(#) $Id: ./src/os_dbd/main.c, 2011/09/08 dcid Exp $
+ */
/* Copyright (C) 2009 Trend Micro Inc.
* All rights reserved.
*
* This program is a free software; you can redistribute it
* and/or modify it under the terms of the GNU General Public
- * License (version 3) as published by the FSF - Free Software
+ * 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
*/
void db_info()
{
print_out(" ");
- print_out("%s %s - %s", __name, __version, __author);
-
+ print_out("%s %s - %s", __ossec_name, __version, __author);
+
#ifdef UMYSQL
print_out("Compiled with MySQL support.");
#endif
#if !defined(UMYSQL) && !defined(UPOSTGRES)
print_out("Compiled without any Database support.");
#endif
-
+
print_out(" ");
print_out("%s",__license);
/* Setting the name */
OS_SetName(ARGV0);
-
+
while((c = getopt(argc, argv, "vVdhtfu:g:D:c:")) != -1){
switch(c){
break;
case 'v':
db_info();
- break;
+ break;
case 'h':
help(ARGV0);
break;
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);
/* Exit here if test config is set */
if(test_config)
exit(0);
-
-
- if(!run_foreground)
+
+
+ if(!run_foreground)
{
/* Going on daemon mode */
nowDaemon();
}
-
+
/* Not configured */
if(c == 0)
{
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);
/* 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);
c++;
sleep(c * 60);
-
+
}
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);
ErrorExit(CONFIG_ERROR, ARGV0, cfg);
}
-
- /* Changing user */
+
+ /* Changing user */
if(Privsep_SetUser(uid) < 0)
ErrorExit(SETUID_ERROR,ARGV0,user);
/* 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);