From 5bf363ec2155f64cc9ace90357af9be44a963bd6 Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Tue, 30 Apr 2019 18:35:58 +0200 Subject: installer: stop/uninstall/start all WireGuard services Also clean up quite a few things. Signed-off-by: Simon Rozman Signed-off-by: Jason A. Donenfeld --- installer/ca.js | 41 +++++++++++++++++++++++++++++++++++++++++ installer/wireguard.wxs | 15 +++++++++++---- updater/msirunner_windows.go | 2 +- 3 files changed, 53 insertions(+), 5 deletions(-) create mode 100644 installer/ca.js diff --git a/installer/ca.js b/installer/ca.js new file mode 100644 index 00000000..811d3016 --- /dev/null +++ b/installer/ca.js @@ -0,0 +1,41 @@ +/* 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/wireguard.wxs b/installer/wireguard.wxs index da31c3c6..3d4766dc 100644 --- a/installer/wireguard.wxs +++ b/installer/wireguard.wxs @@ -27,12 +27,13 @@ + - + + @@ -98,6 +97,14 @@ + + + + + + diff --git a/updater/msirunner_windows.go b/updater/msirunner_windows.go index 286cec1e..7a4e9d72 100644 --- a/updater/msirunner_windows.go +++ b/updater/msirunner_windows.go @@ -20,7 +20,7 @@ func runMsi(msiPath string) error { // BUG: The Go documentation says that its built-in shell quoting isn't good for msiexec.exe. // See https://github.com/golang/go/issues/15566. But perhaps our limited set of options // actually works fine? Investigate this! - return exec.Command(path.Join(system32, "msiexec.exe"), "/qb", "/i", msiPath).Run() + return exec.Command(path.Join(system32, "msiexec.exe"), "/qb-", "/i", msiPath).Run() } func msiSaveDirectory() (string, error) { -- cgit v1.2.3-59-g8ed1b