[7.3devl] Using PGPASSWORDFILE with psql requires -U option?

Started by Gordon Runkleover 23 years ago7 messages
#1Gordon Runkle
gar@integrated-dynamics.com

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

#2Alvaro Herrera
alvherre@atentus.com
In reply to: Gordon Runkle (#1)
Re: [7.3devl] Using PGPASSWORDFILE with psql requires -U

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"

#3Tom Lane
tgl@sss.pgh.pa.us
In reply to: Alvaro Herrera (#2)
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

#4Dann Corbit
DCorbit@connx.com
In reply to: Tom Lane (#3)
Re: [7.3devl] Using PGPASSWORDFILE with psql requires -U

-----Original Message-----
From: Tom Lane [mailto:tgl@sss.pgh.pa.us]
Sent: Thursday, August 29, 2002 9:07 PM
To: Alvaro Herrera
Cc: Gordon Runkle; pgsql-hackers@postgresql.org
Subject: Re: [HACKERS] [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() ?

The strdup() function is non-standard, and need not exist in a C
implementation.

#5Alvaro Herrera
alvherre@atentus.com
In reply to: Dann Corbit (#4)
Re: [7.3devl] Using PGPASSWORDFILE with psql requires -U

Dann Corbit dijo:

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() ?

The strdup() function is non-standard, and need not exist in a C
implementation.

Actually I have nothing against strdup(), and I think I have seen it in
Pg source. I just didn't think about it ;-)

Feel free to change it if you want...

--
Alvaro Herrera (<alvherre[a]atentus.com>)
One man's impedance mismatch is another man's layer of abstraction.
(Lincoln Yeoh)

#6Tom Lane
tgl@sss.pgh.pa.us
In reply to: Dann Corbit (#4)
Re: [7.3devl] Using PGPASSWORDFILE with psql requires -U

"Dann Corbit" <DCorbit@connx.com> writes:

What have you got against strdup() ?

The strdup() function is non-standard, and need not exist in a C
implementation.

But it *does* exist in all Postgres implementations. This is what
we carry around a port/ directory for ...

regards, tom lane

#7Bruce Momjian
pgman@candle.pha.pa.us
In reply to: Alvaro Herrera (#2)
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