3 /* Copyright (C) 2009 Trend Micro Inc.
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
12 /* Functions to handle the configuration files
17 #include "reports-config.h"
20 /* Filter argument. */
21 static int _filter_arg(char *mystr)
30 if((*mystr >= 'a' && *mystr <= 'z') ||
31 (*mystr >= 'A' && *mystr <= 'Z') ||
32 (*mystr >= '0' && *mystr <= '9') ||
33 *mystr == '-' || *mystr == '_')
48 int Read_CReports(XML_NODE node, void *config, void *config2)
53 char *xml_title = "title";
54 char *xml_type = "type";
55 char *xml_categories = "category";
56 char *xml_group = "group";
57 char *xml_rule = "rule";
58 char *xml_level = "level";
59 char *xml_location = "location";
60 char *xml_showlogs = "showlogs";
61 char *xml_srcip = "srcip";
62 char *xml_user = "user";
63 char *xml_frequency = "frequency";
64 char *xml_email = "email_to";
67 monitor_config *mon_config = (monitor_config *)config;
70 /* Getting any configured entry. */
71 if(mon_config->reports)
73 while(mon_config->reports[s])
78 /* Allocating the memory for the config. */
79 os_realloc(mon_config->reports, (s + 2) * sizeof(report_config *),
81 os_calloc(1, sizeof(report_config), mon_config->reports[s]);
82 mon_config->reports[s + 1] = NULL;
85 /* Zeroing the elements. */
86 mon_config->reports[s]->title = NULL;
87 mon_config->reports[s]->args = NULL;
88 mon_config->reports[s]->relations = NULL;
89 mon_config->reports[s]->type = NULL;
90 mon_config->reports[s]->emailto = NULL;
92 mon_config->reports[s]->r_filter.group = NULL;
93 mon_config->reports[s]->r_filter.rule = NULL;
94 mon_config->reports[s]->r_filter.level = NULL;
95 mon_config->reports[s]->r_filter.location = NULL;
96 mon_config->reports[s]->r_filter.srcip = NULL;
97 mon_config->reports[s]->r_filter.user = NULL;
98 mon_config->reports[s]->r_filter.related_group = 0;
99 mon_config->reports[s]->r_filter.related_rule = 0;
100 mon_config->reports[s]->r_filter.related_level = 0;
101 mon_config->reports[s]->r_filter.related_location = 0;
102 mon_config->reports[s]->r_filter.related_srcip = 0;
103 mon_config->reports[s]->r_filter.related_user = 0;
104 mon_config->reports[s]->r_filter.report_name = NULL;
105 mon_config->reports[s]->r_filter.show_alerts = 0;
109 /* Reading the XML. */
112 if(!node[i]->element)
114 merror(XML_ELEMNULL, __local_name);
117 else if(!node[i]->content)
119 merror(XML_VALUENULL, __local_name, node[i]->element);
122 else if(strcmp(node[i]->element, xml_title) == 0)
124 if(!mon_config->reports[s]->title)
126 os_strdup(node[i]->content, mon_config->reports[s]->title);
129 else if(strcmp(node[i]->element, xml_type) == 0)
131 if(strcmp(node[i]->content, "email") == 0)
133 if(!mon_config->reports[s]->type)
135 os_strdup(node[i]->content, mon_config->reports[s]->type);
140 merror(XML_VALUEERR, __local_name,node[i]->element,node[i]->content);
143 else if(strcmp(node[i]->element, xml_frequency) == 0)
146 else if(strcmp(node[i]->element, xml_showlogs) == 0)
148 if(strcasecmp(node[i]->content, "yes") == 0)
150 mon_config->reports[s]->r_filter.show_alerts = 1;
153 else if(strcmp(node[i]->element, xml_categories) == 0)
156 _filter_arg(node[i]->content);
159 os_strdup(node[i]->content, ncat);
161 if(os_report_configfilter("group", ncat,
162 &mon_config->reports[s]->r_filter, REPORT_FILTER) < 0)
164 merror(CONFIG_ERROR, __local_name, "user argument");
167 else if((strcmp(node[i]->element, xml_group) == 0)||
168 (strcmp(node[i]->element, xml_rule) == 0)||
169 (strcmp(node[i]->element, xml_level) == 0)||
170 (strcmp(node[i]->element, xml_location) == 0)||
171 (strcmp(node[i]->element, xml_srcip) == 0)||
172 (strcmp(node[i]->element, xml_user) == 0))
174 int reportf = REPORT_FILTER;
176 _filter_arg(node[i]->content);
178 if(node[i]->attributes && node[i]->values)
180 if(node[i]->attributes[0] && node[i]->values[0])
182 if(strcmp(node[i]->attributes[0], "type") == 0)
184 if(strcmp(node[i]->values[0], "relation") == 0)
186 reportf = REPORT_RELATED;
190 merror("%s: WARN: Invalid value for 'relation' attribute: '%s'. (ignored).", __local_name, node[i]->values[0]);
197 merror("%s: WARN: Invalid attribute: %s (ignored). ", __local_name, node[i]->attributes[0]);
204 os_strdup(node[i]->content, ncat);
206 if(os_report_configfilter(node[i]->element, ncat,
207 &mon_config->reports[s]->r_filter, reportf) < 0)
209 merror("%s: Invalid filter: %s:%s (ignored).", __local_name, node[i]->element, node[i]->content);
212 else if(strcmp(node[i]->element, xml_email) == 0)
214 mon_config->reports[s]->emailto = os_AddStrArray(node[i]->content, mon_config->reports[s]->emailto);
218 merror(XML_INVELEM, __local_name, node[i]->element);
225 /* Setting proper report type. */
226 mon_config->reports[s]->r_filter.report_type = REPORT_TYPE_DAILY;
228 if(mon_config->reports[s]->emailto == NULL)
230 if(mon_config->reports[s]->title)
231 merror("%s: No \"email to\" configured for the report '%s'. Ignoring it.", __local_name, mon_config->reports[s]->title);
233 merror("%s: No \"email to\" and title configured for report. Ignoring it.", __local_name);
236 if(!mon_config->reports[s]->title)
238 os_strdup("OSSEC Report (unnamed)", mon_config->reports[s]->title);
240 mon_config->reports[s]->r_filter.report_name = mon_config->reports[s]->title;