summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorDavid Lönnhager <david.l@mullvad.net>2020-01-09 15:51:20 +0100
committerDavid Lönnhager <david.l@mullvad.net>2020-01-09 15:51:20 +0100
commit5b6e776eb9508cc684acf0b7e24ba49101f618a2 (patch)
tree15f91c803a90b3ca43b82e721ba7ed47f4e83757
parent882c4bcaa4163e91ed7a97ba86f30f1fdf1dc420 (diff)
parentd461128a941d909f8373b7bace8653f9fd6ea964 (diff)
downloadmullvadvpn-5b6e776eb9508cc684acf0b7e24ba49101f618a2.tar.xz
mullvadvpn-5b6e776eb9508cc684acf0b7e24ba49101f618a2.zip
Merge branch 'service-marked-for-deletion-fix'
-rw-r--r--CHANGELOG.md2
-rw-r--r--dist-assets/windows/installer.nsh54
-rw-r--r--windows/nsis-plugins/nsis-plugins.sln6
-rw-r--r--windows/nsis-plugins/src/string/dllmain.cpp11
-rw-r--r--windows/nsis-plugins/src/string/stdafx.cpp8
-rw-r--r--windows/nsis-plugins/src/string/stdafx.h16
-rw-r--r--windows/nsis-plugins/src/string/string.cpp81
-rw-r--r--windows/nsis-plugins/src/string/string.def5
-rw-r--r--windows/nsis-plugins/src/string/string.vcxproj122
-rw-r--r--windows/nsis-plugins/src/string/string.vcxproj.filters15
-rw-r--r--windows/nsis-plugins/src/string/targetver.h12
11 files changed, 332 insertions, 0 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index ea3d4af60e..e6d2d0ddea 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -44,6 +44,8 @@ Line wrap the file at 100 chars. Th
#### Windows
- Fix regression due to which a TAP adapter issue was not given as the specific block reason when
the tunnel could not be started.
+- Fix occasional failure to shut down the old daemon process during installation by killing it if
+ necessary.
#### Android
- Fix crash when starting the app right after quitting it.
diff --git a/dist-assets/windows/installer.nsh b/dist-assets/windows/installer.nsh
index 09e31000eb..1bf8b65ac9 100644
--- a/dist-assets/windows/installer.nsh
+++ b/dist-assets/windows/installer.nsh
@@ -45,6 +45,7 @@
!define LOG_VOID 1
# Windows error codes
+!define ERROR_SERVICE_MARKED_FOR_DELETE 1072
!define ERROR_SERVICE_DEPENDENCY_DELETED 1075
# Override electron-builder generated application settings key.
@@ -476,6 +477,13 @@
Push $0
Push $1
+ Push $2
+
+ Var /GLOBAL InstallService_Counter
+ Push 0
+ Pop $InstallService_Counter
+
+ InstallService_RegisterService:
log::Log "Running $\"mullvad-daemon$\" for it to self-register as a service"
nsExec::ExecToStack '"$INSTDIR\resources\mullvad-daemon.exe" --register-service'
@@ -486,6 +494,51 @@
${If} $0 != 0
StrCpy $R0 "Failed to install Mullvad service: error $0"
log::LogWithDetails $R0 $1
+
+ #
+ # Parse service error
+ #
+ string::Find $1 "(os error " 0
+ Pop $0
+
+ ${If} $0 == -1
+ log::Log "Failed to parse service error"
+ Goto InstallService_return
+ ${EndIf}
+
+ IntOp $0 $0 + 10
+
+ string::Find $1 ")" $0
+ Pop $2
+
+ IntOp $2 $2 - $0
+
+ ${If} $2 < 1
+ log::Log "Failed to parse service error"
+ Goto InstallService_return
+ ${EndIf}
+
+ StrCpy $0 $1 $2 $0
+
+ StrCpy $R0 "Service error code: $0"
+ log::Log $R0
+
+ #
+ # Forcibly kill old process if stuck
+ #
+ ${If} $0 == ${ERROR_SERVICE_MARKED_FOR_DELETE}
+ log::Log "Attempt to forcibly kill stuck process"
+ nsExec::ExecToStack '"$SYSDIR\taskkill.exe" /f /fi "SERVICES eq mullvadvpn"'
+ Pop $0
+ Pop $1
+
+ # Retry service installation
+ IntOp $InstallService_Counter $InstallService_Counter + 1
+ ${If} $InstallService_Counter < 2
+ Goto InstallService_RegisterService
+ ${EndIf}
+ ${EndIf}
+
Goto InstallService_return
${EndIf}
@@ -513,6 +566,7 @@
InstallService_return:
+ Pop $2
Pop $1
Pop $0
diff --git a/windows/nsis-plugins/nsis-plugins.sln b/windows/nsis-plugins/nsis-plugins.sln
index 2268ac575d..3186f53b46 100644
--- a/windows/nsis-plugins/nsis-plugins.sln
+++ b/windows/nsis-plugins/nsis-plugins.sln
@@ -41,6 +41,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
src\error.h = src\error.h
EndProjectSection
EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "string", "src\string\string.vcxproj", "{645B4CB5-623A-41CC-8B05-2268A5AE6C47}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x86 = Debug|x86
@@ -75,6 +77,10 @@ Global
{EF53BD9F-6D69-42BB-8635-958531776283}.Debug|x86.Build.0 = Debug|Win32
{EF53BD9F-6D69-42BB-8635-958531776283}.Release|x86.ActiveCfg = Release|Win32
{EF53BD9F-6D69-42BB-8635-958531776283}.Release|x86.Build.0 = Release|Win32
+ {645B4CB5-623A-41CC-8B05-2268A5AE6C47}.Debug|x86.ActiveCfg = Debug|Win32
+ {645B4CB5-623A-41CC-8B05-2268A5AE6C47}.Debug|x86.Build.0 = Debug|Win32
+ {645B4CB5-623A-41CC-8B05-2268A5AE6C47}.Release|x86.ActiveCfg = Release|Win32
+ {645B4CB5-623A-41CC-8B05-2268A5AE6C47}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
diff --git a/windows/nsis-plugins/src/string/dllmain.cpp b/windows/nsis-plugins/src/string/dllmain.cpp
new file mode 100644
index 0000000000..a5a44613dd
--- /dev/null
+++ b/windows/nsis-plugins/src/string/dllmain.cpp
@@ -0,0 +1,11 @@
+#include "stdafx.h"
+#include <windows.h>
+
+BOOL APIENTRY DllMain(HMODULE, DWORD reason, LPVOID)
+{
+ //
+ // Avoid doing work in DllMain since the loader lock is held
+ //
+
+ return TRUE;
+}
diff --git a/windows/nsis-plugins/src/string/stdafx.cpp b/windows/nsis-plugins/src/string/stdafx.cpp
new file mode 100644
index 0000000000..1eed162b91
--- /dev/null
+++ b/windows/nsis-plugins/src/string/stdafx.cpp
@@ -0,0 +1,8 @@
+// stdafx.cpp : source file that includes just the standard includes
+// string.pch will be the pre-compiled header
+// stdafx.obj will contain the pre-compiled type information
+
+#include "stdafx.h"
+
+// TODO: reference any additional headers you need in STDAFX.H
+// and not in this file
diff --git a/windows/nsis-plugins/src/string/stdafx.h b/windows/nsis-plugins/src/string/stdafx.h
new file mode 100644
index 0000000000..f3a07375c7
--- /dev/null
+++ b/windows/nsis-plugins/src/string/stdafx.h
@@ -0,0 +1,16 @@
+// stdafx.h : include file for standard system include files,
+// or project specific include files that are used frequently, but
+// are changed infrequently
+//
+
+#pragma once
+
+#include "targetver.h"
+
+#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
+// Windows Header Files:
+#include <windows.h>
+
+
+
+// TODO: reference additional headers your program requires here
diff --git a/windows/nsis-plugins/src/string/string.cpp b/windows/nsis-plugins/src/string/string.cpp
new file mode 100644
index 0000000000..6071e6303d
--- /dev/null
+++ b/windows/nsis-plugins/src/string/string.cpp
@@ -0,0 +1,81 @@
+#include "stdafx.h"
+#include <nsis/pluginapi.h>
+#include <stdexcept>
+#include <string>
+
+// Suppress warnings caused by broken legacy code
+#pragma warning (push)
+#pragma warning (disable: 4005)
+#include <nsis/pluginapi.h>
+#pragma warning (pop)
+
+namespace
+{
+
+std::wstring PopString()
+{
+ //
+ // NSIS functions popstring() and popstringn() require that you definitely size the buffer
+ // before popping the string. Let's do it ourselves instead.
+ //
+
+ if (!g_stacktop || !*g_stacktop)
+ {
+ throw std::runtime_error("NSIS variable stack is corrupted");
+ }
+
+ stack_t *th = *g_stacktop;
+
+ std::wstring copy(th->text);
+
+ *g_stacktop = th->next;
+ GlobalFree((HGLOBAL)th);
+
+ return copy;
+}
+
+} // anonymous namespace
+
+//
+// Find "string" "substring" begin_offset
+//
+// Return the position of "substring" in "string", starting from 'begin_offset'.
+// If the substring is not found or if an error occurs, return -1.
+//
+
+void __declspec(dllexport) NSISCALL Find
+(
+ HWND hwndParent,
+ int string_size,
+ LPTSTR variables,
+ stack_t **stacktop,
+ extra_parameters *extra,
+ ...
+)
+{
+ EXDLL_INIT();
+
+ try
+ {
+ const auto searchString = PopString();
+ const auto substring = PopString();
+ const auto offset = popint();
+ const auto position = searchString.find(substring, offset);
+
+ if (std::wstring::npos == position)
+ {
+ pushint(-1);
+ return;
+ }
+
+ pushint((int)position);
+ }
+ catch (const std::exception &)
+ {
+ pushint(-1);
+ }
+ catch (...)
+ {
+ pushint(-1);
+ }
+}
diff --git a/windows/nsis-plugins/src/string/string.def b/windows/nsis-plugins/src/string/string.def
new file mode 100644
index 0000000000..730d40f21e
--- /dev/null
+++ b/windows/nsis-plugins/src/string/string.def
@@ -0,0 +1,5 @@
+LIBRARY string
+
+EXPORTS
+
+Find
diff --git a/windows/nsis-plugins/src/string/string.vcxproj b/windows/nsis-plugins/src/string/string.vcxproj
new file mode 100644
index 0000000000..bc3f32f528
--- /dev/null
+++ b/windows/nsis-plugins/src/string/string.vcxproj
@@ -0,0 +1,122 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project DefaultTargets="Build" ToolsVersion="16.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <ItemGroup Label="ProjectConfigurations">
+ <ProjectConfiguration Include="Debug|Win32">
+ <Configuration>Debug</Configuration>
+ <Platform>Win32</Platform>
+ </ProjectConfiguration>
+ <ProjectConfiguration Include="Release|Win32">
+ <Configuration>Release</Configuration>
+ <Platform>Win32</Platform>
+ </ProjectConfiguration>
+ </ItemGroup>
+ <PropertyGroup Label="Globals">
+ <VCProjectVersion>16.0</VCProjectVersion>
+ <ProjectGuid>{645B4CB5-623A-41CC-8B05-2268A5AE6C47}</ProjectGuid>
+ <Keyword>Win32Proj</Keyword>
+ <RootNamespace>string</RootNamespace>
+ <WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
+ </PropertyGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
+ <ConfigurationType>DynamicLibrary</ConfigurationType>
+ <UseDebugLibraries>true</UseDebugLibraries>
+ <PlatformToolset>v142</PlatformToolset>
+ <CharacterSet>Unicode</CharacterSet>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
+ <ConfigurationType>DynamicLibrary</ConfigurationType>
+ <UseDebugLibraries>false</UseDebugLibraries>
+ <PlatformToolset>v142</PlatformToolset>
+ <WholeProgramOptimization>true</WholeProgramOptimization>
+ <CharacterSet>Unicode</CharacterSet>
+ </PropertyGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
+ <ImportGroup Label="ExtensionSettings">
+ </ImportGroup>
+ <ImportGroup Label="Shared">
+ </ImportGroup>
+ <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+ </ImportGroup>
+ <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+ </ImportGroup>
+ <PropertyGroup Label="UserMacros" />
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+ <LinkIncremental>true</LinkIncremental>
+ <OutDir>$(SolutionDir)bin\$(Platform)-$(Configuration)\</OutDir>
+ <IntDir>$(SolutionDir)bin\temp\$(Platform)-$(Configuration)\$(ProjectName)\</IntDir>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+ <LinkIncremental>false</LinkIncremental>
+ <OutDir>$(SolutionDir)bin\$(Platform)-$(Configuration)\</OutDir>
+ <IntDir>$(SolutionDir)bin\temp\$(Platform)-$(Configuration)\$(ProjectName)\</IntDir>
+ </PropertyGroup>
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+ <ClCompile>
+ <PrecompiledHeader>Use</PrecompiledHeader>
+ <WarningLevel>Level3</WarningLevel>
+ <Optimization>Disabled</Optimization>
+ <SDLCheck>true</SDLCheck>
+ <PreprocessorDefinitions>WIN32;_DEBUG;STRING_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ <ConformanceMode>true</ConformanceMode>
+ <AdditionalIncludeDirectories>$(ProjectDir)../../../../dist-assets/binaries/x86_64-pc-windows-msvc/;$(ProjectDir)../</AdditionalIncludeDirectories>
+ <LanguageStandard>stdcpplatest</LanguageStandard>
+ <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
+ </ClCompile>
+ <Link>
+ <SubSystem>Windows</SubSystem>
+ <GenerateDebugInformation>true</GenerateDebugInformation>
+ <ImageHasSafeExceptionHandlers>false</ImageHasSafeExceptionHandlers>
+ <AdditionalLibraryDirectories>$(ProjectDir)../../../../dist-assets/binaries/x86_64-pc-windows-msvc/nsis/;$(SolutionDir)bin\$(Platform)-$(Configuration)\</AdditionalLibraryDirectories>
+ <AdditionalDependencies>pluginapi-x86-unicode.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies>
+ <IgnoreSpecificDefaultLibraries>libc.lib</IgnoreSpecificDefaultLibraries>
+ <ModuleDefinitionFile>string.def</ModuleDefinitionFile>
+ </Link>
+ </ItemDefinitionGroup>
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+ <ClCompile>
+ <PrecompiledHeader>Use</PrecompiledHeader>
+ <WarningLevel>Level3</WarningLevel>
+ <Optimization>MaxSpeed</Optimization>
+ <FunctionLevelLinking>true</FunctionLevelLinking>
+ <IntrinsicFunctions>true</IntrinsicFunctions>
+ <SDLCheck>true</SDLCheck>
+ <PreprocessorDefinitions>WIN32;NDEBUG;STRING_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ <ConformanceMode>true</ConformanceMode>
+ <AdditionalIncludeDirectories>$(ProjectDir)../../../../dist-assets/binaries/x86_64-pc-windows-msvc/;$(ProjectDir)../</AdditionalIncludeDirectories>
+ <RuntimeLibrary>MultiThreaded</RuntimeLibrary>
+ <LanguageStandard>stdcpplatest</LanguageStandard>
+ </ClCompile>
+ <Link>
+ <SubSystem>Windows</SubSystem>
+ <EnableCOMDATFolding>true</EnableCOMDATFolding>
+ <OptimizeReferences>true</OptimizeReferences>
+ <GenerateDebugInformation>true</GenerateDebugInformation>
+ <ImageHasSafeExceptionHandlers>false</ImageHasSafeExceptionHandlers>
+ <AdditionalLibraryDirectories>$(ProjectDir)../../../../dist-assets/binaries/x86_64-pc-windows-msvc/nsis/;$(SolutionDir)bin\$(Platform)-$(Configuration)\</AdditionalLibraryDirectories>
+ <AdditionalDependencies>pluginapi-x86-unicode.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies>
+ <IgnoreSpecificDefaultLibraries>libc.lib</IgnoreSpecificDefaultLibraries>
+ <ModuleDefinitionFile>string.def</ModuleDefinitionFile>
+ </Link>
+ </ItemDefinitionGroup>
+ <ItemGroup>
+ <ClInclude Include="stdafx.h" />
+ <ClInclude Include="targetver.h" />
+ </ItemGroup>
+ <ItemGroup>
+ <ClCompile Include="dllmain.cpp" />
+ <ClCompile Include="stdafx.cpp">
+ <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
+ <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
+ </ClCompile>
+ <ClCompile Include="string.cpp" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="string.def" />
+ </ItemGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
+ <ImportGroup Label="ExtensionTargets">
+ </ImportGroup>
+</Project> \ No newline at end of file
diff --git a/windows/nsis-plugins/src/string/string.vcxproj.filters b/windows/nsis-plugins/src/string/string.vcxproj.filters
new file mode 100644
index 0000000000..f18503432e
--- /dev/null
+++ b/windows/nsis-plugins/src/string/string.vcxproj.filters
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <ItemGroup>
+ <ClInclude Include="stdafx.h" />
+ <ClInclude Include="targetver.h" />
+ </ItemGroup>
+ <ItemGroup>
+ <ClCompile Include="dllmain.cpp" />
+ <ClCompile Include="stdafx.cpp" />
+ <ClCompile Include="string.cpp" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="string.def" />
+ </ItemGroup>
+</Project> \ No newline at end of file
diff --git a/windows/nsis-plugins/src/string/targetver.h b/windows/nsis-plugins/src/string/targetver.h
new file mode 100644
index 0000000000..ae4a5c032c
--- /dev/null
+++ b/windows/nsis-plugins/src/string/targetver.h
@@ -0,0 +1,12 @@
+#pragma once
+
+// Including SDKDDKVer.h defines the highest available Windows platform.
+
+// If you wish to build your application for a previous Windows platform, include WinSDKVer.h and
+// set the _WIN32_WINNT macro to the platform you wish to support before including SDKDDKVer.h.
+
+#include <WinSDKVer.h>
+
+#define _WIN32_WINNT _WIN32_WINNT_WIN7
+
+#include <SDKDDKVer.h>