summaryrefslogtreecommitdiff
path: root/hscript/meta.cc
diff options
context:
space:
mode:
authorA. Wilcox <AWilcox@Wilcox-Tech.com>2019-10-14 12:24:04 -0500
committerA. Wilcox <AWilcox@Wilcox-Tech.com>2019-10-14 12:24:04 -0500
commitaacaf526065b0a138b0c65b421c92c4c6562c810 (patch)
tree0bacc3ad446a593dc9041aa7d9cd2997d30d653b /hscript/meta.cc
parent3f0108072f60c3cbf8ba6c59f6c8062ee50cf0de (diff)
downloadhorizon-aacaf526065b0a138b0c65b421c92c4c6562c810.tar.gz
horizon-aacaf526065b0a138b0c65b421c92c4c6562c810.tar.bz2
horizon-aacaf526065b0a138b0c65b421c92c4c6562c810.tar.xz
horizon-aacaf526065b0a138b0c65b421c92c4c6562c810.zip
hscript: Handle dots correctly in Hostname::validate
Diffstat (limited to 'hscript/meta.cc')
-rw-r--r--hscript/meta.cc5
1 files changed, 3 insertions, 2 deletions
diff --git a/hscript/meta.cc b/hscript/meta.cc
index 1234350..994278c 100644
--- a/hscript/meta.cc
+++ b/hscript/meta.cc
@@ -60,6 +60,7 @@ bool Hostname::validate(ScriptOptions) const {
"hostname: component too long",
"each component must be less than 64 characters");
}
+ last_dot = next_dot;
} while(next_dot != this->_value.size());
return !any_failure;
@@ -68,19 +69,19 @@ bool Hostname::validate(ScriptOptions) const {
bool Hostname::execute(ScriptOptions opts) const {
/* Set the hostname of the target computer */
std::string actual;
+ std::string::size_type dot = this->_value.find_first_of('.');
if(this->_value.size() > 64) {
/* Linux has a nodename limit of 64 characters.
* That's fine, because we have a limit of 64 chars per segment.
* Assuming a dot is present, just chop at the first dot. */
- std::string::size_type dot = this->_value.find_first_of('.');
if(dot == std::string::npos || dot >= 64) {
output_error("installfile:" + std::to_string(this->lineno()),
"hostname: nodename too long",
"Linux requires nodename to be <= 64 characters.");
return false;
}
- std::copy_n(this->_value.cbegin(), dot - 1, actual.begin());
+ actual = this->_value.substr(0, dot);
} else {
actual = this->_value;
}