1 /* @(#) $Id: ./src/config/global-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 "os_net/os_net.h"
19 #include "global-config.h"
20 #include "mail-config.h"
23 void AssignIgnore_Global(char **ignores, void *configp)
27 Config = (_Config *)configp;
30 Config->syscheck_ignore = ignores;
35 /* GlobalConfSK v0.1: 2006/04/26
36 * v0.1 Getting the ignore fields.
38 int Read_GlobalSK(XML_NODE node, void *configp, void *mailp)
42 char *xml_ignore = "ignore";
43 char *xml_auto_ignore = "auto_ignore";
44 char *xml_alert_new_files = "alert_new_files";
48 Config = (_Config *)configp;
51 /* Shouldn't be here if !Config */
56 /* Getting right white_size */
57 if(Config && Config->syscheck_ignore)
60 ww = Config->syscheck_ignore;
73 merror(XML_ELEMNULL, ARGV0);
76 else if(!node[i]->content)
78 merror(XML_VALUENULL, ARGV0, node[i]->element);
81 else if(strcmp(node[i]->element,xml_auto_ignore) == 0)
83 if(strcmp(node[i]->content, "yes") == 0)
85 Config->syscheck_auto_ignore = 1;
87 else if(strcmp(node[i]->content, "no") == 0)
89 Config->syscheck_auto_ignore = 0;
93 merror(XML_VALUEERR,ARGV0,node[i]->element,node[i]->content);
97 else if(strcmp(node[i]->element,xml_alert_new_files) == 0)
99 if(strcmp(node[i]->content, "yes") == 0)
101 Config->syscheck_alert_new = 1;
103 else if(strcmp(node[i]->content, "no") == 0)
105 Config->syscheck_alert_new = 0;
109 merror(XML_VALUEERR,ARGV0,node[i]->element,node[i]->content);
113 else if(strcmp(node[i]->element,xml_ignore) == 0)
116 Config->syscheck_ignore =
117 realloc(Config->syscheck_ignore, sizeof(char *)*ign_size);
118 if(!Config->syscheck_ignore)
120 merror(MEM_ERROR, ARGV0);
124 os_strdup(node[i]->content,Config->syscheck_ignore[ign_size -2]);
125 Config->syscheck_ignore[ign_size -1] = NULL;
134 /* GlobalConf v0.2: 2005/03/03
135 * v0.2: Changing to support the new OS_XML
137 int Read_Global(XML_NODE node, void *configp, void *mailp)
141 /* White list size */
143 int hostname_white_size = 1;
147 /* XML definitions */
148 char *xml_mailnotify = "email_notification";
149 char *xml_logall = "logall";
150 char *xml_integrity = "integrity_checking";
151 char *xml_rootcheckd = "rootkit_detection";
152 char *xml_hostinfo = "host_information";
153 char *xml_picviz = "picviz_output";
154 char *xml_picviz_socket = "picviz_socket";
155 char *xml_prelude = "prelude_output";
156 char *xml_prelude_profile = "prelude_profile";
157 char *xml_prelude_log_level = "prelude_log_level";
158 char *xml_stats = "stats";
159 char *xml_memorysize = "memory_size";
160 char *xml_white_list = "white_list";
161 char *xml_compress_alerts = "compress_alerts";
163 char *xml_emailto = "email_to";
164 char *xml_emailfrom = "email_from";
165 char *xml_smtpserver = "smtp_server";
166 char *xml_mailmaxperhour = "email_maxperhour";
170 char *xml_geoip_db_path = "geoip_db_path";
171 char *xml_geoip6_db_path = "geoip6_db_path";
177 Config = (_Config *)configp;
178 Mail = (MailConfig *)mailp;
180 /* Getting right white_size */
181 if(Config && Config->white_list)
184 ww = Config->white_list;
193 /* Getting right white_size */
194 if(Config && Config->hostname_white_list)
197 ww = Config->hostname_white_list;
201 hostname_white_size++;
206 /* Getting mail_to size */
220 if(!node[i]->element)
222 merror(XML_ELEMNULL, ARGV0);
225 else if(!node[i]->content)
227 merror(XML_VALUENULL, ARGV0, node[i]->element);
230 /* Mail notification */
231 else if(strcmp(node[i]->element, xml_mailnotify) == 0)
233 if(strcmp(node[i]->content, "yes") == 0)
235 if(Config) Config->mailnotify = 1;
236 if(Mail) Mail->mn = 1;
238 else if(strcmp(node[i]->content, "no") == 0)
240 if(Config) Config->mailnotify = 0;
241 if(Mail) Mail->mn = 0;
245 merror(XML_VALUEERR,ARGV0,node[i]->element,node[i]->content);
250 else if(strcmp(node[i]->element, xml_picviz) == 0)
252 if(strcmp(node[i]->content, "yes") == 0)
254 if(Config) Config->picviz = 1;
256 else if(strcmp(node[i]->content, "no") == 0)
258 if(Config) Config->picviz = 0;
262 merror(XML_VALUEERR,ARGV0,node[i]->element, node[i]->content);
266 else if(strcmp(node[i]->element, xml_picviz_socket) == 0)
270 os_strdup(node[i]->content, Config->picviz_socket);
273 /* Prelude support */
274 else if(strcmp(node[i]->element, xml_prelude) == 0)
276 if(strcmp(node[i]->content, "yes") == 0)
278 if(Config) Config->prelude = 1;
280 else if(strcmp(node[i]->content, "no") == 0)
282 if(Config) Config->prelude = 0;
286 merror(XML_VALUEERR,ARGV0,node[i]->element, node[i]->content);
290 else if(strcmp(node[i]->element, xml_prelude_profile) == 0)
294 Config->prelude_profile = strdup(node[i]->content);
297 else if(strcmp(node[i]->element, xml_prelude_log_level) == 0)
299 if(!OS_StrIsNum(node[i]->content))
301 merror(XML_VALUEERR,ARGV0,node[i]->element,node[i]->content);
307 Config->prelude_log_level = atoi(node[i]->content);
311 else if(strcmp(node[i]->element, xml_logall) == 0)
313 if(strcmp(node[i]->content, "yes") == 0)
314 { if(Config) Config->logall = 1;}
315 else if(strcmp(node[i]->content, "no") == 0)
316 {if(Config) Config->logall = 0;}
319 merror(XML_VALUEERR,ARGV0,node[i]->element,node[i]->content);
323 /* compress alerts */
324 else if(strcmp(node[i]->element, xml_compress_alerts) == 0)
326 /* removed from here -- compatility issues only */
329 else if(strcmp(node[i]->element, xml_integrity) == 0)
331 if(!OS_StrIsNum(node[i]->content))
333 merror(XML_VALUEERR,ARGV0,node[i]->element,node[i]->content);
338 Config->integrity = atoi(node[i]->content);
342 else if(strcmp(node[i]->element, xml_rootcheckd) == 0)
344 if(!OS_StrIsNum(node[i]->content))
346 merror(XML_VALUEERR,ARGV0,node[i]->element,node[i]->content);
351 Config->rootcheck = atoi(node[i]->content);
355 else if(strcmp(node[i]->element, xml_hostinfo) == 0)
357 if(!OS_StrIsNum(node[i]->content))
359 merror(XML_VALUEERR,ARGV0,node[i]->element,node[i]->content);
364 Config->hostinfo = atoi(node[i]->content);
368 else if(strcmp(node[i]->element, xml_stats) == 0)
370 if(!OS_StrIsNum(node[i]->content))
372 merror(XML_VALUEERR,ARGV0,node[i]->element,node[i]->content);
377 Config->stats = atoi(node[i]->content);
380 else if(strcmp(node[i]->element, xml_memorysize) == 0)
382 if(!OS_StrIsNum(node[i]->content))
384 merror(XML_VALUEERR,ARGV0,node[i]->element,node[i]->content);
389 Config->memorysize = atoi(node[i]->content);
393 else if(strcmp(node[i]->element, xml_white_list) == 0)
395 /* Windows do not need it */
398 char *ip_address_regex =
399 "^[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}/?"
400 "([0-9]{0,2}|[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3})$";
402 if(Config && OS_PRegex(node[i]->content, ip_address_regex))
406 realloc(Config->white_list, sizeof(os_ip *)*white_size);
407 if(!Config->white_list)
409 merror(MEM_ERROR, ARGV0);
413 os_calloc(1, sizeof(os_ip), Config->white_list[white_size -2]);
414 Config->white_list[white_size -1] = NULL;
416 if(!OS_IsValidIP(node[i]->content,
417 Config->white_list[white_size -2]))
419 merror(INVALID_IP, ARGV0,
424 /* Adding hostname */
427 hostname_white_size++;
428 Config->hostname_white_list =
429 realloc(Config->hostname_white_list,
430 sizeof(OSMatch *)*hostname_white_size);
432 if(!Config->hostname_white_list)
434 merror(MEM_ERROR, ARGV0);
439 Config->hostname_white_list[hostname_white_size -2]);
440 Config->hostname_white_list[hostname_white_size -1] = NULL;
444 Config->hostname_white_list[hostname_white_size -2],
447 merror(REGEX_COMPILE, ARGV0, node[i]->content,
448 Config->hostname_white_list
449 [hostname_white_size -2]->error);
459 * email_to, email_from, smtp_Server and maxperhour.
460 * We will use a separate structure for that.
462 else if(strcmp(node[i]->element, xml_emailto) == 0)
465 if(!OS_PRegex(node[i]->content, "[a-zA-Z0-9\\._-]+@[a-zA-Z0-9\\._-]"))
467 merror("%s: ERROR: Invalid Email address: %s.", ARGV0, node[i]->content);
475 Mail->to = realloc(Mail->to, sizeof(char *)*mailto_size);
478 merror(MEM_ERROR, ARGV0);
482 os_strdup(node[i]->content, Mail->to[mailto_size - 2]);
483 Mail->to[mailto_size - 1] = NULL;
486 else if(strcmp(node[i]->element, xml_emailfrom) == 0)
494 os_strdup(node[i]->content, Mail->from);
497 else if(strcmp(node[i]->element, xml_smtpserver) == 0)
500 if(Mail && (Mail->mn))
502 Mail->smtpserver = OS_GetHost(node[i]->content, 5);
503 if(!Mail->smtpserver)
505 merror(INVALID_SMTP, ARGV0, node[i]->content);
511 else if(strcmp(node[i]->element, xml_mailmaxperhour) == 0)
515 if(!OS_StrIsNum(node[i]->content))
517 merror(XML_VALUEERR,ARGV0,node[i]->element,node[i]->content);
520 Mail->maxperhour = atoi(node[i]->content);
522 if((Mail->maxperhour <= 0) || (Mail->maxperhour > 9999))
524 merror(XML_VALUEERR,ARGV0,node[i]->element,node[i]->content);
530 /* GeoIP v4 DB location */
531 else if(strcmp(node[i]->element, xml_geoip_db_path) == 0)
535 os_strdup(node[i]->content, Config->geoip_db_path);
538 /* GeoIP v6 DB location */
539 else if(strcmp(node[i]->element, xml_geoip6_db_path) == 0)
543 os_strdup(node[i]->content, Config->geoip6_db_path);
549 merror(XML_INVELEM, ARGV0, node[i]->element);