1 /* @(#) $Id: ./src/config/reports-config.c, 2011/09/08 dcid Exp $
4 /* Copyright (C) 2009 Trend Micro Inc.
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
13 /* Functions to handle the configuration files
18 #include "reports-config.h"
21 /* Filter argument. */
22 static int _filter_arg(char *mystr)
31 if((*mystr >= 'a' && *mystr <= 'z') ||
32 (*mystr >= 'A' && *mystr <= 'Z') ||
33 (*mystr >= '0' && *mystr <= '9') ||
34 *mystr == '-' || *mystr == '_')
49 int Read_CReports(XML_NODE node, void *config, void *config2)
54 char *xml_title = "title";
55 char *xml_type = "type";
56 char *xml_categories = "category";
57 char *xml_group = "group";
58 char *xml_rule = "rule";
59 char *xml_level = "level";
60 char *xml_location = "location";
61 char *xml_showlogs = "showlogs";
62 char *xml_srcip = "srcip";
63 char *xml_user = "user";
64 char *xml_frequency = "frequency";
65 char *xml_email = "email_to";
68 monitor_config *mon_config = (monitor_config *)config;
71 /* Getting any configured entry. */
72 if(mon_config->reports)
74 while(mon_config->reports[s])
79 /* Allocating the memory for the config. */
80 os_realloc(mon_config->reports, (s + 2) * sizeof(report_config *),
82 os_calloc(1, sizeof(report_config), mon_config->reports[s]);
83 mon_config->reports[s + 1] = NULL;
86 /* Zeroing the elements. */
87 mon_config->reports[s]->title = NULL;
88 mon_config->reports[s]->args = NULL;
89 mon_config->reports[s]->relations = NULL;
90 mon_config->reports[s]->type = NULL;
91 mon_config->reports[s]->emailto = NULL;
93 mon_config->reports[s]->r_filter.group = NULL;
94 mon_config->reports[s]->r_filter.rule = NULL;
95 mon_config->reports[s]->r_filter.level = NULL;
96 mon_config->reports[s]->r_filter.location = NULL;
97 mon_config->reports[s]->r_filter.srcip = NULL;
98 mon_config->reports[s]->r_filter.user = NULL;
99 mon_config->reports[s]->r_filter.related_group = 0;
100 mon_config->reports[s]->r_filter.related_rule = 0;
101 mon_config->reports[s]->r_filter.related_level = 0;
102 mon_config->reports[s]->r_filter.related_location = 0;
103 mon_config->reports[s]->r_filter.related_srcip = 0;
104 mon_config->reports[s]->r_filter.related_user = 0;
105 mon_config->reports[s]->r_filter.report_name = NULL;
106 mon_config->reports[s]->r_filter.show_alerts = 0;
110 /* Reading the XML. */
113 if(!node[i]->element)
115 merror(XML_ELEMNULL, __local_name);
118 else if(!node[i]->content)
120 merror(XML_VALUENULL, __local_name, node[i]->element);
123 else if(strcmp(node[i]->element, xml_title) == 0)
125 if(!mon_config->reports[s]->title)
127 os_strdup(node[i]->content, mon_config->reports[s]->title);
130 else if(strcmp(node[i]->element, xml_type) == 0)
132 if(strcmp(node[i]->content, "email") == 0)
134 if(!mon_config->reports[s]->type)
136 os_strdup(node[i]->content, mon_config->reports[s]->type);
141 merror(XML_VALUEERR, __local_name,node[i]->element,node[i]->content);
144 else if(strcmp(node[i]->element, xml_frequency) == 0)
147 else if(strcmp(node[i]->element, xml_showlogs) == 0)
149 if(strcasecmp(node[i]->content, "yes") == 0)
151 mon_config->reports[s]->r_filter.show_alerts = 1;
154 else if(strcmp(node[i]->element, xml_categories) == 0)
157 _filter_arg(node[i]->content);
160 os_strdup(node[i]->content, ncat);
162 if(os_report_configfilter("group", ncat,
163 &mon_config->reports[s]->r_filter, REPORT_FILTER) < 0)
165 merror(CONFIG_ERROR, __local_name, "user argument");
168 else if((strcmp(node[i]->element, xml_group) == 0)||
169 (strcmp(node[i]->element, xml_rule) == 0)||
170 (strcmp(node[i]->element, xml_level) == 0)||
171 (strcmp(node[i]->element, xml_location) == 0)||
172 (strcmp(node[i]->element, xml_srcip) == 0)||
173 (strcmp(node[i]->element, xml_user) == 0))
175 int reportf = REPORT_FILTER;
177 _filter_arg(node[i]->content);
179 if(node[i]->attributes && node[i]->values)
181 if(node[i]->attributes[0] && node[i]->values[0])
183 if(strcmp(node[i]->attributes[0], "type") == 0)
185 if(strcmp(node[i]->values[0], "relation") == 0)
187 reportf = REPORT_RELATED;
191 merror("%s: WARN: Invalid value for 'relation' attribute: '%s'. (ignored).", __local_name, node[i]->values[0]);
198 merror("%s: WARN: Invalid attribute: %s (ignored). ", __local_name, node[i]->attributes[0]);
205 os_strdup(node[i]->content, ncat);
207 if(os_report_configfilter(node[i]->element, ncat,
208 &mon_config->reports[s]->r_filter, reportf) < 0)
210 merror("%s: Invalid filter: %s:%s (ignored).", __local_name, node[i]->element, node[i]->content);
213 else if(strcmp(node[i]->element, xml_email) == 0)
215 mon_config->reports[s]->emailto = os_AddStrArray(node[i]->content, mon_config->reports[s]->emailto);
219 merror(XML_INVELEM, __local_name, node[i]->element);
226 /* Setting proper report type. */
227 mon_config->reports[s]->r_filter.report_type = REPORT_TYPE_DAILY;
229 if(mon_config->reports[s]->emailto == NULL)
231 if(mon_config->reports[s]->title)
232 merror("%s: No \"email to\" configured for the report '%s'. Ignoring it.", __local_name, mon_config->reports[s]->title);
234 merror("%s: No \"email to\" and title configured for report. Ignoring it.", __local_name);
237 if(!mon_config->reports[s]->title)
239 os_strdup("OSSEC Report (unnamed)", mon_config->reports[s]->title);
241 mon_config->reports[s]->r_filter.report_name = mon_config->reports[s]->title;