[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[ossec-cvs] ossec-hids: db_op.c (HEAD) main.c (HEAD) mysql.schema (HEAD) postgresql.schema (HEAD) server.c (HEAD) [dcid]



Module name:	ossec-hids
Changes by:	dcid	07/08/26 22:49:32

Modified files:
	db_op.c main.c mysql.schema postgresql.schema server.c

Log message:
Description: Adding enable option to ossec-control and a few small fixes.
Reviewed by: dcid
Bug:

Index: db_op.c
===================================================================
RCS file: /usr/cvsroot/ossec-hids/src/os_dbd/db_op.c,v
diff -u -r1.6 -r1.7
--- db_op.c	25 Aug 2007 13:24:04 -0000	1.6
+++ db_op.c	27 Aug 2007 01:49:32 -0000	1.7
@@ -31,6 +31,11 @@
 
 
 
+/* Error count */
+int _db_err = 0;
+
+
+
 /** void osdb_escapestr
  * Escapes a null terminated string before inserting into the database.
  * We built a white list of allowed characters at insert_map. Everything
@@ -55,6 +60,20 @@
     if(*(str -1) == '\\')
     {
         *(str-1) = '\0';
+    }
+}
+
+
+
+/** void osdb_checkerror(void *db_conn)
+ * Checks for errors and handle it appropriately.
+ */
+void osdb_checkerror(void *db_conn)
+{
+    /* If error count is too large, we try to reconnect. */
+    if(_db_err > 10)
+    {
+        osdb_close(db_conn);
     }
 }
 

Index: main.c
===================================================================
RCS file: /usr/cvsroot/ossec-hids/src/os_dbd/main.c,v
diff -u -r1.5 -r1.6
--- main.c	25 Aug 2007 13:24:04 -0000	1.5
+++ main.c	27 Aug 2007 01:49:32 -0000	1.6
@@ -169,7 +169,11 @@
         merror(DB_CONFIGERR, ARGV0);
         ErrorExit(CONFIG_ERROR, ARGV0, cfg);
     }
-    debug1("%s: DEBUG: db connected.", ARGV0);
+    
+
+    /* We must notify that we connected -- easy debugging */
+    verbose("%s: Connected to database '%s' at '%s'.", 
+            ARGV0, db_config.db, db_config.host);
 
     
     /* Privilege separation */	

Index: mysql.schema
===================================================================
RCS file: /usr/cvsroot/ossec-hids/src/os_dbd/mysql.schema,v
diff -u -r1.4 -r1.5
--- mysql.schema	19 Aug 2007 13:32:11 -0000	1.4
+++ mysql.schema	27 Aug 2007 01:49:32 -0000	1.5
@@ -1,3 +1,17 @@
+# @(#) $Id$ */
+#
+# Copyright (C) 2003-2007 Daniel B. Cid <dcid@xxxxxxxxx>
+# 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
+# Foundation.
+#
+# License details at the LICENSE file included with OSSEC or
+# online at: http://www.ossec.net/en/licensing.html
+
+
 CREATE TABLE category
     (
     cat_id      SMALLINT    UNSIGNED NOT NULL   AUTO_INCREMENT,

Index: postgresql.schema
===================================================================
RCS file: /usr/cvsroot/ossec-hids/src/os_dbd/postgresql.schema,v
diff -u -r1.1 -r1.2
--- postgresql.schema	25 Aug 2007 16:12:50 -0000	1.1
+++ postgresql.schema	27 Aug 2007 01:49:32 -0000	1.2
@@ -1,3 +1,17 @@
+-- @(#) $Id$ */
+--
+-- Copyright (C) 2003-2007 Daniel B. Cid <dcid@xxxxxxxxx>
+-- 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
+-- Foundation.
+--
+-- License details at the LICENSE file included with OSSEC or
+-- online at: http://www.ossec.net/en/licensing.html
+          
+
 BEGIN;
 
 CREATE TABLE category

Index: server.c
===================================================================
RCS file: /usr/cvsroot/ossec-hids/src/os_dbd/server.c,v
diff -u -r1.3 -r1.4
--- server.c	25 Aug 2007 13:24:04 -0000	1.3
+++ server.c	27 Aug 2007 01:49:32 -0000	1.4
@@ -53,20 +53,42 @@
     
     memset(sql_query, '\0', OS_SIZE_1024);
 
-    /* Generating SQL */
+    /* Checking if the server is present */
     snprintf(sql_query, OS_SIZE_1024 -1,
-            "INSERT INTO "
-            "server(id, last_contact, version, hostname, information) "
-            "VALUES (NULL, '%u', '%s', '%s', '%s') ON DUPLICATE KEY UPDATE "
-            "last_contact='%u',version='%s',information='%s'",
-            (unsigned int)time(0), __version, server, info, 
-            (unsigned int)time(0), __version, info);
+            "SELECT id from server where hostname = '%s'",
+            server);
+    
+    /* If not present, we insert */
+    if(osdb_query_select(db_config->conn, sql_query) == 0)
+    {
+        snprintf(sql_query, OS_SIZE_1024 -1,
+                "INSERT INTO "
+                "server(id, last_contact, version, hostname, information) "
+                "VALUES (NULL, '%u', '%s', '%s', '%s')",
+                (unsigned int)time(0), __version, server, info);
 
+        /* Checking return code. */
+        if(!osdb_query_insert(db_config->conn, sql_query))
+        {
+            merror(DB_MAINERROR, ARGV0);
+        }
+    }
 
-    /* Checking return code. */
-    if(!osdb_query_insert(db_config->conn, sql_query))
+    /* If it is, we update it */
+    else
     {
-        merror(DB_MAINERROR, ARGV0);
+
+        snprintf(sql_query, OS_SIZE_1024 -1,
+                "UPDATE server SET "
+                "last_contact='%u',version='%s',information='%s' "
+                "WHERE hostname = '%s'",
+                (unsigned int)time(0), __version, info, server);
+
+        /* Checking return code. */
+        if(!osdb_query_insert(db_config->conn, sql_query))
+        {
+            merror(DB_MAINERROR, ARGV0);
+        }
     }
 
     return(0);


OSSEC home | Main Index | Thread Index


OSSEC project: www.ossec.net.
Mailling list information: http://www.ossec.net/en/mailing_lists.html.