summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPablo Neira Ayuso <pablo@netfilter.org>2011-02-25 18:05:59 +0100
committerPablo Neira Ayuso <pablo@netfilter.org>2011-02-25 18:57:28 +0100
commite7e229fd66454a11317b2386948ff2055903e7ea (patch)
tree849604620f0f8f1f42de9dd09a49d7a3b34914ac
parentff196ff7ff31e7dc38260bd54d5e0e9e99bf3839 (diff)
sqlite3: remove automatic creation of table `daily'
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>
-rw-r--r--doc/sqlite3.txt7
-rw-r--r--doc/ulogd.sgml11
-rw-r--r--output/sqlite3/ulogd_output_SQLITE3.c46
3 files changed, 17 insertions, 47 deletions
diff --git a/doc/sqlite3.txt b/doc/sqlite3.txt
deleted file mode 100644
index 97e8bc9..0000000
--- a/doc/sqlite3.txt
+++ /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"
diff --git a/doc/ulogd.sgml b/doc/ulogd.sgml
index 8e31fb6..547b56a 100644
--- a/doc/ulogd.sgml
+++ b/doc/ulogd.sgml
@@ -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:
diff --git a/output/sqlite3/ulogd_output_SQLITE3.c b/output/sqlite3/ulogd_output_SQLITE3.c
index 0913cd9..3cd2106 100644
--- a/output/sqlite3/ulogd_output_SQLITE3.c
+++ b/output/sqlite3/ulogd_output_SQLITE3.c
@@ -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++) {