]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
add support for building GeoIP2 on windows
authorEvan Hunt <each@isc.org>
Thu, 4 Jul 2019 17:20:49 +0000 (10:20 -0700)
committerEvan Hunt <each@isc.org>
Thu, 4 Jul 2019 19:05:32 +0000 (12:05 -0700)
14 files changed:
bin/named/config.c
bin/named/geoip.c
bin/named/server.c
bin/named/win32/named.vcxproj.filters.in
bin/named/win32/named.vcxproj.in
bin/tests/system/feature-test.c
config.h.win32
doc/arm/Bv9ARM-book.xml
lib/dns/include/dns/geoip.h
lib/dns/tests/geoip_test.c
lib/dns/win32/libdns.vcxproj.filters.in
lib/dns/win32/libdns.vcxproj.in
lib/isc/win32/libisc.vcxproj.in
win32utils/Configure

index f077156afa409b985ea9da3421fcd1473a4652fc..078a3e9362340e60952b961ee93311241bb3cd97 100644 (file)
@@ -66,8 +66,10 @@ options {\n\
 #ifndef WIN32
 "      files unlimited;\n"
 #endif
-#ifdef HAVE_GEOIP2
+#if defined(HAVE_GEOIP2) && !defined(WIN32)
 "      geoip-directory \"" MAXMINDDB_PREFIX "/share/GeoIP2\";\n"
+#elif defined(HAVE_GEOIP2)
+"      geoip-directory \".\";\n"
 #endif
 "\
 #      has-old-clients <obsolete>;\n\
index 28dd54ebdba0c7c748c526421a9839ea160c8a66..1610c66cea8653a46dde3623f41a4485cc50432c 100644 (file)
@@ -29,7 +29,7 @@
 #include <named/log.h>
 #include <named/geoip.h>
 
-static dns_geoip_databases_t geoip_table = DNS_GEOIP_DATABASE_INIT;
+static dns_geoip_databases_t geoip_table;
 
 #if defined(HAVE_GEOIP)
 static void
@@ -100,7 +100,7 @@ open_geoip2(const char *dir, const char *dbfile, MMDB_s *mmdb) {
                isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL,
                              NAMED_LOGMODULE_SERVER, ISC_LOG_ERROR,
                              "GeoIP2 database '%s/%s': path too long",
-                             (dir != NULL) ? dir : ".", dbfile);
+                             dir, dbfile);
                return (NULL);
        }
 
@@ -141,6 +141,10 @@ named_geoip_load(char *dir) {
 #if defined(HAVE_GEOIP2)
        REQUIRE(dir != NULL);
 
+       isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL,
+                     NAMED_LOGMODULE_SERVER, ISC_LOG_INFO,
+                     "looking for GeoIP2 databases in '%s'", dir);
+
        named_g_geoip->country = open_geoip2(dir, "GeoIP2-Country.mmdb",
                                             &geoip_country);
        if (named_g_geoip->country == NULL) {
index 65769fbd7fdbd7ff92dd147ce7638b50a4f91452..b3adb4d314c93dd62ad8a8844cf628ff62af1af2 100644 (file)
@@ -8296,8 +8296,6 @@ load_configuration(const char *filename, named_server_t *server,
                char *dir;
                DE_CONST(cfg_obj_asstring(obj), dir);
                named_geoip_load(dir);
-       } else {
-               named_geoip_load(NULL);
        }
        named_g_aclconfctx->geoip = named_g_geoip;
 #endif /* HAVE_GEOIP || HAVE_GEOIP2 */
index 60b2ec26ac8cc3c418dfc7c5e56e09aa571df38c..9bdb73d8a36c6e9de070ef820c3f3c479639c5a4 100644 (file)
       <Filter>Source Files</Filter>
     </ClCompile>
 @END GEOIP
+@IF GEOIPLEGACY
+    <ClCompile Include="..\geoip.c">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+@END GEOIPLEGACY
     <ClCompile Include="..\log.c">
       <Filter>Source Files</Filter>
     </ClCompile>
       <Filter>Header Files</Filter>
     </ClInclude>
 @END GEOIP
+@IF GEOIPLEGACY
+    <ClInclude Include="..\include\named\geoip.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
+@END GEOIPLEGACY
     <ClInclude Include="..\include\named\globals.h">
       <Filter>Header Files</Filter>
     </ClInclude>
index 9433e72f8fe3206a06322d411a93e873c75ec170..0c7b0b2913db2fd32afdd07db9de02be27d9ee34 100644 (file)
 @IF GEOIP
     <ClCompile Include="..\geoip.c" />
 @END GEOIP
+@IF GEOIPLEGACY
+    <ClCompile Include="..\geoip.c" />
+@END GEOIPLEGACY
     <ClCompile Include="..\log.c" />
     <ClCompile Include="..\logconf.c" />
     <ClCompile Include="..\main.c" />
 @IF GEOIP
     <ClInclude Include="..\include\named\geoip.h" />
 @END GEOIP
+@IF GEOIPLEGACY
+    <ClInclude Include="..\include\named\geoip.h" />
+@END GEOIPLEGACY
     <ClInclude Include="..\include\named\globals.h" />
     <ClInclude Include="..\include\named\log.h" />
     <ClInclude Include="..\include\named\logconf.h" />
index 7288210d77f2a0803cea3114009842b175c37f0b..ff92ad26a029163fbb01124f79b4e043d2cf5c02 100644 (file)
@@ -43,6 +43,7 @@ usage() {
        fprintf(stderr, "       --gssapi\n");
        fprintf(stderr, "       --have-dlopen\n");
        fprintf(stderr, "       --have-geoip\n");
+       fprintf(stderr, "       --have-geoip2\n");
        fprintf(stderr, "       --have-libxml2\n");
        fprintf(stderr, "       --ipv6only=no\n");
        fprintf(stderr, "       --with-idn\n");
index b95d77f9a00fdcec499d5be024a7e832b9febf09..fdbe44a07a7f7a7a2dd48289306779f4bd5fcd81 100644 (file)
@@ -313,6 +313,9 @@ typedef __int64 off_t;
 /* Build with GeoIP support */
 @HAVE_GEOIP@
 
+/* Build with GeoIP2 support */
+@HAVE_GEOIP2@
+
 /* define if idnkit support is to be included. */
 @WITH_IDN@
 
index 92b086f2dbd84a31c4dbfb83b753cd1c23ab7c51..53f73ca4f06e31802b496cb283e909608b7cb606 100644 (file)
@@ -4565,8 +4565,9 @@ badresp:1,adberr:0,findfail:0,valfail:0]
                module: for example, if the library is installed in
                <filename>/usr/local/lib</filename>, then the default
                <command>geoip-directory</command> will be
-               <filename>/usr/local/share/GeoIP</filename>.
-               See <xref linkend="acl"/> for details about
+               <filename>/usr/local/share/GeoIP</filename>. On Windows,
+               the default is the <command>named</command> working
+               directory.  See <xref linkend="acl"/> for details about
                <command>geoip</command> ACLs.
              </para>
            </listitem>
index d79a85c9fdf75c420ebf041acfe0c02366da6e53..623cbae5ad9a4aa14df501b24ba8f44b922d66e9 100644 (file)
@@ -93,8 +93,6 @@ struct dns_geoip_databases {
        void *domain;           /* GeoIP2-Domain */
        void *isp;              /* GeoIP2-ISP */
        void *as;               /* GeoIP2-ASN or GeoLite2-ASN */
-#define DNS_GEOIP_DATABASE_INIT \
-       { NULL, NULL, NULL, NULL, NULL }
 #else /* HAVE_GEOIP */
        void *country_v4;       /* GeoIP DB 1 */
        void *city_v4;          /* GeoIP DB 2 or 6 */
@@ -106,8 +104,6 @@ struct dns_geoip_databases {
        void *domain;           /* GeoIP DB 11 */
        void *country_v6;       /* GeoIP DB 12 */
        void *city_v6;          /* GeoIP DB 30 or 31 */
-#define DNS_GEOIP_DATABASE_INIT \
-       { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL }
 #endif /* HAVE_GEOIP */
 };
 
index fc5fe381a554fd24921159a293956fb86db0b900..4e9e63a4ab411ec60aca6c3925b2e5384a021f92 100644 (file)
@@ -68,7 +68,7 @@ _teardown(void **state) {
        return (0);
 }
 
-static dns_geoip_databases_t geoip = DNS_GEOIP_DATABASE_INIT;
+static dns_geoip_databases_t geoip;
 #endif /* HAVE_GEOIP || HAVE_GEOIP2 */
 
 #if defined(HAVE_GEOIP2)
index 4f2a2e8463e127e8c7ccdeeaf870135a24e28c93..6257361f7cca0f54a86bbec53a169ef20b0f980a 100644 (file)
       <Filter>Library Source Files</Filter>
     </ClCompile>
 @IF GEOIP
-    <ClCompile Include="..\geoip.c">
+    <ClCompile Include="..\geoip2.c">
       <Filter>Library Source Files</Filter>
     </ClCompile>
 @END GEOIP
+@IF GEOIPLEGACY
+    <ClCompile Include="..\geoip.c">
+      <Filter>Library Source Files</Filter>
+    </ClCompile>
+@END GEOIPLEGACY
     <ClCompile Include="..\ipkeylist.c">
       <Filter>Library Source Files</Filter>
     </ClCompile>
       <Filter>Library Header Files</Filter>
     </ClInclude>
 @END GEOIP
+@IF GEOIPLEGACY
+    <ClInclude Include="..\include\dns\geoip.h">
+      <Filter>Library Header Files</Filter>
+    </ClInclude>
+@END GEOIPLEGACY
     <ClInclude Include="..\include\dns\ipkeylist.h">
       <Filter>Library Header Files</Filter>
     </ClInclude>
index 1b17a5f96e9230e226455691c4498936c446d976..a5c565110e056f14afeb282ef50c5f59580a895e 100644 (file)
     <ClCompile Include="..\fixedname.c" />
     <ClCompile Include="..\forward.c" />
 @IF GEOIP
-    <ClCompile Include="..\geoip.c" />
+    <ClCompile Include="..\geoip2.c" />
 @END GEOIP
+@IF GEOIPLEGACY
+    <ClCompile Include="..\geoip.c" />
+@END GEOIPLEGACY
     <ClCompile Include="..\gssapictx.c" />
     <ClCompile Include="..\gssapi_link.c" />
     <ClCompile Include="..\hmac_link.c" />
 @IF GEOIP
     <ClInclude Include="..\include\dns\geoip.h" />
 @END GEOIP
+@IF GEOIPLEGACY
+    <ClInclude Include="..\include\dns\geoip.h" />
+@END GEOIPLEGACY
     <ClInclude Include="..\include\dns\ipkeylist.h" />
     <ClInclude Include="..\include\dns\iptable.h" />
     <ClInclude Include="..\include\dns\journal.h" />
index a49f76baffb0dccf7a7ce3b0e42a561fd76dbe43..01d3ba26995cd4fac13490b6939ecdc52f7772f4 100644 (file)
@@ -107,11 +107,11 @@ copy @K5SPRT_DLL@ ..\Build\Debug\
 copy @WSHELP_DLL@ ..\Build\Debug\
 @END GSSAPI
 
-@IF GEOIP
+@IF GEOIPLEGACY
 echo Copying the GeoIP DLL.
 
 copy @GEOIP_DLL@ ..\Build\Debug\
-@END GEOIP
+@END GEOIPLEGACY
 
 @IF IDNKIT
 echo Copying the IDN kit DLL.
@@ -254,11 +254,11 @@ copy @K5SPRT_DLL@ ..\Build\Release\
 copy @WSHELP_DLL@ ..\Build\Release\
 @END GSSAPI
 
-@IF GEOIP
+@IF GEOIPLEGACY
 echo Copying the GeoIP DLL.
 
 copy @GEOIP_DLL@ ..\Build\Release\
-@END GEOIP
+@END GEOIPLEGACY
 
 @IF IDNKIT
 echo Copying the IDN kit DLL.
index 67a8d046188208e40bc08e7a40be2e7c0bd2da66..36d2f8fb98e253a137cb8c4fd755eb236bef4084 100644 (file)
@@ -196,6 +196,7 @@ my @substdefh = ("AES_CC",
                  "CONFIGARGS",
                  "DNS_RDATASET_FIXED",
                  "HAVE_GEOIP",
+                 "HAVE_GEOIP2",
                  "HAVE_GEOIP_CITY_V6",
                  "HAVE_GEOIP_V6",
                  "HAVE_LIBXML2",
@@ -335,6 +336,7 @@ my %configcond;
 my @substcond = ("ATOMIC",
                  "GSSAPI",
                  "GEOIP",
+                 "GEOIPLEGACY",
                  "IDNKIT",
                  "LIBXML2",
                  "OPENSSL",
@@ -370,6 +372,7 @@ my @withlist = ("aes",
                 "extra-tests",
                 "gssapi",
                 "geoip",
+                "geoip2",
                 "iconv",
                 "idn",
                 "openssl",
@@ -427,6 +430,7 @@ my @help = (
 "  with-gssapi[=PATH]    build with MIT KfW GSSAPI yes|no|path\n",
 "  with-libxml2[=PATH]   build with libxml2 library yes|no|path\n",
 "  with-geoip[=PATH]     build with GeoIP support yes|no|path\n",
+"  with-geoip2[=PATH]    build with GeoIP2 support yes|no|path\n",
 "  with-pssuspend[=COMMAND] specify pssuspend command\n",
 "  with-python[=COMMAND] specify python interpreter python|command\n",
 "  with-readline[=PATH]  build with readline library support yes|no|path\n",
@@ -474,6 +478,8 @@ my $validation_default = "auto";
 my $gssapi_path = "C:\\Program\ Files\\MIT\\Kerberos\\";
 my $use_geoip = "no";
 my $geoip_path = "";
+my $use_geoip2 = "no";
+my $geoip2_path = "";
 my $use_libxml2 = "auto";
 my $libxml2_path = "..\\..\\";
 my $with_pssuspend = "no";
@@ -783,6 +789,17 @@ sub mywith {
                 $geoip_path = $val;
             }
         }
+    } elsif ($key =~ /^geoip2$/i) {
+        if ($val !~ /^no$/i) {
+            $use_geoip2 = "yes";
+            # Disable GeoIP legacy.
+            $use_geoip = "no";
+            if ($val !~ /^yes$/i) {
+                $geoip2_path = $val;
+            } else {
+                $geoip2_path = "..\\..\\GeoIP2";
+            }
+        }
     } elsif ($key =~ /^readline$/i) {
         if ($val !~ /^no$/i) {
             $use_readline = "yes";
@@ -983,6 +1000,11 @@ if ($verbose) {
     } else {
         print "geoip-path: $geoip_path\n";
     }
+    if ($use_geoip2 eq "no") {
+        print "geoip2: disabled\n";
+    } else {
+        print "geoip2-path: $geoip2_path\n";
+    }
     if ($use_readline eq "no") {
         print "readline: disabled\n";
     } else {
@@ -1479,6 +1501,7 @@ EOF
             $configdefh{"HAVE_DH_GET0_KEY"} = 1;
             $configdefh{"HAVE_ECDSA_SIG_GET0"} = 1;
             $configdefh{"HAVE_RSA_SET0_KEY"} = 1;
+            $configdefh{"HAVE_CRYPTO_ZALLOC"} = 1;
             $configdefh{"HAVE_EVP_CIPHER_CTX_FREE"} = 1;
             $configdefh{"HAVE_EVP_CIPHER_CTX_NEW"} = 1;
             $configdefh{"HAVE_EVP_MD_CTX_FREE"} = 1;
@@ -1736,7 +1759,7 @@ if ($use_geoip eq "no") {
         print "geoip library is disabled\n";
     }
 } else {
-    $configcond{"GEOIP"} = 1;
+    $configcond{"GEOIPLEGACY"} = 1;
     $geoip_path = File::Spec->rel2abs($geoip_path);
     if ($verbose) {
         print "checking for geoip directory at \"$geoip_path\"\n";
@@ -1844,6 +1867,55 @@ EOF
     $configdefh{"HAVE_GEOIP_CITY_V6"} = 1;
 }
 
+# with-geoip2
+if ($use_geoip2 eq "no") {
+    if ($verbose) {
+        print "geoip2 library is disabled\n";
+    }
+} else {
+    $configcond{"GEOIP"} = 1;
+    $geoip2_path = File::Spec->rel2abs($geoip2_path);
+    if ($verbose) {
+        print "checking for geoip2 directory at \"$geoip2_path\"\n";
+    }
+    if (!-f File::Spec->catfile($geoip2_path, "maxminddb.h")) {
+        die "can't find maxminddb.h include\n";
+    }
+    if (!-f File::Spec->catfile($geoip2_path, "maxminddb_config.h")) {
+        die "can't find maxminddb_config.h include\n";
+    }
+    if (!-f File::Spec->catfile($geoip2_path, "libmaxminddb.lib")) {
+        die "can't find libmaxminddb.lib library\n";
+    }
+    $configinc{"GEOIP_INC"} = "$geoip2_path";
+    my $geoip2_lib = File::Spec->catfile($geoip2_path, "libmaxminddb.lib");
+    $configlib{"GEOIP_LIB"} = "$geoip2_lib";
+    my $geoip_inc = qq(/I "$geoip2_path");
+    my $geoip2_libs = qq("$geoip2_lib" Ws2_32.Lib);
+
+    if ($verbose) {
+        print "checking for GeoIP2 support\n";
+    }
+    open F, ">testgeoip2.c" || die $!;
+    print F << 'EOF';
+#include <maxminddb.h>
+int main(void) {
+       return MMDB_lib_version() != 0;
+}
+EOF
+    close F;
+    $compret = `cl /nologo $geoip_inc /MD testgeoip2.c $geoip2_libs`;
+    if (grep { -f and -x } ".\\testgeoip2.exe") {
+        `.\\testgeoip2.exe`;
+        if ($? == 0) {
+            die "GeoIP2 test failed\n";
+        }
+    } else {
+        die "can't compile GeoIP2 test: $compret\n";
+    }
+    $configdefh{"HAVE_GEOIP2"} = 1;
+}
+
 # with-readline
 if ($use_readline eq "no") {
     if ($verbose) {
@@ -2951,6 +3023,7 @@ exit 0;
 #  --with-cc-alg supported
 #  --with-randomdev not supported on WIN32 (makes no sense)
 #  --with-geoip supported
+#  --with-geoip2 supported
 #  --with-gssapi supported with MIT (K)erberos (f)or (W)indows
 #  --with-lmdb no supported on WIN32 (port is not reliable)
 #  --with-libxml2 supported