Allow the .pgpass hostname to match the default socket directory, as
authorBruce Momjian
Wed, 17 May 2006 21:50:54 +0000 (21:50 +0000)
committerBruce Momjian
Wed, 17 May 2006 21:50:54 +0000 (21:50 +0000)
well as a blank pghost.

doc/src/sgml/libpq.sgml
src/interfaces/libpq/fe-connect.c

index b856262d1e18813ad822b45d6f09aa6a7381dd29..aef1129844cf9d6ff41d564987f469f3a5f56622 100644 (file)
@@ -1,4 +1,4 @@
-
+
 
  
   <application>libpq</application> - C Library
@@ -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 : or
 \, escape this character with \.
-A hostname of localhost matches both host (TCP)
-and local (Unix domain socket) connections coming from the
-local machine.
+A hostname of localhost matches both TCP host (hostname localhost)
+and Unix domain socket local (pghost empty or the default socket directory)
+connections coming from the local machine.
 
 
 
index 98d834b5954b377b56fd579b0216be2cf6a7dc15..45dae72728655656b3ae8cf19b92e4f03f8ac65b 100644 (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;