summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--hostname-model.lua12
1 files changed, 12 insertions, 0 deletions
diff --git a/hostname-model.lua b/hostname-model.lua
index 8e20707..31c3e84 100644
--- a/hostname-model.lua
+++ b/hostname-model.lua
@@ -27,6 +27,18 @@ end
mymodule.update_name = function(self, name)
local success = true
+ -- Hostname must be less than 64 characters, characters in set 0-9a-z-, and not start/end with -
+ if string.len(name.value.hostname.value) == 0 or string.len(name.value.hostname.value) > 63 then
+ name.value.hostname.errtxt = "Illegal length"
+ success = false
+ elseif string.find(name.value.hostname.value, "[^-0-9a-zA-Z]") then
+ name.value.hostname.errtxt = "Contains illegal character"
+ success = false
+ elseif string.find(name.value.hostname.value, "^-") or string.find(name.value.hostname.value, "-$") then
+ name.value.hostname.errtxt = "Illegal start/end character"
+ success = false
+ end
+
if success then
fs.write_file("/etc/hostname", name.value.hostname.value)
modelfunctions.run_executable({"hostname", "-F", "/etc/hostname"})