-/* @(#) $Id: alert.c,v 1.8 2009/06/24 17:06:29 dcid Exp $ */
+/* @(#) $Id$ */
/* 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 OS_Alert_InsertDB(alert_data *al_data, DBConfig *db_config)
{
+ int i;
unsigned int s_ip = 0, d_ip = 0, location_id = 0;
int *loc_id;
- char sql_query[OS_SIZE_2048 +1];
+ char sql_query[OS_SIZE_8192 +1];
+ char *fulllog = NULL;
/* Clearing the memory before insert */
- memset(sql_query, '\0', OS_SIZE_2048 +1);
+ sql_query[0] = '\0';
+ sql_query[OS_SIZE_8192] = '\0';
/* Converting srcip to int */
/* Escaping strings */
osdb_escapestr(al_data->user);
- osdb_escapestr(al_data->log[0]);
/* We first need to insert the location */
}
+ i = 0;
+ while(al_data->log[i])
+ {
+ fulllog = os_LoadString(fulllog, al_data->log[i]);
+ i++;
+ }
+ osdb_escapestr(fulllog);
+
+
/* Inserting data */
if(db_config->db_type == POSTGDB)
{
/* On postgres we need to escape the user field. */
- snprintf(sql_query, OS_SIZE_2048,
+ snprintf(sql_query, OS_SIZE_8192,
"INSERT INTO "
"data(id, server_id, \"user\", full_log) "
"VALUES ('%u', '%u', '%s', '%s') ",
db_config->alert_id, db_config->server_id,
- al_data->user, al_data->log[0]);
+ al_data->user, fulllog);
}
else
{
- snprintf(sql_query, OS_SIZE_2048,
+ snprintf(sql_query, OS_SIZE_8192,
"INSERT INTO "
"data(id, server_id, user, full_log) "
"VALUES ('%u', '%u', '%s', '%s') ",
db_config->alert_id, db_config->server_id,
- al_data->user, al_data->log[0]);
+ al_data->user, fulllog);
}
+
+ free(fulllog);
+ fulllog = NULL;
/* Inserting into the db */
/* Generating final SQL */
- snprintf(sql_query, OS_SIZE_2048,
+ snprintf(sql_query, OS_SIZE_8192,
"INSERT INTO "
"alert(id,server_id,rule_id,timestamp,location_id,src_ip) "
"VALUES ('%u', '%u', '%u','%u', '%u', '%lu')",