Tom Lane wrote:

Andrew Dunstan <[EMAIL PROTECTED]> writes:
The one place that very slightly bothers me is the ::1 line in pg_hba.conf. The fact that it comes last in the default config is its saving grace - it won't ever be reached by a passing connection. I think at least, though, we should put a warning comment line in front of it,

If you like, you can improve initdb to comment that line out if
getaddrinfo chokes on "::1", rather than believing HAVE_IPV6.

                        

Good idea. Here's a patch for that. Rather than commenting it out I used the slightly newer initdb facility to remove it and the associated comment line altogether.

Passes "make check" on my linux box.

cheers

andrew
Index: src/bin/initdb/initdb.c
===================================================================
RCS file: /home/cvsmirror/pgsql/src/bin/initdb/initdb.c,v
retrieving revision 1.94
diff -c -r1.94 initdb.c
*** src/bin/initdb/initdb.c	2 Aug 2005 15:16:27 -0000	1.94
--- src/bin/initdb/initdb.c	21 Aug 2005 23:41:25 -0000
***************
*** 148,156 ****
  static char *xstrdup(const char *s);
  static char **replace_token(char **lines,
  							const char *token, const char *replacement);
- #ifndef HAVE_UNIX_SOCKETS
  static char **filter_lines_with_token(char **lines, const char *token);
- #endif
  static char **readfile(char *path);
  static void writefile(char *path, char **lines);
  static FILE *popen_check(const char *command, const char *mode);
--- 148,154 ----
***************
*** 330,336 ****
   *
   * a sort of poor man's grep -v
   */
- #ifndef HAVE_UNIX_SOCKETS
  static char **
  filter_lines_with_token(char **lines, const char *token)
  {
--- 328,333 ----
***************
*** 351,357 ****
  
  	return result;
  }
- #endif
  
  /*
   * get the lines from a text file
--- 348,353 ----
***************
*** 1157,1162 ****
--- 1153,1170 ----
  	char	  **conflines;
  	char		repltok[100];
  	char		path[MAXPGPATH];
+ 	
+     struct addrinfo *gai_result;
+     struct addrinfo hints;
+ 
+ 	hints.ai_flags = AI_NUMERICHOST;
+ 	hints.ai_family = PF_UNSPEC;
+ 	hints.ai_socktype = 0;
+ 	hints.ai_protocol = 0;
+ 	hints.ai_addrlen = 0;
+ 	hints.ai_canonname = NULL;
+ 	hints.ai_addr = NULL;
+ 	hints.ai_next = NULL;
  
  	fputs(_("creating configuration files ... "), stdout);
  	fflush(stdout);
***************
*** 1210,1220 ****
  	conflines = replace_token(conflines,"@remove-line-for-nolocal@","");
  #endif
  
! #ifndef HAVE_IPV6
! 	conflines = replace_token(conflines,
! 							  "host    all         all         ::1",
! 							  "#host    all         all         ::1");
! #endif
  
  	/* Replace default authentication methods */
  	conflines = replace_token(conflines,
--- 1218,1234 ----
  	conflines = replace_token(conflines,"@remove-line-for-nolocal@","");
  #endif
  
! 	/* 
! 	 * runtime test for IPv6 support (previously compile time test).
! 	 * this lets us build on hosts with IPv6 support and run
! 	 * on hosts without, especially on Windows.
! 	 * 
! 	 */
! 	if (getaddrinfo("::1", NULL, &hints, &gai_result) != 0)
! 		conflines = filter_lines_with_token(conflines,
! 											"@remove-line-for-no-ip6@");
! 	else
! 		conflines = replace_token(conflines,"@remove-line-for-no-ip6@","");
  
  	/* Replace default authentication methods */
  	conflines = replace_token(conflines,
Index: src/backend/libpq/pg_hba.conf.sample
===================================================================
RCS file: /home/cvsmirror/pgsql/src/backend/libpq/pg_hba.conf.sample,v
retrieving revision 1.59
diff -c -r1.59 pg_hba.conf.sample
*** src/backend/libpq/pg_hba.conf.sample	15 Aug 2005 02:40:25 -0000	1.59
--- src/backend/libpq/pg_hba.conf.sample	21 Aug 2005 23:33:30 -0000
***************
*** 67,71 ****
  @[EMAIL PROTECTED]   all         all                               @authmethod@
  # IPv4 local connections:
  host    all         all         127.0.0.1/32          @authmethod@
! # IPv6 local connections:
! host    all         all         ::1/128               @authmethod@
--- 67,71 ----
  @[EMAIL PROTECTED]   all         all                               @authmethod@
  # IPv4 local connections:
  host    all         all         127.0.0.1/32          @authmethod@
! @[EMAIL PROTECTED] IPv6 local connections:
! @[EMAIL PROTECTED]    all         all         ::1/128               @authmethod@

---------------------------(end of broadcast)---------------------------
TIP 3: Have you checked our extensive FAQ?

               http://www.postgresql.org/docs/faq

Reply via email to