1 /* @(#) $Id: global-config.c,v 1.24 2009/07/23 19:31:35 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 "os_net/os_net.h"
18 #include "global-config.h"
19 #include "mail-config.h"
22 void AssignIgnore_Global(char **ignores, void *configp)
26 Config = (_Config *)configp;
29 Config->syscheck_ignore = ignores;
34 /* GlobalConfSK v0.1: 2006/04/26
35 * v0.1 Getting the ignore fields.
37 int Read_GlobalSK(XML_NODE node, void *configp, void *mailp)
41 char *xml_ignore = "ignore";
42 char *xml_auto_ignore = "auto_ignore";
43 char *xml_alert_new_files = "alert_new_files";
47 Config = (_Config *)configp;
50 /* Shouldn't be here if !Config */
55 /* Getting right white_size */
56 if(Config && Config->syscheck_ignore)
59 ww = Config->syscheck_ignore;
72 merror(XML_ELEMNULL, ARGV0);
75 else if(!node[i]->content)
77 merror(XML_VALUENULL, ARGV0, node[i]->element);
80 else if(strcmp(node[i]->element,xml_auto_ignore) == 0)
82 if(strcmp(node[i]->content, "yes") == 0)
84 Config->syscheck_auto_ignore = 1;
86 else if(strcmp(node[i]->content, "no") == 0)
88 Config->syscheck_auto_ignore = 0;
92 merror(XML_VALUEERR,ARGV0,node[i]->element,node[i]->content);
96 else if(strcmp(node[i]->element,xml_alert_new_files) == 0)
98 if(strcmp(node[i]->content, "yes") == 0)
100 Config->syscheck_alert_new = 1;
102 else if(strcmp(node[i]->content, "no") == 0)
104 Config->syscheck_alert_new = 0;
108 merror(XML_VALUEERR,ARGV0,node[i]->element,node[i]->content);
112 else if(strcmp(node[i]->element,xml_ignore) == 0)
115 Config->syscheck_ignore =
116 realloc(Config->syscheck_ignore, sizeof(char *)*ign_size);
117 if(!Config->syscheck_ignore)
119 merror(MEM_ERROR, ARGV0);
123 os_strdup(node[i]->content,Config->syscheck_ignore[ign_size -2]);
124 Config->syscheck_ignore[ign_size -1] = NULL;
133 /* GlobalConf v0.2: 2005/03/03
134 * v0.2: Changing to support the new OS_XML
136 int Read_Global(XML_NODE node, void *configp, void *mailp)
140 /* White list size */
142 int hostname_white_size = 1;
146 /* XML definitions */
147 char *xml_mailnotify = "email_notification";
148 char *xml_logall = "logall";
149 char *xml_integrity = "integrity_checking";
150 char *xml_rootcheckd = "rootkit_detection";
151 char *xml_hostinfo = "host_information";
152 char *xml_picviz = "picviz_output";
153 char *xml_picviz_socket = "picviz_socket";
154 char *xml_prelude = "prelude_output";
155 char *xml_prelude_profile = "prelude_profile";
156 char *xml_prelude_log_level = "prelude_log_level";
157 char *xml_stats = "stats";
158 char *xml_memorysize = "memory_size";
159 char *xml_white_list = "white_list";
160 char *xml_compress_alerts = "compress_alerts";
162 char *xml_emailto = "email_to";
163 char *xml_emailfrom = "email_from";
164 char *xml_smtpserver = "smtp_server";
165 char *xml_mailmaxperhour = "email_maxperhour";
170 Config = (_Config *)configp;
171 Mail = (MailConfig *)mailp;
173 /* Getting right white_size */
174 if(Config && Config->white_list)
177 ww = Config->white_list;
186 /* Getting right white_size */
187 if(Config && Config->hostname_white_list)
190 ww = Config->hostname_white_list;
194 hostname_white_size++;
199 /* Getting mail_to size */
213 if(!node[i]->element)
215 merror(XML_ELEMNULL, ARGV0);
218 else if(!node[i]->content)
220 merror(XML_VALUENULL, ARGV0, node[i]->element);
223 /* Mail notification */
224 else if(strcmp(node[i]->element, xml_mailnotify) == 0)
226 if(strcmp(node[i]->content, "yes") == 0)
228 if(Config) Config->mailnotify = 1;
229 if(Mail) Mail->mn = 1;
231 else if(strcmp(node[i]->content, "no") == 0)
233 if(Config) Config->mailnotify = 0;
234 if(Mail) Mail->mn = 0;
238 merror(XML_VALUEERR,ARGV0,node[i]->element,node[i]->content);
243 else if(strcmp(node[i]->element, xml_picviz) == 0)
245 if(strcmp(node[i]->content, "yes") == 0)
247 if(Config) Config->picviz = 1;
249 else if(strcmp(node[i]->content, "no") == 0)
251 if(Config) Config->picviz = 0;
255 merror(XML_VALUEERR,ARGV0,node[i]->element, node[i]->content);
259 else if(strcmp(node[i]->element, xml_picviz_socket) == 0)
263 os_strdup(node[i]->content, Config->picviz_socket);
266 /* Prelude support */
267 else if(strcmp(node[i]->element, xml_prelude) == 0)
269 if(strcmp(node[i]->content, "yes") == 0)
271 if(Config) Config->prelude = 1;
273 else if(strcmp(node[i]->content, "no") == 0)
275 if(Config) Config->prelude = 0;
279 merror(XML_VALUEERR,ARGV0,node[i]->element, node[i]->content);
283 else if(strcmp(node[i]->element, xml_prelude_profile) == 0)
287 Config->prelude_profile = strdup(node[i]->content);
290 else if(strcmp(node[i]->element, xml_prelude_log_level) == 0)
292 if(!OS_StrIsNum(node[i]->content))
294 merror(XML_VALUEERR,ARGV0,node[i]->element,node[i]->content);
300 Config->prelude_log_level = atoi(node[i]->content);
304 else if(strcmp(node[i]->element, xml_logall) == 0)
306 if(strcmp(node[i]->content, "yes") == 0)
307 { if(Config) Config->logall = 1;}
308 else if(strcmp(node[i]->content, "no") == 0)
309 {if(Config) Config->logall = 0;}
312 merror(XML_VALUEERR,ARGV0,node[i]->element,node[i]->content);
316 /* compress alerts */
317 else if(strcmp(node[i]->element, xml_compress_alerts) == 0)
319 /* removed from here -- compatility issues only */
322 else if(strcmp(node[i]->element, xml_integrity) == 0)
324 if(!OS_StrIsNum(node[i]->content))
326 merror(XML_VALUEERR,ARGV0,node[i]->element,node[i]->content);
331 Config->integrity = atoi(node[i]->content);
335 else if(strcmp(node[i]->element, xml_rootcheckd) == 0)
337 if(!OS_StrIsNum(node[i]->content))
339 merror(XML_VALUEERR,ARGV0,node[i]->element,node[i]->content);
344 Config->rootcheck = atoi(node[i]->content);
348 else if(strcmp(node[i]->element, xml_hostinfo) == 0)
350 if(!OS_StrIsNum(node[i]->content))
352 merror(XML_VALUEERR,ARGV0,node[i]->element,node[i]->content);
357 Config->hostinfo = atoi(node[i]->content);
361 else if(strcmp(node[i]->element, xml_stats) == 0)
363 if(!OS_StrIsNum(node[i]->content))
365 merror(XML_VALUEERR,ARGV0,node[i]->element,node[i]->content);
370 Config->stats = atoi(node[i]->content);
373 else if(strcmp(node[i]->element, xml_memorysize) == 0)
375 if(!OS_StrIsNum(node[i]->content))
377 merror(XML_VALUEERR,ARGV0,node[i]->element,node[i]->content);
382 Config->memorysize = atoi(node[i]->content);
386 else if(strcmp(node[i]->element, xml_white_list) == 0)
388 /* Windows do not need it */
391 char *ip_address_regex =
392 "^[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}/?"
393 "([0-9]{0,2}|[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3})$";
395 if(Config && OS_PRegex(node[i]->content, ip_address_regex))
399 realloc(Config->white_list, sizeof(os_ip *)*white_size);
400 if(!Config->white_list)
402 merror(MEM_ERROR, ARGV0);
406 os_calloc(1, sizeof(os_ip), Config->white_list[white_size -2]);
407 Config->white_list[white_size -1] = NULL;
409 if(!OS_IsValidIP(node[i]->content,
410 Config->white_list[white_size -2]))
412 merror(INVALID_IP, ARGV0,
417 /* Adding hostname */
420 hostname_white_size++;
421 Config->hostname_white_list =
422 realloc(Config->hostname_white_list,
423 sizeof(OSMatch *)*hostname_white_size);
425 if(!Config->hostname_white_list)
427 merror(MEM_ERROR, ARGV0);
432 Config->hostname_white_list[hostname_white_size -2]);
433 Config->hostname_white_list[hostname_white_size -1] = NULL;
437 Config->hostname_white_list[hostname_white_size -2],
440 merror(REGEX_COMPILE, ARGV0, node[i]->content,
441 Config->hostname_white_list
442 [hostname_white_size -2]->error);
452 * email_to, email_from, smtp_Server and maxperhour.
453 * We will use a separate structure for that.
455 else if(strcmp(node[i]->element, xml_emailto) == 0)
458 if(!OS_PRegex(node[i]->content, "[a-zA-Z0-9\\._-]+@[a-zA-Z0-9\\._-]"))
460 merror("%s: ERROR: Invalid Email address: %s.", ARGV0, node[i]->content);
468 Mail->to = realloc(Mail->to, sizeof(char *)*mailto_size);
471 merror(MEM_ERROR, ARGV0);
475 os_strdup(node[i]->content, Mail->to[mailto_size - 2]);
476 Mail->to[mailto_size - 1] = NULL;
479 else if(strcmp(node[i]->element, xml_emailfrom) == 0)
487 os_strdup(node[i]->content, Mail->from);
490 else if(strcmp(node[i]->element, xml_smtpserver) == 0)
493 if(Mail && (Mail->mn))
495 Mail->smtpserver = OS_GetHost(node[i]->content, 5);
496 if(!Mail->smtpserver)
498 merror(INVALID_SMTP, ARGV0, node[i]->content);
504 else if(strcmp(node[i]->element, xml_mailmaxperhour) == 0)
508 if(!OS_StrIsNum(node[i]->content))
510 merror(XML_VALUEERR,ARGV0,node[i]->element,node[i]->content);
513 Mail->maxperhour = atoi(node[i]->content);
515 if((Mail->maxperhour <= 0) || (Mail->maxperhour > 9999))
517 merror(XML_VALUEERR,ARGV0,node[i]->element,node[i]->content);
524 merror(XML_INVELEM, ARGV0, node[i]->element);