Imported Upstream version 2.5.1
[ossec-hids.git] / src / os_dbd / alert.c
index 56fd1a3..517b65c 100755 (executable)
@@ -1,11 +1,11 @@
-/* @(#) $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
@@ -106,13 +106,16 @@ int __DBInsertLocation(char *location, DBConfig *db_config)
  */
 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 */
@@ -131,7 +134,6 @@ int OS_Alert_InsertDB(alert_data *al_data, DBConfig *db_config)
 
     /* Escaping strings */
     osdb_escapestr(al_data->user);
-    osdb_escapestr(al_data->log[0]);
 
 
     /* We first need to insert the location */
@@ -164,26 +166,38 @@ int OS_Alert_InsertDB(alert_data *al_data, DBConfig *db_config)
     }
     
 
+    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 */
@@ -195,7 +209,7 @@ int OS_Alert_InsertDB(alert_data *al_data, DBConfig *db_config)
 
 
     /* 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')",