From 479bbdc50a45ca9ae62ac15a1ee7445a6cbbe42a Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Tue, 11 May 2021 19:43:34 +0200 Subject: [PATCH] api: only mark GUID as in-use if Status != NotPresent Signed-off-by: Jason A. Donenfeld --- api/adapter.c | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/api/adapter.c b/api/adapter.c index 5cc0dad..c15a420 100644 --- a/api/adapter.c +++ b/api/adapter.c @@ -3,6 +3,22 @@ * Copyright (C) 2018-2021 WireGuard LLC. All Rights Reserved. */ +#include +#include +#include +#define _NTDEF_ /* TODO: figure out how to include ntsecapi and winternal together without requiring this */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include /* Keep these two at bottom in this order, so that we only generate extra GUIDs for devpkey. The other keys we'll get from uuid.lib like usual. */ +#include + #include "adapter.h" #include "elevate.h" #include "entry.h" @@ -14,20 +30,6 @@ #include "resource.h" #include "wintun-inf.h" -#include -#include -#define _NTDEF_ /* TODO: figure out how to include ntsecapi and winternal together without requiring this */ -#include -#include -#include -#include -#include -#include -#include -#include -#include /* Keep these two at bottom in this order, so that we only generate extra GUIDs for devpkey. The other keys we'll get from uuid.lib like usual. */ -#include - #pragma warning(disable : 4221) /* nonstandard: address of automatic in initializer */ #define WAIT_FOR_REGISTRY_TIMEOUT 10000 /* ms */ @@ -1452,8 +1454,9 @@ static _Return_type_success_(return != NULL) WINTUN_ADAPTER *CreateAdapter( if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, RegPath, 0, KEY_QUERY_VALUE, &Key) == ERROR_SUCCESS) { RegCloseKey(Key); - NET_LUID Luid; - if (ConvertInterfaceGuidToLuid(RequestedGUID, &Luid) == NO_ERROR) + MIB_IF_ROW2 IfRow = { 0 }; + if (ConvertInterfaceGuidToLuid(RequestedGUID, &IfRow.InterfaceLuid) == NO_ERROR && + GetIfEntry2(&IfRow) == NO_ERROR && IfRow.OperStatus != IfOperStatusNotPresent) { SetLastError( LOG_ERROR(ERROR_ALREADY_EXISTS, L"Requested GUID is already in use: %s", RequestedGUIDStr));