diff options
author | Ted Trask <ttrask01@yahoo.com> | 2015-04-28 09:51:38 -0400 |
---|---|---|
committer | Ted Trask <ttrask01@yahoo.com> | 2015-04-28 09:51:38 -0400 |
commit | 71831dfc470e2aa9c3104294a8c2ca785a480cf8 (patch) | |
tree | 64796ed247212821d7143dd74d95635b4e24a88b | |
parent | 660ca1c7d242925642cb4ad89b77d7a852db0f7a (diff) | |
download | acf-alpine-baselayout-71831dfc470e2aa9c3104294a8c2ca785a480cf8.tar.bz2 acf-alpine-baselayout-71831dfc470e2aa9c3104294a8c2ca785a480cf8.tar.xz |
Implement hostname validation
-rw-r--r-- | hostname-model.lua | 12 |
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"}) |