aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/installer
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2019-05-01 09:49:14 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2019-05-01 09:52:16 +0200
commit0047901952de45dff95abef78d333f5c866627a1 (patch)
treecdc90e3c18843a3ea967923bfede4bd201357dd2 /installer
parentui: fix logic error in confview (diff)
downloadwireguard-windows-0047901952de45dff95abef78d333f5c866627a1.tar.xz
wireguard-windows-0047901952de45dff95abef78d333f5c866627a1.zip
installer: remove window flash and add logging
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'installer')
-rw-r--r--installer/ca.js41
-rw-r--r--installer/serviceevaluation.js92
-rw-r--r--installer/wireguard.wxs4
3 files changed, 94 insertions, 43 deletions
diff --git a/installer/ca.js b/installer/ca.js
deleted file mode 100644
index 811d3016..00000000
--- a/installer/ca.js
+++ /dev/null
@@ -1,41 +0,0 @@
-/* SPDX-License-Identifier: MIT
- *
- * Copyright (C) 2019 WireGuard LLC. All Rights Reserved.
- */
-
-function EvaluateWireGuardServices() {
- var inst = Session.Installer;
- var db = Session.Database;
- var view = db.OpenView("INSERT INTO `ServiceControl` (`ServiceControl`, `Name`, `Event`, `Component_`) VALUES(?, ?, ?, ?) TEMPORARY");
- var rec = inst.CreateRecord(4);
- var wsh = new ActiveXObject("WScript.Shell");
- var shl = new ActiveXObject("Shell.Application");
- var fso = new ActiveXObject("Scripting.FileSystemObject");
- var serviceKey = "HKEY_LOCAL_MACHINE\\System\\CurrentControlSet\\Services";
- var servicePrefix = "WireGuardTunnel$";
- var serviceKeyPrefix = serviceKey + "\\" + servicePrefix;
- var allowedNameFormat = new RegExp("^[a-zA-Z0-9_=+.-]{1,32}$");
- var msiOperators = new RegExp("[=+-]", "g");
- var index = 0;
-
- function insertServiceControl(serviceName) {
- rec.StringData (1/*ServiceControl*/) = serviceName.replace(msiOperators, "_") + (index++).toString();
- rec.StringData (2/*Name */) = serviceName;
- rec.IntegerData(3/*Event */) = 0x2/*msidbServiceControlEventStop*/ | 0x20/*msidbServiceControlEventUninstallStop*/ | 0x80/*msidbServiceControlEventUninstallDelete*/ | (shl.IsServiceRunning(serviceName) ? 0x1/*msidbServiceControlEventStart*/ : 0);
- rec.StringData (4/*Component */) = "WireGuardExecutable";
-
- view.Execute(rec);
- }
-
- insertServiceControl("WireGuardManager");
-
- var exe = wsh.Exec(fso.BuildPath(fso.GetSpecialFolder(1), "reg.exe") + " QUERY \"" + serviceKey + "\"");
- var lines = exe.StdOut.ReadAll().split(new RegExp("\r?\n", "g"));
- for (var i = 0; i < lines.length; ++i) {
- if (lines[i].length > serviceKeyPrefix.length && lines[i].substring(0, serviceKeyPrefix.length) == serviceKeyPrefix) {
- var tunnelName = lines[i].substring(serviceKeyPrefix.length);
- if (tunnelName.match(allowedNameFormat) != null)
- insertServiceControl(servicePrefix + tunnelName);
- }
- }
-}
diff --git a/installer/serviceevaluation.js b/installer/serviceevaluation.js
new file mode 100644
index 00000000..bf2a700c
--- /dev/null
+++ b/installer/serviceevaluation.js
@@ -0,0 +1,92 @@
+/* SPDX-License-Identifier: MIT
+ *
+ * Copyright (C) 2019 WireGuard LLC. All Rights Reserved.
+ */
+
+var wsh = new ActiveXObject("WScript.Shell");
+var shl = new ActiveXObject("Shell.Application");
+var fso = new ActiveXObject("Scripting.FileSystemObject");
+
+function logMessage(msg) {
+ var record = Installer.CreateRecord(1);
+ record.StringData(0) = "WireGuard service evaluation: [1]";
+ record.StringData(1) = msg.toString();
+ Session.Message(0x04000000, record);
+}
+
+// I'd rather use wsh.Exec, so that we can just do ".Stdout.ReadAll()", but
+// this results in a scary flashing command window. The below is the best
+// workaround we can find yet. We'll keep searching for more clever tricks.
+function runWithNoWindowFlash(command) {
+ //TODO: Seems pretty unlikely that this temp file is secure...
+ var tmpfile = fso.BuildPath(fso.GetSpecialFolder(2), fso.GetTempName());
+ //TODO: Obviously cmd and tmpfile are unescaped here...
+ var cmd = fso.BuildPath(fso.GetSpecialFolder(1), "cmd.exe") + " /c " + command + " > " + tmpfile;
+ var ret = wsh.Run(cmd, 0, true);
+ if (ret != 0) {
+ logMessage("Command " + cmd + " exited with error " + ret.toString());
+ try {
+ fso.DeleteFile(tmpfile);
+ } catch (e) {}
+ return "";
+ }
+ var txt;
+ try {
+ var file = fso.OpenTextFile(tmpfile, 1);
+ txt = file.ReadAll();
+ file.Close();
+ } catch (e) {
+ logMessage("Unable to read temporary file " + tmpfile + " for command " + cmd + ": " + e.toString());
+ try {
+ fso.DeleteFile(tmpfile);
+ } catch (e) {}
+ return "";
+ }
+ try {
+ fso.DeleteFile(tmpfile);
+ } catch(e) {}
+ return txt;
+}
+
+function EvaluateWireGuardServices() {
+ var inst = Session.Installer;
+ var db = Session.Database;
+ var view = db.OpenView("INSERT INTO `ServiceControl` (`ServiceControl`, `Name`, `Event`, `Component_`) VALUES(?, ?, ?, ?) TEMPORARY");
+ var rec = inst.CreateRecord(4);
+ var serviceKey = "HKEY_LOCAL_MACHINE\\System\\CurrentControlSet\\Services";
+ var servicePrefix = "WireGuardTunnel$";
+ var serviceKeyPrefix = serviceKey + "\\" + servicePrefix;
+ var allowedNameFormat = new RegExp("^[a-zA-Z0-9_=+.-]{1,32}$");
+ var msiOperators = new RegExp("[=+-]", "g");
+ var index = 0;
+
+ function insertServiceControl(serviceName) {
+ var flags = 0x2/*msidbServiceControlEventStop*/ | 0x20/*msidbServiceControlEventUninstallStop*/ | 0x80/*msidbServiceControlEventUninstallDelete*/;
+
+ if (shl.IsServiceRunning(serviceName)) {
+ flags |= 0x1/*msidbServiceControlEventStart*/;
+ logMessage("Scheduling stop on upgrade/uninstall and removal on uninstall of service " + serviceName);
+ } else {
+ logMessage("Scheduling removal on uninstall of service " + serviceName);
+ }
+
+ rec.StringData (1/*ServiceControl*/) = serviceName.replace(msiOperators, "_") + (index++).toString();
+ rec.StringData (2/*Name */) = serviceName;
+ rec.IntegerData(3/*Event */) = flags;
+ rec.StringData (4/*Component_ */) = "WireGuardExecutable";
+
+ view.Execute(rec);
+ }
+
+ insertServiceControl("WireGuardManager");
+
+ var txt = runWithNoWindowFlash(fso.BuildPath(fso.GetSpecialFolder(1), "reg.exe") + " query \"" + serviceKey + "\"");
+ var lines = txt.split(new RegExp("\r?\n", "g"));
+ for (var i = 0; i < lines.length; ++i) {
+ if (lines[i].length > serviceKeyPrefix.length && lines[i].substring(0, serviceKeyPrefix.length) == serviceKeyPrefix) {
+ var tunnelName = lines[i].substring(serviceKeyPrefix.length);
+ if (tunnelName.match(allowedNameFormat) != null)
+ insertServiceControl(servicePrefix + tunnelName);
+ }
+ }
+}
diff --git a/installer/wireguard.wxs b/installer/wireguard.wxs
index 3d4766dc..c88e7af9 100644
--- a/installer/wireguard.wxs
+++ b/installer/wireguard.wxs
@@ -27,7 +27,7 @@
<MediaTemplate EmbedCab="yes" CompressionLevel="high"/>
<Icon Id="icon.ico" SourceFile="..\ui\icon\icon.ico"/>
- <Binary Id="ca.js" SourceFile="ca.js"/>
+ <Binary Id="serviceevaluation.js" SourceFile="serviceevaluation.js"/>
<Property Id="ARPPRODUCTICON" Value="icon.ico"/>
<Property Id="ARPURLINFOABOUT" Value="https://www.wireguard.com/"/>
@@ -100,7 +100,7 @@
<!--
Evaluate WireGuard services and populate ServiceControl table
-->
- <CustomAction Id="EvaluateWireGuardServices" BinaryKey="ca.js" JScriptCall="EvaluateWireGuardServices"/>
+ <CustomAction Id="EvaluateWireGuardServices" BinaryKey="serviceevaluation.js" JScriptCall="EvaluateWireGuardServices"/>
<InstallExecuteSequence>
<Custom Action="EvaluateWireGuardServices" After="FindRelatedProducts"/>
</InstallExecuteSequence>