From a6c6d0a42920fb9332f810e949fdf5fe20262f22 Mon Sep 17 00:00:00 2001 From: "A. Wilcox" Date: Tue, 8 Oct 2019 22:08:14 -0500 Subject: hscript: Use StringKey for Hostname (+ others), implement RootPassphrase --- hscript/CMakeLists.txt | 1 + hscript/meta.hh | 8 +++----- hscript/script.cc | 14 +++++++++++--- hscript/user.cc | 35 +++++++++++++++++++++++++++++++++++ hscript/user.hh | 14 +++++++++++--- 5 files changed, 61 insertions(+), 11 deletions(-) (limited to 'hscript') diff --git a/hscript/CMakeLists.txt b/hscript/CMakeLists.txt index 02ef574..a36bee5 100644 --- a/hscript/CMakeLists.txt +++ b/hscript/CMakeLists.txt @@ -3,6 +3,7 @@ set(HSCRIPT_SOURCE key.cc meta.cc network.cc + user.cc ) set(HSCRIPT_INCLUDE diff --git a/hscript/meta.hh b/hscript/meta.hh index 6515259..1db411d 100644 --- a/hscript/meta.hh +++ b/hscript/meta.hh @@ -20,15 +20,13 @@ namespace Horizon { namespace Keys { -class Hostname : public Key { +class Hostname : public StringKey { private: - const std::string _name; - Hostname(int _line, const std::string my_name) : Key(_line), - _name(my_name) {} + Hostname(int _line, const std::string my_name) : + StringKey(_line, my_name) {} public: static Key *parseFromData(const std::string data, int lineno, int *errors, int *warnings); - const std::string name() const { return this->_name; } bool validate() const override; bool execute() const override; }; diff --git a/hscript/script.cc b/hscript/script.cc index 69afb30..4d5a730 100644 --- a/hscript/script.cc +++ b/hscript/script.cc @@ -110,7 +110,7 @@ struct Script::ScriptPrivate { } else if(key_name == "hostname") { if(this->hostname) { DUPLICATE_ERROR(this->hostname, std::string("hostname"), - this->hostname->name()) + this->hostname->value()) return false; } std::unique_ptr name( @@ -133,8 +133,16 @@ struct Script::ScriptPrivate { delete install; return true; } else if(key_name == "rootpw") { - /*! TODO: implement */ - return false; + if(this->rootpw) { + DUPLICATE_ERROR(this->rootpw, std::string("rootpw"), + "an encrypted passphrase") + return false; + } + std::unique_ptr name( + dynamic_cast(key_obj) + ); + this->rootpw = std::move(name); + return true; } else if(key_name == "mount") { /*! TODO: implement */ return false; diff --git a/hscript/user.cc b/hscript/user.cc index e69de29..12d01fc 100644 --- a/hscript/user.cc +++ b/hscript/user.cc @@ -0,0 +1,35 @@ +/* + * user.cc - Implementation of the Key classes for user account data + * libhscript, the HorizonScript library for + * Project Horizon + * + * Copyright (c) 2019 Adélie Linux and contributors. All rights reserved. + * This code is licensed under the AGPL 3.0 license, as noted in the + * LICENSE-code file in the root directory of this repository. + * + * SPDX-License-Identifier: AGPL-3.0-only + */ + +#include "user.hh" +#include "util/output.hh" + +using namespace Horizon::Keys; + +Key *RootPassphrase::parseFromData(const std::string data, int lineno, + int *errors, int *warnings) { + if(data.size() < 5 || data[0] != '$' || data[2] != '$') { + if(errors) *errors += 1; + output_error("installfile:" + std::to_string(lineno), + "rootpw: value is not a crypt-style encrypted passphrase"); + return nullptr; + } + return new RootPassphrase(lineno, data); +} + +bool RootPassphrase::validate() const { + return false; +} + +bool RootPassphrase::execute() const { + return false; +} diff --git a/hscript/user.hh b/hscript/user.hh index 39a3eea..9bb1bd7 100644 --- a/hscript/user.hh +++ b/hscript/user.hh @@ -18,16 +18,24 @@ namespace Horizon { namespace Keys { -class RootPassphrase : public Key { +class RootPassphrase : public StringKey { +private: + RootPassphrase(int _line, const std::string my_pw) : + StringKey(_line, my_pw) {} +public: + static Key *parseFromData(const std::string data, int lineno, int *errors, + int *warnings); + bool validate() const override; + bool execute() const override; }; -class Username : public Key { +class Username : public StringKey { }; class UserAlias : public Key { }; -class UserPassphrase : public Key { +class UserPassphrase : public StringKey { }; class UserIcon : public Key { -- cgit v1.2.3-60-g2f50