summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Babinsky <mbabinsk@redhat.com>2016-07-04 12:43:08 +0200
committerMartin Basti <mbasti@redhat.com>2016-07-20 16:23:24 +0200
commit15cfd0ee20fd05735473d3677b6f9f349339197e (patch)
treea6998b272664ba78c7d4511a77eb45431b914d75
parentf0a61546f552d4df887617167f7dc1378cb95083 (diff)
downloadfreeipa-15cfd0ee20fd05735473d3677b6f9f349339197e.tar.gz
freeipa-15cfd0ee20fd05735473d3677b6f9f349339197e.tar.xz
freeipa-15cfd0ee20fd05735473d3677b6f9f349339197e.zip
allow multiple dashes in the components of server hostname
Relax the check for valid hostname component by allowing multiple consecutive '-' or '/' characters int he middle of the label (the first/last character must still be alphanumeric or underscore). Also use verbose regex format to document its structure. https://fedorahosted.org/freeipa/ticket/4710 Reviewed-By: Martin Basti <mbasti@redhat.com>
-rw-r--r--ipalib/util.py13
1 files changed, 10 insertions, 3 deletions
diff --git a/ipalib/util.py b/ipalib/util.py
index d101514ca..0cd5c091e 100644
--- a/ipalib/util.py
+++ b/ipalib/util.py
@@ -194,9 +194,16 @@ def validate_dns_label(dns_label, allow_underscore=False, allow_slash=False):
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)
+ label_regex = r'''^[%(base)s%(extra)s] # must begin with an alphanumeric
+ # character, or underscore if
+ # allow_underscore is True
+ ([%(base)s%(extra)s%(middle)s]* # can contain all allowed character
+ # classes in the middle
+ [%(base)s%(extra)s])*$ # must end with alphanumeric
+ # character or underscore if
+ # allow_underscore is True
+ ''' % dict(base=base_chars, extra=extra_chars, middle=middle_chars)
+ regex = re.compile(label_regex, re.IGNORECASE | re.VERBOSE)
if not dns_label:
raise ValueError(_('empty DNS label'))