mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2026-09-03 20:52:56 -05:00
Parse netmasks in IP addresses passed to server install.
ticket 1212
This commit is contained in:
committed by
Martin Kosek
parent
868d4e734e
commit
80b4b3d44b
+12
-1
@@ -18,7 +18,8 @@
|
||||
#
|
||||
|
||||
import ConfigParser
|
||||
from optparse import Option, Values, OptionParser, IndentedHelpFormatter
|
||||
from optparse import Option, Values, OptionParser, IndentedHelpFormatter, OptionValueError
|
||||
from copy import copy
|
||||
|
||||
import socket
|
||||
import ipapython.dnsclient
|
||||
@@ -46,12 +47,22 @@ class IPAFormatter(IndentedHelpFormatter):
|
||||
ret += "%s %s\n" % (spacing, line)
|
||||
return ret
|
||||
|
||||
def check_ip_option(option, opt, value):
|
||||
from ipapython.ipautil import CheckedIPAddress
|
||||
try:
|
||||
return CheckedIPAddress(value, parse_netmask=(option.type == "ipnet"))
|
||||
except Exception as e:
|
||||
raise OptionValueError("option %s: invalid IP address %s: %s" % (opt, value, e))
|
||||
|
||||
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")
|
||||
TYPE_CHECKER = copy(Option.TYPE_CHECKER)
|
||||
TYPE_CHECKER["ipaddr"] = TYPE_CHECKER["ipnet"] = check_ip_option
|
||||
|
||||
class IPAOptionParser(OptionParser):
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user