From 9ba3e3f1b594c291999b45a036acbe3abb6b1126 Mon Sep 17 00:00:00 2001
From: Thomas Jach
Date: Tue, 2 Jul 2019 16:27:42 -0700
Subject: [PATCH] convert geoip to geoip2 in win32utils/Configure
---
bin/named/config.c | 4 +-
bin/named/geoip.c | 6 +-
bin/named/server.c | 5 +-
config.h.win32 | 3 -
doc/arm/Bv9ARM-book.xml | 5 +-
lib/dns/win32/libdns.vcxproj.filters.in | 2 +-
lib/dns/win32/libdns.vcxproj.in | 2 +-
lib/isc/win32/libisc.vcxproj.in | 12 --
win32utils/Configure | 146 +++++++-----------------
9 files changed, 54 insertions(+), 131 deletions(-)
diff --git a/bin/named/config.c b/bin/named/config.c
index 6f6da2facd..cc74012e7f 100644
--- a/bin/named/config.c
+++ b/bin/named/config.c
@@ -64,8 +64,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 f72895ee17..83fbd96e67 100644
--- a/bin/named/geoip.c
+++ b/bin/named/geoip.c
@@ -40,7 +40,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);
}
@@ -78,6 +78,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) {
diff --git a/bin/named/server.c b/bin/named/server.c
index a8f0872992..d1ca372a4a 100644
--- a/bin/named/server.c
+++ b/bin/named/server.c
@@ -8270,12 +8270,11 @@ load_configuration(const char *filename, named_server_t *server,
*/
obj = NULL;
result = named_config_get(maps, "geoip-directory", &obj);
- if (result == ISC_R_SUCCESS && cfg_obj_isstring(obj)) {
+ INSIST(result == ISC_R_SUCCESS);
+ if (cfg_obj_isstring(obj)) {
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_GEOIP2 */
diff --git a/config.h.win32 b/config.h.win32
index 0fe66c5f19..fda2009e51 100644
--- a/config.h.win32
+++ b/config.h.win32
@@ -310,9 +310,6 @@ typedef __int64 off_t;
/* Define to 1 if you have the `readline' function. */
@HAVE_READLINE@
-/* Build with GeoIP support */
-@HAVE_GEOIP@
-
/* Build with GeoIP2 support */
@HAVE_GEOIP2@
diff --git a/doc/arm/Bv9ARM-book.xml b/doc/arm/Bv9ARM-book.xml
index 37ba6fcd8a..fbd5e939e6 100644
--- a/doc/arm/Bv9ARM-book.xml
+++ b/doc/arm/Bv9ARM-book.xml
@@ -4562,8 +4562,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/win32/libdns.vcxproj.filters.in b/lib/dns/win32/libdns.vcxproj.filters.in
index 4f2a2e8463..56f12aeba2 100644
--- a/lib/dns/win32/libdns.vcxproj.filters.in
+++ b/lib/dns/win32/libdns.vcxproj.filters.in
@@ -103,7 +103,7 @@
Library Source Files
@IF GEOIP
-
+
Library Source Files
@END GEOIP
diff --git a/lib/dns/win32/libdns.vcxproj.in b/lib/dns/win32/libdns.vcxproj.in
index bb5ef0dd60..2317624d09 100644
--- a/lib/dns/win32/libdns.vcxproj.in
+++ b/lib/dns/win32/libdns.vcxproj.in
@@ -139,7 +139,7 @@
@IF GEOIP
-
+
@END GEOIP
diff --git a/lib/isc/win32/libisc.vcxproj.in b/lib/isc/win32/libisc.vcxproj.in
index 0d5aa96709..9e8133c637 100644
--- a/lib/isc/win32/libisc.vcxproj.in
+++ b/lib/isc/win32/libisc.vcxproj.in
@@ -109,12 +109,6 @@ copy @K5SPRT_DLL@ ..\Build\Debug\
copy @WSHELP_DLL@ ..\Build\Debug\
@END GSSAPI
-@IF GEOIP
-echo Copying the GeoIP DLL.
-
-copy @GEOIP_DLL@ ..\Build\Debug\
-@END GEOIP
-
@IF IDNKIT
echo Copying the IDN kit DLL.
@@ -258,12 +252,6 @@ copy @K5SPRT_DLL@ ..\Build\Release\
copy @WSHELP_DLL@ ..\Build\Release\
@END GSSAPI
-@IF GEOIP
-echo Copying the GeoIP DLL.
-
-copy @GEOIP_DLL@ ..\Build\Release\
-@END GEOIP
-
@IF IDNKIT
echo Copying the IDN kit DLL.
diff --git a/win32utils/Configure b/win32utils/Configure
index a378f44847..aee6ee7f0b 100644
--- a/win32utils/Configure
+++ b/win32utils/Configure
@@ -195,9 +195,7 @@ my %configdefh;
my @substdefh = ("AES_CC",
"CONFIGARGS",
"DNS_RDATASET_FIXED",
- "HAVE_GEOIP",
- "HAVE_GEOIP_CITY_V6",
- "HAVE_GEOIP_V6",
+ "HAVE_GEOIP2",
"HAVE_LIBXML2",
"HAVE_OPENSSL_ED25519",
"HAVE_OPENSSL_ED448",
@@ -283,7 +281,6 @@ my %configdll;
my @substdll = ("COMERR_DLL",
"GSSAPI_DLL",
- "GEOIP_DLL",
"ICONV_DLL",
"IDN_DLL",
"KRB5_DLL",
@@ -369,7 +366,7 @@ my @withlist = ("aes",
"eddsa",
"extra-tests",
"gssapi",
- "geoip",
+ "geoip2",
"iconv",
"idn",
"openssl",
@@ -426,7 +423,7 @@ my @help = (
" with-cc-alg choose the algorithm for cookies aes|sha1|sha256\n",
" 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",
@@ -472,8 +469,8 @@ my $cookie_algorithm = "aes";
my $use_gssapi = "no";
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";
@@ -776,11 +773,13 @@ sub mywith {
$use_libxml2 = "yes";
$libxml2_path = $val;
}
- } elsif ($key =~ /^geoip$/i) {
+ } elsif ($key =~ /^geoip2$/i) {
if ($val !~ /^no$/i) {
- $use_geoip = "yes";
+ $use_geoip2 = "yes";
if ($val !~ /^yes$/i) {
- $geoip_path = $val;
+ $geoip2_path = $val;
+ } else {
+ $geoip2_path = "..\\..\\GeoIP2";
}
}
} elsif ($key =~ /^readline$/i) {
@@ -978,10 +977,10 @@ if ($verbose) {
} else {
print "libxml2-path: $libxml2_path\n";
}
- if ($use_geoip eq "no") {
- print "geoip: disabled\n";
+ if ($use_geoip2 eq "no") {
+ print "geoip2: disabled\n";
} else {
- print "geoip-path: $geoip_path\n";
+ print "geoip2-path: $geoip2_path\n";
}
if ($use_readline eq "no") {
print "readline: disabled\n";
@@ -1479,6 +1478,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;
@@ -1730,118 +1730,53 @@ if ($use_gssapi ne "yes") {
# disable-auto-validation
$configdefh{"VALIDATION_DEFAULT"} = "\"$validation_default\"";
-# with-geoip
-if ($use_geoip eq "no") {
+# with-geoip2
+if ($use_geoip2 eq "no") {
if ($verbose) {
- print "geoip library is disabled\n";
+ print "geoip2 library is disabled\n";
}
} else {
$configcond{"GEOIP"} = 1;
- $geoip_path = File::Spec->rel2abs($geoip_path);
+ $geoip2_path = File::Spec->rel2abs($geoip2_path);
if ($verbose) {
- print "checking for geoip directory at \"$geoip_path\"\n";
+ print "checking for geoip2 directory at \"$geoip2_path\"\n";
}
- if (!-f File::Spec->catfile($geoip_path, "GeoIP.h")) {
- die "can't find GeoIP.h include\n";
+ if (!-f File::Spec->catfile($geoip2_path, "maxminddb.h")) {
+ die "can't find maxminddb.h include\n";
}
- if (!-f File::Spec->catfile($geoip_path, "GeoIP.lib")) {
- die "can't find Geoip.lib library\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($geoip_path, "GeoIP.dll")) {
- die "can't find Geoip.dll DLL\n";
+ if (!-f File::Spec->catfile($geoip2_path, "libmaxminddb.lib")) {
+ die "can't find libmaxminddb.lib library\n";
}
- $configinc{"GEOIP_INC"} = "$geoip_path";
- my $geoip_lib = File::Spec->catfile($geoip_path, "GeoIP.lib");
- $configlib{"GEOIP_LIB"} = "$geoip_lib";
- my $geoip_dll = File::Spec->catfile($geoip_path, "GeoIP.dll");
- $configdll{"GEOIP_DLL"} = "$geoip_dll";
+ $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 GeoIP support\n";
- }
- my $ret = `copy "$geoip_dll" .`;
- if ($? != 0) {
- die "Can't copy GeoIP DLL to working directory: $ret\n";
- }
- open F, ">testgeoip.c" || die $!;
- print F << 'EOF';
-extern void *GeoIP_open();
-
-int main() {
- return GeoIP_open != 0;
-}
-EOF
- close F;
- $compret = `cl /nologo /MD testgeoip.c "$geoip_lib"`;
- if (grep { -f and -x } ".\\testgeoip.exe") {
- `.\\testgeoip.exe`;
- if ($? == 0) {
- die "GeoIP test failed\n";
- }
- } else {
- die "can't compile GeoIP test: $compret\n";
- }
- $configdefh{"HAVE_GEOIP"} = 1;
-
- if ($verbose) {
- print "checking for GeoIP Country IPv6 support\n";
- }
- my $geoip_inc = qq(/I "$geoip_path");
- my $geoip_libs = qq("$geoip_lib" ws2_32.lib);
- open F, ">testgeoip1.c" || die $!;
- print F << 'EOF';
-#include
-
-struct in6_addr in6;
-int flag = 1;
-
-int main() {
- if (flag)
- return 1;
- return GeoIP_country_name_by_ipnum_v6(NULL, in6) != NULL;
-}
-EOF
- close F;
- $compret = `cl /nologo $geoip_inc /MD testgeoip1.c $geoip_libs`;
- if (grep { -f and -x } ".\\testgeoip1.exe") {
- `.\\testgeoip1.exe`;
- if ($? == 0) {
- die "GeoIP Country IPv6 test failed\n";
- }
- } else {
- die "can't compile GeoIP Country IPv6 test: $compret\n";
- }
- $configdefh{"HAVE_GEOIP_V6"} = 1;
-
- if ($verbose) {
- print "checking for GeoIP City IPv6 support\n";
+ print "checking for GeoIP2 support\n";
}
open F, ">testgeoip2.c" || die $!;
print F << 'EOF';
-#include
-#include
-
-struct in6_addr in6;
-int i = GEOIP_CITY_EDITION_REV0_V6;
-int flag = 1;
-
-int main() {
- if (flag)
- return 1;
- return GeoIP_record_by_ipnum_v6(NULL, in6) != NULL;
+#include
+int main(void) {
+ return MMDB_lib_version() != 0;
}
EOF
close F;
- $compret = `cl /nologo $geoip_inc /MD testgeoip2.c $geoip_libs`;
+ $compret = `cl /nologo $geoip_inc /MD testgeoip2.c $geoip2_libs`;
if (grep { -f and -x } ".\\testgeoip2.exe") {
`.\\testgeoip2.exe`;
if ($? == 0) {
- die "GeoIP City IPv6 test failed\n";
+ die "GeoIP2 test failed\n";
}
} else {
- die "can't compile GeoIP City IPv6 test: $compret\n";
+ die "can't compile GeoIP2 test: $compret\n";
}
- $configdefh{"HAVE_GEOIP_CITY_V6"} = 1;
+ $configdefh{"HAVE_GEOIP2"} = 1;
}
# with-readline
@@ -2746,9 +2681,6 @@ sub makeinstallfile {
print LOUT "krb5_32.dll-BCFT\n";
}
}
- if ($use_geoip eq "yes") {
- print LOUT "libgeoip.dll-BCFT\n";
- }
if ($use_idn eq "yes") {
print LOUT "idnkit.dll-BCFT\n";
print LOUT "iconv.dll-BCFT\n";
@@ -2950,7 +2882,7 @@ exit 0;
# --with-aes supported
# --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