summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorEmīls Piņķis <emils@mullvad.net>2019-06-11 21:07:48 +0100
committerEmīls Piņķis <emils@mullvad.net>2019-06-11 21:07:48 +0100
commitd4a6e0b411b72f9e14eb6caee6c91dd31b612acf (patch)
tree750fc0eca4e50b85df82491ee129dc59e0596c20
parent63ebe7ac2f4602bcd1cf9439c6ba5fe177ef028e (diff)
parent3f1a27e0581d54ec20ae40ee5ce9296626f6c578 (diff)
downloadmullvadvpn-d4a6e0b411b72f9e14eb6caee6c91dd31b612acf.tar.xz
mullvadvpn-d4a6e0b411b72f9e14eb6caee6c91dd31b612acf.zip
Merge branch 'installer-remove-relay-list'
-rw-r--r--dist-assets/linux/before-install.sh2
-rwxr-xr-xdist-assets/pkg-scripts/preinstall2
-rw-r--r--dist-assets/windows/installer.nsh40
-rw-r--r--windows/nsis-plugins/src/cleanup/cleaningops.cpp14
-rw-r--r--windows/nsis-plugins/src/cleanup/cleaningops.h5
-rw-r--r--windows/nsis-plugins/src/cleanup/cleanup.cpp38
-rw-r--r--windows/nsis-plugins/src/cleanup/cleanup.def1
7 files changed, 101 insertions, 1 deletions
diff --git a/dist-assets/linux/before-install.sh b/dist-assets/linux/before-install.sh
index 2c940688b2..71fe8ae5ab 100644
--- a/dist-assets/linux/before-install.sh
+++ b/dist-assets/linux/before-install.sh
@@ -7,3 +7,5 @@ if which systemctl &> /dev/null; then
systemctl disable mullvad-daemon.service
fi
fi
+
+rm -f /var/cache/mullvad-vpn/relays.json || true
diff --git a/dist-assets/pkg-scripts/preinstall b/dist-assets/pkg-scripts/preinstall
index 0b243f255b..c07fa0e15d 100755
--- a/dist-assets/pkg-scripts/preinstall
+++ b/dist-assets/pkg-scripts/preinstall
@@ -75,3 +75,5 @@ if [ -d "$OLD_CACHE_DIR" ]; then
mv "$OLD_CACHE_DIR"/* "$NEW_CACHE_DIR/" || echo "Unable to migrate cache. No cache files?"
rm -rf "$OLD_CACHE_DIR"
fi
+
+rm -f "$NEW_CACHE_DIR/relays.json" || true
diff --git a/dist-assets/windows/installer.nsh b/dist-assets/windows/installer.nsh
index 5e4bb2f53e..64b12f01d6 100644
--- a/dist-assets/windows/installer.nsh
+++ b/dist-assets/windows/installer.nsh
@@ -37,6 +37,10 @@
!define PTI_GENERAL_ERROR 0
!define PTI_SUCCESS 1
+# Return codes from cleanup::RemoveRelayCache
+!define RRC_GENERAL_ERROR 0
+!define RRC_SUCCESS 1
+
# Windows error codes
!define ERROR_SERVICE_DEPENDENCY_DELETED 1075
@@ -416,6 +420,40 @@
!define RemoveSettings '!insertmacro "RemoveSettings"'
#
+# RemoveRelayCache
+#
+# Call into helper DLL instructing it to remove all relay cache.
+# Currently, errors are only logged and not propagated.
+#
+!macro RemoveRelayCache
+
+ log::Log "RemoveRelayCache()"
+
+ Push $0
+ Push $1
+
+ cleanup::RemoveRelayCache
+
+ Pop $0
+ Pop $1
+
+ ${If} $0 != ${RRC_SUCCESS}
+ log::Log "Failed to remove relay cache: $1"
+ Goto RemoveRelayCache_return
+ ${EndIf}
+
+ log::Log "RemoveRelayCache() completed successfully"
+
+ RemoveRelayCache_return:
+
+ Pop $1
+ Pop $0
+
+!macroend
+
+!define RemoveRelayCache '!insertmacro "RemoveRelayCache"'
+
+#
# customInit
#
# This macro is activated right when the installer first starts up.
@@ -471,6 +509,8 @@
SetShellVarContext current
RMDir /r "$APPDATA\${PRODUCT_NAME}"
+ ${RemoveRelayCache}
+
${ExtractDriver}
${InstallDriver}
diff --git a/windows/nsis-plugins/src/cleanup/cleaningops.cpp b/windows/nsis-plugins/src/cleanup/cleaningops.cpp
index 3a0764d91c..dec5ec198f 100644
--- a/windows/nsis-plugins/src/cleanup/cleaningops.cpp
+++ b/windows/nsis-plugins/src/cleanup/cleaningops.cpp
@@ -272,4 +272,18 @@ void RemoveSettingsServiceUser()
RemoveDirectoryW(std::wstring(L"\\\\?\\").append(mullvadAppData).c_str());
}
+void RemoveRelayCacheServiceUser()
+{
+ const auto localAppData = GetSystemUserLocalAppData();
+ const auto mullvadAppData = std::experimental::filesystem::path(localAppData).append(L"Mullvad VPN");
+
+ common::fs::ScopedNativeFileSystem nativeFileSystem;
+
+ common::security::AddAdminToObjectDacl(mullvadAppData, SE_FILE_OBJECT);
+
+ const auto cacheFile = std::experimental::filesystem::path(mullvadAppData).append(L"relays.json");
+
+ std::experimental::filesystem::remove(cacheFile);
+}
+
}
diff --git a/windows/nsis-plugins/src/cleanup/cleaningops.h b/windows/nsis-plugins/src/cleanup/cleaningops.h
index 219d4333de..40ce97e81e 100644
--- a/windows/nsis-plugins/src/cleanup/cleaningops.h
+++ b/windows/nsis-plugins/src/cleanup/cleaningops.h
@@ -7,7 +7,10 @@ void RemoveLogsCacheCurrentUser();
void RemoveLogsCacheOtherUsers();
void RemoveLogsServiceUser();
void RemoveCacheServiceUser();
-
void RemoveSettingsServiceUser();
+// Remove only the relay cache, leaving other cache files untouched.
+// This is useful when updating the app.
+void RemoveRelayCacheServiceUser();
+
}
diff --git a/windows/nsis-plugins/src/cleanup/cleanup.cpp b/windows/nsis-plugins/src/cleanup/cleanup.cpp
index c7890d60b7..ea8d59ac79 100644
--- a/windows/nsis-plugins/src/cleanup/cleanup.cpp
+++ b/windows/nsis-plugins/src/cleanup/cleanup.cpp
@@ -1,5 +1,6 @@
#include <stdafx.h>
#include "cleaningops.h"
+#include <libcommon/string.h>
#include <windows.h>
#include <nsis/pluginapi.h>
#include <functional>
@@ -79,3 +80,40 @@ void __declspec(dllexport) NSISCALL RemoveSettings
pushint(RemoveSettingsStatus::GENERAL_ERROR);
}
}
+
+enum class RemoveRelayCacheStatus
+{
+ GENERAL_ERROR = 0,
+ SUCCESS
+};
+
+void __declspec(dllexport) NSISCALL RemoveRelayCache
+(
+ HWND hwndParent,
+ int string_size,
+ LPTSTR variables,
+ stack_t **stacktop,
+ extra_parameters *extra,
+ ...
+)
+{
+ EXDLL_INIT();
+
+ try
+ {
+ cleaningops::RemoveRelayCacheServiceUser();
+
+ pushstring(L"");
+ pushint(RemoveRelayCacheStatus::SUCCESS);
+ }
+ catch (const std::exception &err)
+ {
+ pushstring(common::string::ToWide(err.what()).c_str());
+ pushint(RemoveRelayCacheStatus::GENERAL_ERROR);
+ }
+ catch (...)
+ {
+ pushstring(L"Unspecified error");
+ pushint(RemoveRelayCacheStatus::GENERAL_ERROR);
+ }
+}
diff --git a/windows/nsis-plugins/src/cleanup/cleanup.def b/windows/nsis-plugins/src/cleanup/cleanup.def
index 590d311b7a..8752772b8d 100644
--- a/windows/nsis-plugins/src/cleanup/cleanup.def
+++ b/windows/nsis-plugins/src/cleanup/cleanup.def
@@ -4,3 +4,4 @@ EXPORTS
RemoveLogsAndCache
RemoveSettings
+RemoveRelayCache