summaryrefslogtreecommitdiff
path: root/hscript/network.cc
diff options
context:
space:
mode:
authorA. Wilcox <AWilcox@Wilcox-Tech.com>2019-10-14 07:59:39 -0500
committerA. Wilcox <AWilcox@Wilcox-Tech.com>2019-10-14 07:59:39 -0500
commit3599b5f49c90870f890cb5c50ca8c8e87a0fc534 (patch)
tree6c4def483a11ba18980f711ad7cf3139dce7e489 /hscript/network.cc
parent014d500546a2713be0b789fbccd3350c96d22a4f (diff)
downloadhorizon-3599b5f49c90870f890cb5c50ca8c8e87a0fc534.tar.gz
horizon-3599b5f49c90870f890cb5c50ca8c8e87a0fc534.tar.bz2
horizon-3599b5f49c90870f890cb5c50ca8c8e87a0fc534.tar.xz
horizon-3599b5f49c90870f890cb5c50ca8c8e87a0fc534.zip
hscript: Ensure netssid iface is a wireless one
Diffstat (limited to 'hscript/network.cc')
-rw-r--r--hscript/network.cc31
1 files changed, 28 insertions, 3 deletions
diff --git a/hscript/network.cc b/hscript/network.cc
index 09c5510..62881f9 100644
--- a/hscript/network.cc
+++ b/hscript/network.cc
@@ -11,8 +11,11 @@
*/
#include <algorithm>
-#include <arpa/inet.h>
-#include <net/if.h>
+#include <arpa/inet.h> /* inet_pton */
+#include <linux/wireless.h> /* struct iwreq */
+#include <string.h> /* strerror */
+#include <sys/ioctl.h> /* ioctl, ioctl numbers */
+#include <unistd.h> /* close */
#include "network.hh"
#include "util/output.hh"
@@ -309,7 +312,29 @@ 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)) {
- return false;
+ 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;
+ }
+ memcpy(&request.ifr_ifrn.ifrn_name, this->_iface.c_str(),
+ this->_iface.size());
+ errno = 0;
+ if(ioctl(my_sock, SIOCGIWNAME, &request) == -1) {
+ if(errno == EOPNOTSUPP) {
+ output_warning("installfile:" + std::to_string(this->lineno()),
+ "netssid: interface specified is not wireless");
+ return false;
+ } else {
+ output_error("installfile:" + std::to_string(this->lineno()),
+ "netssid: error communicating with wireless device");
+ return false;
+ }
+ }
+ ::close(my_sock);
+ return true;
}
return true;
}