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

Поиск
Список
Период
Сортировка
Искать

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

От:
Gordon 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

Re: [7.3devl] Using PGPASSWORDFILE with psql requires -U

От:
Alvaro Herrera <alvherre@atentus.com>
Дата:
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 ()
"La felicidad no es mañana. La felicidad es ahora"


Re: [7.3devl] Using PGPASSWORDFILE with psql requires -U

От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
Alvaro Herrera  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

Re: [7.3devl] Using PGPASSWORDFILE with psql requires -U

От:
Bruce Momjian <pgman@candle.pha.pa.us>
Дата:

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

FAQ