From: Evan Hunt Date: Thu, 4 Jul 2019 17:40:31 +0000 (-0700) Subject: add support for building GeoIP2 on windows X-Git-Tag: v9.11.9~3^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cf9c7959a017a6d8742e2ad089660715689ce011;p=thirdparty%2Fbind9.git add support for building GeoIP2 on windows --- diff --git a/bin/named/config.c b/bin/named/config.c index 1d6e9d4b1ea..32c454a6da2 100644 --- a/bin/named/config.c +++ b/bin/named/config.c @@ -70,8 +70,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 ;\n\ diff --git a/bin/named/geoip.c b/bin/named/geoip.c index 6bf0ab1a31f..d560f8fbcfa 100644 --- a/bin/named/geoip.c +++ b/bin/named/geoip.c @@ -29,7 +29,7 @@ #include #include -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(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_SERVER, ISC_LOG_ERROR, "GeoIP2 database '%s/%s': path too long", - (dir != NULL) ? dir : ".", dbfile); + dir, dbfile); return (NULL); } @@ -141,6 +141,10 @@ ns_geoip_load(char *dir) { #if defined(HAVE_GEOIP2) REQUIRE(dir != NULL); + isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, + NS_LOGMODULE_SERVER, ISC_LOG_INFO, + "looking for GeoIP2 databases in '%s'", dir); + ns_g_geoip->country = open_geoip2(dir, "GeoIP2-Country.mmdb", &geoip_country); if (ns_g_geoip->country == NULL) { diff --git a/bin/named/server.c b/bin/named/server.c index 1ed1f1e5bd0..767d83f9d78 100644 --- a/bin/named/server.c +++ b/bin/named/server.c @@ -7644,8 +7644,6 @@ load_configuration(const char *filename, ns_server_t *server, char *dir; DE_CONST(cfg_obj_asstring(obj), dir); ns_geoip_load(dir); - } else { - ns_geoip_load(NULL); } ns_g_aclconfctx->geoip = ns_g_geoip; diff --git a/bin/named/win32/named.vcxproj.filters.in b/bin/named/win32/named.vcxproj.filters.in index 8cc6a7b21f0..8a5173e34a3 100644 --- a/bin/named/win32/named.vcxproj.filters.in +++ b/bin/named/win32/named.vcxproj.filters.in @@ -44,6 +44,11 @@ Source Files @END GEOIP +@IF GEOIPLEGACY + + Source Files + +@END GEOIPLEGACY Source Files @@ -141,6 +146,11 @@ Header Files @END GEOIP +@IF GEOIPLEGACY + + Header Files + +@END GEOIPLEGACY Header Files diff --git a/bin/named/win32/named.vcxproj.in b/bin/named/win32/named.vcxproj.in index f2d70ccf102..908224363ac 100644 --- a/bin/named/win32/named.vcxproj.in +++ b/bin/named/win32/named.vcxproj.in @@ -110,6 +110,9 @@ @IF GEOIP @END GEOIP +@IF GEOIPLEGACY + +@END GEOIPLEGACY @@ -146,6 +149,9 @@ @IF GEOIP @END GEOIP +@IF GEOIPLEGACY + +@END GEOIPLEGACY diff --git a/bin/tests/system/feature-test.c b/bin/tests/system/feature-test.c index 826d8f0c4c1..27a02d0b3ab 100644 --- a/bin/tests/system/feature-test.c +++ b/bin/tests/system/feature-test.c @@ -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, " --rpz-nsdname\n"); diff --git a/config.h.win32 b/config.h.win32 index 2995830bae8..71b94415f46 100644 --- a/config.h.win32 +++ b/config.h.win32 @@ -382,6 +382,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@ diff --git a/doc/arm/Bv9ARM-book.xml b/doc/arm/Bv9ARM-book.xml index 5b04144a3a6..6cb0f1caf33 100644 --- a/doc/arm/Bv9ARM-book.xml +++ b/doc/arm/Bv9ARM-book.xml @@ -4714,8 +4714,9 @@ badresp:1,adberr:0,findfail:0,valfail:0] module: for example, if the library is installed in /usr/local/lib, then the default geoip-directory will be - /usr/local/share/GeoIP. - See for details about + /usr/local/share/GeoIP. On Windows, + the default is the named working + directory. See for details about geoip ACLs. diff --git a/lib/dns/include/dns/geoip.h b/lib/dns/include/dns/geoip.h index c41a2c21f75..2b336e12970 100644 --- a/lib/dns/include/dns/geoip.h +++ b/lib/dns/include/dns/geoip.h @@ -92,8 +92,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 */ @@ -105,8 +103,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 */ }; diff --git a/lib/dns/tests/geoip_test.c b/lib/dns/tests/geoip_test.c index 50922ea5955..7d45941b9cb 100644 --- a/lib/dns/tests/geoip_test.c +++ b/lib/dns/tests/geoip_test.c @@ -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) diff --git a/lib/dns/win32/libdns.vcxproj.filters.in b/lib/dns/win32/libdns.vcxproj.filters.in index 5c510434c0d..6124247e59c 100644 --- a/lib/dns/win32/libdns.vcxproj.filters.in +++ b/lib/dns/win32/libdns.vcxproj.filters.in @@ -103,10 +103,15 @@ Library Source Files @IF GEOIP - + Library Source Files @END GEOIP +@IF GEOIPLEGACY + + Library Source Files + +@END GEOIPLEGACY Library Source Files @@ -463,6 +468,11 @@ Library Header Files @END GEOIP +@IF GEOIPLEGACY + + Library Header Files + +@END GEOIPLEGACY Library Header Files diff --git a/lib/dns/win32/libdns.vcxproj.in b/lib/dns/win32/libdns.vcxproj.in index 7ceb68b9a36..e0985640b8a 100644 --- a/lib/dns/win32/libdns.vcxproj.in +++ b/lib/dns/win32/libdns.vcxproj.in @@ -138,8 +138,11 @@ @IF GEOIP - + @END GEOIP +@IF GEOIPLEGACY + +@END GEOIPLEGACY @@ -268,6 +271,9 @@ @IF GEOIP @END GEOIP +@IF GEOIPLEGACY + +@END GEOIPLEGACY diff --git a/lib/isc/win32/libisc.vcxproj.in b/lib/isc/win32/libisc.vcxproj.in index fb9222a8710..bb0456ff5a9 100644 --- a/lib/isc/win32/libisc.vcxproj.in +++ b/lib/isc/win32/libisc.vcxproj.in @@ -109,11 +109,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. @@ -261,11 +261,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. diff --git a/win32utils/Configure b/win32utils/Configure index 27b00af8d3c..93939f32136 100644 --- a/win32utils/Configure +++ b/win32utils/Configure @@ -351,6 +351,7 @@ my @substdefh = ("AES_CC", "HAVE_EVP_SHA512", "HAVE_FIPS_MODE", "HAVE_GEOIP", + "HAVE_GEOIP2", "HAVE_GEOIP_CITY_V6", "HAVE_GEOIP_V6", "HAVE_LIBXML2", @@ -492,6 +493,7 @@ my @substcond = ("AES", "ATOMIC", "GSSAPI", "GEOIP", + "GEOIPLEGACY", "IDNKIT", "LIBXML2", "OPENSSL", @@ -530,6 +532,7 @@ my @withlist = ("aes", "extra-tests", "gssapi", "geoip", + "geoip2", "gost", "iconv", "idn", @@ -595,6 +598,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", @@ -644,6 +648,8 @@ my $use_gssapi = "no"; 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"; @@ -983,6 +989,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"; @@ -1229,6 +1246,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 { @@ -2363,7 +2385,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"; @@ -2471,6 +2493,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 +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) { @@ -3590,6 +3661,7 @@ exit 0; # --with-aes supported # --with-cc-alg supported # --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