diff options
author | Juan B. Rodriguez <jbrodriguez@gmail.com> | 2018-04-15 14:01:06 -0500 |
---|---|---|
committer | Juan B. Rodriguez <jbrodriguez@gmail.com> | 2018-04-15 14:01:06 -0500 |
commit | 3e3c18c8120bdd41793aefa0f6added6f46b5522 (patch) | |
tree | db12f804d4bb0dbc782a3cadb335a79a46d44391 /src/conf-mode | |
parent | e309f63b8404f32336333f995e0526dc68638a7c (diff) | |
download | vyos-1x-3e3c18c8120bdd41793aefa0f6added6f46b5522.tar.gz vyos-1x-3e3c18c8120bdd41793aefa0f6added6f46b5522.zip |
Implement regex to check for hostname syntax
Diffstat (limited to 'src/conf-mode')
-rw-r--r-- | src/conf-mode/vyos-config-host-name.py | 5 |
1 files changed, 4 insertions, 1 deletions
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) |