[hostcfgd] hostcfgd will exit when set hostname in DEVICE_METADATA (#3394)
Signed-off-by: ouxiaolong <ouxiaolong@asterfusion.com>
This commit is contained in:
parent
905d429022
commit
b6a09999de
@ -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("."))
|
||||
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user