]> git.ipfire.org Git - thirdparty/ulogd2.git/commitdiff
sqlite3: remove automatic creation of table `daily'
authorPablo Neira Ayuso <pablo@netfilter.org>
Fri, 25 Feb 2011 17:05:59 +0000 (18:05 +0100)
committerPablo Neira Ayuso <pablo@netfilter.org>
Fri, 25 Feb 2011 17:57:28 +0000 (18:57 +0100)
This patch removes the creation of the `daily' table. Now, we assume
that the table that we use are created before launching ulogd2.

This code is broken because you have to specify in the configuration
file that the table used is `daily', otherwise this `daily' table is
created and dropped during the daemon starting, but not used.

Moreover, the code explicit shows a message that it says:

/* FIXME make this configurable */

So, I think that this patch is the way to go :-).

This patch also documents the table creation in ulogd.sgml

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
doc/sqlite3.txt [deleted file]
doc/ulogd.sgml
output/sqlite3/ulogd_output_SQLITE3.c

diff --git a/doc/sqlite3.txt b/doc/sqlite3.txt
deleted file mode 100644 (file)
index 97e8bc9..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-XXX: This has to go in ulogd.sgml, later.
-
-To create the database file, you have to:
-$ sqlite3 file.db < sqlite3.table
-
-To check that we are logging stuff into it correctly:
-sqlite3 ulogd.sqlite3db "SELECT * from ulog"
index 8e31fb6f5b6489f3019c5bc3661f9c00fb51fe6c..547b56af039081b08a79b2178d531ee662006b5b 100644 (file)
@@ -576,7 +576,16 @@ unsigned integer into the table.
 <p>
 You may want to have a look at the file '<tt>doc/sqlite3.table</tt>' as an
 example table including fields to log all keys from ulogd_BASE.so. Just delete
-the fields you are not interested in, and create the table.
+the fields you are not interested in, and create the table. This file contains
+two tables, one for packet-based logging and another for flow-based logging.
+
+<p>
+To create the database file with the tables, you have to invoke the following
+command: <tt>sqlite3 ulogd.sqlite3db < sqlite3.table</tt>
+
+<p>
+To check that we are logging stuff into it correctly:
+sqlite3 ulogd.sqlite3db "SELECT * from ulog_ct"
 
 <p>
 The module defines the following configuration directives:
index 0913cd9292dcb503dc19177811916aa45914de59..3cd2106ff3677cb502716837a943d3a2f4944b7c 100644 (file)
@@ -40,9 +40,6 @@
 
 #define CFG_BUFFER_DEFAULT             10
 
-/* number of colums we have (really should be configurable) */
-#define DB_NUM_COLS    11
-
 #if 0
 #define DEBUGP(x, args...)     fprintf(stderr, x, ## args)
 #else
@@ -314,37 +311,6 @@ db_count_cols(struct ulogd_pluginstance *pi, sqlite3_stmt **stmt)
        return sqlite3_column_count(*stmt);
 }
 
-
-/* FIXME make this configurable */
-#define SQL_CREATE_STR \
-               "create table daily(ip_saddr integer, ip_daddr integer, " \
-               "ip_protocol integer, l4_dport integer, raw_in_pktlen integer, " \
-               "raw_in_pktcount integer, raw_out_pktlen integer, " \
-               "raw_out_pktcount integer, flow_start_day integer, " \
-               "flow_start_sec integer, flow_duration integer)"
-
-static int
-db_create_tbl(struct ulogd_pluginstance *pi)
-{
-       struct sqlite3_priv *priv = (void *)pi->private;
-       char *errmsg;
-       int ret;
-
-       sqlite3_exec(priv->dbh, "drop table daily", NULL, NULL, NULL);
-
-       ret = sqlite3_exec(priv->dbh, SQL_CREATE_STR, NULL, NULL, &errmsg);
-       if (ret != SQLITE_OK) {
-               ulogd_log(ULOGD_ERROR, "SQLITE3: create table: %s\n", errmsg);
-               sqlite3_free(errmsg);
-
-               return -1;
-       }
-
-       return 0;
-}
-
-
-
 /* initialize DB, possibly creating it */
 static int
 sqlite3_init_db(struct ulogd_pluginstance *pi)
@@ -360,11 +326,13 @@ sqlite3_init_db(struct ulogd_pluginstance *pi)
                return -1;
 
        num_cols = db_count_cols(pi, &schema_stmt);
-       if (num_cols != DB_NUM_COLS) {
-               if (db_create_tbl(pi) < 0)
-                       return -1;
-
-               num_cols = db_count_cols(pi, &schema_stmt);
+       if (num_cols <= 0) {
+               ulogd_log(ULOGD_ERROR, "table `%s' is empty or missing in "
+                                      "file `%s'. Did you created this "
+                                      "table in the database file? Please, "
+                                      "see ulogd2 documentation.\n",
+                                       table_ce(pi), db_ce(pi));
+               return -1;
        }
 
        for (col = 0; col < num_cols; col++) {