summaryrefslogtreecommitdiff
path: root/res
diff options
context:
space:
mode:
authorTilghman Lesher <tilghman@meg.abyt.es>2008-02-22 22:39:21 +0000
committerTilghman Lesher <tilghman@meg.abyt.es>2008-02-22 22:39:21 +0000
commit9392dae2d6b9d4a16567df3694fdf47c548c4860 (patch)
treed72aaf2ae4faa244ffe4260cb861b73b642427c8 /res
parent0bcd2ae4b0655514c76f0ed9ac49303986380791 (diff)
Allow database password to be NULL and several other cleanups.
(closes issue #12048) Reported by: bukaj Patches: 20080222__bug12048.diff.txt uploaded by Corydon76 (license 14) Tested by: bukaj git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@104036 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'res')
-rw-r--r--res/res_config_pgsql.c35
1 files changed, 16 insertions, 19 deletions
diff --git a/res/res_config_pgsql.c b/res/res_config_pgsql.c
index 81da43456..df744592b 100644
--- a/res/res_config_pgsql.c
+++ b/res/res_config_pgsql.c
@@ -912,23 +912,21 @@ static int pgsql_reconnect(const char *database)
pgsqlConn = NULL;
}
- if ((!pgsqlConn) && (!ast_strlen_zero(dbhost) || !ast_strlen_zero(dbsock)) && !ast_strlen_zero(dbuser) && !ast_strlen_zero(dbpass) && !ast_strlen_zero(my_database)) {
- char *connInfo = NULL;
- unsigned int size = 100 + strlen(dbhost)
- + strlen(dbuser)
- + strlen(dbpass)
- + strlen(my_database);
-
- if (!(connInfo = ast_malloc(size)))
- return 0;
-
- sprintf(connInfo, "host=%s port=%d dbname=%s user=%s password=%s",
- dbhost, dbport, my_database, dbuser, dbpass);
- ast_debug(1, "%u connInfo=%s\n", size, connInfo);
- pgsqlConn = PQconnectdb(connInfo);
- ast_debug(1, "%u connInfo=%s\n", size, connInfo);
+ /* DB password can legitimately be 0-length */
+ if ((!pgsqlConn) && (!ast_strlen_zero(dbhost) || !ast_strlen_zero(dbsock)) && !ast_strlen_zero(dbuser) && dbpass && !ast_strlen_zero(my_database)) {
+ struct ast_str *connInfo = ast_str_create(32);
+
+ ast_str_set(&connInfo, 0, "host=%s port=%d dbname=%s user=%s",
+ dbhost, dbport, my_database, dbuser);
+ if (!ast_strlen_zero(dbpass))
+ ast_str_append(&connInfo, 0, " password=%s", dbpass);
+
+ ast_debug(1, "%u connInfo=%s\n", connInfo->len, connInfo->str);
+ pgsqlConn = PQconnectdb(connInfo->str);
+ ast_debug(1, "%u connInfo=%s\n", connInfo->len, connInfo->str);
ast_free(connInfo);
connInfo = NULL;
+
ast_debug(1, "pgsqlConn=%p\n", pgsqlConn);
if (pgsqlConn && PQstatus(pgsqlConn) == CONNECTION_OK) {
ast_debug(1, "PostgreSQL RealTime: Successfully connected to database.\n");
@@ -936,13 +934,12 @@ static int pgsql_reconnect(const char *database)
return 1;
} else {
ast_log(LOG_ERROR,
- "PostgreSQL RealTime: Failed to connect database server %s on %s. Check debug for more info.\n",
- dbname, dbhost);
- ast_debug(1, "PostgreSQL RealTime: Cannot Connect: %s\n", PQresultErrorMessage(NULL));
+ "PostgreSQL RealTime: Failed to connect database %s on %s: %s\n",
+ dbname, dbhost, PQresultErrorMessage(NULL));
return 0;
}
} else {
- ast_debug(1, "PostgreSQL RealTime: Everything is fine.\n");
+ ast_debug(1, "PostgreSQL RealTime: One or more of the parameters in the config does not pass our validity checks.\n");
return 1;
}
}