api: fallback to hard-coded version

Windows 7 doesn't have DriverMajorVersion and DriverMinorVersion
registry values yet.

Signed-off-by: Simon Rozman <simon@rozman.si>
This commit is contained in:
Simon Rozman 2020-10-29 12:04:34 +01:00
parent e11897e343
commit 4a575d210a
4 changed files with 20 additions and 18 deletions

View File

@ -541,7 +541,7 @@ CreateAdapterData(
HeapFree(ModuleHeap, 0, ValueStr);
/* Read the NetLuidIndex value. */
Result = RegistryQueryDWORD(Key, L"NetLuidIndex", &(*Adapter)->LuidIndex);
Result = RegistryQueryDWORD(Key, L"NetLuidIndex", &(*Adapter)->LuidIndex, TRUE);
if (Result != ERROR_SUCCESS)
{
LOG(WINTUN_LOG_ERR, L"Failed to query NetLuidIndex value");
@ -549,7 +549,7 @@ CreateAdapterData(
}
/* Read the NetLuidIndex value. */
Result = RegistryQueryDWORD(Key, L"*IfType", &(*Adapter)->IfType);
Result = RegistryQueryDWORD(Key, L"*IfType", &(*Adapter)->IfType, TRUE);
if (Result != ERROR_SUCCESS)
{
LOG(WINTUN_LOG_ERR, L"Failed to query *IfType value");

View File

@ -22,25 +22,19 @@ WintunGetVersion(
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);
Result = RegistryQueryDWORD(Key, L"DriverMajorVersion", DriverVersionMaj);
if (Result != ERROR_SUCCESS)
if (RegistryQueryDWORD(Key, L"DriverMajorVersion", DriverVersionMaj, FALSE) != ERROR_SUCCESS ||
RegistryQueryDWORD(Key, L"DriverMinorVersion", DriverVersionMin, FALSE) != ERROR_SUCCESS)
{
LOG(WINTUN_LOG_ERR, L"Failed to query DriverMajorVersion value");
goto cleanupKey;
*DriverVersionMaj = WINTUN_VERSION_MAJ;
*DriverVersionMin = WINTUN_VERSION_MIN;
}
Result = RegistryQueryDWORD(Key, L"DriverMinorVersion", DriverVersionMin);
if (Result != ERROR_SUCCESS)
{
LOG(WINTUN_LOG_ERR, L"Failed to query DriverMinorVersion value");
goto cleanupKey;
}
Result = RegistryQueryDWORD(Key, L"NdisMajorVersion", NdisVersionMaj);
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);
Result = RegistryQueryDWORD(Key, L"NdisMinorVersion", NdisVersionMin, TRUE);
if (Result != ERROR_SUCCESS)
LOG(WINTUN_LOG_ERR, L"Failed to query NdisMinorVersion value");
cleanupKey:

View File

@ -249,12 +249,16 @@ RegistryQueryStringWait(_In_ HKEY Key, _In_opt_z_ const WCHAR *Name, _In_ DWORD
}
WINTUN_STATUS
RegistryQueryDWORD(_In_ HKEY Key, _In_opt_z_ const WCHAR *Name, _Out_ DWORD *Value)
RegistryQueryDWORD(_In_ HKEY Key, _In_opt_z_ const WCHAR *Name, _Out_ DWORD *Value, _In_ BOOL Log)
{
DWORD ValueType, Size = sizeof(DWORD);
DWORD Result = RegQueryValueExW(Key, Name, NULL, &ValueType, (BYTE *)Value, &Size);
if (Result != ERROR_SUCCESS)
return LOG_ERROR(L"Querying failed", Result);
{
if (Log)
LOG_ERROR(L"Querying failed", Result);
return Result;
}
if (ValueType != REG_DWORD)
{
LOG(WINTUN_LOG_ERR, L"Value is not a DWORD");
@ -284,7 +288,7 @@ RegistryQueryDWORDWait(_In_ HKEY Key, _In_opt_z_ const WCHAR *Name, _In_ DWORD T
LOG_ERROR(L"Failed to setup notification", Result);
break;
}
Result = RegistryQueryDWORD(Key, Name, Value);
Result = RegistryQueryDWORD(Key, Name, Value, FALSE);
if (Result != ERROR_FILE_NOT_FOUND && Result != ERROR_PATH_NOT_FOUND)
break;
LONGLONG TimeLeft = Deadline - GetTickCount64();

View File

@ -118,11 +118,15 @@ RegistryQueryStringWait(_In_ HKEY Key, _In_opt_z_ const WCHAR *Name, _In_ DWORD
*
* @param Value Pointer to DWORD to retrieve registry value.
*
* @Log Set to TRUE to log all failures; FALSE to skip logging the innermost errors. Skipping innermost
* errors reduces log clutter when we are using RegistryQueryDWORD() from
* RegistryQueryDWORDWait() and some errors are expected to occur.
*
* @return ERROR_SUCCESS on success; ERROR_INVALID_DATATYPE when registry value exist but not REG_DWORD type;
* ERROR_INVALID_DATA when registry value size is not 4 bytes; Win32 error code otherwise.
*/
WINTUN_STATUS
RegistryQueryDWORD(_In_ HKEY Key, _In_opt_z_ const WCHAR *Name, _Out_ DWORD *Value);
RegistryQueryDWORD(_In_ HKEY Key, _In_opt_z_ const WCHAR *Name, _Out_ DWORD *Value, _In_ BOOL Log);
/**
* Reads a 32-bit DWORD value from registry key. It waits for the registry value to become available.