new upstream release (3.3.0); modify package compatibility for Stretch
[ossec-hids.git] / src / config / dbd-config.c
1 /* Copyright (C) 2009 Trend Micro Inc.
2  * All right reserved.
3  *
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
7  * Foundation
8  */
9
10 #include "shared.h"
11 #include "dbd-config.h"
12 #include "config.h"
13
14
15 int Read_DB(XML_NODE node, __attribute__((unused)) void *config1, void *config2)
16 {
17     int i = 0;
18     DBConfig *db_config;
19
20     /* XML definitions */
21     const char *xml_dbhost = "hostname";
22     const char *xml_dbuser = "username";
23     const char *xml_dbpass = "password";
24     const char *xml_dbdb = "database";
25     const char *xml_dbport = "port";
26     const char *xml_dbsock = "socket";
27     const char *xml_dbtype = "type";
28
29     db_config = (DBConfig *)config2;
30     if (!db_config) {
31         return (0);
32     }
33
34     /* Read the xml */
35     while (node[i]) {
36         if (!node[i]->element) {
37             merror(XML_ELEMNULL, __local_name);
38             return (OS_INVALID);
39         } else if (!node[i]->content) {
40             merror(XML_VALUENULL, __local_name, node[i]->element);
41             return (OS_INVALID);
42         }
43         /* Mail notification */
44         else if (strcmp(node[i]->element, xml_dbhost) == 0) {
45             os_strdup(node[i]->content, db_config->host);
46         } else if (strcmp(node[i]->element, xml_dbuser) == 0) {
47             os_strdup(node[i]->content, db_config->user);
48         } else if (strcmp(node[i]->element, xml_dbpass) == 0) {
49             os_strdup(node[i]->content, db_config->pass);
50         } else if (strcmp(node[i]->element, xml_dbdb) == 0) {
51             os_strdup(node[i]->content, db_config->db);
52         } else if (strcmp(node[i]->element, xml_dbport) == 0) {
53             db_config->port = (unsigned int) atoi(node[i]->content);
54         } else if (strcmp(node[i]->element, xml_dbsock) == 0) {
55             os_strdup(node[i]->content, db_config->sock);
56         } else if (strcmp(node[i]->element, xml_dbtype) == 0) {
57             if (strcmp(node[i]->content, "mysql") == 0) {
58                 db_config->db_type = MYSQLDB;
59             } else if (strcmp(node[i]->content, "postgresql") == 0) {
60                 db_config->db_type = POSTGDB;
61             } else {
62                 merror(XML_VALUEERR, __local_name, node[i]->element, node[i]->content);
63                 return (OS_INVALID);
64             }
65         } else {
66             merror(XML_INVELEM, __local_name, node[i]->element);
67             return (OS_INVALID);
68         }
69         i++;
70     }
71
72     return (0);
73 }
74