summaryrefslogtreecommitdiffstats
path: root/ipalib/util.py
diff options
context:
space:
mode:
authorMartin Basti <mbasti@redhat.com>2014-11-27 14:16:23 +0100
committerJan Cholasta <jcholast@redhat.com>2014-12-01 12:31:36 +0000
commitca25c92ea89661755d7204ac703e8c419c8929fa (patch)
tree4303e1c3b14cc12ecfc799f9d18fae0a0ceccb5a /ipalib/util.py
parent45dbd12d8886ca2025bcab5b10ec5e004af3d9ab (diff)
downloadfreeipa-ca25c92ea89661755d7204ac703e8c419c8929fa.tar.gz
freeipa-ca25c92ea89661755d7204ac703e8c419c8929fa.tar.xz
freeipa-ca25c92ea89661755d7204ac703e8c419c8929fa.zip
Throw zonemgr error message before installation proceeds
Ticket: https://fedorahosted.org/freeipa/ticket/4771 Reviewed-By: Jan Cholasta <jcholast@redhat.com>
Diffstat (limited to 'ipalib/util.py')
-rw-r--r--ipalib/util.py45
1 files changed, 45 insertions, 0 deletions
diff --git a/ipalib/util.py b/ipalib/util.py
index 7a283106d..2c17d80a0 100644
--- a/ipalib/util.py
+++ b/ipalib/util.py
@@ -28,6 +28,7 @@ import socket
import re
import decimal
import dns
+import encodings
import netaddr
from types import NoneType
from weakref import WeakKeyDictionary
@@ -277,6 +278,7 @@ def validate_zonemgr(zonemgr):
def validate_zonemgr_str(zonemgr):
zonemgr = normalize_zonemgr(zonemgr)
+ validate_idna_domain(zonemgr)
zonemgr = DNSName(zonemgr)
return validate_zonemgr(zonemgr)
@@ -589,3 +591,46 @@ def validate_dnssec_forwarder(ip_addr):
return False
return True
+
+
+def validate_idna_domain(value):
+ """
+ Validate if value is valid IDNA domain.
+
+ If domain is not valid, raises ValueError
+ :param value:
+ :return:
+ """
+ error = None
+
+ try:
+ DNSName(value)
+ except dns.name.BadEscape:
+ error = _('invalid escape code in domain name')
+ except dns.name.EmptyLabel:
+ error = _('empty DNS label')
+ except dns.name.NameTooLong:
+ error = _('domain name cannot be longer than 255 characters')
+ except dns.name.LabelTooLong:
+ error = _('DNS label cannot be longer than 63 characters')
+ except dns.exception.SyntaxError:
+ error = _('invalid domain name')
+ else:
+ #compare if IDN normalized and original domain match
+ #there is N:1 mapping between unicode and IDNA names
+ #user should use normalized names to avoid mistakes
+ labels = re.split(u'[.\uff0e\u3002\uff61]', value, flags=re.UNICODE)
+ try:
+ map(lambda label: label.encode("ascii"), labels)
+ except UnicodeError:
+ # IDNA
+ is_nonnorm = any(encodings.idna.nameprep(x) != x for x in labels)
+ if is_nonnorm:
+ error = _("domain name '%(domain)s' should be normalized to"
+ ": %(normalized)s") % {
+ 'domain': value,
+ 'normalized': '.'.join([encodings.idna.nameprep(x)
+ for x in labels])}
+
+ if error:
+ raise ValueError(error)