From 2374778a55f9380ee5b821eb9563e20aad1bc3de Mon Sep 17 00:00:00 2001 From: "A. Wilcox" Date: Fri, 18 Oct 2019 23:24:48 -0500 Subject: hscript: More LCOV fixes --- hscript/network.cc | 63 +++++++++++++++++++++++++++++------------------------- hscript/user.cc | 4 ++-- 2 files changed, 36 insertions(+), 31 deletions(-) diff --git a/hscript/network.cc b/hscript/network.cc index 1197944..0921aaf 100644 --- a/hscript/network.cc +++ b/hscript/network.cc @@ -37,6 +37,7 @@ bool Network::execute(ScriptOptions) const { return true; } + Key *NetAddress::parseFromData(const std::string &data, int lineno, int *errors, int *warnings) { long elements = std::count(data.cbegin(), data.cend(), ' ') + 1; @@ -226,6 +227,7 @@ bool NetAddress::execute(ScriptOptions) const { return false; } + Key *NetSSID::parseFromData(const std::string &data, int lineno, int *errors, int *warnings) { std::string iface, ssid, secstr, passphrase; @@ -311,40 +313,43 @@ Key *NetSSID::parseFromData(const std::string &data, int lineno, int *errors, } bool NetSSID::validate(ScriptOptions options) const { - /* Runner.Validate.network.netssid.Interface */ - if(options.test(InstallEnvironment)) { - struct iwreq request; - int my_sock = ::socket(AF_INET, SOCK_STREAM, 0); - if(my_sock == -1) { + /* REQ: Runner.Validate.network.netssid.Interface */ + if(!options.test(InstallEnvironment)) { + return true; + } + + /* LCOV_EXCL_START */ + struct iwreq request; + int my_sock = ::socket(AF_INET, SOCK_STREAM, 0); + if(my_sock == -1) { + output_error("installfile:" + std::to_string(this->lineno()), + "netssid: can't open socket", ::strerror(errno)); + return false; + } + memset(&request, 0, sizeof(request)); + memcpy(&request.ifr_ifrn.ifrn_name, this->_iface.c_str(), + this->_iface.size()); + errno = 0; + if(ioctl(my_sock, SIOCGIWNAME, &request) == -1) { + switch(errno) + { + case EOPNOTSUPP: + output_warning("installfile:" + std::to_string(this->lineno()), + "netssid: specified interface is not wireless"); + return true; + case ENODEV: + output_warning("installfile:" + std::to_string(this->lineno()), + "netssid: specified interface does not exist"); + return true; + default: output_error("installfile:" + std::to_string(this->lineno()), - "netssid: can't open socket", ::strerror(errno)); + "netssid: error communicating with wireless device"); return false; } - memset(&request, 0, sizeof(request)); - memcpy(&request.ifr_ifrn.ifrn_name, this->_iface.c_str(), - this->_iface.size()); - errno = 0; - if(ioctl(my_sock, SIOCGIWNAME, &request) == -1) { - switch(errno) - { - case EOPNOTSUPP: - output_warning("installfile:" + std::to_string(this->lineno()), - "netssid: interface specified is not wireless"); - return true; - case ENODEV: - output_warning("installfile:" + std::to_string(this->lineno()), - "netssid: specified interface does not exist"); - return true; - default: - output_error("installfile:" + std::to_string(this->lineno()), - "netssid: error communicating with wireless device"); - return false; - } - } - ::close(my_sock); - return true; } + ::close(my_sock); return true; + /* LCOV_EXCL_STOP */ } bool NetSSID::execute(ScriptOptions) const { diff --git a/hscript/user.cc b/hscript/user.cc index 8382f1c..9bc6864 100644 --- a/hscript/user.cc +++ b/hscript/user.cc @@ -132,6 +132,8 @@ bool RootPassphrase::execute(ScriptOptions options) const { return true; } + /* LCOV_EXCL_START */ + /* This was tested on gwyn during development. */ std::ifstream old_shadow("/target/etc/shadow"); if(!old_shadow) { output_error("installfile:" + std::to_string(this->lineno()), @@ -139,8 +141,6 @@ bool RootPassphrase::execute(ScriptOptions options) const { return false; } - /* LCOV_EXCL_START */ - /* This was tested on gwyn during development. */ std::stringstream shadow_stream; char shadow_line[200]; /* Discard root. */ -- cgit v1.2.3-70-g09d2