From af9a7fa7a5d908600449714c9aa8c34e7c0caee4 Mon Sep 17 00:00:00 2001 From: laforge Date: Sat, 24 Apr 2004 23:04:38 +0000 Subject: - make hostname optional, not mandatory (Andrejs Dubovskis) - make password optional, not mandatory (Andrejs Dubovskis) - fix two memory leaks (Andrejs Dubovskis) - lots of cosmetic fixes --- ulogd/pgsql/ulogd_PGSQL.c | 130 ++++++++++++++++++++++++++-------------------- 1 file changed, 74 insertions(+), 56 deletions(-) (limited to 'ulogd/pgsql') diff --git a/ulogd/pgsql/ulogd_PGSQL.c b/ulogd/pgsql/ulogd_PGSQL.c index 5a1551d..c2a3b71 100644 --- a/ulogd/pgsql/ulogd_PGSQL.c +++ b/ulogd/pgsql/ulogd_PGSQL.c @@ -45,25 +45,39 @@ static char *stmt_val; static char *stmt_ins; /* our configuration directives */ -static config_entry_t db_ce = { NULL, "db", CONFIG_TYPE_STRING, - CONFIG_OPT_MANDATORY, 0, - { } }; +static config_entry_t db_ce = { + .key = "db", + .type = CONFIG_TYPE_STRING, + .options = CONFIG_OPT_MANDATORY, +}; -static config_entry_t host_ce = { &db_ce, "host", CONFIG_TYPE_STRING, - CONFIG_OPT_MANDATORY, 0, - { } }; +static config_entry_t host_ce = { + .next = &db_ce, + .key = "host", + .type = CONFIG_TYPE_STRING, + .options = CONFIG_OPT_NONE, +}; -static config_entry_t user_ce = { &host_ce, "user", CONFIG_TYPE_STRING, - CONFIG_OPT_MANDATORY, 0, - { } }; +static config_entry_t user_ce = { + .next = &host_ce, + .key = "user", + .type = CONFIG_TYPE_STRING, + .options = CONFIG_OPT_MANDATORY, +}; -static config_entry_t pass_ce = { &user_ce, "pass", CONFIG_TYPE_STRING, - CONFIG_OPT_MANDATORY, 0, - { } }; +static config_entry_t pass_ce = { + .next = &user_ce, + .key = "pass", + .type = CONFIG_TYPE_STRING, + .options = CONFIG_OPT_NONE, +}; -static config_entry_t table_ce = { &pass_ce, "table", CONFIG_TYPE_STRING, - CONFIG_OPT_MANDATORY, 0, - { } }; +static config_entry_t table_ce = { + .next = &pass_ce, + .key = "table", + .type = CONFIG_TYPE_STRING, + .options = CONFIG_OPT_MANDATORY, +}; /* our main output function, called by ulogd */ static int pgsql_output(ulog_iret_t *result) @@ -71,7 +85,9 @@ static int pgsql_output(ulog_iret_t *result) struct _field *f; ulog_iret_t *res; PGresult *pgres; +#ifdef IP_AS_STRING char *tmpstr; /* need this for --log-ip-as-string */ +#endif stmt_ins = stmt_val; @@ -223,32 +239,32 @@ static int pgsql_get_columns(const char *table) { PGresult *result; char buf[ULOGD_MAX_KEYLEN]; - char pgbuf[256]; + char pgbuf[256]; char *underscore; struct _field *f; int id; - int intaux; - char *sql; + int intaux; if (!dbh) return 1; - strcpy(pgbuf, "SELECT a.attname FROM pg_class c, pg_attribute a WHERE c.relname ='"); - strncat(pgbuf, table, strlen(table)); - strcat(pgbuf, "' AND a.attnum>0 AND a.attrelid=c.oid ORDER BY a.attnum"); - sql = (char *) malloc(strlen(pgbuf)); - sql = pgbuf; - ulogd_log(ULOGD_DEBUG, sql); - result = PQexec(dbh, sql); - if(!result) { - ulogd_log(ULOGD_DEBUG, "\n result false"); + strcpy(pgbuf, "SELECT a.attname FROM pg_class c, pg_attribute a WHERE c.relname ='"); + strncat(pgbuf, table, strlen(table)); + strcat(pgbuf, "' AND a.attnum>0 AND a.attrelid=c.oid ORDER BY a.attnum"); + ulogd_log(ULOGD_DEBUG, pgbuf); + + result = PQexec(dbh, pgbuf); + if (!result) { + ulogd_log(ULOGD_DEBUG, "\n result false"); + return 1; + } + + if (PQresultStatus(result) != PGRES_TUPLES_OK) { + ulogd_log(ULOGD_DEBUG, "\n pres_command_not_ok"); return 1; - } - if (PQresultStatus(result) != PGRES_TUPLES_OK) { - ulogd_log(ULOGD_DEBUG, "\n pres_command_not_ok"); - return 1; - } - for (intaux=0; intaux