1 /* @(#) $Id: email-alerts-config.c,v 1.10 2009/06/24 17:06:25 dcid Exp $ */
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 3) as published by the FSF - Free Software
12 /* Functions to handle the configuration files
17 #include "mail-config.h"
20 int Read_EmailAlerts(XML_NODE node, void *configp, void *mailp)
26 char *xml_email_to = "email_to";
27 char *xml_email_format = "format";
28 char *xml_email_level = "level";
29 char *xml_email_id = "rule_id";
30 char *xml_email_group = "group";
31 char *xml_email_location = "event_location";
32 char *xml_email_donotdelay = "do_not_delay";
33 char *xml_email_donotgroup = "do_not_group";
37 Mail = (MailConfig *)mailp;
44 /* Getting Granular mail_to size */
45 if(Mail && Mail->gran_to)
59 os_realloc(Mail->gran_to,
60 sizeof(char *)*(granto_size +1), Mail->gran_to);
61 os_realloc(Mail->gran_id,
62 sizeof(int *)*(granto_size +1), Mail->gran_id);
63 os_realloc(Mail->gran_level,
64 sizeof(int)*(granto_size +1), Mail->gran_level);
65 os_realloc(Mail->gran_set,
66 sizeof(int)*(granto_size +1), Mail->gran_set);
67 os_realloc(Mail->gran_format,
68 sizeof(int)*(granto_size +1), Mail->gran_format);
69 os_realloc(Mail->gran_location,
70 sizeof(OSMatch)*(granto_size +1), Mail->gran_location);
71 os_realloc(Mail->gran_group,
72 sizeof(OSMatch)*(granto_size +1), Mail->gran_group);
74 Mail->gran_to[granto_size -1] = NULL;
75 Mail->gran_to[granto_size] = NULL;
77 Mail->gran_id[granto_size -1] = NULL;
78 Mail->gran_id[granto_size] = NULL;
80 Mail->gran_location[granto_size -1] = NULL;
81 Mail->gran_location[granto_size] = NULL;
83 Mail->gran_group[granto_size -1] = NULL;
84 Mail->gran_group[granto_size] = NULL;
86 Mail->gran_level[granto_size -1] = 0;
87 Mail->gran_level[granto_size] = 0;
89 Mail->gran_format[granto_size -1] = FULL_FORMAT;
90 Mail->gran_format[granto_size] = FULL_FORMAT;
92 Mail->gran_set[granto_size -1] = 0;
93 Mail->gran_set[granto_size] = 0;
101 merror(XML_ELEMNULL, ARGV0);
104 else if(!node[i]->content)
106 merror(XML_VALUENULL, ARGV0, node[i]->element);
109 /* Mail notification */
110 else if(strcmp(node[i]->element, xml_email_level) == 0)
112 if(!OS_StrIsNum(node[i]->content))
114 merror(XML_VALUEERR,ARGV0,node[i]->element,node[i]->content);
118 Mail->gran_level[granto_size -1] = atoi(node[i]->content);
120 else if(strcmp(node[i]->element, xml_email_to) == 0)
122 os_strdup(node[i]->content, Mail->gran_to[granto_size -1]);
124 else if(strcmp(node[i]->element, xml_email_id) == 0)
127 char *str_pt = node[i]->content;
129 while(*str_pt != '\0')
131 /* We allow spaces in between */
138 /* If is digit, we get the value
139 * and search for the next digit
142 else if(isdigit((int)*str_pt))
147 debug1("%s: DEBUG: Adding '%d' to granular e-mail",
150 if(!Mail->gran_id[granto_size -1])
152 os_calloc(2,sizeof(int),Mail->gran_id[granto_size -1]);
153 Mail->gran_id[granto_size -1][0] = 0;
154 Mail->gran_id[granto_size -1][1] = 0;
158 while(Mail->gran_id[granto_size -1][id_i] != 0)
163 os_realloc(Mail->gran_id[granto_size -1],
164 (id_i +2) * sizeof(int),
165 Mail->gran_id[granto_size -1]);
166 Mail->gran_id[granto_size -1][id_i +1] = 0;
168 Mail->gran_id[granto_size -1][id_i] = r_id;
171 str_pt = strchr(str_pt, ',');
182 /* Checking for duplicate commas */
183 else if(*str_pt == ',')
196 else if(strcmp(node[i]->element, xml_email_format) == 0)
198 if(strcmp(node[i]->content, "sms") == 0)
200 Mail->gran_format[granto_size -1] = SMS_FORMAT;
202 else if(strcmp(node[i]->content, "default") == 0)
204 /* Default is full format */
208 merror(XML_VALUEERR,ARGV0,node[i]->element,node[i]->content);
212 else if(strcmp(node[i]->element, xml_email_donotdelay) == 0)
214 if((Mail->gran_format[granto_size -1] != SMS_FORMAT) &&
215 (Mail->gran_format[granto_size -1] != DONOTGROUP))
217 Mail->gran_format[granto_size -1] = FORWARD_NOW;
220 else if(strcmp(node[i]->element, xml_email_donotgroup) == 0)
222 if(Mail->gran_format[granto_size -1] != SMS_FORMAT)
224 Mail->gran_format[granto_size -1] = DONOTGROUP;
227 else if(strcmp(node[i]->element, xml_email_location) == 0)
229 os_calloc(1, sizeof(OSMatch),Mail->gran_location[granto_size -1]);
230 if(!OSMatch_Compile(node[i]->content,
231 Mail->gran_location[granto_size -1], 0))
233 merror(REGEX_COMPILE, ARGV0, node[i]->content,
234 Mail->gran_location[granto_size -1]->error);
238 else if(strcmp(node[i]->element, xml_email_group) == 0)
240 os_calloc(1, sizeof(OSMatch),Mail->gran_group[granto_size -1]);
241 if(!OSMatch_Compile(node[i]->content,
242 Mail->gran_group[granto_size -1], 0))
244 merror(REGEX_COMPILE, ARGV0, node[i]->content,
245 Mail->gran_group[granto_size -1]->error);
251 merror(XML_INVELEM, ARGV0, node[i]->element);
257 /* We must have at least one entry set */
258 if((Mail->gran_location[granto_size -1] == NULL &&
259 Mail->gran_level[granto_size -1] == 0 &&
260 Mail->gran_group[granto_size -1] == NULL &&
261 Mail->gran_id[granto_size -1] == NULL &&
262 Mail->gran_format[granto_size -1] == FULL_FORMAT) ||
263 Mail->gran_to[granto_size -1] == NULL)
265 merror(XML_INV_GRAN_MAIL, ARGV0);