1 /* @(#) $Id: csyslogd-config.c,v 1.3 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
16 #include "csyslogd-config.h"
20 int Read_CSyslog(XML_NODE node, void *config, void *config2)
25 char *xml_syslog_server = "server";
26 char *xml_syslog_port = "port";
27 char *xml_syslog_format = "format";
28 char *xml_syslog_level = "level";
29 char *xml_syslog_id = "rule_id";
30 char *xml_syslog_group = "group";
31 char *xml_syslog_location = "event_location";
34 GeneralConfig *gen_config = (GeneralConfig *)config;
35 SyslogConfig **syslog_config = (SyslogConfig **)gen_config->data;
38 /* Getting Granular mail_to size */
41 while(syslog_config[s])
46 /* Allocating the memory for the config. */
47 os_realloc(syslog_config, (s + 2) * sizeof(SyslogConfig *), syslog_config);
48 os_calloc(1, sizeof(SyslogConfig), syslog_config[s]);
49 syslog_config[s + 1] = NULL;
52 /* Zeroing the elements. */
53 syslog_config[s]->server = NULL;
54 syslog_config[s]->rule_id = NULL;
55 syslog_config[s]->group = NULL;
56 syslog_config[s]->location = NULL;
57 syslog_config[s]->level = 0;
58 syslog_config[s]->port = 514;
59 /* local 0 facility (16) + severity 4 - warning. --default */
60 syslog_config[s]->priority = (16 * 8) + 4;
66 merror(XML_ELEMNULL, ARGV0);
69 else if(!node[i]->content)
71 merror(XML_VALUENULL, ARGV0, node[i]->element);
74 else if(strcmp(node[i]->element, xml_syslog_level) == 0)
76 if(!OS_StrIsNum(node[i]->content))
78 merror(XML_VALUEERR,ARGV0,node[i]->element,node[i]->content);
82 syslog_config[s]->level = atoi(node[i]->content);
84 else if(strcmp(node[i]->element, xml_syslog_port) == 0)
86 if(!OS_StrIsNum(node[i]->content))
88 merror(XML_VALUEERR,ARGV0,node[i]->element,node[i]->content);
92 syslog_config[s]->port = atoi(node[i]->content);
94 else if(strcmp(node[i]->element, xml_syslog_server) == 0)
96 os_strdup(node[i]->content, syslog_config[s]->server);
98 else if(strcmp(node[i]->element, xml_syslog_id) == 0)
101 char *str_pt = node[i]->content;
103 while(*str_pt != '\0')
105 /* We allow spaces in between */
112 /* If is digit, we get the value
113 * and search for the next digit
116 else if(isdigit((int)*str_pt))
121 debug1("%s: DEBUG: Adding '%d' to syslog alerting",
124 if(syslog_config[s]->rule_id)
126 while(syslog_config[s]->rule_id[id_i])
130 os_realloc(syslog_config[s]->rule_id,
131 (id_i +2) * sizeof(int),
132 syslog_config[s]->rule_id);
134 syslog_config[s]->rule_id[id_i + i] = 0;
135 syslog_config[s]->rule_id[id_i] = r_id;
137 str_pt = strchr(str_pt, ',');
148 /* Checking for duplicate commas */
149 else if(*str_pt == ',')
162 else if(strcmp(node[i]->element, xml_syslog_format) == 0)
164 if(strcmp(node[i]->content, "default") == 0)
166 /* Default is full format */
170 merror(XML_VALUEERR,ARGV0,node[i]->element,node[i]->content);
174 else if(strcmp(node[i]->element, xml_syslog_location) == 0)
176 os_calloc(1, sizeof(OSMatch),syslog_config[s]->location);
177 if(!OSMatch_Compile(node[i]->content,
178 syslog_config[s]->location, 0))
180 merror(REGEX_COMPILE, ARGV0, node[i]->content,
181 syslog_config[s]->location->error);
185 else if(strcmp(node[i]->element, xml_syslog_group) == 0)
187 os_calloc(1, sizeof(OSMatch),syslog_config[s]->group);
188 if(!OSMatch_Compile(node[i]->content,
189 syslog_config[s]->group, 0))
191 merror(REGEX_COMPILE, ARGV0, node[i]->content,
192 syslog_config[s]->group->error);
198 merror(XML_INVELEM, ARGV0, node[i]->element);
205 /* We must have at least one entry set */
206 if(!syslog_config[s]->server)
208 merror(XML_INV_CSYSLOG, ARGV0);
213 gen_config->data = syslog_config;