summaryrefslogtreecommitdiff
path: root/hscript/meta.cc
diff options
context:
space:
mode:
authorA. Wilcox <AWilcox@Wilcox-Tech.com>2019-10-12 02:04:08 -0500
committerA. Wilcox <AWilcox@Wilcox-Tech.com>2019-10-12 02:04:08 -0500
commitc9ac06657ecf79c5c7bada112a6fc67f87fbcba1 (patch)
treebc25d100c40829d3d4a9a514a7d78985ca798adb /hscript/meta.cc
parentc3bd806edc816ce176e507394250163aab9c7365 (diff)
downloadhorizon-c9ac06657ecf79c5c7bada112a6fc67f87fbcba1.tar.gz
horizon-c9ac06657ecf79c5c7bada112a6fc67f87fbcba1.tar.bz2
horizon-c9ac06657ecf79c5c7bada112a6fc67f87fbcba1.tar.xz
horizon-c9ac06657ecf79c5c7bada112a6fc67f87fbcba1.zip
hscript: Validate 'hostname' keys and add another test
Diffstat (limited to 'hscript/meta.cc')
-rw-r--r--hscript/meta.cc31
1 files changed, 30 insertions, 1 deletions
diff --git a/hscript/meta.cc b/hscript/meta.cc
index 84e026e..5897c8b 100644
--- a/hscript/meta.cc
+++ b/hscript/meta.cc
@@ -31,7 +31,36 @@ Key *Hostname::parseFromData(const std::string data, int lineno, int *errors,
bool Hostname::validate(ScriptOptions) const {
/* Validate that the name is a valid machine or DNS name */
- return false;
+ bool any_failure = false;
+ std::string::size_type last_dot = 0, next_dot = 0;
+
+ if(!isalpha(this->_value[0])) {
+ any_failure = true;
+ output_error("installfile:" + std::to_string(this->lineno()),
+ "hostname: must start with alphabetical character");
+ }
+
+ if(this->_value.size() > 320) {
+ any_failure = true;
+ output_error("installfile:" + std::to_string(this->lineno()),
+ "hostname: value too long",
+ "valid host names must be less than 320 characters");
+ }
+
+ do {
+ next_dot = this->_value.find_first_of('.', next_dot + 1);
+ if(next_dot == std::string::npos) {
+ next_dot = this->_value.size();
+ }
+ if(next_dot - last_dot > 64) {
+ any_failure = true;
+ output_error("installfile:" + std::to_string(this->lineno()),
+ "hostname: component too long",
+ "each component must be less than 64 characters");
+ }
+ } while(next_dot != this->_value.size());
+
+ return any_failure;
}
bool Hostname::execute(ScriptOptions) const {