pmb.helpers.other.validate_hostname: allow periods

According to the linked Wikipedia article, "Hostnames are composed
of a sequence of labels concatenated with dots". As such, allow
periods (dots) in our hostname validation function.

Reviewed-by: Oliver Smith <ollieparanoid@postmarketos.org>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20230412125112.55473-1-newbyte@postmarketos.org%3E
This commit is contained in:
Newbyte 2023-04-12 14:51:12 +02:00 committed by Oliver Smith
parent 89cbae6d31
commit a747aabe33
No known key found for this signature in database
GPG Key ID: 5AE7F5513E0885CB
1 changed files with 6 additions and 5 deletions

View File

@ -267,16 +267,17 @@ def validate_hostname(hostname):
return False
# Check that it only contains valid chars
if not re.match("^[0-9a-z-]*$", hostname):
if not re.match(r"^[0-9a-z-\.]*$", hostname):
logging.fatal("ERROR: Hostname must only contain letters (a-z),"
" digits (0-9) or minus signs (-)")
" digits (0-9), minus signs (-), or periods (.)")
return False
# Check that doesn't begin or end with a minus sign
if hostname[:1] == "-" or hostname[-1:] == "-":
# Check that doesn't begin or end with a minus sign or period
if re.search(r"^-|^\.|-$|\.$", hostname):
logging.fatal("ERROR: Hostname must not begin or end with a minus"
" sign")
" sign or period")
return False
return True