1 /* Copyright (C) 2009 Trend Micro Inc.
4 * This program is a free software; you can redistribute it
5 * and/or modify it under the terms of the GNU General Public
6 * License (version 2) as published by the FSF - Free Software
11 #include "config/global-config.h"
12 #include "config/config.h"
15 /* Read database configuration */
16 int OS_ReadDBConf(__attribute__((unused)) int test_config, const char *cfgfile, DBConfig *db_config)
21 /* Modules for the configuration */
25 /* Allocate config just to get the rules */
26 os_calloc(1, sizeof(_Config), tmp_config);
28 /* Clear configuration variables */
29 tmp_config->includes = NULL;
30 db_config->includes = NULL;
31 db_config->host = NULL;
32 db_config->user = NULL;
33 db_config->pass = NULL;
36 db_config->sock = NULL;
37 db_config->db_type = 0;
38 db_config->maxreconnect = 0;
40 /* Read configuration */
41 if (ReadConfig(modules, cfgfile, tmp_config, db_config) < 0) {
45 /* Assign the rules to db_config and free the rest of the Config */
46 db_config->includes = tmp_config->includes;
49 /* Check if dbd isn't supposed to run */
50 if (!db_config->host &&
56 !db_config->db_type) {
60 /* Check for a valid config */
61 if (!db_config->host ||
65 !db_config->db_type) {
66 merror(DB_MISS_CONFIG, ARGV0);
72 /* Assign the proper location for the function calls */
74 #ifdef MYSQL_DATABASE_ENABLED
75 if (db_config->db_type == MYSQLDB) {
76 osdb_connect = mysql_osdb_connect;
77 osdb_query_insert = mysql_osdb_query_insert;
78 osdb_query_select = mysql_osdb_query_select;
79 osdb_close = mysql_osdb_close;
83 #ifdef PGSQL_DATABASE_ENABLED
84 if (db_config->db_type == POSTGDB) {
85 osdb_connect = postgresql_osdb_connect;
86 osdb_query_insert = postgresql_osdb_query_insert;
87 osdb_query_select = postgresql_osdb_query_select;
88 osdb_close = postgresql_osdb_close;
92 /* Check for config errors */
93 if (db_config->db_type == MYSQLDB) {
94 #ifndef MYSQL_DATABASE_ENABLED
95 merror(DB_COMPILED, ARGV0, "mysql");
98 } else if (db_config->db_type == POSTGDB) {
99 #ifndef PGSQL_DATABASE_ENABLED
100 merror(DB_COMPILED, ARGV0, "postgresql");
105 if (osdb_connect == NULL) {
106 merror("%s: Invalid DB configuration (Internal error?). ", ARGV0);