diff --git a/spam/save_db.cgi b/spam/save_db.cgi
index 70c5f9864..e85644a70 100755
--- a/spam/save_db.cgi
+++ b/spam/save_db.cgi
@@ -17,7 +17,7 @@ if ($in{'mode'} == 0) {
}
elsif ($in{'mode'} == 1) {
# Database of some type
- gethostbyname($in{'dbhost'}) || &error($text{'db_edbhost'});
+ &to_ipaddress($in{'dbhost'}) || &error($text{'db_edbhost'});
$in{'dbdb'} =~ /^[a-z0-9\.\-\_]+$/ || &error($text{'db_edbdb'});
$in{'dbport_def'} || $in{'dbport'} =~ /^\d+$/ ||
&error($text{'db_edbport'});
@@ -26,7 +26,8 @@ elsif ($in{'mode'} == 1) {
}
elsif ($in{'mode'} == 3) {
# LDAP
- gethostbyname($in{'ldaphost'}) || &error($text{'db_eldaphost'});
+ &to_ipaddress($in{'ldaphost'}) || &to_ip6address($in{'ldaphost'}) ||
+ &error($text{'db_eldaphost'});
$in{'ldapport_def'} || $in{'ldapport'} =~ /^\d+$/ ||
&error($text{'db_eldapport'});
$in{'ldapdn'} =~ /^\S+$/ || &error($text{'db_eldapdn'});
diff --git a/spam/spam-lib.pl b/spam/spam-lib.pl
index e89f1ca3d..30791ba54 100755
--- a/spam/spam-lib.pl
+++ b/spam/spam-lib.pl
@@ -905,7 +905,11 @@ if ($@) {
return &text('connect_eldapmod', "Net::LDAP");
}
local $port = $config{'port'} || 389;
-local $ldap = Net::LDAP->new($config{'server'}, port => $port);
+local $inet6 = !&to_ipaddress($config{'server'}) &&
+ &to_ip6address($config{'server'});
+local $ldap = Net::LDAP->new($config{'server'},
+ port => $port,
+ inet6 => $inet6);
if (!$ldap) {
return &text('connect_eldap', "$config{'server'}", $port);
}