/** void *_Rules_ReadInsertDB(RuleInfo *rule, void *db_config) * Insert rules in to the db. */ static void *_Rules_ReadInsertDB(RuleInfo *rule, void *db_config) { /* tmp disable */ /* DBConfig *dbc = (DBConfig *)db_config; */ char sql_query[OS_SIZE_1024]; memset(sql_query, '\0', OS_SIZE_1024); /* Escaping strings */ osdb_escapestr(rule->group); osdb_escapestr(rule->comment); /* Checking level limit */ if(rule->level > 20) 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) { merror("%s: Invalid rule id: %u", ARGV0, rule->sigid); return(NULL); } /* Inserting group into the signature mapping */ _Groups_ReadInsertDB(rule, (DBConfig *) db_config); debug2("%s: DEBUG: Inserting: %d", ARGV0, rule->sigid); /* Generating SQL */ snprintf(sql_query, OS_SIZE_1024 -1, "REPLACE INTO " "signature(rule_id, level, description) " "VALUES ('%u','%u','%s')", rule->sigid, rule->level, rule->comment); /* Checking return code. */ /* if(!osdb_query_insert(dbc->conn, sql_query)) { merror(DB_GENERROR, ARGV0); } */ return(NULL); }
/** void *_Rules_ReadInsertDB(RuleInfo *rule, void *db_config) * Insert rules in to the db. */ void *_Rules_ReadInsertDB(RuleInfo *rule, void *db_config) { DBConfig *dbc = (DBConfig *)db_config; char sql_query[OS_SIZE_1024]; memset(sql_query, '\0', OS_SIZE_1024); /* Escaping strings */ osdb_escapestr(rule->group); osdb_escapestr(rule->comment); /* Checking level limit */ if(rule->level > 20) 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) { merror("%s: Invalid rule id: %u", ARGV0, rule->sigid); return(NULL); } /* 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, "INSERT INTO " "signature(rule_id, level, description) " "VALUES ('%u','%u','%s')", rule->sigid, rule->level, rule->comment); } else { snprintf(sql_query, OS_SIZE_1024 -1, "UPDATE signature SET level='%u',description='%s' " "WHERE rule_id='%u'", rule->level, rule->comment,rule->sigid); } /* Checking return code. */ if(!osdb_query_insert(dbc->conn, sql_query)) { merror(DB_GENERROR, ARGV0); } return(NULL); }