1 /* @(#) $Id: config.c,v 1.9 2009/06/24 17:06:30 dcid Exp $ */
3 /* Copyright (C) 2009 Trend Micro Inc.
6 * This program is a free software; you can redistribute it
7 * and/or modify it under the terms of the GNU General Public
8 * License (version 3) as published by the FSF - Free Software
11 * License details at the LICENSE file included with OSSEC or
12 * online at: http://www.ossec.net/en/licensing.html
17 #include "config/global-config.h"
18 #include "config/config.h"
21 /** int OS_ReadDBConf(int test_config, char *cfgfile, DBConfig *db_config)
22 * Reads database configuration.
24 int OS_ReadDBConf(int test_config, char *cfgfile, DBConfig *db_config)
30 /* Modules for the configuration */
35 /* Allocating config just to get the rules. */
36 os_calloc(1, sizeof(_Config), tmp_config);
39 /* Clearing configuration variables */
40 tmp_config->includes = NULL;
41 db_config->includes = NULL;
42 db_config->host = NULL;
43 db_config->user = NULL;
44 db_config->pass = NULL;
47 db_config->sock = NULL;
48 db_config->db_type = 0;
49 db_config->maxreconnect = 0;
52 /* Reading configuration */
53 if(ReadConfig(modules, cfgfile, tmp_config, db_config) < 0)
57 /* Here, we assign the rules to db_config and free the rest
60 db_config->includes = tmp_config->includes;
64 /* Checking if dbd isn't supposed to run. */
65 if(!db_config->host &&
77 /* Checking for a valid config. */
78 if(!db_config->host ||
84 merror(DB_MISS_CONFIG, ARGV0);
90 /* Assigning the proper location for the function calls */
92 if(db_config->db_type == MYSQLDB)
94 osdb_connect = mysql_osdb_connect;
95 osdb_query_insert = mysql_osdb_query_insert;
96 osdb_query_select = mysql_osdb_query_select;
97 osdb_close = mysql_osdb_close;
102 if(db_config->db_type == POSTGDB)
104 osdb_connect = postgresql_osdb_connect;
105 osdb_query_insert = postgresql_osdb_query_insert;
106 osdb_query_select = postgresql_osdb_query_select;
107 osdb_close = postgresql_osdb_close;
113 /* Checking for config errros (moving from config.c).
115 if(db_config->db_type == MYSQLDB)
118 merror(DB_COMPILED, ARGV0, "mysql");
122 else if(db_config->db_type == POSTGDB)
125 merror(DB_COMPILED, ARGV0, "postgresql");
131 if(osdb_connect == NULL)
133 merror("%s: Invalid DB configuration (Internal error?). ", ARGV0);