1 /* @(#) $Id: ./src/os_dbd/config.c, 2011/09/08 dcid Exp $
4 /* Copyright (C) 2009 Trend Micro Inc.
7 * This program is a free software; you can redistribute it
8 * and/or modify it under the terms of the GNU General Public
9 * License (version 2) as published by the FSF - Free Software
12 * License details at the LICENSE file included with OSSEC or
13 * online at: http://www.ossec.net/en/licensing.html
18 #include "config/global-config.h"
19 #include "config/config.h"
22 /** int OS_ReadDBConf(int test_config, char *cfgfile, DBConfig *db_config)
23 * Reads database configuration.
25 int OS_ReadDBConf(int test_config, char *cfgfile, DBConfig *db_config)
31 /* Modules for the configuration */
36 /* Allocating config just to get the rules. */
37 os_calloc(1, sizeof(_Config), tmp_config);
40 /* Clearing configuration variables */
41 tmp_config->includes = NULL;
42 db_config->includes = NULL;
43 db_config->host = NULL;
44 db_config->user = NULL;
45 db_config->pass = NULL;
48 db_config->sock = NULL;
49 db_config->db_type = 0;
50 db_config->maxreconnect = 0;
53 /* Reading configuration */
54 if(ReadConfig(modules, cfgfile, tmp_config, db_config) < 0)
58 /* Here, we assign the rules to db_config and free the rest
61 db_config->includes = tmp_config->includes;
65 /* Checking if dbd isn't supposed to run. */
66 if(!db_config->host &&
78 /* Checking for a valid config. */
79 if(!db_config->host ||
85 merror(DB_MISS_CONFIG, ARGV0);
91 /* Assigning the proper location for the function calls */
93 if(db_config->db_type == MYSQLDB)
95 osdb_connect = mysql_osdb_connect;
96 osdb_query_insert = mysql_osdb_query_insert;
97 osdb_query_select = mysql_osdb_query_select;
98 osdb_close = mysql_osdb_close;
103 if(db_config->db_type == POSTGDB)
105 osdb_connect = postgresql_osdb_connect;
106 osdb_query_insert = postgresql_osdb_query_insert;
107 osdb_query_select = postgresql_osdb_query_select;
108 osdb_close = postgresql_osdb_close;
114 /* Checking for config errros (moving from config.c).
116 if(db_config->db_type == MYSQLDB)
119 merror(DB_COMPILED, ARGV0, "mysql");
123 else if(db_config->db_type == POSTGDB)
126 merror(DB_COMPILED, ARGV0, "postgresql");
132 if(osdb_connect == NULL)
134 merror("%s: Invalid DB configuration (Internal error?). ", ARGV0);