-/* @(#) $Id$ */
+/* @(#) $Id: ./src/config/rules-config.c, 2011/09/08 dcid Exp $
+ */
/* Copyright (C) 2009 Trend Micro Inc.
* All right reserved.
/* Functions to handle the configuration files
*/
-
+#include "config.h"
#include "shared.h"
#include "global-config.h"
-static int cmpr(const void *a, const void *b) {
+static int cmpr(const void *a, const void *b) {
/*printf("%s - %s\n", *(char **)a, *(char **)b);*/
return strcmp(*(char **)a, *(char **)b);
}
static int file_in_list(int list_size, char *f_name, char *d_name, char **alist)
{
- int i = 0;
+ int i = 0;
for(i=0; i<(list_size-1); i++)
{
if((strcmp(alist[i], f_name) == 0 || strcmp(alist[i], d_name) == 0))
return(1);
}
}
- return(0);
+ return(0);
}
int Read_Rules(XML_NODE node, void *configp, void *mailp)
{
int i = 0;
+ int ii = 0;
int rules_size = 1;
int lists_size = 1;
int decoders_size = 1;
-
+
char path[PATH_MAX +2];
char f_name[PATH_MAX +2];
- int start_point = 0;
+ int start_point = 0;
int att_count = 0;
struct dirent *entry;
- DIR *dfd;
- OSRegex regex;
+ DIR *dfd;
+ OSRegex regex;
/* XML definitions */
char *xml_rules_rule = "rule";
char *xml_rules_rules_dir = "rule_dir";
char *xml_rules_lists = "list";
- char *xml_rules_lists_dir = "list_dir";
char *xml_rules_decoders = "decoder";
char *xml_rules_decoders_dir = "decoder_dir";
_Config *Config;
-
+
Config = (_Config *)configp;
-
+
+ /* initialise OSRegex */
+ regex.patterns = NULL;
+ regex.prts_closure = NULL;
+ regex.prts_str = NULL;
+ regex.sub_strings = NULL;
+
while(node[i])
{
if(!node[i]->element)
return(OS_INVALID);
}
/* Mail notification */
- else if((strcmp(node[i]->element, xml_rules_include) == 0) ||
+ else if((strcmp(node[i]->element, xml_rules_include) == 0) ||
(strcmp(node[i]->element, xml_rules_rule) == 0))
{
rules_size++;
- Config->includes = realloc(Config->includes,
+ Config->includes = realloc(Config->includes,
sizeof(char *)*rules_size);
if(!Config->includes)
{
snprintf(f_name, PATH_MAX +1, "%s/%s", node[i]->content, entry->d_name);
/* Just ignore . and .. */
- if((strcmp(entry->d_name,".") == 0) || (strcmp(entry->d_name,"..") == 0))
+ if((strcmp(entry->d_name,".") == 0) || (strcmp(entry->d_name,"..") == 0))
continue;
/* no dups allowed */
if(!Config->decoders)
{
merror(MEM_ERROR, ARGV0);
+ OSRegex_FreePattern(®ex);
return(-1);
}
debug1("Regex does not match \"%s\"", f_name);
}
}
-
+
closedir(dfd);
/* Sort just then newly added items */
qsort(Config->decoders + start_point , decoders_size- start_point -1, sizeof(char *), cmpr);
}
- int ii=0;
debug1("decoders_size %d", decoders_size);
for(ii=0;ii<decoders_size-1;ii++)
debug1("- %s", Config->decoders[ii]);
snprintf(f_name, PATH_MAX +1, "%s/%s", node[i]->content, entry->d_name);
/* Just ignore . and .. */
- if((strcmp(entry->d_name,".") == 0) || (strcmp(entry->d_name,"..") == 0))
+ if((strcmp(entry->d_name,".") == 0) || (strcmp(entry->d_name,"..") == 0))
continue;
/* no dups allowed */
if(!Config->includes)
{
merror(MEM_ERROR, ARGV0);
+ OSRegex_FreePattern(®ex);
return(-1);
}
debug1("Regex does not match \"%s\"", f_name);
}
}
-
+
closedir(dfd);
/* Sort just then newly added items */
qsort(Config->includes + start_point , rules_size - start_point -1, sizeof(char *), cmpr);
else
{
merror(XML_INVELEM, ARGV0, node[i]->element);
+ OSRegex_FreePattern(®ex);
return(OS_INVALID);
}
i++;