浏览代码

Trac Ticket #46 - (additional 2) setup-ds-admin.pl does not like ipv6 only hostnames

https://fedorahosted.org/389/ticket/46

Fix description:
1) When Socket6 is used, if the same FQDN appears twice in
   /etc/hosts (e.g., localhost.localdomain for 127.0.0.1 and
   ::1), the result from getaddrinfo was not correctly shifted.
2) perl require takes package name. In the commit 850005499bd9-
   2c5b9b0027f944fcd33633c8db46, a tag ':addrinfo" was mistakenly
   passed and it was ignored.  This patch checks the version of
   Socket.  If it is greater than 2.000, getaddrinfo in the
   Socket module is used.  Otherwise, it falls back to Socket6.
Noriko Hosoi 13 年之前
父节点
当前提交
7ef6558922
共有 1 个文件被更改,包括 18 次插入8 次删除
  1. 18 8
      ldap/admin/src/scripts/DSUtil.pm.in

+ 18 - 8
ldap/admin/src/scripts/DSUtil.pm.in

@@ -58,17 +58,20 @@ require Exporter;
 
 use strict;
 
-use Socket;
+my $sockVersion;
 BEGIN {
-    if (eval {require Socket::addrinfo; 1}) {
-        import Socket qw (:addrinfo inet_ntoa 
-                          unpack_sockaddr_in unpack_sockaddr_in6 
-                          AF_INET INADDR_ANY 
-                          PF_INET SO_REUSEADDR SOCK_STREAM SOL_SOCKET);
+    use Socket;
+    $sockVersion = Socket->VERSION;
+    if ($sockVersion >= 2.000) {
+        import Socket qw ( :addrinfo inet_ntoa 
+                       unpack_sockaddr_in unpack_sockaddr_in6 
+                       AF_INET INADDR_ANY 
+                       PF_INET SO_REUSEADDR SOCK_STREAM SOL_SOCKET );
     } elsif (eval {require Socket6; 1}) {
         import Socket6 qw (getaddrinfo getnameinfo unpack_sockaddr_in6);
     }
 }
+$sockVersion = Socket->VERSION;
 use NetAddr::IP::Util qw( ipv6_n2x );
 
 use File::Temp qw(tempfile tempdir);
@@ -221,7 +224,8 @@ sub checkHostname {
     # see if we can resolve the hostname (IPv6 supported)
     my $found = 0;
     my @hostip = ();
-    if (eval {require Socket::addrinfo; 1}) {
+    if ($sockVersion >= 2.000) {
+        debug(1, "Socket version $sockVersion\n");
         my %hints = (socktype => SOCK_STREAM);
         my ($err, @aires) = getaddrinfo($hn, "ldap", \%hints);
         if ($err) {
@@ -249,6 +253,7 @@ sub checkHostname {
             }
         }
     } elsif (eval {require Socket6; 1}) {
+        debug(1, "Socket6\n");
         my @aires = getaddrinfo($hn, "ldap", AF_UNSPEC, SOCK_STREAM);
         if (scalar(@aires) < 5) {
             return $res->getText('warning_no_such_hostname', $hn);
@@ -256,7 +261,11 @@ sub checkHostname {
         my $ailen = scalar(@aires);
         while ($ailen >= 5) {
             debug(1, "found for hostname $hn\n");
-            my ($family, $socktype, $proto, $saddr, $canonname, @aires) = @aires;
+            my $family = shift @aires;
+            my $socktype = shift @aires;
+            my $proto = shift @aires;
+            my $saddr = shift @aires;
+            my $canonname = shift @aires;
             $ailen = scalar(@aires);
             my $ip;
             if ($family == AF_INET) {
@@ -277,6 +286,7 @@ sub checkHostname {
             }
         }
     } else {
+        debug(1, "gethostbyname ...\n");
         # see if we can resolve the hostname
         my ($name, $aliases, $addrtype, $length, @addrs) = gethostbyname($hn);
         if (!$name) {