diff options
author | Bruce Momjian <bruce@momjian.us> | 2006-05-17 21:50:54 +0000 |
---|---|---|
committer | Bruce Momjian <bruce@momjian.us> | 2006-05-17 21:50:54 +0000 |
commit | 18627c553191219319075713848740bb6794e85a (patch) | |
tree | 5cf42aaa8cd96accd91f46571a00fe2fe7a623b1 | |
parent | 71233492540a01fbfaff84dd41c4a532cfacbc9b (diff) | |
download | postgresql-18627c553191219319075713848740bb6794e85a.tar.gz postgresql-18627c553191219319075713848740bb6794e85a.zip |
Allow the .pgpass hostname to match the default socket directory, as
well as a blank pghost.
-rw-r--r-- | doc/src/sgml/libpq.sgml | 8 | ||||
-rw-r--r-- | src/interfaces/libpq/fe-connect.c | 17 |
2 files changed, 20 insertions, 5 deletions
diff --git a/doc/src/sgml/libpq.sgml b/doc/src/sgml/libpq.sgml index b856262d1e1..aef1129844c 100644 --- a/doc/src/sgml/libpq.sgml +++ b/doc/src/sgml/libpq.sgml @@ -1,4 +1,4 @@ -<!-- $PostgreSQL: pgsql/doc/src/sgml/libpq.sgml,v 1.208 2006/05/06 16:25:11 momjian Exp $ --> +<!-- $PostgreSQL: pgsql/doc/src/sgml/libpq.sgml,v 1.209 2006/05/17 21:50:54 momjian Exp $ --> <chapter id="libpq"> <title><application>libpq</application> - C Library</title> @@ -4000,9 +4000,9 @@ current connection parameters will be used. (Therefore, put more-specific entries first when you are using wildcards.) If an entry needs to contain <literal>:</literal> or <literal>\</literal>, escape this character with <literal>\</literal>. -A hostname of <literal>localhost</> matches both <literal>host</> (TCP) -and <literal>local</> (Unix domain socket) connections coming from the -local machine. +A hostname of <literal>localhost</> matches both TCP <literal>host</> (hostname <literal>localhost</>) +and Unix domain socket <literal>local</> (<literal>pghost</> empty or the default socket directory) +connections coming from the local machine. </para> <para> diff --git a/src/interfaces/libpq/fe-connect.c b/src/interfaces/libpq/fe-connect.c index 98d834b5954..45dae727286 100644 --- a/src/interfaces/libpq/fe-connect.c +++ b/src/interfaces/libpq/fe-connect.c @@ -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; |