Skip to content

Commit 479bbdc

Browse files
committed
api: only mark GUID as in-use if Status != NotPresent
Signed-off-by: Jason A. Donenfeld <[email protected]>
1 parent 0d96b90 commit 479bbdc

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

api/adapter.c

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,13 @@
33
* Copyright (C) 2018-2021 WireGuard LLC. All Rights Reserved.
44
*/
55

6-
#include "adapter.h"
7-
#include "elevate.h"
8-
#include "entry.h"
9-
#include "logger.h"
10-
#include "namespace.h"
11-
#include "nci.h"
12-
#include "ntdll.h"
13-
#include "registry.h"
14-
#include "resource.h"
15-
#include "wintun-inf.h"
16-
6+
#include <WinSock2.h>
177
#include <Windows.h>
188
#include <winternl.h>
199
#define _NTDEF_ /* TODO: figure out how to include ntsecapi and winternal together without requiring this */
2010
#include <cfgmgr32.h>
2111
#include <devguid.h>
12+
#include <ws2tcpip.h>
2213
#include <iphlpapi.h>
2314
#include <ndisguid.h>
2415
#include <NTSecAPI.h>
@@ -28,6 +19,17 @@
2819
#include <initguid.h> /* 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. */
2920
#include <devpkey.h>
3021

22+
#include "adapter.h"
23+
#include "elevate.h"
24+
#include "entry.h"
25+
#include "logger.h"
26+
#include "namespace.h"
27+
#include "nci.h"
28+
#include "ntdll.h"
29+
#include "registry.h"
30+
#include "resource.h"
31+
#include "wintun-inf.h"
32+
3133
#pragma warning(disable : 4221) /* nonstandard: address of automatic in initializer */
3234

3335
#define WAIT_FOR_REGISTRY_TIMEOUT 10000 /* ms */
@@ -1452,8 +1454,9 @@ static _Return_type_success_(return != NULL) WINTUN_ADAPTER *CreateAdapter(
14521454
if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, RegPath, 0, KEY_QUERY_VALUE, &Key) == ERROR_SUCCESS)
14531455
{
14541456
RegCloseKey(Key);
1455-
NET_LUID Luid;
1456-
if (ConvertInterfaceGuidToLuid(RequestedGUID, &Luid) == NO_ERROR)
1457+
MIB_IF_ROW2 IfRow = { 0 };
1458+
if (ConvertInterfaceGuidToLuid(RequestedGUID, &IfRow.InterfaceLuid) == NO_ERROR &&
1459+
GetIfEntry2(&IfRow) == NO_ERROR && IfRow.OperStatus != IfOperStatusNotPresent)
14571460
{
14581461
SetLastError(
14591462
LOG_ERROR(ERROR_ALREADY_EXISTS, L"Requested GUID is already in use: %s", RequestedGUIDStr));

0 commit comments

Comments
 (0)