I'm using the current CVS (as of ~1930 EDT, 29AUG02) on RedHat's latest
beta (null).  I find that I need to use the -U option when trying to use
psql and the new PGPASSWORDFILE variable.

Here's what I have in my ~/.pgpw file (pointed to by PGPASSWORDFILE):

localhost:*:az_audit:gar:test

This my Linux userid is 'gar', so it should work, and indeed the error
message in the server log is:

Aug 29 21:02:10 tb02 postgres[18440]: [1] LOG:  connection received: host=127.0.0.1 port=1084
Aug 29 21:02:10 tb02 postgres[18440]: [2] FATAL:  Password authentication failed for user "gar"

Which is odd, because psql clearly knows my userid is 'gar', and
transmits it to the backend correctly.

If I add the '-U gar', then all is well.


Stepping through psql with gdb, I see that in the case where I don't set
-U, the returned password (from is garbled:

(gdb) print conn->pgpass 
$11 = 0x806d228 "testï¿½\021B"

Whereas when I set '-U', the returned password is fine!

(gdb) print conn->pgpass
$15 = 0x806cf08 "test"


It appears that the problem is in PasswordFromFile() in fe_connect.c, but
I'm not sure, as gdb insists that 't' and 'ret' are not in the current
scope when I get to the end of the function.  :-(

But the behaviour is consisten.

Thanks,

Gordon.
-- 
"Far and away the best prize that life has to offer
  is the chance to work hard at work worth doing."
       -- Theodore Roosevelt

Thu, 29 Aug 2002 22:33:39 -0400
Gordon Runkle <gar@integrated-dynamics.com>
[7.3devl] Using PGPASSWORDFILE with psql requires -U option?
Gordon Runkle dijo: 

> I'm using the current CVS (as of ~1930 EDT, 29AUG02) on RedHat's latest
> beta (null).  I find that I need to use the -U option when trying to use
> psql and the new PGPASSWORDFILE variable.

Ok, in private email with Gordon I discovered that I missed by one.
Please apply the following.  Thanks for the report.

Index: src/interfaces/libpq/fe-connect.c
===================================================================
RCS file: /projects/cvsroot/pgsql-server/src/interfaces/libpq/fe-connect.c,v
retrieving revision 1.199
diff -c -r1.199 fe-connect.c
*** src/interfaces/libpq/fe-connect.c	2002/08/29 23:06:32	1.199
--- src/interfaces/libpq/fe-connect.c	2002/08/30 03:52:40
***************
*** 2953,2960 ****
  				(t = pwdfMatchesString(t, dbname)) == NULL ||
  				(t = pwdfMatchesString(t, username)) == NULL)
  			continue;
! 		ret=(char *)malloc(sizeof(char)*strlen(t));
! 		strncpy(ret, t, strlen(t));
  		fclose(fp);
  		return ret;
  	}
--- 2953,2960 ----
  				(t = pwdfMatchesString(t, dbname)) == NULL ||
  				(t = pwdfMatchesString(t, username)) == NULL)
  			continue;
! 		ret=(char *)malloc(sizeof(char)*(strlen(t)+1));
! 		strncpy(ret, t, strlen(t)+1);
  		fclose(fp);
  		return ret;
  	}

-- 
Alvaro Herrera (<alvherre[a]atentus.com>)
"La felicidad no es maï¿½ana. La felicidad es ahora"


Thu, 29 Aug 2002 23:53:02 -0400 (CLT)
Alvaro Herrera <alvherre@atentus.com>
Re: [7.3devl] Using PGPASSWORDFILE with psql requires -U
Alvaro Herrera <alvherre@atentus.com> writes:
> ! 		ret=(char *)malloc(sizeof(char)*strlen(t));
> ! 		strncpy(ret, t, strlen(t));
>
> ! 		ret=(char *)malloc(sizeof(char)*(strlen(t)+1));
> ! 		strncpy(ret, t, strlen(t)+1);

What have you got against strdup() ?

			regards, tom lane

Fri, 30 Aug 2002 00:07:28 -0400
Tom Lane <tgl@sss.pgh.pa.us>
Re: [7.3devl] Using PGPASSWORDFILE with psql requires -U 

Tom has applied a patch to fix this.

---------------------------------------------------------------------------

Alvaro Herrera wrote:
> Gordon Runkle dijo: 
> 
> > I'm using the current CVS (as of ~1930 EDT, 29AUG02) on RedHat's latest
> > beta (null).  I find that I need to use the -U option when trying to use
> > psql and the new PGPASSWORDFILE variable.
> 
> Ok, in private email with Gordon I discovered that I missed by one.
> Please apply the following.  Thanks for the report.
> 
> Index: src/interfaces/libpq/fe-connect.c
> ===================================================================
> RCS file: /projects/cvsroot/pgsql-server/src/interfaces/libpq/fe-connect.c,v
> retrieving revision 1.199
> diff -c -r1.199 fe-connect.c
> *** src/interfaces/libpq/fe-connect.c	2002/08/29 23:06:32	1.199
> --- src/interfaces/libpq/fe-connect.c	2002/08/30 03:52:40
> ***************
> *** 2953,2960 ****
>   				(t = pwdfMatchesString(t, dbname)) == NULL ||
>   				(t = pwdfMatchesString(t, username)) == NULL)
>   			continue;
> ! 		ret=(char *)malloc(sizeof(char)*strlen(t));
> ! 		strncpy(ret, t, strlen(t));
>   		fclose(fp);
>   		return ret;
>   	}
> --- 2953,2960 ----
>   				(t = pwdfMatchesString(t, dbname)) == NULL ||
>   				(t = pwdfMatchesString(t, username)) == NULL)
>   			continue;
> ! 		ret=(char *)malloc(sizeof(char)*(strlen(t)+1));
> ! 		strncpy(ret, t, strlen(t)+1);
>   		fclose(fp);
>   		return ret;
>   	}
> 
> -- 
> Alvaro Herrera (<alvherre[a]atentus.com>)
> "La felicidad no es ma?ana. La felicidad es ahora"
> 
> 
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Don't 'kill -9' the postmaster
> 

-- 
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 359-1001
  +  If your life is a hard drive,     |  13 Roberts Road
  +  Christ can be your backup.        |  Newtown Square, Pennsylvania 19073

Fri, 30 Aug 2002 11:12:34 -0400 (EDT)
Bruce Momjian <pgman@candle.pha.pa.us>
Re: [7.3devl] Using PGPASSWORDFILE with psql requires -U