Actually, using an environment variable had flaky behavior. Instead,
I edited the source around line 287 in ossec-hids-2.5.1/src/os_dbd/
db_op.c (see below), and recompiled OSSEC. The issue is that
PQsetdbLogin function expects the port parameter to be a string. I
converted the port number from in to string and pass it to the
PQsetdbLogin function.
It looks like the postgresql_osdb_connect function in db_op.c was set
up to receive the port number as an int, but abandoned in favor of
NULL since it probably wasn't functioning as expected. I'll try to
report this as a bug/suggestion. A better idea would be to clean up
this function so it has a char *port parameter instead of int.
void *postgresql_osdb_connect(char *host, char *user, char *pass, char
*db,
int port, char *sock)
{
PGconn *conn;
//conn = PQsetdbLogin(host, NULL, NULL, NULL, db, user, pass);
// Convert port to string
char portstr[5];
sprintf(portstr, "%d", port);
conn = PQsetdbLogin(host, portstr, NULL, NULL, db, user, pass);
...
}
Docs on PQsetdbLogin function:
http://www.postgresql.org/docs/8.3/static/libpq-connect.html