Skip to content

Commit bdac983

Browse files
committed
libpq: Fix inadvertent change in .pgpass lookup behavior.
Commit 274bb2b 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
1 parent fed6df4 commit bdac983

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/interfaces/libpq/fe-connect.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -978,9 +978,18 @@ connectOptions2(PGconn *conn)
978978

979979
for (i = 0; i < conn->nconnhost; i++)
980980
{
981-
/* Try to get a password for this host from pgpassfile */
981+
/*
982+
* Try to get a password for this host from pgpassfile. We use host
983+
* name rather than host address in the same manner to PQhost().
984+
*/
985+
char *pwhost = conn->connhost[i].host;
986+
987+
if (conn->connhost[i].type == CHT_HOST_ADDRESS &&
988+
conn->pghost != NULL && conn->pghost[0] != '\0')
989+
pwhost = conn->pghost;
990+
982991
conn->connhost[i].password =
983-
passwordFromFile(conn->connhost[i].host,
992+
passwordFromFile(pwhost,
984993
conn->connhost[i].port,
985994
conn->dbName,
986995
conn->pguser,

0 commit comments

Comments
 (0)