Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Have config_sspi_auth() permit IPv6 localhost connections.
authorNoah Misch <noah@leadboat.com>
Thu, 25 Dec 2014 18:52:03 +0000 (13:52 -0500)
committerNoah Misch <noah@leadboat.com>
Thu, 25 Dec 2014 19:10:21 +0000 (14:10 -0500)
Windows versions later than Windows Server 2003 map "localhost" to ::1.
Account for that in the generated pg_hba.conf, fixing another oversight
in commit f6dc6dd5ba54d52c0733aaafc50da2fbaeabb8b0.  Back-patch to 9.0,
like that commit.

David Rowley and Noah Misch

src/test/regress/pg_regress.c
src/tools/msvc/Mkvcbuild.pm

index 5380dd21118abe96fd86ef2b8b0cf8d6e55be228..6afef7bc816e04ecb7598df9ccfb92bf1502a3e1 100644 (file)
@@ -1043,6 +1043,7 @@ config_sspi_auth(const char *pgdata)
               *domainname;
    char        username[128];
    DWORD       sz = sizeof(username) - 1;
+   bool        have_ipv6;
    char        fname[MAXPGPATH];
    int         res;
    FILE       *hba,
@@ -1062,6 +1063,28 @@ config_sspi_auth(const char *pgdata)
        exit(2);
    }
 
+   /*
+    * Like initdb.c:setup_config(), determine whether the platform recognizes
+    * ::1 (IPv6 loopback) as a numeric host address string.
+    */
+   {
+       struct addrinfo *gai_result;
+       struct addrinfo hints;
+       WSADATA     wsaData;
+
+       hints.ai_flags = AI_NUMERICHOST;
+       hints.ai_family = AF_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;
+
+       have_ipv6 = (WSAStartup(MAKEWORD(2, 2), &wsaData) == 0 &&
+                    getaddrinfo("::1", NULL, &hints, &gai_result) == 0);
+   }
+
    /* Check a Write outcome and report any error. */
 #define CW(cond)   \
    do { \
@@ -1093,6 +1116,9 @@ config_sspi_auth(const char *pgdata)
    CW(fputs("# Configuration written by config_sspi_auth()\n", hba) >= 0);
    CW(fputs("host all all 127.0.0.1/32  sspi include_realm=1 map=regress\n",
             hba) >= 0);
+   if (have_ipv6)
+       CW(fputs("host all all ::1/128  sspi include_realm=1 map=regress\n",
+                hba) >= 0);
    CW(fclose(hba) == 0);
 
    snprintf(fname, sizeof(fname), "%s/pg_ident.conf", pgdata);
index 41d160b19ad41c3c68d37e9325990b18c97ec7b3..5361a5c41e14836db41347ad0e8cfcacf1742d5c 100644 (file)
@@ -264,6 +264,7 @@ sub mkvcbuild
     $pgregress_ecpg->AddIncludeDir('src\test\regress');
     $pgregress_ecpg->AddDefine('HOST_TUPLE="i686-pc-win32vc"');
     $pgregress_ecpg->AddDefine('FRONTEND');
+    $pgregress_ecpg->AddLibrary('ws2_32.lib');
     $pgregress_ecpg->AddReference($libpgport);
 
     # src/bin
@@ -454,6 +455,8 @@ sub mkvcbuild
     $pgregress->AddFile('src\test\regress\pg_regress_main.c');
     $pgregress->AddIncludeDir('src\port');
     $pgregress->AddDefine('HOST_TUPLE="i686-pc-win32vc"');
+    $pgregress->AddDefine('FRONTEND');
+    $pgregress->AddLibrary('ws2_32.lib');
     $pgregress->AddReference($libpgport);
 
     $solution->Save();