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:
parent
e11897e343
commit
4a575d210a
@ -541,7 +541,7 @@ CreateAdapterData(
|
|||||||
HeapFree(ModuleHeap, 0, ValueStr);
|
HeapFree(ModuleHeap, 0, ValueStr);
|
||||||
|
|
||||||
/* Read the NetLuidIndex value. */
|
/* Read the NetLuidIndex value. */
|
||||||
Result = RegistryQueryDWORD(Key, L"NetLuidIndex", &(*Adapter)->LuidIndex);
|
Result = RegistryQueryDWORD(Key, L"NetLuidIndex", &(*Adapter)->LuidIndex, TRUE);
|
||||||
if (Result != ERROR_SUCCESS)
|
if (Result != ERROR_SUCCESS)
|
||||||
{
|
{
|
||||||
LOG(WINTUN_LOG_ERR, L"Failed to query NetLuidIndex value");
|
LOG(WINTUN_LOG_ERR, L"Failed to query NetLuidIndex value");
|
||||||
@ -549,7 +549,7 @@ CreateAdapterData(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Read the NetLuidIndex value. */
|
/* Read the NetLuidIndex value. */
|
||||||
Result = RegistryQueryDWORD(Key, L"*IfType", &(*Adapter)->IfType);
|
Result = RegistryQueryDWORD(Key, L"*IfType", &(*Adapter)->IfType, TRUE);
|
||||||
if (Result != ERROR_SUCCESS)
|
if (Result != ERROR_SUCCESS)
|
||||||
{
|
{
|
||||||
LOG(WINTUN_LOG_ERR, L"Failed to query *IfType value");
|
LOG(WINTUN_LOG_ERR, L"Failed to query *IfType value");
|
||||||
|
18
api/api.c
18
api/api.c
@ -22,25 +22,19 @@ WintunGetVersion(
|
|||||||
RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"SYSTEM\\CurrentControlSet\\Services\\Wintun", 0, KEY_QUERY_VALUE, &Key);
|
RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"SYSTEM\\CurrentControlSet\\Services\\Wintun", 0, KEY_QUERY_VALUE, &Key);
|
||||||
if (Result != ERROR_SUCCESS)
|
if (Result != ERROR_SUCCESS)
|
||||||
return LOG_ERROR(L"Failed to open registry key", Result);
|
return LOG_ERROR(L"Failed to open registry key", Result);
|
||||||
Result = RegistryQueryDWORD(Key, L"DriverMajorVersion", DriverVersionMaj);
|
if (RegistryQueryDWORD(Key, L"DriverMajorVersion", DriverVersionMaj, FALSE) != ERROR_SUCCESS ||
|
||||||
if (Result != ERROR_SUCCESS)
|
RegistryQueryDWORD(Key, L"DriverMinorVersion", DriverVersionMin, FALSE) != ERROR_SUCCESS)
|
||||||
{
|
{
|
||||||
LOG(WINTUN_LOG_ERR, L"Failed to query DriverMajorVersion value");
|
*DriverVersionMaj = WINTUN_VERSION_MAJ;
|
||||||
goto cleanupKey;
|
*DriverVersionMin = WINTUN_VERSION_MIN;
|
||||||
}
|
}
|
||||||
Result = RegistryQueryDWORD(Key, L"DriverMinorVersion", DriverVersionMin);
|
Result = RegistryQueryDWORD(Key, L"NdisMajorVersion", NdisVersionMaj, TRUE);
|
||||||
if (Result != ERROR_SUCCESS)
|
|
||||||
{
|
|
||||||
LOG(WINTUN_LOG_ERR, L"Failed to query DriverMinorVersion value");
|
|
||||||
goto cleanupKey;
|
|
||||||
}
|
|
||||||
Result = RegistryQueryDWORD(Key, L"NdisMajorVersion", NdisVersionMaj);
|
|
||||||
if (Result != ERROR_SUCCESS)
|
if (Result != ERROR_SUCCESS)
|
||||||
{
|
{
|
||||||
LOG(WINTUN_LOG_ERR, L"Failed to query NdisMajorVersion value");
|
LOG(WINTUN_LOG_ERR, L"Failed to query NdisMajorVersion value");
|
||||||
goto cleanupKey;
|
goto cleanupKey;
|
||||||
}
|
}
|
||||||
Result = RegistryQueryDWORD(Key, L"NdisMinorVersion", NdisVersionMin);
|
Result = RegistryQueryDWORD(Key, L"NdisMinorVersion", NdisVersionMin, TRUE);
|
||||||
if (Result != ERROR_SUCCESS)
|
if (Result != ERROR_SUCCESS)
|
||||||
LOG(WINTUN_LOG_ERR, L"Failed to query NdisMinorVersion value");
|
LOG(WINTUN_LOG_ERR, L"Failed to query NdisMinorVersion value");
|
||||||
cleanupKey:
|
cleanupKey:
|
||||||
|
@ -249,12 +249,16 @@ RegistryQueryStringWait(_In_ HKEY Key, _In_opt_z_ const WCHAR *Name, _In_ DWORD
|
|||||||
}
|
}
|
||||||
|
|
||||||
WINTUN_STATUS
|
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 ValueType, Size = sizeof(DWORD);
|
||||||
DWORD Result = RegQueryValueExW(Key, Name, NULL, &ValueType, (BYTE *)Value, &Size);
|
DWORD Result = RegQueryValueExW(Key, Name, NULL, &ValueType, (BYTE *)Value, &Size);
|
||||||
if (Result != ERROR_SUCCESS)
|
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)
|
if (ValueType != REG_DWORD)
|
||||||
{
|
{
|
||||||
LOG(WINTUN_LOG_ERR, L"Value is not a 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);
|
LOG_ERROR(L"Failed to setup notification", Result);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
Result = RegistryQueryDWORD(Key, Name, Value);
|
Result = RegistryQueryDWORD(Key, Name, Value, FALSE);
|
||||||
if (Result != ERROR_FILE_NOT_FOUND && Result != ERROR_PATH_NOT_FOUND)
|
if (Result != ERROR_FILE_NOT_FOUND && Result != ERROR_PATH_NOT_FOUND)
|
||||||
break;
|
break;
|
||||||
LONGLONG TimeLeft = Deadline - GetTickCount64();
|
LONGLONG TimeLeft = Deadline - GetTickCount64();
|
||||||
|
@ -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.
|
* @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;
|
* @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.
|
* ERROR_INVALID_DATA when registry value size is not 4 bytes; Win32 error code otherwise.
|
||||||
*/
|
*/
|
||||||
WINTUN_STATUS
|
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.
|
* Reads a 32-bit DWORD value from registry key. It waits for the registry value to become available.
|
||||||
|
Loading…
Reference in New Issue
Block a user