From 4f9bf7fc5a1fcc3b1beac9b2e1d2e693ae7bd796 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Sun, 9 Dec 2007 19:01:40 +0000 Subject: [PATCH] Fix up the PQconnectionUsedPassword mess: create a separate PQconnectionNeedsPassword function that tells the right thing for whether to prompt for a password, and improve PQconnectionUsedPassword so that it checks whether the password used by the connection was actually supplied as a connection argument, instead of coming from environment or a password file. Per bug report from Mark Cave-Ayland and subsequent discussion. --- doc/src/sgml/libpq.sgml | 32 +++++++++++++++++---- doc/src/sgml/release.sgml | 20 +++++++++++-- src/bin/pg_ctl/pg_ctl.c | 4 +-- src/bin/pg_dump/pg_backup_db.c | 6 ++-- src/bin/pg_dump/pg_dumpall.c | 4 +-- src/bin/psql/command.c | 4 +-- src/bin/psql/startup.c | 4 +-- src/bin/scripts/common.c | 4 +-- src/interfaces/libpq/exports.txt | 3 +- src/interfaces/libpq/fe-auth.c | 5 ++-- src/interfaces/libpq/fe-connect.c | 47 ++++++++++++++++++++++--------- src/interfaces/libpq/libpq-fe.h | 5 ++-- src/interfaces/libpq/libpq-int.h | 5 ++-- 13 files changed, 102 insertions(+), 41 deletions(-) diff --git a/doc/src/sgml/libpq.sgml b/doc/src/sgml/libpq.sgml index 3acbe2c3d3..fec498c19a 100644 --- a/doc/src/sgml/libpq.sgml +++ b/doc/src/sgml/libpq.sgml @@ -1,4 +1,4 @@ - + <application>libpq</application> - C Library @@ -1145,12 +1145,33 @@ typedef struct + + PQconnectionNeedsPasswordPQconnectionNeedsPassword + + + Returns true (1) if the connection authentication method + required a password, but none was available. + Returns false (0) if not. + + + int PQconnectionNeedsPassword(const PGconn *conn); + + + + + + This function can be applied after a failed connection attempt + to decide whether to prompt the user for a password. + + + + PQconnectionUsedPasswordPQconnectionUsedPassword Returns true (1) if the connection authentication method - required a password to be supplied. Returns false (0) if not. + used a caller-supplied password. Returns false (0) if not. int PQconnectionUsedPassword(const PGconn *conn); @@ -1159,9 +1180,10 @@ typedef struct - This function can be applied after either successful or failed - connection attempts. In the case of failure, it can for example - be used to decide whether to prompt the user for a password. + This function detects whether a password supplied to the connection + function was actually used. Passwords obtained from other + sources (such as the .pgpass file) are not considered + caller-supplied. diff --git a/doc/src/sgml/release.sgml b/doc/src/sgml/release.sgml index ef4373fe6d..4bb10cbf61 100644 --- a/doc/src/sgml/release.sgml +++ b/doc/src/sgml/release.sgml @@ -1,4 +1,4 @@ - +