aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/installer
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2020-11-10 13:15:39 +0100
committerJason A. Donenfeld <Jason@zx2c4.com>2020-11-16 18:17:05 +0100
commit49b74832095330df9eef1988250f5ff280dd7ef1 (patch)
treec076e13095bef5597c9d201ea79ab4d728a18ff6 /installer
parentinstaller: prohibit Wow64 installs (diff)
downloadwireguard-windows-49b74832095330df9eef1988250f5ff280dd7ef1.tar.xz
wireguard-windows-49b74832095330df9eef1988250f5ff280dd7ef1.zip
installer: require KB2921916 on Windows 7
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'installer')
-rw-r--r--installer/build.bat2
-rw-r--r--installer/customactions.c62
-rw-r--r--installer/wireguard.wxs8
3 files changed, 71 insertions, 1 deletions
diff --git a/installer/build.bat b/installer/build.bat
index f90791ef..857de64a 100644
--- a/installer/build.bat
+++ b/installer/build.bat
@@ -35,7 +35,7 @@ if exist .deps\prepared goto :build
set WIX=%BUILDDIR%.deps\wix\
set CFLAGS=-O3 -Wall -std=gnu11 -DWINVER=0x0601 -D_WIN32_WINNT=0x0601 -municode -DUNICODE -D_UNICODE -DNDEBUG
set LDFLAGS=-shared -s -Wl,--kill-at -Wl,--major-os-version=6 -Wl,--minor-os-version=1 -Wl,--major-subsystem-version=6 -Wl,--minor-subsystem-version=1 -Wl,--tsaware -Wl,--dynamicbase -Wl,--nxcompat -Wl,--export-all-symbols
- set LDLIBS=-lmsi -lole32 -lshlwapi -lshell32 -luuid
+ set LDLIBS=-lmsi -lole32 -lshlwapi -lshell32 -luuid -lntdll
call :msi x86 i686 x86 || goto :error
call :msi amd64 x86_64 x64 || goto :error
call :msi arm armv7 arm || goto :error
diff --git a/installer/customactions.c b/installer/customactions.c
index 5fe94aec..fc08bee5 100644
--- a/installer/customactions.c
+++ b/installer/customactions.c
@@ -535,3 +535,65 @@ out:
CoUninitialize();
return ret;
}
+
+extern NTAPI __declspec(dllimport) void RtlGetNtVersionNumbers(DWORD *MajorVersion, DWORD *MinorVersion, DWORD *BuildNumber);
+
+__declspec(dllexport) UINT __stdcall CheckKB2921916(MSIHANDLE installer)
+{
+ bool is_com_initialized = SUCCEEDED(CoInitialize(NULL));
+ UINT ret = ERROR_SUCCESS;
+ DWORD maj, min, build, len;
+ HKEY packageKey;
+ TCHAR subkeyName[0x1000], uiLevel[10];
+ MSIHANDLE record;
+
+ RtlGetNtVersionNumbers(&maj, &min, &build);
+ if (maj != 6 || min != 1)
+ goto out;
+
+ ret = RegOpenKeyEx(HKEY_LOCAL_MACHINE, TEXT("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Component Based Servicing\\Packages"), 0, KEY_ENUMERATE_SUB_KEYS, &packageKey);
+ if (ret != ERROR_SUCCESS) {
+ log_errorf(installer, LOG_LEVEL_ERR, ret, TEXT("Unable to open Component Based Servicing\\Packages registry key"));
+ goto out;
+ }
+ for (DWORD i = 0;; ++i) {
+ len = _countof(subkeyName);
+ ret = RegEnumKeyEx(packageKey, i, subkeyName, &len, NULL, NULL, NULL, NULL);
+ if (ret == ERROR_NO_MORE_ITEMS)
+ break;
+ if (ret == ERROR_MORE_DATA)
+ continue;
+ if (ret != ERROR_SUCCESS) {
+ log_errorf(installer, LOG_LEVEL_ERR, ret, TEXT("Unable to enumerate Component Based Servicing\\Packages registry key"));
+ goto close_key;
+ }
+ if (_tcsstr(subkeyName, TEXT("KB2921916")))
+ goto close_key;
+ }
+ ret = ERROR_INSTALL_FAILURE;
+
+ len = _countof(uiLevel);
+ if (MsiGetProperty(installer, TEXT("UILevel"), uiLevel, &len) != ERROR_SUCCESS || _tcstoul(uiLevel, NULL, 10) < INSTALLUILEVEL_BASIC) {
+ log_messagef(installer, LOG_LEVEL_MSIERR, TEXT("Use of WireGuard on Windows 7 requires KB2921916."));
+ goto close_key;
+ }
+
+#ifdef _WIN64
+ static const TCHAR url[] = TEXT("https://download.wireguard.com/windows-toolchain/distfiles/Windows6.1-KB2921916-x64.msu");
+#else
+ static const TCHAR url[] = TEXT("https://download.wireguard.com/windows-toolchain/distfiles/Windows6.1-KB2921916-x86.msu");
+#endif
+ record = MsiCreateRecord(2);
+ MsiRecordSetString(record, 0, TEXT("[1]"));
+ MsiRecordSetString(record, 1, TEXT("Missing Windows Hotfix\n\nUse of WireGuard on Windows 7 requires KB2921916. Would you like to download the hotfix in your web browser?"));
+ if (MsiProcessMessage(installer, INSTALLMESSAGE_USER | MB_ICONWARNING | MB_YESNO, record) == IDYES)
+ ShellExecute(GetForegroundWindow(), NULL, url, NULL, NULL, SW_SHOWNORMAL);
+ MsiCloseHandle(record);
+
+close_key:
+ RegCloseKey(packageKey);
+out:
+ if (is_com_initialized)
+ CoUninitialize();
+ return ret;
+}
diff --git a/installer/wireguard.wxs b/installer/wireguard.wxs
index e675954a..02f0dd54 100644
--- a/installer/wireguard.wxs
+++ b/installer/wireguard.wxs
@@ -100,6 +100,14 @@
</InstallExecuteSequence>
<!--
+ Abort early if running without KB2921916 on Windows 7
+ -->
+ <CustomAction Id="CheckKB2921916" BinaryKey="customactions.dll" DllEntry="CheckKB2921916" />
+ <InstallExecuteSequence>
+ <Custom Action="CheckKB2921916" After="CheckWow64" />
+ </InstallExecuteSequence>
+
+ <!--
Evaluate WireGuard services and populate ServiceControl table
-->
<CustomAction Id="EvaluateWireGuardServices" BinaryKey="customactions.dll" DllEntry="EvaluateWireGuardServices" />