1 /* @(#) $Id: ./src/config/email-alerts-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 "mail-config.h"
21 int Read_EmailAlerts(XML_NODE node, void *configp, void *mailp)
27 char *xml_email_to = "email_to";
28 char *xml_email_format = "format";
29 char *xml_email_level = "level";
30 char *xml_email_id = "rule_id";
31 char *xml_email_group = "group";
32 char *xml_email_location = "event_location";
33 char *xml_email_donotdelay = "do_not_delay";
34 char *xml_email_donotgroup = "do_not_group";
38 Mail = (MailConfig *)mailp;
45 /* Getting Granular mail_to size */
46 if(Mail && Mail->gran_to)
60 os_realloc(Mail->gran_to,
61 sizeof(char *)*(granto_size +1), Mail->gran_to);
62 os_realloc(Mail->gran_id,
63 sizeof(int *)*(granto_size +1), Mail->gran_id);
64 os_realloc(Mail->gran_level,
65 sizeof(int)*(granto_size +1), Mail->gran_level);
66 os_realloc(Mail->gran_set,
67 sizeof(int)*(granto_size +1), Mail->gran_set);
68 os_realloc(Mail->gran_format,
69 sizeof(int)*(granto_size +1), Mail->gran_format);
70 os_realloc(Mail->gran_location,
71 sizeof(OSMatch)*(granto_size +1), Mail->gran_location);
72 os_realloc(Mail->gran_group,
73 sizeof(OSMatch)*(granto_size +1), Mail->gran_group);
75 Mail->gran_to[granto_size -1] = NULL;
76 Mail->gran_to[granto_size] = NULL;
78 Mail->gran_id[granto_size -1] = NULL;
79 Mail->gran_id[granto_size] = NULL;
81 Mail->gran_location[granto_size -1] = NULL;
82 Mail->gran_location[granto_size] = NULL;
84 Mail->gran_group[granto_size -1] = NULL;
85 Mail->gran_group[granto_size] = NULL;
87 Mail->gran_level[granto_size -1] = 0;
88 Mail->gran_level[granto_size] = 0;
90 Mail->gran_format[granto_size -1] = FULL_FORMAT;
91 Mail->gran_format[granto_size] = FULL_FORMAT;
93 Mail->gran_set[granto_size -1] = 0;
94 Mail->gran_set[granto_size] = 0;
100 if(!node[i]->element)
102 merror(XML_ELEMNULL, ARGV0);
105 else if(!node[i]->content)
107 merror(XML_VALUENULL, ARGV0, node[i]->element);
110 /* Mail notification */
111 else if(strcmp(node[i]->element, xml_email_level) == 0)
113 if(!OS_StrIsNum(node[i]->content))
115 merror(XML_VALUEERR,ARGV0,node[i]->element,node[i]->content);
119 Mail->gran_level[granto_size -1] = atoi(node[i]->content);
121 else if(strcmp(node[i]->element, xml_email_to) == 0)
123 os_strdup(node[i]->content, Mail->gran_to[granto_size -1]);
125 else if(strcmp(node[i]->element, xml_email_id) == 0)
128 char *str_pt = node[i]->content;
130 while(*str_pt != '\0')
132 /* We allow spaces in between */
139 /* If is digit, we get the value
140 * and search for the next digit
143 else if(isdigit((int)*str_pt))
148 debug1("%s: DEBUG: Adding '%d' to granular e-mail",
151 if(!Mail->gran_id[granto_size -1])
153 os_calloc(2,sizeof(int),Mail->gran_id[granto_size -1]);
154 Mail->gran_id[granto_size -1][0] = 0;
155 Mail->gran_id[granto_size -1][1] = 0;
159 while(Mail->gran_id[granto_size -1][id_i] != 0)
164 os_realloc(Mail->gran_id[granto_size -1],
165 (id_i +2) * sizeof(int),
166 Mail->gran_id[granto_size -1]);
167 Mail->gran_id[granto_size -1][id_i +1] = 0;
169 Mail->gran_id[granto_size -1][id_i] = r_id;
172 str_pt = strchr(str_pt, ',');
183 /* Checking for duplicate commas */
184 else if(*str_pt == ',')
197 else if(strcmp(node[i]->element, xml_email_format) == 0)
199 if(strcmp(node[i]->content, "sms") == 0)
201 Mail->gran_format[granto_size -1] = SMS_FORMAT;
203 else if(strcmp(node[i]->content, "default") == 0)
205 /* Default is full format */
209 merror(XML_VALUEERR,ARGV0,node[i]->element,node[i]->content);
213 else if(strcmp(node[i]->element, xml_email_donotdelay) == 0)
215 if((Mail->gran_format[granto_size -1] != SMS_FORMAT) &&
216 (Mail->gran_format[granto_size -1] != DONOTGROUP))
218 Mail->gran_format[granto_size -1] = FORWARD_NOW;
221 else if(strcmp(node[i]->element, xml_email_donotgroup) == 0)
223 if(Mail->gran_format[granto_size -1] != SMS_FORMAT)
225 Mail->gran_format[granto_size -1] = DONOTGROUP;
228 else if(strcmp(node[i]->element, xml_email_location) == 0)
230 os_calloc(1, sizeof(OSMatch),Mail->gran_location[granto_size -1]);
231 if(!OSMatch_Compile(node[i]->content,
232 Mail->gran_location[granto_size -1], 0))
234 merror(REGEX_COMPILE, ARGV0, node[i]->content,
235 Mail->gran_location[granto_size -1]->error);
239 else if(strcmp(node[i]->element, xml_email_group) == 0)
241 os_calloc(1, sizeof(OSMatch),Mail->gran_group[granto_size -1]);
242 if(!OSMatch_Compile(node[i]->content,
243 Mail->gran_group[granto_size -1], 0))
245 merror(REGEX_COMPILE, ARGV0, node[i]->content,
246 Mail->gran_group[granto_size -1]->error);
252 merror(XML_INVELEM, ARGV0, node[i]->element);
258 /* We must have at least one entry set */
259 if((Mail->gran_location[granto_size -1] == NULL &&
260 Mail->gran_level[granto_size -1] == 0 &&
261 Mail->gran_group[granto_size -1] == NULL &&
262 Mail->gran_id[granto_size -1] == NULL &&
263 Mail->gran_format[granto_size -1] == FULL_FORMAT) ||
264 Mail->gran_to[granto_size -1] == NULL)
266 merror(XML_INV_GRAN_MAIL, ARGV0);