summaryrefslogtreecommitdiff
path: root/hscript
diff options
context:
space:
mode:
authorA. Wilcox <AWilcox@Wilcox-Tech.com>2019-10-19 20:01:14 -0500
committerA. Wilcox <AWilcox@Wilcox-Tech.com>2019-10-19 20:01:14 -0500
commitf1ef45bd84b57b40b701e094a9b49daac3761f9f (patch)
treea52df6f8dbd231b5ba07c28aa0cc7c8fda919480 /hscript
parent55325a6e780b121f93d35076e4226521ca13ef12 (diff)
downloadhorizon-f1ef45bd84b57b40b701e094a9b49daac3761f9f.tar.gz
horizon-f1ef45bd84b57b40b701e094a9b49daac3761f9f.tar.bz2
horizon-f1ef45bd84b57b40b701e094a9b49daac3761f9f.tar.xz
horizon-f1ef45bd84b57b40b701e094a9b49daac3761f9f.zip
hscript: Implement UserGroups, add tests
Diffstat (limited to 'hscript')
-rw-r--r--hscript/script.cc3
-rw-r--r--hscript/user.cc39
2 files changed, 39 insertions, 3 deletions
diff --git a/hscript/script.cc b/hscript/script.cc
index 8dbf9e1..0d1c10a 100644
--- a/hscript/script.cc
+++ b/hscript/script.cc
@@ -597,9 +597,10 @@ bool Script::validate() const {
})
) {
output_error("installfile:" + std::to_string(group->lineno()),
- "usergroups: group specified twice");
+ "usergroups: duplicate group name specified");
failures++;
}
+ seen_groups.insert(these.begin(), these.end());
}
/* REQ: Runner.Validate.usergroups.Count */
diff --git a/hscript/user.cc b/hscript/user.cc
index 04258e4..ec59a67 100644
--- a/hscript/user.cc
+++ b/hscript/user.cc
@@ -298,11 +298,46 @@ bool UserIcon::execute(ScriptOptions) const {
Key *UserGroups::parseFromData(const std::string &data, int lineno,
int *errors, int *warnings) {
- return nullptr;
+ /* REQ: Runner.Validate.usergroups.Validity */
+ const std::string::size_type sep = data.find_first_of(' ');
+ if(sep == std::string::npos || data.length() == sep + 1) {
+ if(errors) *errors += 1;
+ output_error("installfile:" + std::to_string(lineno),
+ "usergroups: at least one group is required",
+ "expected format is: usergroups [user] [group(,...)]");
+ return nullptr;
+ }
+
+ std::set<std::string> group_set;
+ char next_group[17];
+ std::istringstream stream(data.substr(sep + 1));
+ while(stream.getline(next_group, 17, ',')) {
+ std::string group(next_group);
+ /* REQ: Runner.Validate.usergroups.Group */
+ if(system_groups.find(group) == system_groups.end()) {
+ if(errors) *errors += 1;
+ output_error("installfile:" + std::to_string(lineno),
+ "usergroups: group name '" + group + "' is invalid",
+ "group is not a recognised system group");
+ return nullptr;
+ }
+ group_set.insert(group);
+ }
+ /* REQ: Runner.Validate.usergroups.Group */
+ if(stream.fail() && !stream.eof()) {
+ if(errors) *errors += 1;
+ output_error("installfile:" + std::to_string(lineno),
+ "usergroups: group name exceeds maximum length",
+ "groups may only be 16 characters or less");
+ return nullptr;
+ }
+
+ return new UserGroups(lineno, data.substr(0, sep), group_set);
}
bool UserGroups::validate(ScriptOptions) const {
- return false;
+ /* All validation is done in parsing stage */
+ return true;
}
bool UserGroups::execute(ScriptOptions) const {