diff options
| author | David Lönnhager <david.l@mullvad.net> | 2020-07-24 13:41:54 +0200 |
|---|---|---|
| committer | David Lönnhager <david.l@mullvad.net> | 2020-08-04 10:52:43 +0200 |
| commit | aab79a3d5312cc78eff5185c028dcabeb3ff15ec (patch) | |
| tree | c947e708035f5d948983c7676c92b9e6f3ed20fc /windows | |
| parent | 4128984c95ebd25c8c30ff19fb0e992f4f6f9b5a (diff) | |
| download | mullvadvpn-aab79a3d5312cc78eff5185c028dcabeb3ff15ec.tar.xz mullvadvpn-aab79a3d5312cc78eff5185c028dcabeb3ff15ec.zip | |
Return policy failure causes in WinFw
Diffstat (limited to 'windows')
| -rw-r--r-- | windows/winfw/src/winfw/winfw.cpp | 79 | ||||
| -rw-r--r-- | windows/winfw/src/winfw/winfw.h | 15 |
2 files changed, 70 insertions, 24 deletions
diff --git a/windows/winfw/src/winfw/winfw.cpp b/windows/winfw/src/winfw/winfw.cpp index 3ce26376f7..30d55488b9 100644 --- a/windows/winfw/src/winfw/winfw.cpp +++ b/windows/winfw/src/winfw/winfw.cpp @@ -42,6 +42,23 @@ std::optional<FwContext::PingableHosts> ConvertPingableHosts(const PingableHosts return converted; } +WINFW_POLICY_STATUS +HandlePolicyException(const common::error::WindowsException &err) +{ + if (nullptr != g_logSink) + { + g_logSink(MULLVAD_LOG_LEVEL_ERROR, err.what(), g_logSinkContext); + } + + if (FWP_E_TIMEOUT == err.errorCode()) + { + // TODO: Detect software that may cause this + return WINFW_POLICY_STATUS_LOCK_TIMEOUT; + } + + return WINFW_POLICY_STATUS_GENERAL_FAILURE; +} + } // anonymous namespace WINFW_LINKAGE @@ -176,7 +193,7 @@ WinFw_Deinitialize(WINFW_CLEANUP_POLICY cleanupPolicy) } WINFW_LINKAGE -bool +WINFW_POLICY_STATUS WINFW_API WinFw_ApplyPolicyConnecting( const WinFwSettings *settings, @@ -187,7 +204,7 @@ WinFw_ApplyPolicyConnecting( { if (nullptr == g_fwContext) { - return false; + return WINFW_POLICY_STATUS_GENERAL_FAILURE; } try @@ -212,7 +229,11 @@ WinFw_ApplyPolicyConnecting( *relay, relayClient, ConvertPingableHosts(pingableHosts) - ); + ) ? WINFW_POLICY_STATUS_SUCCESS : WINFW_POLICY_STATUS_GENERAL_FAILURE; + } + catch (common::error::WindowsException &err) + { + return HandlePolicyException(err); } catch (std::exception &err) { @@ -221,16 +242,16 @@ WinFw_ApplyPolicyConnecting( g_logSink(MULLVAD_LOG_LEVEL_ERROR, err.what(), g_logSinkContext); } - return false; + return WINFW_POLICY_STATUS_GENERAL_FAILURE; } catch (...) { - return false; + return WINFW_POLICY_STATUS_GENERAL_FAILURE; } } WINFW_LINKAGE -bool +WINFW_POLICY_STATUS WINFW_API WinFw_ApplyPolicyConnected( const WinFwSettings *settings, @@ -243,7 +264,7 @@ WinFw_ApplyPolicyConnected( { if (nullptr == g_fwContext) { - return false; + return WINFW_POLICY_STATUS_GENERAL_FAILURE; } try @@ -286,7 +307,11 @@ WinFw_ApplyPolicyConnected( relayClient, tunnelInterfaceAlias, tunnelDnsServers - ); + ) ? WINFW_POLICY_STATUS_SUCCESS : WINFW_POLICY_STATUS_GENERAL_FAILURE; + } + catch (common::error::WindowsException &err) + { + return HandlePolicyException(err); } catch (std::exception &err) { @@ -295,16 +320,16 @@ WinFw_ApplyPolicyConnected( g_logSink(MULLVAD_LOG_LEVEL_ERROR, err.what(), g_logSinkContext); } - return false; + return WINFW_POLICY_STATUS_GENERAL_FAILURE; } catch (...) { - return false; + return WINFW_POLICY_STATUS_GENERAL_FAILURE; } } WINFW_LINKAGE -bool +WINFW_POLICY_STATUS WINFW_API WinFw_ApplyPolicyBlocked( const WinFwSettings *settings @@ -312,7 +337,7 @@ WinFw_ApplyPolicyBlocked( { if (nullptr == g_fwContext) { - return false; + return WINFW_POLICY_STATUS_GENERAL_FAILURE; } try @@ -322,7 +347,13 @@ WinFw_ApplyPolicyBlocked( THROW_ERROR("Invalid argument: settings"); } - return g_fwContext->applyPolicyBlocked(*settings); + return g_fwContext->applyPolicyBlocked(*settings) + ? WINFW_POLICY_STATUS_SUCCESS + : WINFW_POLICY_STATUS_GENERAL_FAILURE; + } + catch (common::error::WindowsException &err) + { + return HandlePolicyException(err); } catch (std::exception &err) { @@ -331,16 +362,16 @@ WinFw_ApplyPolicyBlocked( g_logSink(MULLVAD_LOG_LEVEL_ERROR, err.what(), g_logSinkContext); } - return false; + return WINFW_POLICY_STATUS_GENERAL_FAILURE; } catch (...) { - return false; + return WINFW_POLICY_STATUS_GENERAL_FAILURE; } } WINFW_LINKAGE -bool +WINFW_POLICY_STATUS WINFW_API WinFw_Reset() { @@ -348,10 +379,18 @@ WinFw_Reset() { if (nullptr == g_fwContext) { - return ObjectPurger::Execute(ObjectPurger::GetRemoveAllFunctor()); + return ObjectPurger::Execute(ObjectPurger::GetRemoveAllFunctor()) + ? WINFW_POLICY_STATUS_SUCCESS + : WINFW_POLICY_STATUS_GENERAL_FAILURE; } - return g_fwContext->reset(); + return g_fwContext->reset() + ? WINFW_POLICY_STATUS_SUCCESS + : WINFW_POLICY_STATUS_GENERAL_FAILURE; + } + catch (common::error::WindowsException &err) + { + return HandlePolicyException(err); } catch (std::exception &err) { @@ -360,10 +399,10 @@ WinFw_Reset() g_logSink(MULLVAD_LOG_LEVEL_ERROR, err.what(), g_logSinkContext); } - return false; + return WINFW_POLICY_STATUS_GENERAL_FAILURE; } catch (...) { - return false; + return WINFW_POLICY_STATUS_GENERAL_FAILURE; } } diff --git a/windows/winfw/src/winfw/winfw.h b/windows/winfw/src/winfw/winfw.h index ca4e4b8317..796b034762 100644 --- a/windows/winfw/src/winfw/winfw.h +++ b/windows/winfw/src/winfw/winfw.h @@ -132,6 +132,13 @@ typedef struct tag_PingableHosts } PingableHosts; +enum WINFW_POLICY_STATUS +{ + WINFW_POLICY_STATUS_SUCCESS = 0, + WINFW_POLICY_STATUS_GENERAL_FAILURE = 1, + WINFW_POLICY_STATUS_LOCK_TIMEOUT = 2, +}; + // // ApplyPolicyConnecting: // @@ -142,7 +149,7 @@ PingableHosts; // extern "C" WINFW_LINKAGE -bool +WINFW_POLICY_STATUS WINFW_API WinFw_ApplyPolicyConnecting( const WinFwSettings *settings, @@ -169,7 +176,7 @@ WinFw_ApplyPolicyConnecting( // extern "C" WINFW_LINKAGE -bool +WINFW_POLICY_STATUS WINFW_API WinFw_ApplyPolicyConnected( const WinFwSettings *settings, @@ -188,7 +195,7 @@ WinFw_ApplyPolicyConnected( // extern "C" WINFW_LINKAGE -bool +WINFW_POLICY_STATUS WINFW_API WinFw_ApplyPolicyBlocked( const WinFwSettings *settings @@ -201,6 +208,6 @@ WinFw_ApplyPolicyBlocked( // extern "C" WINFW_LINKAGE -bool +WINFW_POLICY_STATUS WINFW_API WinFw_Reset(); |
