Imported Upstream version 2.7
[ossec-hids.git] / src / config / alerts-config.c
1 /*   $OSSEC, alerts-config.c, v0.1, 2005/04/02, Daniel B. Cid$   */
2
3 /* Copyright (C) 2009 Trend Micro Inc.
4  * All right reserved.
5  *
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 2) as published by the FSF - Free Software
9  * Foundation
10  */
11
12 /* Functions to handle the configuration files
13  */
14
15
16 #include "shared.h"
17 #include "global-config.h"
18
19
20 int Read_Alerts(XML_NODE node, void *configp, void *mailp)
21 {
22     int i = 0;
23
24     /* XML definitions */
25     char *xml_email_level = "email_alert_level";
26     char *xml_log_level = "log_alert_level";
27
28 #ifdef GEOIP
29     /* GeoIP */
30     char *xml_log_geoip = "use_geoip";
31 #endif
32
33     _Config *Config;
34
35     Config = (_Config *)configp;
36
37
38     while(node[i])
39     {
40         if(!node[i]->element)
41         {
42             merror(XML_ELEMNULL, ARGV0);
43             return(OS_INVALID);
44         }
45         else if(!node[i]->content)
46         {
47             merror(XML_VALUENULL, ARGV0, node[i]->element);
48             return(OS_INVALID);
49         }
50         /* Mail notification */
51         else if(strcmp(node[i]->element, xml_email_level) == 0)
52         {
53             if(!OS_StrIsNum(node[i]->content))
54             {
55                 merror(XML_VALUEERR,ARGV0,node[i]->element,node[i]->content);
56                 return(OS_INVALID);
57             }
58
59             Config->mailbylevel = atoi(node[i]->content);
60         }
61         /* Log alerts */
62         else if(strcmp(node[i]->element, xml_log_level) == 0)
63         {
64             if(!OS_StrIsNum(node[i]->content))
65             {
66                 merror(XML_VALUEERR,ARGV0,node[i]->element,node[i]->content);
67                 return(OS_INVALID);
68             }
69             Config->logbylevel  = atoi(node[i]->content);
70         }
71 #ifdef GEOIP
72         /* Enable GeoIP */
73         else if(strcmp(node[i]->element, xml_log_geoip) == 0)
74         {
75             if(strcmp(node[i]->content, "yes") == 0)
76                 { if(Config) Config->loggeoip = 1;}
77             else if(strcmp(node[i]->content, "no") == 0)
78                 {if(Config) Config->loggeoip = 0;}
79             else
80             {
81                 merror(XML_VALUEERR,ARGV0,node[i]->element,node[i]->content);
82                 return(OS_INVALID);
83             }
84
85         }
86 #endif
87         else
88         {
89             merror(XML_INVELEM, ARGV0, node[i]->element);
90             return(OS_INVALID);
91         }
92         i++;
93     }
94     return(0);
95 }
96
97
98 /* EOF */