diff options
Diffstat (limited to 'src/bin/psql')
| -rw-r--r-- | src/bin/psql/command.c | 12 | ||||
| -rw-r--r-- | src/bin/psql/startup.c | 15 |
2 files changed, 13 insertions, 14 deletions
diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c index 8f103f1c21..936c56b203 100644 --- a/src/bin/psql/command.c +++ b/src/bin/psql/command.c @@ -3,7 +3,7 @@ * * Copyright (c) 2000-2007, PostgreSQL Global Development Group * - * $PostgreSQL: pgsql/src/bin/psql/command.c,v 1.179 2007/03/03 17:19:11 momjian Exp $ + * $PostgreSQL: pgsql/src/bin/psql/command.c,v 1.180 2007/07/08 19:07:38 tgl Exp $ */ #include "postgres_fe.h" #include "command.h" @@ -1110,11 +1110,11 @@ do_connect(char *dbname, char *user, char *host, char *port) * If the user asked to be prompted for a password, ask for one now. If * not, use the password from the old connection, provided the username * has not changed. Otherwise, try to connect without a password first, - * and then ask for a password if we got the appropriate error message. + * and then ask for a password if needed. * - * XXX: this behavior is broken. It leads to spurious connection attempts - * in the postmaster's log, and doing a string comparison against the - * returned error message is pretty fragile. + * XXX: this behavior leads to spurious connection attempts recorded + * in the postmaster's log. But libpq offers no API that would let us + * obtain a password and then continue with the first connection attempt. */ if (pset.getPassword) { @@ -1141,7 +1141,7 @@ do_connect(char *dbname, char *user, char *host, char *port) * Connection attempt failed; either retry the connection attempt with * a new password, or give up. */ - if (strcmp(PQerrorMessage(n_conn), PQnoPasswordSupplied) == 0) + if (!password && PQconnectionUsedPassword(n_conn)) { PQfinish(n_conn); password = prompt_for_password(user); diff --git a/src/bin/psql/startup.c b/src/bin/psql/startup.c index f8b9744273..65c2e1d906 100644 --- a/src/bin/psql/startup.c +++ b/src/bin/psql/startup.c @@ -3,7 +3,7 @@ * * Copyright (c) 2000-2007, PostgreSQL Global Development Group * - * $PostgreSQL: pgsql/src/bin/psql/startup.c,v 1.140 2007/02/01 19:10:29 momjian Exp $ + * $PostgreSQL: pgsql/src/bin/psql/startup.c,v 1.141 2007/07/08 19:07:38 tgl Exp $ */ #include "postgres_fe.h" @@ -108,7 +108,7 @@ main(int argc, char *argv[]) char *username = NULL; char *password = NULL; char *password_prompt = NULL; - bool need_pass; + bool new_pass; set_pglocale_pgservice(argv[0], "psql"); @@ -204,23 +204,22 @@ main(int argc, char *argv[]) /* loop until we have a password if requested by backend */ do { - need_pass = false; + new_pass = false; pset.db = PQsetdbLogin(options.host, options.port, NULL, NULL, options.action == ACT_LIST_DB && options.dbname == NULL ? "postgres" : options.dbname, username, password); if (PQstatus(pset.db) == CONNECTION_BAD && - strcmp(PQerrorMessage(pset.db), PQnoPasswordSupplied) == 0 && + PQconnectionUsedPassword(pset.db) && + password == NULL && !feof(stdin)) { PQfinish(pset.db); - need_pass = true; - free(password); - password = NULL; password = simple_prompt(password_prompt, 100, false); + new_pass = true; } - } while (need_pass); + } while (new_pass); free(username); free(password); |
