Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit c52aab5

Browse files
committed
Get rid of pgpass_from_client tracking inside libpq --- given the conclusion
that presence of the password in the conninfo string must be checked *before* risking a connection attempt, there is no point in checking it afterwards. This makes the specification of PQconnectionUsedPassword() a bit simpler and perhaps more generally useful, too.
1 parent cae7ad9 commit c52aab5

File tree

3 files changed

+12
-35
lines changed

3 files changed

+12
-35
lines changed

doc/src/sgml/libpq.sgml

+4-8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- $PostgreSQL: pgsql/doc/src/sgml/libpq.sgml,v 1.264 2008/09/22 13:55:13 tgl Exp $ -->
1+
<!-- $PostgreSQL: pgsql/doc/src/sgml/libpq.sgml,v 1.265 2008/09/22 14:21:44 tgl Exp $ -->
22

33
<chapter id="libpq">
44
<title><application>libpq</application> - C Library</title>
@@ -1201,7 +1201,6 @@ PQconninfoOption *PQconninfoParse(const char *conninfo, char **errmsg);
12011201
<synopsis>
12021202
int PQconnectionNeedsPassword(const PGconn *conn);
12031203
</synopsis>
1204-
12051204
</para>
12061205

12071206
<para>
@@ -1216,19 +1215,16 @@ PQconninfoOption *PQconninfoParse(const char *conninfo, char **errmsg);
12161215
<listitem>
12171216
<para>
12181217
Returns true (1) if the connection authentication method
1219-
used a caller-supplied password. Returns false (0) if not.
1218+
used a password. Returns false (0) if not.
12201219

12211220
<synopsis>
12221221
int PQconnectionUsedPassword(const PGconn *conn);
12231222
</synopsis>
1224-
12251223
</para>
12261224

12271225
<para>
1228-
This function detects whether a password supplied to the connection
1229-
function was actually used. Passwords obtained from other
1230-
sources (such as the <filename>.pgpass</> file) are not considered
1231-
caller-supplied.
1226+
This function can be applied after either a failed or successful
1227+
connection attempt to detect whether the server demanded a password.
12321228
</para>
12331229
</listitem>
12341230
</varlistentry>

src/interfaces/libpq/fe-connect.c

+7-25
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/interfaces/libpq/fe-connect.c,v 1.361 2008/09/22 13:55:14 tgl Exp $
11+
* $PostgreSQL: pgsql/src/interfaces/libpq/fe-connect.c,v 1.362 2008/09/22 14:21:44 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -232,8 +232,7 @@ static PGconn *makeEmptyPGconn(void);
232232
static void freePGconn(PGconn *conn);
233233
static void closePGconn(PGconn *conn);
234234
static PQconninfoOption *conninfo_parse(const char *conninfo,
235-
PQExpBuffer errorMessage, bool use_defaults,
236-
bool *password_from_string);
235+
PQExpBuffer errorMessage, bool use_defaults);
237236
static char *conninfo_getval(PQconninfoOption *connOptions,
238237
const char *keyword);
239238
static void defaultNoticeReceiver(void *arg, const PGresult *res);
@@ -377,8 +376,7 @@ connectOptions1(PGconn *conn, const char *conninfo)
377376
/*
378377
* Parse the conninfo string
379378
*/
380-
connOptions = conninfo_parse(conninfo, &conn->errorMessage, true,
381-
&conn->pgpass_from_client);
379+
connOptions = conninfo_parse(conninfo, &conn->errorMessage, true);
382380
if (connOptions == NULL)
383381
{
384382
conn->status = CONNECTION_BAD;
@@ -474,7 +472,6 @@ connectOptions2(PGconn *conn)
474472
conn->dbName, conn->pguser);
475473
if (conn->pgpass == NULL)
476474
conn->pgpass = strdup(DefaultPassword);
477-
conn->pgpass_from_client = false;
478475
}
479476

480477
/*
@@ -560,14 +557,12 @@ PQconninfoOption *
560557
PQconndefaults(void)
561558
{
562559
PQExpBufferData errorBuf;
563-
bool password_from_string;
564560
PQconninfoOption *connOptions;
565561

566562
initPQExpBuffer(&errorBuf);
567563
if (errorBuf.data == NULL)
568564
return NULL; /* out of memory already :-( */
569-
connOptions = conninfo_parse("", &errorBuf, true,
570-
&password_from_string);
565+
connOptions = conninfo_parse("", &errorBuf, true);
571566
termPQExpBuffer(&errorBuf);
572567
return connOptions;
573568
}
@@ -668,7 +663,6 @@ PQsetdbLogin(const char *pghost, const char *pgport, const char *pgoptions,
668663
if (conn->pgpass)
669664
free(conn->pgpass);
670665
conn->pgpass = strdup(pwd);
671-
conn->pgpass_from_client = true;
672666
}
673667

674668
/*
@@ -3127,16 +3121,14 @@ PQconninfoOption *
31273121
PQconninfoParse(const char *conninfo, char **errmsg)
31283122
{
31293123
PQExpBufferData errorBuf;
3130-
bool password_from_string;
31313124
PQconninfoOption *connOptions;
31323125

31333126
if (errmsg)
31343127
*errmsg = NULL; /* default */
31353128
initPQExpBuffer(&errorBuf);
31363129
if (errorBuf.data == NULL)
31373130
return NULL; /* out of memory already :-( */
3138-
connOptions = conninfo_parse(conninfo, &errorBuf, false,
3139-
&password_from_string);
3131+
connOptions = conninfo_parse(conninfo, &errorBuf, false);
31403132
if (connOptions == NULL && errmsg)
31413133
*errmsg = errorBuf.data;
31423134
else
@@ -3152,12 +3144,10 @@ PQconninfoParse(const char *conninfo, char **errmsg)
31523144
* left in errorMessage.
31533145
* Defaults are supplied (from a service file, environment variables, etc)
31543146
* for unspecified options, but only if use_defaults is TRUE.
3155-
* *password_from_string is set TRUE if we got a password from the
3156-
* conninfo string, otherwise FALSE.
31573147
*/
31583148
static PQconninfoOption *
31593149
conninfo_parse(const char *conninfo, PQExpBuffer errorMessage,
3160-
bool use_defaults, bool *password_from_string)
3150+
bool use_defaults)
31613151
{
31623152
char *pname;
31633153
char *pval;
@@ -3168,8 +3158,6 @@ conninfo_parse(const char *conninfo, PQExpBuffer errorMessage,
31683158
PQconninfoOption *options;
31693159
PQconninfoOption *option;
31703160

3171-
*password_from_string = false; /* default result */
3172-
31733161
/* Make a working copy of PQconninfoOptions */
31743162
options = malloc(sizeof(PQconninfoOptions));
31753163
if (options == NULL)
@@ -3326,12 +3314,6 @@ conninfo_parse(const char *conninfo, PQExpBuffer errorMessage,
33263314
free(buf);
33273315
return NULL;
33283316
}
3329-
3330-
/*
3331-
* Special handling for password
3332-
*/
3333-
if (strcmp(option->keyword, "password") == 0)
3334-
*password_from_string = (option->val[0] != '\0');
33353317
}
33363318

33373319
/* Done with the modifiable input string */
@@ -3597,7 +3579,7 @@ PQconnectionUsedPassword(const PGconn *conn)
35973579
{
35983580
if (!conn)
35993581
return false;
3600-
if (conn->password_needed && conn->pgpass_from_client)
3582+
if (conn->password_needed)
36013583
return true;
36023584
else
36033585
return false;

src/interfaces/libpq/libpq-int.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
1313
* Portions Copyright (c) 1994, Regents of the University of California
1414
*
15-
* $PostgreSQL: pgsql/src/interfaces/libpq/libpq-int.h,v 1.133 2008/09/19 16:40:40 tgl Exp $
15+
* $PostgreSQL: pgsql/src/interfaces/libpq/libpq-int.h,v 1.134 2008/09/22 14:21:44 tgl Exp $
1616
*
1717
*-------------------------------------------------------------------------
1818
*/
@@ -290,7 +290,6 @@ struct pg_conn
290290
char *dbName; /* database name */
291291
char *pguser; /* Postgres username and password, if any */
292292
char *pgpass;
293-
bool pgpass_from_client; /* did password come from connect args? */
294293
char *sslmode; /* SSL mode (require,prefer,allow,disable) */
295294
#if defined(KRB5) || defined(ENABLE_GSS) || defined(ENABLE_SSPI)
296295
char *krbsrvname; /* Kerberos service name */

0 commit comments

Comments
 (0)