diff options
author | A. Wilcox <AWilcox@Wilcox-Tech.com> | 2019-10-24 01:34:51 -0500 |
---|---|---|
committer | A. Wilcox <AWilcox@Wilcox-Tech.com> | 2019-10-24 01:34:51 -0500 |
commit | 30b63f19fedde7b60bf99f3a68c0437a0c93b64e (patch) | |
tree | b47af6071422452d35f864c089f9c08a0a72fac2 | |
parent | 725e3f9f0c401aa34bb0d3d01bb8119797d038f7 (diff) | |
download | horizon-30b63f19fedde7b60bf99f3a68c0437a0c93b64e.tar.gz horizon-30b63f19fedde7b60bf99f3a68c0437a0c93b64e.tar.bz2 horizon-30b63f19fedde7b60bf99f3a68c0437a0c93b64e.tar.xz horizon-30b63f19fedde7b60bf99f3a68c0437a0c93b64e.zip |
hscript: Finally implement R.V.network.netaddress.Interface
-rw-r--r-- | hscript/network.cc | 31 | ||||
-rw-r--r-- | tests/fixtures/0064-netssid-simple-wpa.installfile | 1 |
2 files changed, 30 insertions, 2 deletions
diff --git a/hscript/network.cc b/hscript/network.cc index e8f27b9..14e33b4 100644 --- a/hscript/network.cc +++ b/hscript/network.cc @@ -231,8 +231,35 @@ Key *NetAddress::parseFromData(const std::string &data, int lineno, int *errors, } } -bool NetAddress::validate(ScriptOptions) const { - /* possible to validate an address in the Installation Environment? */ +bool NetAddress::validate(ScriptOptions opts) const { + if(!opts.test(InstallEnvironment)) { + return true; + } + +#ifdef HAS_INSTALL_ENV + /* Retrieving the index is always valid, and is not even privileged. */ + struct ifreq request; + int my_sock = ::socket(AF_INET, SOCK_STREAM, 0); + if(my_sock == -1) { + output_error("installfile:" + std::to_string(this->lineno()), + "netaddress: can't open socket", ::strerror(errno)); + return false; + } + memset(&request, 0, sizeof(request)); + memcpy(&request.ifr_name, _iface.c_str(), _iface.size()); + errno = 0; + if(ioctl(my_sock, SIOCGIFFLAGS, &request) == -1) { + if(errno == ENODEV) { + output_warning("installfile:" + std::to_string(this->lineno()), + "netaddress: specified interface does not exist"); + return true; + } + output_error("installfile:" + std::to_string(this->lineno()), + "netaddress: trouble communicating with interface", + ::strerror(errno)); + return false; + } +#endif return true; } diff --git a/tests/fixtures/0064-netssid-simple-wpa.installfile b/tests/fixtures/0064-netssid-simple-wpa.installfile index c49c428..1cec2e1 100644 --- a/tests/fixtures/0064-netssid-simple-wpa.installfile +++ b/tests/fixtures/0064-netssid-simple-wpa.installfile @@ -4,3 +4,4 @@ pkginstall adelie-base rootpw $6$gumtLGmHwOVIRpQR$2M9PUO24hy5mofzWWf9a.YLbzOgOlUby1g0hDj.wG67E2wrrvys59fq02PPdxBdbgkLZFtjfEx6MHZwMBamwu/ mount /dev/sda1 / netssid wlan0 "Fox5G" wpa shhsekrit +netaddress wlan0 dhcp |