-/* @(#) $Id: rules.c,v 1.9 2009/06/24 17:06:30 dcid Exp $ */
+/* @(#) $Id: ./src/os_dbd/rules.c, 2011/09/08 dcid Exp $
+ */
/* Copyright (C) 2009 Trend Micro Inc.
* All rights reserved.
*
* This program is a free software; you can redistribute it
* and/or modify it under the terms of the GNU General Public
- * License (version 3) as published by the FSF - Free Software
+ * License (version 2) as published by the FSF - Free Software
* Foundation
*
* License details at the LICENSE file included with OSSEC or
int __Groups_InsertGroup(char *group, DBConfig *db_config)
{
char sql_query[OS_SIZE_1024];
-
+
memset(sql_query, '\0', OS_SIZE_1024);
/* Generating SQL */
char *tmp_group;
char *tmp_str;
-
+
debug1("%s: DEBUG: entering _Groups_ReadInsertDB", ARGV0);
{
return;
}
-
+
tmp_str = strchr(rule->group, ',');
tmp_group = rule->group;
while(*tmp_group == ' ')
tmp_group++;
-
+
/* Checking for empty group */
if(*tmp_group == '\0')
{
}
}
-
+
/* Getting next category */
tmp_group = tmp_str;
if(tmp_group)
tmp_str = strchr(tmp_group, ',');
}
}
-
+
return;
}
char sql_query[OS_SIZE_1024];
memset(sql_query, '\0', OS_SIZE_1024);
-
+
/* Escaping strings */
osdb_escapestr(rule->group);
osdb_escapestr(rule->comment);
rule->level = 20;
if(rule->level < 0)
rule->level = 0;
-
-
+
+
debug1("%s: DEBUG: entering _Rules_ReadInsertDB()", ARGV0);
-
-
+
+
/* Checking rule limit */
if(rule->sigid < 0 || rule->sigid > 9999999)
{
/* Inserting group into the signature mapping */
_Groups_ReadInsertDB(rule, db_config);
-
-
-
+
+
+
debug2("%s: DEBUG: Inserting: %d", ARGV0, rule->sigid);
-
+
/* Generating SQL */
snprintf(sql_query, OS_SIZE_1024 -1,
"SELECT id FROM signature "
"where rule_id = %u",
rule->sigid);
-
+
if(osdb_query_select(dbc->conn, sql_query) == 0)
{
snprintf(sql_query, OS_SIZE_1024 -1,
rule->level, rule->comment,rule->sigid);
}
-
+
/* Checking return code. */
if(!osdb_query_insert(dbc->conn, sql_query))
{
int OS_InsertRulesDB(DBConfig *db_config)
{
char **rulesfiles;
-
+
rulesfiles = db_config->includes;
while(rulesfiles && *rulesfiles)
{
debug1("%s: Reading rules file: '%s'", ARGV0, *rulesfiles);
-
+
if(OS_ReadXMLRules(*rulesfiles, _Rules_ReadInsertDB, db_config) < 0)
{
merror(RULES_ERROR, ARGV0, *rulesfiles);