pgreco / rpms / ipa

Forked from forks/areguera/rpms/ipa 4 years ago
Clone

Blame SOURCES/0197-CheckedIPAddress-remove-match_local-param.patch

483b06
From c4482f0441e610c077d550c10b9525f97ea2f984 Mon Sep 17 00:00:00 2001
483b06
From: Martin Basti <mbasti@redhat.com>
483b06
Date: Wed, 14 Jun 2017 14:54:43 +0200
483b06
Subject: [PATCH] CheckedIPAddress: remove match_local param
483b06
483b06
This parameter is unused in code. We are no longer testing if IP address
483b06
matches an interface in constructor.
483b06
483b06
https://pagure.io/freeipa/issue/4317
483b06
483b06
Reviewed-By: David Kupka <dkupka@redhat.com>
483b06
---
483b06
 ipapython/config.py                     |  5 ++---
483b06
 ipapython/ipautil.py                    | 10 +---------
483b06
 ipaserver/install/installutils.py       |  2 +-
483b06
 ipaserver/plugins/dns.py                |  4 ++--
483b06
 ipaserver/plugins/host.py               |  2 +-
483b06
 ipatests/test_ipapython/test_ipautil.py |  3 +--
483b06
 6 files changed, 8 insertions(+), 18 deletions(-)
483b06
483b06
diff --git a/ipapython/config.py b/ipapython/config.py
483b06
index 9db2dcd4dbf3ed0fbe3e3166c3f0c5bae0f1716b..6349892fe88757629129f464401efce64e30f058 100644
483b06
--- a/ipapython/config.py
483b06
+++ b/ipapython/config.py
483b06
@@ -68,10 +68,9 @@ class IPAFormatter(IndentedHelpFormatter):
483b06
 def check_ip_option(option, opt, value):
483b06
     from ipapython.ipautil import CheckedIPAddress
483b06
 
483b06
-    ip_local = option.ip_local is True
483b06
     ip_netmask = option.ip_netmask is True
483b06
     try:
483b06
-        return CheckedIPAddress(value, parse_netmask=ip_netmask, match_local=ip_local)
483b06
+        return CheckedIPAddress(value, parse_netmask=ip_netmask)
483b06
     except Exception as e:
483b06
         raise OptionValueError("option %s: invalid IP address %s: %s" % (opt, value, e))
483b06
 
483b06
@@ -86,7 +85,7 @@ class IPAOption(Option):
483b06
     optparse.Option subclass with support of options labeled as
483b06
     security-sensitive such as passwords.
483b06
     """
483b06
-    ATTRS = Option.ATTRS + ["sensitive", "ip_local", "ip_netmask"]
483b06
+    ATTRS = Option.ATTRS + ["sensitive", "ip_netmask"]
483b06
     TYPES = Option.TYPES + ("ip", "dn")
483b06
     TYPE_CHECKER = copy(Option.TYPE_CHECKER)
483b06
     TYPE_CHECKER["ip"] = check_ip_option
483b06
diff --git a/ipapython/ipautil.py b/ipapython/ipautil.py
483b06
index 2c020e3ecbf4d8b969511a6dd9b36ee955ba1f15..5a6bf5a27d5a6e25c51fbaa6e2b1167652e2735d 100644
483b06
--- a/ipapython/ipautil.py
483b06
+++ b/ipapython/ipautil.py
483b06
@@ -135,7 +135,7 @@ class CheckedIPAddress(UnsafeIPAddress):
483b06
 
483b06
     Reserved or link-local addresses are never accepted.
483b06
     """
483b06
-    def __init__(self, addr, match_local=False, parse_netmask=True,
483b06
+    def __init__(self, addr, parse_netmask=True,
483b06
                  allow_loopback=False, allow_multicast=False):
483b06
         try:
483b06
             super(CheckedIPAddress, self).__init__(addr)
483b06
@@ -166,14 +166,6 @@ class CheckedIPAddress(UnsafeIPAddress):
483b06
         if not allow_multicast and self.is_multicast():
483b06
             raise ValueError("cannot use multicast IP address {}".format(addr))
483b06
 
483b06
-        if match_local:
483b06
-            intf_details = self.get_matching_interface()
483b06
-            if not intf_details:
483b06
-                raise ValueError('no network interface matches the IP address '
483b06
-                                 'and netmask {}'.format(addr))
483b06
-            else:
483b06
-                self.set_ip_net(intf_details.ifnet)
483b06
-
483b06
         if self._net is None:
483b06
             if self.version == 4:
483b06
                 self._net = netaddr.IPNetwork(
483b06
diff --git a/ipaserver/install/installutils.py b/ipaserver/install/installutils.py
483b06
index 3521d555914714351160213df60ed9167ac6e370..01930c4de6f0edd16b31aeba1c926fe581e9635b 100644
483b06
--- a/ipaserver/install/installutils.py
483b06
+++ b/ipaserver/install/installutils.py
483b06
@@ -585,7 +585,7 @@ def get_server_ip_address(host_name, unattended, setup_dns, ip_addresses):
483b06
     if len(hostaddr):
483b06
         for ha in hostaddr:
483b06
             try:
483b06
-                ips.append(ipautil.CheckedIPAddress(ha, match_local=False))
483b06
+                ips.append(ipautil.CheckedIPAddress(ha))
483b06
             except ValueError as e:
483b06
                 root_logger.warning("Invalid IP address %s for %s: %s", ha, host_name, unicode(e))
483b06
 
483b06
diff --git a/ipaserver/plugins/dns.py b/ipaserver/plugins/dns.py
483b06
index f0e6c48f06313def57cdd6a4c7114357c9d8de8a..f01baf515525c43824eddf06abc7af9fef228efe 100644
483b06
--- a/ipaserver/plugins/dns.py
483b06
+++ b/ipaserver/plugins/dns.py
483b06
@@ -567,7 +567,7 @@ def add_records_for_host_validation(option_name, host, domain, ip_addresses, che
483b06
     for ip_address in ip_addresses:
483b06
         try:
483b06
             ip = CheckedIPAddress(
483b06
-                ip_address, match_local=False, allow_multicast=True)
483b06
+                ip_address, allow_multicast=True)
483b06
         except Exception as e:
483b06
             raise errors.ValidationError(name=option_name, error=unicode(e))
483b06
 
483b06
@@ -599,7 +599,7 @@ def add_records_for_host(host, domain, ip_addresses, add_forward=True, add_rever
483b06
 
483b06
     for ip_address in ip_addresses:
483b06
         ip = CheckedIPAddress(
483b06
-            ip_address, match_local=False, allow_multicast=True)
483b06
+            ip_address, allow_multicast=True)
483b06
 
483b06
         if add_forward:
483b06
             add_forward_record(domain, host, unicode(ip))
483b06
diff --git a/ipaserver/plugins/host.py b/ipaserver/plugins/host.py
483b06
index 1e1f9d82dfdfcf9e7fef65ce729cd8ee7b76e605..364e5be6002eeb9c5e6b4c594b71f38169598227 100644
483b06
--- a/ipaserver/plugins/host.py
483b06
+++ b/ipaserver/plugins/host.py
483b06
@@ -245,7 +245,7 @@ def validate_ipaddr(ugettext, ipaddr):
483b06
     Verify that we have either an IPv4 or IPv6 address.
483b06
     """
483b06
     try:
483b06
-        CheckedIPAddress(ipaddr, match_local=False)
483b06
+        CheckedIPAddress(ipaddr)
483b06
     except Exception as e:
483b06
         return unicode(e)
483b06
     return None
483b06
diff --git a/ipatests/test_ipapython/test_ipautil.py b/ipatests/test_ipapython/test_ipautil.py
483b06
index 6427935b162b087c55e069cb2a576a7379cbe7a7..9c351bd0ed9cd96488ac74deadf97996668a75d2 100644
483b06
--- a/ipatests/test_ipapython/test_ipautil.py
483b06
+++ b/ipatests/test_ipapython/test_ipautil.py
483b06
@@ -30,11 +30,10 @@ from ipapython import ipautil
483b06
 
483b06
 pytestmark = pytest.mark.tier0
483b06
 
483b06
-
483b06
 def make_ipaddress_checker(addr, words=None, prefixlen=None):
483b06
     def check_ipaddress():
483b06
         try:
483b06
-            ip = ipautil.CheckedIPAddress(addr, match_local=False)
483b06
+            ip = ipautil.CheckedIPAddress(addr)
483b06
             assert ip.words == words and ip.prefixlen == prefixlen
483b06
         except Exception:
483b06
             assert words is None and prefixlen is None
483b06
-- 
483b06
2.9.4
483b06