pgsql: Avoid misleading psql password prompt when username ismultiply

Поиск
Список
Период
Сортировка
От Tom Lane
Тема pgsql: Avoid misleading psql password prompt when username ismultiply
Дата
Msg-id E1egDgC-000302-FN@gemulon.postgresql.org
обсуждение исходный текст
Список pgsql-committers
Avoid misleading psql password prompt when username is multiply specified.

When a password is needed, cases such as
        psql -d "postgresql://alice@localhost/testdb" -U bob
would incorrectly prompt for "Password for user bob: ", when actually the
connection will be attempted with username alice.  The priority order of
which name to use isn't that important here, but the misleading prompt is.

When we are prompting for a password after initial connection failure,
we can fix this reliably by looking at PQuser(conn) to see how libpq
interpreted the connection arguments.  But when we're doing a forced
password prompt because of a -W switch, we can't use that solution.
Fortunately, because the main use of -W is for noninteractive situations,
it's less critical to produce a helpful prompt in such cases.  I made
the startup prompt for -W just say "Password: " all the time, rather
than expending extra code on trying to identify which username to use.
In the case of a \c command (after -W has been given), there's already
logic in do_connect that determines whether the "dbname" is a connstring
or URI, so we can avoid lobotomizing the prompt except in cases that
are actually dubious.  (We could do similarly in startup.c if anyone
complains, but for now it seems not worthwhile, especially since that
would still be only a partial solution.)

Per bug #15025 from Akos Vandra.  Although this is arguably a bug fix,
it doesn't seem worth back-patching.  The case where it matters seems
like a very corner-case usage, and someone might complain that we'd
changed the behavior of -W in a minor release.

Discussion: https://postgr.es/m/20180123130013.7407.24749@wrigleys.postgresql.org

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/15be27460191a9ffb149cc98f6fbf97c369a6b1e

Modified Files
--------------
src/bin/psql/command.c | 17 ++++++++++++++---
src/bin/psql/startup.c | 31 +++++++++++++++++++++----------
2 files changed, 35 insertions(+), 13 deletions(-)


В списке pgsql-committers по дате отправления:

Предыдущее
От: Amit Langote
Дата:
Сообщение: Re: pgsql: Local partitioned indexes
Следующее
От: Peter Eisentraut
Дата:
Сообщение: pgsql: psql documentation fixes