aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Haas <rhaas@postgresql.org>2017-05-01 11:27:09 -0400
committerRobert Haas <rhaas@postgresql.org>2017-05-01 11:29:00 -0400
commitbdac9836d3b910c5fd592aaeaac3c2e2e1defcad (patch)
tree9ce40fa043da49e2223d60a71c207179763f692b
parentfed6df486dca1b9e53d3f560031b9a236c99f4bb (diff)
downloadpostgresql-bdac9836d3b910c5fd592aaeaac3c2e2e1defcad.tar.gz
postgresql-bdac9836d3b910c5fd592aaeaac3c2e2e1defcad.zip
libpq: Fix inadvertent change in .pgpass lookup behavior.
Commit 274bb2b3857cc987cfa21d14775cae9b0dababa5 caused password file lookups to use the hostaddr in preference to the host, but that was not intended and the documented behavior is the opposite. Report and patch by Kyotaro Horiguchi. Discussion: http://postgr.es/m/20170428.165432.60857995.horiguchi.kyotaro@lab.ntt.co.jp
-rw-r--r--src/interfaces/libpq/fe-connect.c13
1 files changed, 11 insertions, 2 deletions
diff --git a/src/interfaces/libpq/fe-connect.c b/src/interfaces/libpq/fe-connect.c
index 74e26edad66..eb5aaf70985 100644
--- a/src/interfaces/libpq/fe-connect.c
+++ b/src/interfaces/libpq/fe-connect.c
@@ -978,9 +978,18 @@ connectOptions2(PGconn *conn)
for (i = 0; i < conn->nconnhost; i++)
{
- /* Try to get a password for this host from pgpassfile */
+ /*
+ * Try to get a password for this host from pgpassfile. We use host
+ * name rather than host address in the same manner to PQhost().
+ */
+ char *pwhost = conn->connhost[i].host;
+
+ if (conn->connhost[i].type == CHT_HOST_ADDRESS &&
+ conn->pghost != NULL && conn->pghost[0] != '\0')
+ pwhost = conn->pghost;
+
conn->connhost[i].password =
- passwordFromFile(conn->connhost[i].host,
+ passwordFromFile(pwhost,
conn->connhost[i].port,
conn->dbName,
conn->pguser,