Re: Warning about invalid .pgpass passwords

Bruce Momjian <bruce@momjian.us>

From: Bruce Momjian <bruce@momjian.us>
To: Alvaro Herrera <alvherre@commandprompt.com>
Cc: Tom Lane <tgl@sss.pgh.pa.us>, Eamonn Martin <mas01em@gold.ac.uk>, PostgreSQL-development <pgsql-hackers@postgresql.org>
Date: 2010-03-11T21:35:40Z
Lists: pgsql-hackers
Alvaro Herrera wrote:
> Bruce Momjian wrote:
> 
> > + static void
> > + dot_pg_pass_warning(PGconn *conn)
> > + {
> > + 	/* If it was 'invalid authorization', add .pgpass mention */
> > + 	if (conn->dot_pgpass_used && conn->password_needed && conn->result &&
> > + 		/* only works with >= 9.0 servers */
> > + 		atoi(PQresultErrorField(conn->result, PG_DIAG_SQLSTATE)) ==
> > + 			SQLSTATE_TO_BASE10(ERRCODE_INVALID_PASSWORD_SPECIFICATION))
> > + 		appendPQExpBufferStr(&conn->errorMessage,
> > + 			libpq_gettext("password retrieved from .pgpass\n"));
> > + }
> 
> This bit seems strange ...  I think we just do strcmp() to compare sqlstates?

Uh, the PQresultErrorField is a string, while
ERRCODE_INVALID_PASSWORD_SPECIFICATI is a 4-byte value in base-64.  
Yea, it's true.  For excitement, see the MAKE_SQLSTATE macro.

-- 
  Bruce Momjian  <bruce@momjian.us>        http://momjian.us
  EnterpriseDB                             http://enterprisedb.com

  PG East:  http://www.enterprisedb.com/community/nav-pg-east-2010.do