aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Rozman <simon@rozman.si>2020-10-29 12:04:34 +0100
committerSimon Rozman <simon@rozman.si>2020-10-31 10:41:46 +0100
commit4a575d210a34384787d4936dfb96d6b8cb2ea48c (patch)
tree0cde3fe255d641812a1af9f741c23312b03bfe48
parentapi: depretiate WintunIsPacketAvailable() (diff)
downloadwintun-4a575d210a34384787d4936dfb96d6b8cb2ea48c.tar.xz
wintun-4a575d210a34384787d4936dfb96d6b8cb2ea48c.zip
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>
-rw-r--r--api/adapter.c4
-rw-r--r--api/api.c18
-rw-r--r--api/registry.c10
-rw-r--r--api/registry.h6
4 files changed, 20 insertions, 18 deletions
diff --git a/api/adapter.c b/api/adapter.c
index 0035e8d..63e1e76 100644
--- a/api/adapter.c
+++ b/api/adapter.c
@@ -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");
diff --git a/api/api.c b/api/api.c
index 7735a24..983596e 100644
--- a/api/api.c
+++ b/api/api.c
@@ -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)
- {
- LOG(WINTUN_LOG_ERR, L"Failed to query DriverMajorVersion value");
- goto cleanupKey;
- }
- Result = RegistryQueryDWORD(Key, L"DriverMinorVersion", DriverVersionMin);
- 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 DriverMinorVersion value");
- goto cleanupKey;
+ *DriverVersionMaj = WINTUN_VERSION_MAJ;
+ *DriverVersionMin = WINTUN_VERSION_MIN;
}
- 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:
diff --git a/api/registry.c b/api/registry.c
index 3975eef..45e4b21 100644
--- a/api/registry.c
+++ b/api/registry.c
@@ -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();
diff --git a/api/registry.h b/api/registry.h
index fb7d742..a8e5f5f 100644
--- a/api/registry.h
+++ b/api/registry.h
@@ -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.