new upstream release (3.3.0); modify package compatibility for Stretch
[ossec-hids.git] / src / config / alerts-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 "global-config.h"
12 #include "config.h"
13
14
15 int Read_Alerts(XML_NODE node, void *configp, __attribute__((unused)) void *mailp)
16 {
17     int i = 0;
18
19     /* XML definitions */
20     const char *xml_email_level = "email_alert_level";
21     const char *xml_log_level = "log_alert_level";
22
23 #ifdef LIBGEOIP_ENABLED
24     /* GeoIP */
25     const char *xml_log_geoip = "use_geoip";
26 #endif
27
28     _Config *Config;
29     Config = (_Config *)configp;
30
31     if (!Config) {
32         merror("%s: ERROR: Configuration handle is NULL.", __local_name);
33         return (OS_INVALID);
34     }
35
36     while (node[i]) {
37         if (!node[i]->element) {
38             merror(XML_ELEMNULL, __local_name);
39             return (OS_INVALID);
40         } else if (!node[i]->content) {
41             merror(XML_VALUENULL, __local_name, node[i]->element);
42             return (OS_INVALID);
43         }
44         /* Mail notification */
45         else if (strcmp(node[i]->element, xml_email_level) == 0) {
46             if (!OS_StrIsNum(node[i]->content)) {
47                 merror(XML_VALUEERR, __local_name, node[i]->element, node[i]->content);
48                 return (OS_INVALID);
49             }
50
51             Config->mailbylevel = (u_int8_t) atoi(node[i]->content);
52         }
53         /* Log alerts */
54         else if (strcmp(node[i]->element, xml_log_level) == 0) {
55             if (!OS_StrIsNum(node[i]->content)) {
56                 merror(XML_VALUEERR, __local_name, node[i]->element, node[i]->content);
57                 return (OS_INVALID);
58             }
59             Config->logbylevel  = (u_int8_t) atoi(node[i]->content);
60         }
61 #ifdef LIBGEOIP_ENABLED
62         /* Enable GeoIP */
63         else if (strcmp(node[i]->element, xml_log_geoip) == 0) {
64             if (strcmp(node[i]->content, "yes") == 0) {
65                 Config->loggeoip = 1;
66             } else if (strcmp(node[i]->content, "no") == 0) {
67                 Config->loggeoip = 0;
68             } else {
69                 merror(XML_VALUEERR, __local_name, node[i]->element, node[i]->content);
70                 return (OS_INVALID);
71             }
72
73         }
74 #endif
75         else {
76             merror(XML_INVELEM, __local_name, node[i]->element);
77             return (OS_INVALID);
78         }
79         i++;
80     }
81     return (0);
82 }
83