From 3e3c18c8120bdd41793aefa0f6added6f46b5522 Mon Sep 17 00:00:00 2001 From: "Juan B. Rodriguez" Date: Sun, 15 Apr 2018 14:01:06 -0500 Subject: Implement regex to check for hostname syntax --- src/conf-mode/vyos-config-host-name.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/conf-mode/vyos-config-host-name.py b/src/conf-mode/vyos-config-host-name.py index a0e70b8ea..da053d9f6 100644 --- a/src/conf-mode/vyos-config-host-name.py +++ b/src/conf-mode/vyos-config-host-name.py @@ -25,6 +25,7 @@ from vyos.util import ConfigError hostname_config = "/etc/hostname" mailname_config = "/etc/mailname" +hostname_regex = re.compile("^[A-Za-z0-9][-.A-Za-z0-9]*[A-Za-z0-9]$") def get_config(): conf = Config() @@ -42,7 +43,9 @@ def verify(config): # check for invalid host # pattern $VAR(@) "^[[:alnum:]][-.[:alnum:]]*[[:alnum:]]$" ; "invalid host name $VAR(@)" - # TODO + valid = hostname_regex.match(config.hostname) + if (!valid): + raise ConfigError('invalid host name' + config.hostname) # pattern $VAR(@) "^.{1,63}$" ; "invalid host-name length" length = len(config.hostname) -- cgit v1.2.3