Blame SOURCES/perl-ldap-0.68-Do-not-default-IO-Socket-IP-to-AI_ADDRCONFIG-flag.patch

50c90e
From 957a39309fa2f8a85a6b8a0a2c5b1751a151cb8b Mon Sep 17 00:00:00 2001
50c90e
From: =?UTF-8?q?Petr=20P=C3=ADsa=C5=99?= <ppisar@redhat.com>
50c90e
Date: Tue, 16 Feb 2021 15:29:58 +0100
50c90e
Subject: [PATCH] Do not default IO::Socket::IP to AI_ADDRCONFIG flag
50c90e
MIME-Version: 1.0
50c90e
Content-Type: text/plain; charset=UTF-8
50c90e
Content-Transfer-Encoding: 8bit
50c90e
50c90e
t/40connect.t fails if the only available network interface is
50c90e
loopback and IO::Socket::IP is installed:
50c90e
50c90e
    # perl -Ilib -I. t/40connect.t
50c90e
    1..3
50c90e
    ok 1 - client with IPv4/IPv6 auto-selection, bound to ::1
50c90e
    ldap://localhost:9009/ Name or service not known at t/common.pl line 157.
50c90e
    # Looks like your test exited with 22 just after 1.
50c90e
50c90e
The reason is that IO::Socket::IP by default resolves host names with
50c90e
AI_ADDRCONFIG flag and in the particular case (no interfaces other
50c90e
than loopback) a system resolver (glibc in my case) hides both IPv4
50c90e
and IPv6 addreses of the hostname (e.g. localhost).
50c90e
50c90e
See <https://rt.cpan.org/Ticket/Display.html?id=104793> for more
50c90e
details.
50c90e
50c90e
I applied a workaround similar to one found in IO-Socket-SSL.
50c90e
I believe that other Socket implementations perl-ldap can use do not
50c90e
suffer from this problem.
50c90e
50c90e
Signed-off-by: Petr Písař <ppisar@redhat.com>
50c90e
---
50c90e
 lib/Net/LDAP.pm | 3 +++
50c90e
 1 file changed, 3 insertions(+)
50c90e
50c90e
diff --git a/lib/Net/LDAP.pm b/lib/Net/LDAP.pm
50c90e
index 5dfe3e3..be11d12 100644
50c90e
--- a/lib/Net/LDAP.pm
50c90e
+++ b/lib/Net/LDAP.pm
50c90e
@@ -167,6 +167,9 @@ sub connect_ldap {
50c90e
     LocalAddr  => $arg->{localaddr} || undef,
50c90e
     Proto      => 'tcp',
50c90e
     ($class eq 'IO::Socket::IP' ? 'Family' : 'Domain')     => $domain,
50c90e
+    # Work around IO::Socket::IP defaulting to AI_ADDRCONFIG which breaks
50c90e
+    # resolution if only a loopback interface is available. CPAN RT#104793.
50c90e
+    ($class eq 'IO::Socket::IP' and $domain ne AF_UNSPEC ? ('GetAddrInfoFlags' => 0) : ()),
50c90e
     MultiHomed => $arg->{multihomed},
50c90e
     Timeout    => defined $arg->{timeout}
50c90e
 		 ? $arg->{timeout}
50c90e
-- 
50c90e
2.26.2
50c90e