From: | Robert Haas <robertmhaas(at)gmail(dot)com> |
---|---|
To: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
Cc: | PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org> |
Subject: | Re: Bizarre behavior in libpq's searching of ~/.pgpass |
Date: | 2018-07-31 11:41:58 |
Message-ID: | CA+TgmoYwNjrapiDo6BEpMCEVc0GxNSUKd8hObsUZJLEsVnpUqA@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
On Fri, Jul 27, 2018 at 11:38 PM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> I noticed that there's some strange coding in libpq's choice of
> what hostname to use for searching ~/.pgpass for a password.
> Historically (pre-v10), it just used the pghost parameter:
>
> conn->pgpass = PasswordFromFile(conn->pghost, conn->pgport,
> conn->dbName, conn->pguser);
>
> no ifs, ands, or buts, except for the fact that PasswordFromFile
> replaces its hostname parameter with "localhost" if it's null or
> matches the default socket directory. This is per the documentation
> (see sections 34.1.2 and 34.15).
>
> Since v10 we've got this:
>
> char *pwhost = conn->connhost[i].host;
>
> if (conn->connhost[i].type == CHT_HOST_ADDRESS &&
> conn->connhost[i].host != NULL &&
> conn->connhost[i].host[0] != '\0')
> pwhost = conn->connhost[i].hostaddr;
>
> conn->connhost[i].password =
> passwordFromFile(pwhost,
> conn->connhost[i].port,
> conn->dbName,
> conn->pguser,
> conn->pgpassfile);
>
> Now that's just bizarre on its face: take hostaddr if it's specified,
> but only if host is also specified? And it certainly doesn't match
> the documentation.
Yeah, that's bad code. The intent was that if you set host=a,b you
probably want to use either 'a' or 'b' as the thing to look up in
.pgpass, not 'a,b', but the implementation leaves something to be
desired.
--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company
From | Date | Subject | |
---|---|---|---|
Next Message | Andrew Dunstan | 2018-07-31 12:23:55 | Re: Allow auto_explain to log to NOTICE |
Previous Message | Alexander Lakhin | 2018-07-31 11:40:05 | Re: make installcheck-world in a clean environment |