summaryrefslogtreecommitdiffstats
path: root/ipalib
diff options
context:
space:
mode:
Diffstat (limited to 'ipalib')
-rw-r--r--ipalib/constants.py1
-rw-r--r--ipalib/util.py53
2 files changed, 54 insertions, 0 deletions
diff --git a/ipalib/constants.py b/ipalib/constants.py
index 05ba1adbb..bcddb5b97 100644
--- a/ipalib/constants.py
+++ b/ipalib/constants.py
@@ -123,6 +123,7 @@ DEFAULT_CONFIG = (
('container_caacl', DN(('cn', 'caacls'), ('cn', 'ca'))),
('container_locations', DN(('cn', 'locations'), ('cn', 'etc'))),
('container_ca', DN(('cn', 'cas'), ('cn', 'ca'))),
+ ('container_dnsservers', DN(('cn', 'servers'), ('cn', 'dns'))),
# Ports, hosts, and URIs:
('xmlrpc_uri', 'http://localhost:8888/ipa/xml'),
diff --git a/ipalib/util.py b/ipalib/util.py
index 4b5f11509..68d11fc6c 100644
--- a/ipalib/util.py
+++ b/ipalib/util.py
@@ -898,3 +898,56 @@ class classproperty(object):
def getter(self, fget):
self.fget = fget
return self
+
+
+def normalize_hostname(hostname):
+ """Use common fqdn form without the trailing dot"""
+ if hostname.endswith(u'.'):
+ hostname = hostname[:-1]
+ hostname = hostname.lower()
+ return hostname
+
+
+def hostname_validator(ugettext, value):
+ try:
+ validate_hostname(value)
+ except ValueError as e:
+ return _('invalid domain-name: %s') % unicode(e)
+
+ return None
+
+
+def ipaddr_validator(ugettext, ipaddr, ip_version=None):
+ try:
+ ip = netaddr.IPAddress(str(ipaddr), flags=netaddr.INET_PTON)
+
+ if ip_version is not None:
+ if ip.version != ip_version:
+ return _(
+ 'invalid IP address version (is %(value)d, must be '
+ '%(required_value)d)!') % dict(
+ value=ip.version,
+ required_value=ip_version
+ )
+ except (netaddr.AddrFormatError, ValueError):
+ return _('invalid IP address format')
+ return None
+
+
+def validate_bind_forwarder(ugettext, forwarder):
+ ip_address, sep, port = forwarder.partition(u' port ')
+
+ ip_address_validation = ipaddr_validator(ugettext, ip_address)
+
+ if ip_address_validation is not None:
+ return ip_address_validation
+
+ if sep:
+ try:
+ port = int(port)
+ if port < 0 or port > 65535:
+ raise ValueError()
+ except ValueError:
+ return _('%(port)s is not a valid port' % dict(port=port))
+
+ return None