From a747aabe3390c880437e1f2dd9fbf2efff90bb66 Mon Sep 17 00:00:00 2001 From: Newbyte Date: Wed, 12 Apr 2023 14:51:12 +0200 Subject: [PATCH] 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 Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20230412125112.55473-1-newbyte@postmarketos.org%3E --- pmb/helpers/other.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/pmb/helpers/other.py b/pmb/helpers/other.py index 602f08cb..91d3345c 100644 --- a/pmb/helpers/other.py +++ b/pmb/helpers/other.py @@ -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