Skip to content

Commit

Permalink
[hostcfgd] hostcfgd will exit when set hostname in DEVICE_METADATA (s…
Browse files Browse the repository at this point in the history
…onic-net#3394)

Signed-off-by: ouxiaolong <ouxiaolong@asterfusion.com>
  • Loading branch information
ouxlwhu authored and jleveque committed Sep 25, 2019
1 parent 905d429 commit b6a0999
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions files/image_config/hostcfgd/hostcfgd
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,8 @@ TACPLUS_SERVER_TIMEOUT_DEFAULT = "5"
TACPLUS_SERVER_AUTH_TYPE_DEFAULT = "pap"


def is_valid_hostname(name):
if hostname[-1] == ".":
hostname = hostname[:-1] # strip exactly one dot from the right, if present
if len(hostname) > 253:
def is_valid_hostname(hostname):
if hostname[-1] == "." or len(hostname) > 253:
return False
allowed = re.compile("(?!-)[A-Z\d-]{1,63}(?<!-)$", re.IGNORECASE)
return all(allowed.match(x) for x in hostname.split("."))
Expand Down Expand Up @@ -267,6 +265,7 @@ class HostConfigDaemon:
syslog.syslog(syslog.LOG_WARNING, "hostname key is missing")
return
if not is_valid_hostname(hostname):
syslog.syslog(syslog.LOG_WARNING, "hostname {} is invalid".format(hostname))
return
if hostname == self.hostname_cache:
return
Expand Down

0 comments on commit b6a0999

Please sign in to comment.