From b5836e9fb9b78c6b9034a735034610c7a97276a1 Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Sun, 1 Nov 2020 05:54:56 +0100 Subject: [PATCH] api: make version function uniform Signed-off-by: Jason A. Donenfeld --- api/adapter.c | 8 ++++---- api/entry.c | 33 --------------------------------- api/wintun.h | 18 +++--------------- 3 files changed, 7 insertions(+), 52 deletions(-) diff --git a/api/adapter.c b/api/adapter.c index 95b844b..5431bc3 100644 --- a/api/adapter.c +++ b/api/adapter.c @@ -1381,8 +1381,8 @@ CreateTemporaryDirectory(_Out_cap_c_(MAX_PATH) WCHAR *RandomTempSubDirectory) return ERROR_SUCCESS; } -static DWORDLONG -RunningWintunVersion(void) +DWORDLONG +WintunGetVersion(void) { DWORDLONG Version = 0; PRTL_PROCESS_MODULES Modules; @@ -1424,7 +1424,7 @@ out: static BOOL EnsureWintunUnloaded(VOID) { 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); return !Loaded; } @@ -1461,7 +1461,7 @@ InstallDriver(_Out_writes_z_(MAX_PATH) WCHAR InfStorePath[MAX_PATH], _Inout_ BOO goto cleanupDelete; } - DWORDLONG LoadedDriverVersion = RunningWintunVersion(); + DWORDLONG LoadedDriverVersion = WintunGetVersion(); HDEVINFO DevInfo = INVALID_HANDLE_VALUE; SP_DEVINFO_DATA_LIST *ExistingAdapters = NULL; if (LoadedDriverVersion) diff --git a/api/entry.c b/api/entry.c index 2232c18..3dd42bb 100644 --- a/api/entry.c +++ b/api/entry.c @@ -22,39 +22,6 @@ HINSTANCE ResourceModule; HANDLE ModuleHeap; 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) { if (dliNotify != dliNotePreLoadLibrary) diff --git a/api/wintun.h b/api/wintun.h index fabe03d..f39e33c 100644 --- a/api/wintun.h +++ b/api/wintun.h @@ -164,23 +164,11 @@ typedef WINTUN_STATUS(WINAPI *WINTUN_GET_ADAPTER_NAME_FUNC)( _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. - * - * @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. + * @return The version number on success, or 0 if failure. */ -typedef WINTUN_STATUS(WINAPI *WINTUN_GET_VERSION_FUNC)( - _Out_ DWORD *DriverVersionMaj, - _Out_ DWORD *DriverVersionMin, - _Out_ DWORD *NdisVersionMaj, - _Out_ DWORD *NdisVersionMin); +typedef DWORDLONG(WINAPI *WINTUN_GET_VERSION_FUNC)(void); /** * Sets name of the Wintun adapter.