summaryrefslogtreecommitdiff
path: root/src/interfaces/libpq/fe-auth.c
diff options
context:
space:
mode:
authorRobert Haas2016-11-03 13:25:20 +0000
committerRobert Haas2016-11-03 13:25:20 +0000
commit274bb2b3857cc987cfa21d14775cae9b0dababa5 (patch)
tree488b5fd46e2cb4acdab7fb2dd30c4e4d1d4bb7d1 /src/interfaces/libpq/fe-auth.c
parent770671062f130a830aa89100c9aa2d26f8d4bf32 (diff)
libpq: Allow connection strings and URIs to specify multiple hosts.
It's also possible to specify a separate port for each host. Previously, we'd loop over every address returned by looking up the host name; now, we'll try every address for every host name. Patch by me. Victor Wagner wrote an earlier patch for this feature, which I read, but I didn't use any of his code. Review by Mithun Cy.
Diffstat (limited to 'src/interfaces/libpq/fe-auth.c')
-rw-r--r--src/interfaces/libpq/fe-auth.c28
1 files changed, 17 insertions, 11 deletions
diff --git a/src/interfaces/libpq/fe-auth.c b/src/interfaces/libpq/fe-auth.c
index 404bc93306d..19171fb676a 100644
--- a/src/interfaces/libpq/fe-auth.c
+++ b/src/interfaces/libpq/fe-auth.c
@@ -683,20 +683,26 @@ pg_fe_sendauth(AuthRequest areq, PGconn *conn)
case AUTH_REQ_MD5:
case AUTH_REQ_PASSWORD:
- conn->password_needed = true;
- if (conn->pgpass == NULL || conn->pgpass[0] == '\0')
{
- printfPQExpBuffer(&conn->errorMessage,
- PQnoPasswordSupplied);
- return STATUS_ERROR;
- }
- if (pg_password_sendauth(conn, conn->pgpass, areq) != STATUS_OK)
- {
- printfPQExpBuffer(&conn->errorMessage,
+ char *password = conn->connhost[conn->whichhost].password;
+
+ if (password == NULL)
+ password = conn->pgpass;
+ conn->password_needed = true;
+ if (password == NULL || password[0] == '\0')
+ {
+ printfPQExpBuffer(&conn->errorMessage,
+ PQnoPasswordSupplied);
+ return STATUS_ERROR;
+ }
+ if (pg_password_sendauth(conn, password, areq) != STATUS_OK)
+ {
+ printfPQExpBuffer(&conn->errorMessage,
"fe_sendauth: error sending password authentication\n");
- return STATUS_ERROR;
+ return STATUS_ERROR;
+ }
+ break;
}
- break;
case AUTH_REQ_SCM_CREDS:
if (pg_local_sendauth(conn) != STATUS_OK)