From: Eric Leblond <eric@regit.org>
To: netfilter-devel <netfilter-devel@vger.kernel.org>
Cc: Bob Hockney <zeus@ix.netcom.com>, Eric Leblond <eric@regit.org>
Subject: [PATCH 2/3] Handle postgresql schemas correctly
Date: Fri, 21 Dec 2012 15:01:52 +0100 [thread overview]
Message-ID: <1356098513-18684-3-git-send-email-eric@regit.org> (raw)
In-Reply-To: <1356098513-18684-1-git-send-email-eric@regit.org>
From: Bob Hockney <zeus@ix.netcom.com>
Add 'schema' variable to look into corresponding schema.
Signed-off-by: Eric Leblond <eric@regit.org>
---
output/pgsql/ulogd_output_PGSQL.c | 35 +++++++++++++++++++++++++++++++----
ulogd.conf.in | 4 ++++
2 files changed, 35 insertions(+), 4 deletions(-)
diff --git a/output/pgsql/ulogd_output_PGSQL.c b/output/pgsql/ulogd_output_PGSQL.c
index cd793ca..f246153 100644
--- a/output/pgsql/ulogd_output_PGSQL.c
+++ b/output/pgsql/ulogd_output_PGSQL.c
@@ -105,9 +105,16 @@ static int pgsql_namespace(struct ulogd_pluginstance *upi)
}
if (PQresultStatus(pi->pgres) == PGRES_TUPLES_OK) {
- ulogd_log(ULOGD_DEBUG, "using schema %s\n",
- schema_ce(upi->config_kset).u.string);
- pi->db_inst.schema = schema_ce(upi->config_kset).u.string;
+ if (PQntuples(pi->pgres)) {
+ ulogd_log(ULOGD_DEBUG, "using schema %s\n",
+ schema_ce(upi->config_kset).u.string);
+ pi->db_inst.schema = schema_ce(upi->config_kset).u.string;
+ } else {
+ ulogd_log(ULOGD_ERROR, "schema %s not found: %s\n",
+ schema_ce(upi->config_kset).u.string, PQerrorMessage(pi->dbh));
+ PQclear(pi->pgres);
+ return -1;
+ }
} else {
pi->db_inst.schema = NULL;
}
@@ -223,6 +230,8 @@ static int open_db_pgsql(struct ulogd_pluginstance *upi)
char *user = user_ce(upi->config_kset).u.string;
char *pass = pass_ce(upi->config_kset).u.string;
char *db = db_ce(upi->config_kset).u.string;
+ char *schema = NULL;
+ char pgbuf[128];
/* 80 is more than what we need for the fixed parts below */
len = 80 + strlen(user) + strlen(db);
@@ -270,11 +279,29 @@ static int open_db_pgsql(struct ulogd_pluginstance *upi)
}
if (pgsql_namespace(upi)) {
- ulogd_log(ULOGD_ERROR, "unable to test for pgsql schemas\n");
+ ulogd_log(ULOGD_ERROR, "problem testing for pgsql schemas\n");
close_db_pgsql(upi);
return -1;
}
+ pi=(struct pgsql_instance *)upi->private;
+ schema = pi->db_inst.schema;
+
+ if (!(schema == NULL) && (strcmp(schema,"public"))) {
+ snprintf(pgbuf, 128, "SET search_path='%.63s', \"$user\", 'public'", schema);
+ pi->pgres = PQexec(pi->dbh, pgbuf);
+ if ((PQresultStatus(pi->pgres) == PGRES_COMMAND_OK)) {
+ PQclear(pi->pgres);
+ } else {
+ ulogd_log(ULOGD_ERROR, "could not set search path to (%s): %s\n",
+ schema, PQerrorMessage(pi->dbh));
+ PQclear(pi->pgres);
+ close_db_pgsql(upi);
+ return -1;
+ }
+
+ }
+
return 0;
}
diff --git a/ulogd.conf.in b/ulogd.conf.in
index 3bd464b..c630b88 100644
--- a/ulogd.conf.in
+++ b/ulogd.conf.in
@@ -213,6 +213,7 @@ db="nulog"
host="localhost"
user="nupik"
table="ulog"
+#schema="public"
pass="changeme"
procedure="INSERT_PACKET_FULL"
@@ -221,6 +222,7 @@ db="nulog"
host="localhost"
user="nupik"
table="ulog2_ct"
+#schema="public"
pass="changeme"
procedure="INSERT_CT"
@@ -229,6 +231,7 @@ db="nulog"
host="localhost"
user="nupik"
table="ulog2_ct"
+#schema="public"
pass="changeme"
procedure="INSERT_OR_REPLACE_CT"
@@ -237,6 +240,7 @@ db="nulog"
host="localhost"
user="nupik"
table="nfacct"
+#schema="public"
pass="changeme"
procedure="INSERT_NFACCT"
--
1.7.10.4
next prev parent reply other threads:[~2012-12-21 14:02 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-12-21 14:01 [ulogd patches 0/3] IPv6 improvements Eric Leblond
2012-12-21 14:01 ` [PATCH 1/3] Fix parsing of ipv6 flowlabel and tc fields Eric Leblond
2012-12-21 14:01 ` Eric Leblond [this message]
2012-12-21 14:01 ` [PATCH 3/3] Add additional ip6 header fields to database scripts Eric Leblond
2012-12-27 8:22 ` [ulogd patches 0/3] IPv6 improvements Eric Leblond
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1356098513-18684-3-git-send-email-eric@regit.org \
--to=eric@regit.org \
--cc=netfilter-devel@vger.kernel.org \
--cc=zeus@ix.netcom.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.