Implements a way to pass match_local and parse_netmask parameters
to IP option checker.

Now, there is just one common option type "ip" with new optional
attributes "ip_local" and "ip_netmask" which can be used to
pass IP address validation parameters.

https://fedorahosted.org/freeipa/ticket/1333

>From 8c6dd974cd734109e06c9cd1ca45bf8b09310793 Mon Sep 17 00:00:00 2001
From: Martin Kosek <mko...@redhat.com>
Date: Thu, 16 Jun 2011 10:47:11 +0200
Subject: [PATCH] Improve IP address handling in IPA option parser

Implements a way to pass match_local and parse_netmask parameters
to IP option checker.

Now, there is just one common option type "ip" with new optional
attributes "ip_local" and "ip_netmask" which can be used to
pass IP address validation parameters.

https://fedorahosted.org/freeipa/ticket/1333
---
 install/tools/ipa-dns-install     |    4 ++--
 install/tools/ipa-replica-install |    2 +-
 install/tools/ipa-replica-prepare |    3 ++-
 install/tools/ipa-server-install  |    5 +++--
 ipapython/config.py               |   11 +++++++----
 5 files changed, 15 insertions(+), 10 deletions(-)

diff --git a/install/tools/ipa-dns-install b/install/tools/ipa-dns-install
index 39998ac47b02244aaec1d09a14980db25ec636f4..b5295b5c7567c3d559ad808d1752d79c1d915573 100755
--- a/install/tools/ipa-dns-install
+++ b/install/tools/ipa-dns-install
@@ -38,9 +38,9 @@ def parse_options():
     parser.add_option("-d", "--debug", dest="debug", action="store_true",
                       default=False, help="print debugging information")
     parser.add_option("--ip-address", dest="ip_address",
-                      type="ipnet", help="Master Server IP Address")
+                      type="ip", ip_netmask=True, ip_local=True, help="Master Server IP Address")
     parser.add_option("--forwarder", dest="forwarders", action="append",
-                      type="ipaddr", help="Add a DNS forwarder")
+                      type="ip", help="Add a DNS forwarder")
     parser.add_option("--no-forwarders", dest="no_forwarders", action="store_true",
                       default=False, help="Do not add any DNS forwarders, use root servers instead")
     parser.add_option("--no-reverse", dest="no_reverse",
diff --git a/install/tools/ipa-replica-install b/install/tools/ipa-replica-install
index f91ac51a60f848f57e5820d609ef6c6356ed5246..c39d992de8c42a1d1e1e641e541aacb705946d40 100755
--- a/install/tools/ipa-replica-install
+++ b/install/tools/ipa-replica-install
@@ -64,7 +64,7 @@ def parse_options():
     parser.add_option("--setup-dns", dest="setup_dns", action="store_true",
                       default=False, help="configure bind with our zone")
     parser.add_option("--forwarder", dest="forwarders", action="append",
-                      type="ipaddr", help="Add a DNS forwarder")
+                      type="ip", help="Add a DNS forwarder")
     parser.add_option("--no-forwarders", dest="no_forwarders", action="store_true",
                       default=False, help="Do not add any DNS forwarders, use root servers instead")
     parser.add_option("--no-reverse", dest="no_reverse", action="store_true",
diff --git a/install/tools/ipa-replica-prepare b/install/tools/ipa-replica-prepare
index 8117bfcddc32a826869973485718c63875df76e1..97dd96a19befe3740bfde5fa8e1ab062c875c583 100755
--- a/install/tools/ipa-replica-prepare
+++ b/install/tools/ipa-replica-prepare
@@ -54,7 +54,8 @@ def parse_options():
     parser.add_option("-p", "--password", dest="password", 
                       help="Directory Manager (existing master) password")
     parser.add_option("--ip-address", dest="ip_address",
-                      type="ipnet", help="Add A and PTR records of the future replica")
+                      type="ip", ip_netmask=True,
+                      help="Add A and PTR records of the future replica")
     parser.add_option("--ca", dest="ca_file", default="/root/cacert.p12",
                       help="Location of CA PKCS#12 file, default /root/cacert.p12")
     parser.add_option("--no-pkinit", dest="setup_pkinit", action="store_false",
diff --git a/install/tools/ipa-server-install b/install/tools/ipa-server-install
index 8fb13a3a76819b7b34b0b7196409d950c3737e6d..886d391a26664faedb8fda084f4dd90ed5540e90 100755
--- a/install/tools/ipa-server-install
+++ b/install/tools/ipa-server-install
@@ -100,11 +100,12 @@ def parse_options():
                       help="File containing PKCS#10 of the external CA chain")
     parser.add_option("--hostname", dest="host_name", help="fully qualified name of server")
     parser.add_option("--ip-address", dest="ip_address",
-                      type="ipnet", help="Master Server IP Address")
+                      type="ip", ip_netmask=True, ip_local=True,
+                      help="Master Server IP Address")
     parser.add_option("--setup-dns", dest="setup_dns", action="store_true",
                       default=False, help="configure bind with our zone")
     parser.add_option("--forwarder", dest="forwarders", action="append",
-                      type="ipaddr", help="Add a DNS forwarder")
+                      type="ip", help="Add a DNS forwarder")
     parser.add_option("--no-forwarders", dest="no_forwarders", action="store_true",
                       default=False, help="Do not add any DNS forwarders, use root servers instead")
     parser.add_option("--no-reverse", dest="no_reverse", action="store_true",
diff --git a/ipapython/config.py b/ipapython/config.py
index c78508541b497770bf596c46f314a5e52b8c9eba..051e39f92c8c0a8289c0bfdf8a53ad761c0457f6 100644
--- a/ipapython/config.py
+++ b/ipapython/config.py
@@ -49,8 +49,11 @@ class IPAFormatter(IndentedHelpFormatter):
 
 def check_ip_option(option, opt, value):
     from ipapython.ipautil import CheckedIPAddress
+
+    ip_local = option.ip_local is True
+    ip_netmask = option.ip_netmask is True
     try:
-        return CheckedIPAddress(value, parse_netmask=(option.type == "ipnet"))
+        return CheckedIPAddress(value, parse_netmask=ip_netmask, match_local=ip_local)
     except Exception as e:
         raise OptionValueError("option %s: invalid IP address %s: %s" % (opt, value, e))
 
@@ -59,10 +62,10 @@ class IPAOption(Option):
     optparse.Option subclass with support of options labeled as
     security-sensitive such as passwords.
     """
-    ATTRS = Option.ATTRS + ["sensitive"]
-    TYPES = Option.TYPES + ("ipaddr", "ipnet")
+    ATTRS = Option.ATTRS + ["sensitive", "ip_local", "ip_netmask"]
+    TYPES = Option.TYPES + ("ip",)
     TYPE_CHECKER = copy(Option.TYPE_CHECKER)
-    TYPE_CHECKER["ipaddr"] = TYPE_CHECKER["ipnet"] = check_ip_option
+    TYPE_CHECKER["ip"] = check_ip_option
 
 class IPAOptionParser(OptionParser):
     """
-- 
1.7.5.2

_______________________________________________
Freeipa-devel mailing list
Freeipa-devel@redhat.com
https://www.redhat.com/mailman/listinfo/freeipa-devel

Reply via email to