Imported Upstream version 2.7
[ossec-hids.git] / src / config / dbd-config.c
1 /* @(#) $Id: ./src/config/dbd-config.c, 2011/09/08 dcid Exp $
2  */
3
4 /* Copyright (C) 2009 Trend Micro Inc.
5  * All right reserved.
6  *
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
10  * Foundation
11  */
12
13 /* Functions to handle the dbd configuration files
14  */
15
16
17 #include "shared.h"
18 #include "dbd-config.h"
19
20
21 int Read_DB(XML_NODE node, void *config1, void *config2)
22 {
23     int i = 0;
24     DBConfig *db_config;
25
26
27     /* XML definitions */
28     char *xml_dbhost = "hostname";
29     char *xml_dbuser = "username";
30     char *xml_dbpass = "password";
31     char *xml_dbdb = "database";
32     char *xml_dbport = "port";
33     char *xml_dbsock = "socket";
34     char *xml_dbtype = "type";
35
36
37     db_config = (DBConfig *)config2;
38     if(!db_config)
39     {
40         return(0);
41     }
42
43
44     /* Reading the xml */
45     while(node[i])
46     {
47         if(!node[i]->element)
48         {
49             merror(XML_ELEMNULL, ARGV0);
50             return(OS_INVALID);
51         }
52         else if(!node[i]->content)
53         {
54             merror(XML_VALUENULL, ARGV0, node[i]->element);
55             return(OS_INVALID);
56         }
57         /* Mail notification */
58         else if(strcmp(node[i]->element, xml_dbhost) == 0)
59         {
60             os_strdup(node[i]->content, db_config->host);
61         }
62         else if(strcmp(node[i]->element, xml_dbuser) == 0)
63         {
64             os_strdup(node[i]->content, db_config->user);
65         }
66         else if(strcmp(node[i]->element, xml_dbpass) == 0)
67         {
68             os_strdup(node[i]->content, db_config->pass);
69         }
70         else if(strcmp(node[i]->element, xml_dbdb) == 0)
71         {
72             os_strdup(node[i]->content, db_config->db);
73         }
74         else if(strcmp(node[i]->element, xml_dbport) == 0)
75         {
76             db_config->port = atoi(node[i]->content);
77         }
78         else if(strcmp(node[i]->element, xml_dbsock) == 0)
79         {
80             os_strdup(node[i]->content, db_config->sock);
81         }
82         else if(strcmp(node[i]->element, xml_dbtype) == 0)
83         {
84             if(strcmp(node[i]->content, "mysql") == 0)
85             {
86                 db_config->db_type = MYSQLDB;
87             }
88             else if(strcmp(node[i]->content, "postgresql") == 0)
89             {
90                 db_config->db_type = POSTGDB;
91             }
92             else
93             {
94                 merror(XML_VALUEERR,ARGV0,node[i]->element,node[i]->content);
95                 return(OS_INVALID);
96             }
97         }
98         else
99         {
100             merror(XML_INVELEM, ARGV0, node[i]->element);
101             return(OS_INVALID);
102         }
103         i++;
104     }
105
106
107     return(0);
108 }
109
110
111 /* EOF */