1
0
mirror of https://github.com/postgres/postgres.git synced 2025-06-27 23:21:58 +03:00

Allow the .pgpass hostname to match the default socket directory, as

well as a blank pghost.
This commit is contained in:
Bruce Momjian
2006-05-17 21:50:54 +00:00
parent 7123349254
commit 18627c5531
2 changed files with 20 additions and 5 deletions

View File

@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/interfaces/libpq/fe-connect.c,v 1.328 2006/03/14 22:48:23 tgl Exp $
* $PostgreSQL: pgsql/src/interfaces/libpq/fe-connect.c,v 1.329 2006/05/17 21:50:54 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@ -3106,9 +3106,24 @@ PasswordFromFile(char *hostname, char *port, char *dbname, char *username)
if (username == NULL || strlen(username) == 0)
return NULL;
/* 'localhost' matches pghost of '' or the default socket directory */
if (hostname == NULL)
hostname = DefaultHost;
else if (is_absolute_path(hostname))
{
char canon_host[MAXPGPATH];
char canon_def_socket[MAXPGPATH];
StrNCpy(canon_host, hostname, MAXPGPATH);
StrNCpy(canon_def_socket, DEFAULT_PGSOCKET_DIR, MAXPGPATH);
canonicalize_path(canon_host);
canonicalize_path(canon_def_socket);
if (strcmp(canon_host, canon_def_socket) == 0)
hostname = DefaultHost;
}
if (port == NULL)
port = DEF_PGPORT_STR;