2020-07-03 12:26:06 +02:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0
|
|
|
|
*
|
|
|
|
* Copyright (C) 2018-2020 WireGuard LLC. All Rights Reserved.
|
|
|
|
*/
|
|
|
|
|
2020-07-21 16:57:36 +02:00
|
|
|
#include "pch.h"
|
2020-07-03 12:26:06 +02:00
|
|
|
|
|
|
|
HINSTANCE ResourceModule;
|
|
|
|
|
2020-07-21 18:19:15 +02:00
|
|
|
/**
|
|
|
|
* Returns the version of the Wintun driver and NDIS system currently loaded.
|
2020-07-24 08:29:55 +02:00
|
|
|
*
|
|
|
|
* @param DriverVersionMaj Pointer to a DWORD to receive the Wintun driver major version number.
|
|
|
|
*
|
|
|
|
* @param DriverVersionMin Pointer to a DWORD to receive the Wintun driver minor version number.
|
|
|
|
*
|
|
|
|
* @param NdisVersionMaj Pointer to a DWORD to receive the NDIS major version number.
|
|
|
|
*
|
|
|
|
* @param NdisVersionMin Pointer to a DWORD to receive the NDIS minor version number.
|
|
|
|
*
|
|
|
|
* @return ERROR_SUCCESS on success; Win32 error code otherwise.
|
2020-07-21 18:19:15 +02:00
|
|
|
*/
|
|
|
|
WINTUN_STATUS WINAPI
|
|
|
|
WintunGetVersion(
|
|
|
|
_Out_ DWORD *DriverVersionMaj,
|
|
|
|
_Out_ DWORD *DriverVersionMin,
|
|
|
|
_Out_ DWORD *NdisVersionMaj,
|
|
|
|
_Out_ DWORD *NdisVersionMin)
|
|
|
|
{
|
|
|
|
HKEY Key;
|
|
|
|
DWORD Result =
|
|
|
|
RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"SYSTEM\\CurrentControlSet\\Services\\Wintun", 0, KEY_QUERY_VALUE, &Key);
|
|
|
|
if (Result != ERROR_SUCCESS)
|
2020-10-14 13:04:29 +02:00
|
|
|
return LOG_ERROR(L"Failed to open registry key", Result);
|
2020-07-21 18:19:15 +02:00
|
|
|
Result = RegistryQueryDWORD(Key, L"DriverMajorVersion", DriverVersionMaj);
|
|
|
|
if (Result != ERROR_SUCCESS)
|
2020-10-13 19:40:52 +02:00
|
|
|
{
|
2020-10-14 13:04:29 +02:00
|
|
|
LOG_ERROR(L"Failed to query DriverMajorVersion value", Result);
|
2020-07-21 18:19:15 +02:00
|
|
|
goto cleanupKey;
|
2020-10-13 19:40:52 +02:00
|
|
|
}
|
2020-07-21 18:19:15 +02:00
|
|
|
Result = RegistryQueryDWORD(Key, L"DriverMinorVersion", DriverVersionMin);
|
|
|
|
if (Result != ERROR_SUCCESS)
|
2020-10-13 19:40:52 +02:00
|
|
|
{
|
2020-10-14 13:04:29 +02:00
|
|
|
LOG_ERROR(L"Failed to query DriverMinorVersion value", Result);
|
2020-07-21 18:19:15 +02:00
|
|
|
goto cleanupKey;
|
2020-10-13 19:40:52 +02:00
|
|
|
}
|
2020-07-21 18:19:15 +02:00
|
|
|
Result = RegistryQueryDWORD(Key, L"NdisMajorVersion", NdisVersionMaj);
|
|
|
|
if (Result != ERROR_SUCCESS)
|
2020-10-13 19:40:52 +02:00
|
|
|
{
|
2020-10-14 13:04:29 +02:00
|
|
|
LOG_ERROR(L"Failed to query NdisMajorVersion value", Result);
|
2020-07-21 18:19:15 +02:00
|
|
|
goto cleanupKey;
|
2020-10-13 19:40:52 +02:00
|
|
|
}
|
2020-07-21 18:19:15 +02:00
|
|
|
Result = RegistryQueryDWORD(Key, L"NdisMinorVersion", NdisVersionMin);
|
2020-10-13 19:40:52 +02:00
|
|
|
if (Result != ERROR_SUCCESS)
|
2020-10-14 13:04:29 +02:00
|
|
|
LOG_ERROR(L"Failed to query NdisMinorVersion value", Result);
|
2020-07-21 18:19:15 +02:00
|
|
|
cleanupKey:
|
|
|
|
RegCloseKey(Key);
|
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
2020-07-03 12:26:06 +02:00
|
|
|
BOOL APIENTRY
|
|
|
|
DllMain(_In_ HINSTANCE hinstDLL, _In_ DWORD fdwReason, _In_ LPVOID lpvReserved)
|
|
|
|
{
|
|
|
|
UNREFERENCED_PARAMETER(lpvReserved);
|
|
|
|
|
|
|
|
switch (fdwReason)
|
|
|
|
{
|
|
|
|
case DLL_PROCESS_ATTACH:
|
|
|
|
ResourceModule = hinstDLL;
|
2020-07-03 16:49:47 +02:00
|
|
|
NamespaceInit();
|
2020-07-07 15:32:06 +02:00
|
|
|
NciInit();
|
2020-07-28 12:30:12 +02:00
|
|
|
DevmgmtInit();
|
2020-07-03 16:49:47 +02:00
|
|
|
break;
|
|
|
|
|
2020-07-03 12:26:06 +02:00
|
|
|
case DLL_PROCESS_DETACH:
|
2020-07-28 12:30:12 +02:00
|
|
|
DevmgmtCleanup();
|
2020-07-07 15:32:06 +02:00
|
|
|
NciCleanup();
|
2020-07-03 16:49:47 +02:00
|
|
|
NamespaceCleanup();
|
2020-07-03 12:26:06 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|