api: make version function uniform

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
Jason A. Donenfeld 2020-11-01 05:54:56 +01:00 committed by Simon Rozman
parent 99097022fe
commit b5836e9fb9
3 changed files with 7 additions and 52 deletions

View File

@ -1381,8 +1381,8 @@ CreateTemporaryDirectory(_Out_cap_c_(MAX_PATH) WCHAR *RandomTempSubDirectory)
return ERROR_SUCCESS; return ERROR_SUCCESS;
} }
static DWORDLONG DWORDLONG
RunningWintunVersion(void) WintunGetVersion(void)
{ {
DWORDLONG Version = 0; DWORDLONG Version = 0;
PRTL_PROCESS_MODULES Modules; PRTL_PROCESS_MODULES Modules;
@ -1424,7 +1424,7 @@ out:
static BOOL EnsureWintunUnloaded(VOID) static BOOL EnsureWintunUnloaded(VOID)
{ {
BOOL Loaded; BOOL Loaded;
for (int i = 0; (Loaded = RunningWintunVersion() != 0) != FALSE && i < 300; ++i) for (int i = 0; (Loaded = WintunGetVersion() != 0) != FALSE && i < 300; ++i)
Sleep(50); Sleep(50);
return !Loaded; return !Loaded;
} }
@ -1461,7 +1461,7 @@ InstallDriver(_Out_writes_z_(MAX_PATH) WCHAR InfStorePath[MAX_PATH], _Inout_ BOO
goto cleanupDelete; goto cleanupDelete;
} }
DWORDLONG LoadedDriverVersion = RunningWintunVersion(); DWORDLONG LoadedDriverVersion = WintunGetVersion();
HDEVINFO DevInfo = INVALID_HANDLE_VALUE; HDEVINFO DevInfo = INVALID_HANDLE_VALUE;
SP_DEVINFO_DATA_LIST *ExistingAdapters = NULL; SP_DEVINFO_DATA_LIST *ExistingAdapters = NULL;
if (LoadedDriverVersion) if (LoadedDriverVersion)

View File

@ -22,39 +22,6 @@ HINSTANCE ResourceModule;
HANDLE ModuleHeap; HANDLE ModuleHeap;
SECURITY_ATTRIBUTES SecurityAttributes = { .nLength = sizeof(SECURITY_ATTRIBUTES) }; SECURITY_ATTRIBUTES SecurityAttributes = { .nLength = sizeof(SECURITY_ATTRIBUTES) };
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)
return LOG_ERROR(L"Failed to open registry key", Result);
if (RegistryQueryDWORD(Key, L"DriverMajorVersion", DriverVersionMaj, FALSE) != ERROR_SUCCESS ||
RegistryQueryDWORD(Key, L"DriverMinorVersion", DriverVersionMin, FALSE) != ERROR_SUCCESS)
{
/* TODO: Drop the fallback to WINTUN_VERSION_MAJ & WINTUN_VERSION_MIN when Windows 7 support is discontinued. */
*DriverVersionMaj = WINTUN_VERSION_MAJ;
*DriverVersionMin = WINTUN_VERSION_MIN;
}
Result = RegistryQueryDWORD(Key, L"NdisMajorVersion", NdisVersionMaj, TRUE);
if (Result != ERROR_SUCCESS)
{
LOG(WINTUN_LOG_ERR, L"Failed to query NdisMajorVersion value");
goto cleanupKey;
}
Result = RegistryQueryDWORD(Key, L"NdisMinorVersion", NdisVersionMin, TRUE);
if (Result != ERROR_SUCCESS)
LOG(WINTUN_LOG_ERR, L"Failed to query NdisMinorVersion value");
cleanupKey:
RegCloseKey(Key);
return Result;
}
static FARPROC WINAPI DelayedLoadLibraryHook(unsigned dliNotify, PDelayLoadInfo pdli) static FARPROC WINAPI DelayedLoadLibraryHook(unsigned dliNotify, PDelayLoadInfo pdli)
{ {
if (dliNotify != dliNotePreLoadLibrary) if (dliNotify != dliNotePreLoadLibrary)

View File

@ -164,23 +164,11 @@ typedef WINTUN_STATUS(WINAPI *WINTUN_GET_ADAPTER_NAME_FUNC)(
_Out_cap_c_(MAX_ADAPTER_NAME) WCHAR *Name); _Out_cap_c_(MAX_ADAPTER_NAME) WCHAR *Name);
/** /**
* Returns the version of the Wintun driver and NDIS system currently loaded. * Determines the version of the Wintun driver currently loaded.
* *
* @param DriverVersionMaj Pointer to a DWORD to receive the Wintun driver major version number. * @return The version number on success, or 0 if failure.
*
* @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.
*/ */
typedef WINTUN_STATUS(WINAPI *WINTUN_GET_VERSION_FUNC)( typedef DWORDLONG(WINAPI *WINTUN_GET_VERSION_FUNC)(void);
_Out_ DWORD *DriverVersionMaj,
_Out_ DWORD *DriverVersionMin,
_Out_ DWORD *NdisVersionMaj,
_Out_ DWORD *NdisVersionMin);
/** /**
* Sets name of the Wintun adapter. * Sets name of the Wintun adapter.