aboutsummaryrefslogtreecommitdiffstats
path: root/api/adapter.c
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2020-11-09 13:02:31 +0100
committerJason A. Donenfeld <Jason@zx2c4.com>2020-11-09 13:11:07 +0100
commit7c5233a80e5c36c1a4871b8cd58c563a56d22606 (patch)
tree74ae42544f26593ef664502f8470c465f79a5e7a /api/adapter.c
parentapi: manipulate process token if thread token didn't require impersonation (diff)
downloadwintun-7c5233a80e5c36c1a4871b8cd58c563a56d22606.tar.xz
wintun-7c5233a80e5c36c1a4871b8cd58c563a56d22606.zip
api: account for adapter disappearing during deletion
This makes the race less fatal. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'api/adapter.c')
-rw-r--r--api/adapter.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/api/adapter.c b/api/adapter.c
index 6c1a5b5..325a29e 100644
--- a/api/adapter.c
+++ b/api/adapter.c
@@ -1707,8 +1707,9 @@ _Return_type_success_(return != FALSE) BOOL WINAPI WintunDeleteAdapter(
SP_REMOVEDEVICE_PARAMS Params = { .ClassInstallHeader = { .cbSize = sizeof(SP_CLASSINSTALL_HEADER),
.InstallFunction = DIF_REMOVE },
.Scope = DI_REMOVEDEVICE_GLOBAL };
- if (!SetupDiSetClassInstallParamsW(DevInfo, &DevInfoData, &Params.ClassInstallHeader, sizeof(Params)) ||
- !SetupDiCallClassInstaller(DIF_REMOVE, DevInfo, &DevInfoData))
+ if ((!SetupDiSetClassInstallParamsW(DevInfo, &DevInfoData, &Params.ClassInstallHeader, sizeof(Params)) ||
+ !SetupDiCallClassInstaller(DIF_REMOVE, DevInfo, &DevInfoData)) &&
+ GetLastError() != ERROR_NO_SUCH_DEVINST)
{
LastError = LOG_LAST_ERROR(L"Failed to remove existing adapter");
goto cleanupDevInfo;
@@ -1759,8 +1760,9 @@ static _Return_type_success_(return != FALSE) BOOL
LOG(WINTUN_LOG_WARN, L"Failed to force close adapter handles");
LOG(WINTUN_LOG_INFO, L"Removing existing adapter");
- if (!SetupDiSetClassInstallParamsW(DevInfo, &DevInfoData, &Params.ClassInstallHeader, sizeof(Params)) ||
- !SetupDiCallClassInstaller(DIF_REMOVE, DevInfo, &DevInfoData))
+ if ((!SetupDiSetClassInstallParamsW(DevInfo, &DevInfoData, &Params.ClassInstallHeader, sizeof(Params)) ||
+ !SetupDiCallClassInstaller(DIF_REMOVE, DevInfo, &DevInfoData)) &&
+ GetLastError() != ERROR_NO_SUCH_DEVINST)
{
LOG_LAST_ERROR(L"Failed to remove existing adapter");
LastError = LastError != ERROR_SUCCESS ? LastError : GetLastError();