summaryrefslogtreecommitdiffstats
path: root/ipalib/util.py
diff options
context:
space:
mode:
authorMartin Basti <mbasti@redhat.com>2014-01-31 15:42:31 +0100
committerMartin Kosek <mkosek@redhat.com>2014-02-11 17:21:11 +0100
commit8ede71fd8404a6e49e564a47b6dc7171d63cc8db (patch)
tree8dfb6b946bf935a27db75fa5251daa3446aca9ad /ipalib/util.py
parent11505d9bce3a375af7f22686ef2a9e3a3a70e397 (diff)
downloadfreeipa-8ede71fd8404a6e49e564a47b6dc7171d63cc8db.tar.gz
freeipa-8ede71fd8404a6e49e564a47b6dc7171d63cc8db.tar.xz
freeipa-8ede71fd8404a6e49e564a47b6dc7171d63cc8db.zip
DNS classless support for reverse domains
Now users can add reverse zones in classless form: 0/25.1.168.192.in-addr.arpa. 0-25.1.168.192.in-addr.arpa. 128/25 NS ns.example.com. 10 CNAME 10.128/25.1.168.192.in-addr.arpa. Ticket: https://fedorahosted.org/freeipa/ticket/4143 Reviewed-By: Jan Cholasta <jcholast@redhat.com>
Diffstat (limited to 'ipalib/util.py')
-rw-r--r--ipalib/util.py61
1 files changed, 36 insertions, 25 deletions
diff --git a/ipalib/util.py b/ipalib/util.py
index 1701fbdd1..fcc4b1591 100644
--- a/ipalib/util.py
+++ b/ipalib/util.py
@@ -215,34 +215,45 @@ def normalize_zone(zone):
else:
return zone
-def validate_dns_label(dns_label, allow_underscore=False):
- label_chars = r'a-z0-9'
- underscore_err_msg = ''
- if allow_underscore:
- label_chars += "_"
- underscore_err_msg = u' _,'
- label_regex = r'^[%(chars)s]([%(chars)s-]?[%(chars)s])*$' % dict(chars=label_chars)
- regex = re.compile(label_regex, re.IGNORECASE)
-
- if not dns_label:
- raise ValueError(_('empty DNS label'))
-
- if len(dns_label) > 63:
- raise ValueError(_('DNS label cannot be longer that 63 characters'))
-
- if not regex.match(dns_label):
- raise ValueError(_('only letters, numbers,%(underscore)s and - are allowed. ' \
- 'DNS label may not start or end with -') \
- % dict(underscore=underscore_err_msg))
-
-def validate_domain_name(domain_name, allow_underscore=False):
+
+def validate_dns_label(dns_label, allow_underscore=False, allow_slash=False):
+ base_chars = 'a-z0-9'
+ extra_chars = ''
+ middle_chars = ''
+
+ if allow_underscore:
+ extra_chars += '_'
+ if allow_slash:
+ middle_chars += '/'
+
+ middle_chars = middle_chars + '-' #has to be always the last in the regex [....-]
+
+ label_regex = r'^[%(base)s%(extra)s]([%(base)s%(extra)s%(middle)s]?[%(base)s%(extra)s])*$' \
+ % dict(base=base_chars, extra=extra_chars, middle=middle_chars)
+ regex = re.compile(label_regex, re.IGNORECASE)
+
+ if not dns_label:
+ raise ValueError(_('empty DNS label'))
+
+ if len(dns_label) > 63:
+ raise ValueError(_('DNS label cannot be longer that 63 characters'))
+
+ if not regex.match(dns_label):
+ chars = ', '.join("'%s'" % c for c in extra_chars + middle_chars)
+ chars2 = ', '.join("'%s'" % c for c in middle_chars)
+ raise ValueError(_("only letters, numbers, %(chars)s are allowed. " \
+ "DNS label may not start or end with %(chars2)s") \
+ % dict(chars=chars, chars2=chars2))
+
+
+def validate_domain_name(domain_name, allow_underscore=False, allow_slash=False):
if domain_name.endswith('.'):
domain_name = domain_name[:-1]
domain_name = domain_name.split(".")
# apply DNS name validator to every name part
- map(lambda label:validate_dns_label(label,allow_underscore), domain_name)
+ map(lambda label:validate_dns_label(label, allow_underscore, allow_slash), domain_name)
def validate_zonemgr(zonemgr):
@@ -287,7 +298,7 @@ def validate_zonemgr(zonemgr):
local_part.split(local_part_sep)):
raise ValueError(local_part_errmsg)
-def validate_hostname(hostname, check_fqdn=True, allow_underscore=False):
+def validate_hostname(hostname, check_fqdn=True, allow_underscore=False, allow_slash=False):
""" See RFC 952, 1123
:param hostname Checked value
@@ -305,9 +316,9 @@ def validate_hostname(hostname, check_fqdn=True, allow_underscore=False):
if '.' not in hostname:
if check_fqdn:
raise ValueError(_('not fully qualified'))
- validate_dns_label(hostname,allow_underscore)
+ validate_dns_label(hostname, allow_underscore, allow_slash)
else:
- validate_domain_name(hostname,allow_underscore)
+ validate_domain_name(hostname, allow_underscore, allow_slash)
def normalize_sshpubkey(value):
return SSHPublicKey(value).openssh()