api: simplify logger macros names

WINTUN_LOGGER_... => LOGGER_... => LOG_...

Those macros are internal, so they don/t need to start with WINTUN_...

Replacing the noun LOGGER_... with the verb LOG_... makes the code more
natural to read now.

Signed-off-by: Simon Rozman <simon@rozman.si>
This commit is contained in:
Simon Rozman 2020-10-14 13:04:29 +02:00 committed by Jason A. Donenfeld
parent e157d421ec
commit 78b7a01eb3
6 changed files with 143 additions and 143 deletions

View File

@ -31,28 +31,28 @@ WintunGetVersion(
DWORD Result = DWORD Result =
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 WINTUN_LOGGER_ERROR(L"Failed to open registry key", Result); return LOG_ERROR(L"Failed to open registry key", Result);
Result = RegistryQueryDWORD(Key, L"DriverMajorVersion", DriverVersionMaj); Result = RegistryQueryDWORD(Key, L"DriverMajorVersion", DriverVersionMaj);
if (Result != ERROR_SUCCESS) if (Result != ERROR_SUCCESS)
{ {
WINTUN_LOGGER_ERROR(L"Failed to query DriverMajorVersion value", Result); LOG_ERROR(L"Failed to query DriverMajorVersion value", Result);
goto cleanupKey; goto cleanupKey;
} }
Result = RegistryQueryDWORD(Key, L"DriverMinorVersion", DriverVersionMin); Result = RegistryQueryDWORD(Key, L"DriverMinorVersion", DriverVersionMin);
if (Result != ERROR_SUCCESS) if (Result != ERROR_SUCCESS)
{ {
WINTUN_LOGGER_ERROR(L"Failed to query DriverMinorVersion value", Result); LOG_ERROR(L"Failed to query DriverMinorVersion value", Result);
goto cleanupKey; goto cleanupKey;
} }
Result = RegistryQueryDWORD(Key, L"NdisMajorVersion", NdisVersionMaj); Result = RegistryQueryDWORD(Key, L"NdisMajorVersion", NdisVersionMaj);
if (Result != ERROR_SUCCESS) if (Result != ERROR_SUCCESS)
{ {
WINTUN_LOGGER_ERROR(L"Failed to query NdisMajorVersion value", Result); LOG_ERROR(L"Failed to query NdisMajorVersion value", Result);
goto cleanupKey; goto cleanupKey;
} }
Result = RegistryQueryDWORD(Key, L"NdisMinorVersion", NdisVersionMin); Result = RegistryQueryDWORD(Key, L"NdisMinorVersion", NdisVersionMin);
if (Result != ERROR_SUCCESS) if (Result != ERROR_SUCCESS)
WINTUN_LOGGER_ERROR(L"Failed to query NdisMinorVersion value", Result); LOG_ERROR(L"Failed to query NdisMinorVersion value", Result);
cleanupKey: cleanupKey:
RegCloseKey(Key); RegCloseKey(Key);
return Result; return Result;

View File

@ -51,7 +51,7 @@ GetDeviceRegistryProperty(
DWORD Result = GetLastError(); DWORD Result = GetLastError();
HeapFree(Heap, 0, *Buf); HeapFree(Heap, 0, *Buf);
if (Result != ERROR_INSUFFICIENT_BUFFER) if (Result != ERROR_INSUFFICIENT_BUFFER)
return WINTUN_LOGGER_ERROR(L"Querying property failed", Result); return LOG_ERROR(L"Querying property failed", Result);
} }
} }
@ -91,7 +91,7 @@ GetDeviceRegistryString(
HeapFree(GetProcessHeap(), 0, *Buf); HeapFree(GetProcessHeap(), 0, *Buf);
return Result; return Result;
default: default:
WINTUN_LOGGER(WINTUN_LOG_ERR, L"Property is not a string"); LOG(WINTUN_LOG_ERR, L"Property is not a string");
HeapFree(GetProcessHeap(), 0, *Buf); HeapFree(GetProcessHeap(), 0, *Buf);
return ERROR_INVALID_DATATYPE; return ERROR_INVALID_DATATYPE;
} }
@ -133,7 +133,7 @@ GetDeviceRegistryMultiString(
HeapFree(GetProcessHeap(), 0, *Buf); HeapFree(GetProcessHeap(), 0, *Buf);
return Result; return Result;
default: default:
WINTUN_LOGGER(WINTUN_LOG_ERR, L"Property is not a string"); LOG(WINTUN_LOG_ERR, L"Property is not a string");
HeapFree(GetProcessHeap(), 0, *Buf); HeapFree(GetProcessHeap(), 0, *Buf);
return ERROR_INVALID_DATATYPE; return ERROR_INVALID_DATATYPE;
} }
@ -164,7 +164,7 @@ CheckReboot(_In_ HDEVINFO DevInfo, _In_ SP_DEVINFO_DATA *DevInfoData)
SP_DEVINSTALL_PARAMS_W DevInstallParams = { .cbSize = sizeof(SP_DEVINSTALL_PARAMS_W) }; SP_DEVINSTALL_PARAMS_W DevInstallParams = { .cbSize = sizeof(SP_DEVINSTALL_PARAMS_W) };
if (!SetupDiGetDeviceInstallParamsW(DevInfo, DevInfoData, &DevInstallParams)) if (!SetupDiGetDeviceInstallParamsW(DevInfo, DevInfoData, &DevInstallParams))
{ {
WINTUN_LOGGER_LAST_ERROR(L"Retrieving device installation parameters failed"); LOG_LAST_ERROR(L"Retrieving device installation parameters failed");
return FALSE; return FALSE;
} }
return (DevInstallParams.Flags & (DI_NEEDREBOOT | DI_NEEDRESTART)) != 0; return (DevInstallParams.Flags & (DI_NEEDREBOOT | DI_NEEDRESTART)) != 0;
@ -178,10 +178,10 @@ SetQuietInstall(_In_ HDEVINFO DevInfo, _In_ SP_DEVINFO_DATA *DevInfoData)
{ {
SP_DEVINSTALL_PARAMS_W DevInstallParams = { .cbSize = sizeof(SP_DEVINSTALL_PARAMS_W) }; SP_DEVINSTALL_PARAMS_W DevInstallParams = { .cbSize = sizeof(SP_DEVINSTALL_PARAMS_W) };
if (!SetupDiGetDeviceInstallParamsW(DevInfo, DevInfoData, &DevInstallParams)) if (!SetupDiGetDeviceInstallParamsW(DevInfo, DevInfoData, &DevInstallParams))
return WINTUN_LOGGER_LAST_ERROR(L"Retrieving device installation parameters failed"); return LOG_LAST_ERROR(L"Retrieving device installation parameters failed");
DevInstallParams.Flags |= DI_QUIETINSTALL; DevInstallParams.Flags |= DI_QUIETINSTALL;
if (!SetupDiSetDeviceInstallParamsW(DevInfo, DevInfoData, &DevInstallParams)) if (!SetupDiSetDeviceInstallParamsW(DevInfo, DevInfoData, &DevInstallParams))
return WINTUN_LOGGER_LAST_ERROR(L"Setting device installation parameters failed"); return LOG_LAST_ERROR(L"Setting device installation parameters failed");
return ERROR_SUCCESS; return ERROR_SUCCESS;
} }
@ -202,17 +202,17 @@ GetNetCfgInstanceId(_In_ HDEVINFO DevInfo, _In_ SP_DEVINFO_DATA *DevInfoData, _O
{ {
HKEY Key = SetupDiOpenDevRegKey(DevInfo, DevInfoData, DICS_FLAG_GLOBAL, 0, DIREG_DRV, KEY_QUERY_VALUE); HKEY Key = SetupDiOpenDevRegKey(DevInfo, DevInfoData, DICS_FLAG_GLOBAL, 0, DIREG_DRV, KEY_QUERY_VALUE);
if (Key == INVALID_HANDLE_VALUE) if (Key == INVALID_HANDLE_VALUE)
return WINTUN_LOGGER_LAST_ERROR(L"Opening device registry key failed"); return LOG_LAST_ERROR(L"Opening device registry key failed");
WCHAR *ValueStr; WCHAR *ValueStr;
DWORD Result = RegistryQueryString(Key, L"NetCfgInstanceId", &ValueStr); DWORD Result = RegistryQueryString(Key, L"NetCfgInstanceId", &ValueStr);
if (Result != ERROR_SUCCESS) if (Result != ERROR_SUCCESS)
{ {
WINTUN_LOGGER_ERROR(L"Failed to query NetCfgInstanceId value", Result); LOG_ERROR(L"Failed to query NetCfgInstanceId value", Result);
goto cleanupKey; goto cleanupKey;
} }
if (FAILED(CLSIDFromString(ValueStr, CfgInstanceID))) if (FAILED(CLSIDFromString(ValueStr, CfgInstanceID)))
{ {
WINTUN_LOGGER(WINTUN_LOG_ERR, L"NetCfgInstanceId is not a GUID"); LOG(WINTUN_LOG_ERR, L"NetCfgInstanceId is not a GUID");
Result = ERROR_INVALID_DATA; Result = ERROR_INVALID_DATA;
} }
else else
@ -242,7 +242,7 @@ GetDevInfoData(_In_ const GUID *CfgInstanceID, _Out_ HDEVINFO *DevInfo, _Out_ SP
{ {
*DevInfo = SetupDiGetClassDevsExW(&GUID_DEVCLASS_NET, NULL, NULL, DIGCF_PRESENT, NULL, NULL, NULL); *DevInfo = SetupDiGetClassDevsExW(&GUID_DEVCLASS_NET, NULL, NULL, DIGCF_PRESENT, NULL, NULL, NULL);
if (!*DevInfo) if (!*DevInfo)
return WINTUN_LOGGER_LAST_ERROR(L"Failed to get present class devices"); return LOG_LAST_ERROR(L"Failed to get present class devices");
for (DWORD EnumIndex = 0;; ++EnumIndex) for (DWORD EnumIndex = 0;; ++EnumIndex)
{ {
DevInfoData->cbSize = sizeof(SP_DEVINFO_DATA); DevInfoData->cbSize = sizeof(SP_DEVINFO_DATA);
@ -312,13 +312,13 @@ IsPoolMember(
DWORD Result = GetDeviceRegistryString(DevInfo, DevInfoData, SPDRP_DEVICEDESC, &DeviceDesc); DWORD Result = GetDeviceRegistryString(DevInfo, DevInfoData, SPDRP_DEVICEDESC, &DeviceDesc);
if (Result != ERROR_SUCCESS) if (Result != ERROR_SUCCESS)
{ {
WINTUN_LOGGER_ERROR(L"Failed to query device description property", Result); LOG_ERROR(L"Failed to query device description property", Result);
return Result; return Result;
} }
Result = GetDeviceRegistryString(DevInfo, DevInfoData, SPDRP_FRIENDLYNAME, &FriendlyName); Result = GetDeviceRegistryString(DevInfo, DevInfoData, SPDRP_FRIENDLYNAME, &FriendlyName);
if (Result != ERROR_SUCCESS) if (Result != ERROR_SUCCESS)
{ {
WINTUN_LOGGER_ERROR(L"Failed to query friendly name property", Result); LOG_ERROR(L"Failed to query friendly name property", Result);
goto cleanupDeviceDesc; goto cleanupDeviceDesc;
} }
WCHAR PoolDeviceTypeName[MAX_POOL_DEVICE_TYPE]; WCHAR PoolDeviceTypeName[MAX_POOL_DEVICE_TYPE];
@ -371,7 +371,7 @@ CreateAdapterData(
/* Open HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\<class>\<id> registry key. */ /* Open HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\<class>\<id> registry key. */
HKEY Key = SetupDiOpenDevRegKey(DevInfo, DevInfoData, DICS_FLAG_GLOBAL, 0, DIREG_DRV, KEY_QUERY_VALUE); HKEY Key = SetupDiOpenDevRegKey(DevInfo, DevInfoData, DICS_FLAG_GLOBAL, 0, DIREG_DRV, KEY_QUERY_VALUE);
if (Key == INVALID_HANDLE_VALUE) if (Key == INVALID_HANDLE_VALUE)
return WINTUN_LOGGER_LAST_ERROR(L"Opening device registry key failed"); return LOG_LAST_ERROR(L"Opening device registry key failed");
HANDLE Heap = GetProcessHeap(); HANDLE Heap = GetProcessHeap();
*Adapter = HeapAlloc(Heap, 0, sizeof(WINTUN_ADAPTER)); *Adapter = HeapAlloc(Heap, 0, sizeof(WINTUN_ADAPTER));
@ -386,12 +386,12 @@ CreateAdapterData(
Result = RegistryQueryString(Key, L"NetCfgInstanceId", &ValueStr); Result = RegistryQueryString(Key, L"NetCfgInstanceId", &ValueStr);
if (Result != ERROR_SUCCESS) if (Result != ERROR_SUCCESS)
{ {
WINTUN_LOGGER_ERROR(L"Failed to query NetCfgInstanceId value", Result); LOG_ERROR(L"Failed to query NetCfgInstanceId value", Result);
goto cleanupAdapter; goto cleanupAdapter;
} }
if (FAILED(CLSIDFromString(ValueStr, &(*Adapter)->CfgInstanceID))) if (FAILED(CLSIDFromString(ValueStr, &(*Adapter)->CfgInstanceID)))
{ {
WINTUN_LOGGER(WINTUN_LOG_ERR, L"NetCfgInstanceId is not a GUID"); LOG(WINTUN_LOG_ERR, L"NetCfgInstanceId is not a GUID");
HeapFree(Heap, 0, ValueStr); HeapFree(Heap, 0, ValueStr);
Result = ERROR_INVALID_DATA; Result = ERROR_INVALID_DATA;
goto cleanupAdapter; goto cleanupAdapter;
@ -402,7 +402,7 @@ CreateAdapterData(
Result = RegistryQueryDWORD(Key, L"NetLuidIndex", &(*Adapter)->LuidIndex); Result = RegistryQueryDWORD(Key, L"NetLuidIndex", &(*Adapter)->LuidIndex);
if (Result != ERROR_SUCCESS) if (Result != ERROR_SUCCESS)
{ {
WINTUN_LOGGER_ERROR(L"Failed to query NetLuidIndex value", Result); LOG_ERROR(L"Failed to query NetLuidIndex value", Result);
goto cleanupAdapter; goto cleanupAdapter;
} }
@ -410,7 +410,7 @@ CreateAdapterData(
Result = RegistryQueryDWORD(Key, L"*IfType", &(*Adapter)->IfType); Result = RegistryQueryDWORD(Key, L"*IfType", &(*Adapter)->IfType);
if (Result != ERROR_SUCCESS) if (Result != ERROR_SUCCESS)
{ {
WINTUN_LOGGER_ERROR(L"Failed to query *IfType value", Result); LOG_ERROR(L"Failed to query *IfType value", Result);
goto cleanupAdapter; goto cleanupAdapter;
} }
@ -418,7 +418,7 @@ CreateAdapterData(
if (!SetupDiGetDeviceInstanceIdW( if (!SetupDiGetDeviceInstanceIdW(
DevInfo, DevInfoData, (*Adapter)->DevInstanceID, _countof((*Adapter)->DevInstanceID), &Size)) DevInfo, DevInfoData, (*Adapter)->DevInstanceID, _countof((*Adapter)->DevInstanceID), &Size))
{ {
Result = WINTUN_LOGGER_LAST_ERROR(L"Failed to get device instance ID"); Result = LOG_LAST_ERROR(L"Failed to get device instance ID");
goto cleanupAdapter; goto cleanupAdapter;
} }
@ -476,17 +476,17 @@ GetTcpipInterfaceRegPath(_In_ const WINTUN_ADAPTER *Adapter, _Out_cap_c_(MAX_REG
GetTcpipAdapterRegPath(Adapter, TcpipAdapterRegPath); GetTcpipAdapterRegPath(Adapter, TcpipAdapterRegPath);
Result = RegOpenKeyExW(HKEY_LOCAL_MACHINE, TcpipAdapterRegPath, 0, KEY_QUERY_VALUE, &TcpipAdapterRegKey); Result = RegOpenKeyExW(HKEY_LOCAL_MACHINE, TcpipAdapterRegPath, 0, KEY_QUERY_VALUE, &TcpipAdapterRegKey);
if (Result != ERROR_SUCCESS) if (Result != ERROR_SUCCESS)
return WINTUN_LOGGER_ERROR(L"Failed to open registry key", Result); return LOG_ERROR(L"Failed to open registry key", Result);
WCHAR *Paths; WCHAR *Paths;
Result = RegistryQueryString(TcpipAdapterRegKey, L"IpConfig", &Paths); Result = RegistryQueryString(TcpipAdapterRegKey, L"IpConfig", &Paths);
if (Result != ERROR_SUCCESS) if (Result != ERROR_SUCCESS)
{ {
WINTUN_LOGGER_ERROR(L"Failed to query IpConfig value", Result); LOG_ERROR(L"Failed to query IpConfig value", Result);
goto cleanupTcpipAdapterRegKey; goto cleanupTcpipAdapterRegKey;
} }
if (!Paths[0]) if (!Paths[0])
{ {
WINTUN_LOGGER(WINTUN_LOG_ERR, L"IpConfig is empty"); LOG(WINTUN_LOG_ERR, L"IpConfig is empty");
Result = ERROR_INVALID_DATA; Result = ERROR_INVALID_DATA;
goto cleanupPaths; goto cleanupPaths;
} }
@ -535,7 +535,7 @@ WintunGetAdapter(
HDEVINFO DevInfo = SetupDiGetClassDevsExW(&GUID_DEVCLASS_NET, NULL, NULL, DIGCF_PRESENT, NULL, NULL, NULL); HDEVINFO DevInfo = SetupDiGetClassDevsExW(&GUID_DEVCLASS_NET, NULL, NULL, DIGCF_PRESENT, NULL, NULL, NULL);
if (DevInfo == INVALID_HANDLE_VALUE) if (DevInfo == INVALID_HANDLE_VALUE)
{ {
Result = WINTUN_LOGGER_LAST_ERROR(L"Failed to get present class devices"); Result = LOG_LAST_ERROR(L"Failed to get present class devices");
goto cleanupMutex; goto cleanupMutex;
} }
@ -572,7 +572,7 @@ WintunGetAdapter(
Result = GetDeviceRegistryMultiString(DevInfo, &DevInfoData, SPDRP_HARDWAREID, &Hwids); Result = GetDeviceRegistryMultiString(DevInfo, &DevInfoData, SPDRP_HARDWAREID, &Hwids);
if (Result != ERROR_SUCCESS) if (Result != ERROR_SUCCESS)
{ {
WINTUN_LOGGER_ERROR(L"Failed to query hardware ID", Result); LOG_ERROR(L"Failed to query hardware ID", Result);
goto cleanupDevInfo; goto cleanupDevInfo;
} }
if (!IsOurHardwareID(Hwids)) if (!IsOurHardwareID(Hwids))
@ -593,7 +593,7 @@ WintunGetAdapter(
Result = IsPoolMember(Pool, DevInfo, &DevInfoData, &IsMember); Result = IsPoolMember(Pool, DevInfo, &DevInfoData, &IsMember);
if (Result != ERROR_SUCCESS) if (Result != ERROR_SUCCESS)
{ {
WINTUN_LOGGER_ERROR(L"Failed to determine pool membership", Result); LOG_ERROR(L"Failed to determine pool membership", Result);
goto cleanupDevInfo; goto cleanupDevInfo;
} }
if (!IsMember) if (!IsMember)
@ -604,7 +604,7 @@ WintunGetAdapter(
Result = CreateAdapterData(Pool, DevInfo, &DevInfoData, Adapter); Result = CreateAdapterData(Pool, DevInfo, &DevInfoData, Adapter);
if (Result != ERROR_SUCCESS) if (Result != ERROR_SUCCESS)
WINTUN_LOGGER_ERROR(L"Failed to create adapter data", Result); LOG_ERROR(L"Failed to create adapter data", Result);
goto cleanupDevInfo; goto cleanupDevInfo;
} }
@ -631,7 +631,7 @@ ConvertInterfaceAliasToGuid(_In_z_ const WCHAR *Name, _Out_ GUID *Guid)
NET_LUID Luid; NET_LUID Luid;
DWORD Result = ConvertInterfaceAliasToLuid(Name, &Luid); DWORD Result = ConvertInterfaceAliasToLuid(Name, &Luid);
if (Result != NO_ERROR) if (Result != NO_ERROR)
return WINTUN_LOGGER_ERROR(L"Failed convert interface alias name to the locally unique identifier", Result); return LOG_ERROR(L"Failed convert interface alias name to the locally unique identifier", Result);
return ConvertInterfaceLuidToGuid(&Luid, Guid); return ConvertInterfaceLuidToGuid(&Luid, Guid);
} }
@ -676,7 +676,7 @@ WintunSetAdapterName(_In_ const WINTUN_ADAPTER *Adapter, _In_z_count_c_(MAX_ADAP
if (Result == ERROR_SUCCESS) if (Result == ERROR_SUCCESS)
break; break;
if (i > MaxSuffix || Result != ERROR_DUP_NAME) if (i > MaxSuffix || Result != ERROR_DUP_NAME)
return WINTUN_LOGGER_ERROR(L"Setting adapter name failed", Result); return LOG_ERROR(L"Setting adapter name failed", Result);
_snwprintf_s(AvailableName, _countof(AvailableName), _TRUNCATE, L"%.*s %d", MAX_ADAPTER_NAME, Name, i + 1); _snwprintf_s(AvailableName, _countof(AvailableName), _TRUNCATE, L"%.*s %d", MAX_ADAPTER_NAME, Name, i + 1);
} }
@ -686,7 +686,7 @@ WintunSetAdapterName(_In_ const WINTUN_ADAPTER *Adapter, _In_z_count_c_(MAX_ADAP
GetDeviceRegPath(Adapter, DeviceRegPath); GetDeviceRegPath(Adapter, DeviceRegPath);
Result = RegOpenKeyExW(HKEY_LOCAL_MACHINE, DeviceRegPath, 0, KEY_SET_VALUE, &DeviceRegKey); Result = RegOpenKeyExW(HKEY_LOCAL_MACHINE, DeviceRegPath, 0, KEY_SET_VALUE, &DeviceRegKey);
if (Result != ERROR_SUCCESS) if (Result != ERROR_SUCCESS)
return WINTUN_LOGGER_ERROR(L"Failed to open registry key", Result); return LOG_ERROR(L"Failed to open registry key", Result);
WCHAR PoolDeviceTypeName[MAX_POOL_DEVICE_TYPE]; WCHAR PoolDeviceTypeName[MAX_POOL_DEVICE_TYPE];
GetPoolDeviceTypeName(Adapter->Pool, PoolDeviceTypeName); GetPoolDeviceTypeName(Adapter->Pool, PoolDeviceTypeName);
Result = RegSetKeyValueW( Result = RegSetKeyValueW(
@ -804,14 +804,14 @@ WintunCreateAdapter(
HDEVINFO DevInfo = SetupDiCreateDeviceInfoListExW(&GUID_DEVCLASS_NET, NULL, NULL, NULL); HDEVINFO DevInfo = SetupDiCreateDeviceInfoListExW(&GUID_DEVCLASS_NET, NULL, NULL, NULL);
if (DevInfo == INVALID_HANDLE_VALUE) if (DevInfo == INVALID_HANDLE_VALUE)
{ {
Result = WINTUN_LOGGER_LAST_ERROR(L"Creating empty device information set failed"); Result = LOG_LAST_ERROR(L"Creating empty device information set failed");
goto cleanupMutex; goto cleanupMutex;
} }
WCHAR ClassName[MAX_CLASS_NAME_LEN]; WCHAR ClassName[MAX_CLASS_NAME_LEN];
if (!SetupDiClassNameFromGuidExW(&GUID_DEVCLASS_NET, ClassName, _countof(ClassName), NULL, NULL, NULL)) if (!SetupDiClassNameFromGuidExW(&GUID_DEVCLASS_NET, ClassName, _countof(ClassName), NULL, NULL, NULL))
{ {
Result = WINTUN_LOGGER_LAST_ERROR(L"Retrieving class name associated with class GUID failed"); Result = LOG_LAST_ERROR(L"Retrieving class name associated with class GUID failed");
goto cleanupDevInfo; goto cleanupDevInfo;
} }
@ -822,26 +822,26 @@ WintunCreateAdapter(
if (!SetupDiCreateDeviceInfoW( if (!SetupDiCreateDeviceInfoW(
DevInfo, ClassName, &GUID_DEVCLASS_NET, PoolDeviceTypeName, NULL, DICD_GENERATE_ID, &DevInfoData)) DevInfo, ClassName, &GUID_DEVCLASS_NET, PoolDeviceTypeName, NULL, DICD_GENERATE_ID, &DevInfoData))
{ {
Result = WINTUN_LOGGER_LAST_ERROR(L"Creating new device information element failed"); Result = LOG_LAST_ERROR(L"Creating new device information element failed");
goto cleanupDevInfo; goto cleanupDevInfo;
} }
SetQuietInstall(DevInfo, &DevInfoData); SetQuietInstall(DevInfo, &DevInfoData);
if (!SetupDiSetSelectedDevice(DevInfo, &DevInfoData)) if (!SetupDiSetSelectedDevice(DevInfo, &DevInfoData))
{ {
Result = WINTUN_LOGGER_LAST_ERROR(L"Failed selecting device"); Result = LOG_LAST_ERROR(L"Failed selecting device");
goto cleanupDevInfo; goto cleanupDevInfo;
} }
static const WCHAR Hwids[_countof(WINTUN_HWID) + 1 /*Multi-string terminator*/] = WINTUN_HWID; static const WCHAR Hwids[_countof(WINTUN_HWID) + 1 /*Multi-string terminator*/] = WINTUN_HWID;
if (!SetupDiSetDeviceRegistryPropertyW(DevInfo, &DevInfoData, SPDRP_HARDWAREID, (const BYTE *)Hwids, sizeof(Hwids))) if (!SetupDiSetDeviceRegistryPropertyW(DevInfo, &DevInfoData, SPDRP_HARDWAREID, (const BYTE *)Hwids, sizeof(Hwids)))
{ {
Result = WINTUN_LOGGER_LAST_ERROR(L"Failed setting hardware ID"); Result = LOG_LAST_ERROR(L"Failed setting hardware ID");
goto cleanupDevInfo; goto cleanupDevInfo;
} }
if (!SetupDiBuildDriverInfoList(DevInfo, &DevInfoData, SPDIT_COMPATDRIVER)) /* TODO: This takes ~510ms */ if (!SetupDiBuildDriverInfoList(DevInfo, &DevInfoData, SPDIT_COMPATDRIVER)) /* TODO: This takes ~510ms */
{ {
Result = WINTUN_LOGGER_LAST_ERROR(L"Failed building driver info list"); Result = LOG_LAST_ERROR(L"Failed building driver info list");
goto cleanupDevInfo; goto cleanupDevInfo;
} }
@ -883,18 +883,18 @@ WintunCreateAdapter(
if (!DriverVersion) if (!DriverVersion)
{ {
WINTUN_LOGGER(WINTUN_LOG_ERR, L"No appropriate drivers found"); LOG(WINTUN_LOG_ERR, L"No appropriate drivers found");
Result = ERROR_FILE_NOT_FOUND; Result = ERROR_FILE_NOT_FOUND;
goto cleanupDriverInfoList; goto cleanupDriverInfoList;
} }
if (!SetupDiCallClassInstaller(DIF_REGISTERDEVICE, DevInfo, &DevInfoData)) if (!SetupDiCallClassInstaller(DIF_REGISTERDEVICE, DevInfo, &DevInfoData))
{ {
Result = WINTUN_LOGGER_LAST_ERROR(L"Registering device failed"); Result = LOG_LAST_ERROR(L"Registering device failed");
goto cleanupDevice; goto cleanupDevice;
} }
if (!SetupDiCallClassInstaller(DIF_REGISTER_COINSTALLERS, DevInfo, &DevInfoData)) if (!SetupDiCallClassInstaller(DIF_REGISTER_COINSTALLERS, DevInfo, &DevInfoData))
WINTUN_LOGGER_LAST_ERROR(L"Registering coinstallers failed"); LOG_LAST_ERROR(L"Registering coinstallers failed");
HKEY NetDevRegKey = INVALID_HANDLE_VALUE; HKEY NetDevRegKey = INVALID_HANDLE_VALUE;
const int PollTimeout = 50 /* ms */; const int PollTimeout = 50 /* ms */;
@ -907,7 +907,7 @@ WintunCreateAdapter(
} }
if (NetDevRegKey == INVALID_HANDLE_VALUE) if (NetDevRegKey == INVALID_HANDLE_VALUE)
{ {
Result = WINTUN_LOGGER_LAST_ERROR(L"Failed to open device-specific registry key"); Result = LOG_LAST_ERROR(L"Failed to open device-specific registry key");
goto cleanupDevice; goto cleanupDevice;
} }
if (RequestedGUID) if (RequestedGUID)
@ -922,17 +922,17 @@ WintunCreateAdapter(
StringFromGUID2(RequestedGUID, RequestedGUIDStr, _countof(RequestedGUIDStr)) * sizeof(WCHAR)); StringFromGUID2(RequestedGUID, RequestedGUIDStr, _countof(RequestedGUIDStr)) * sizeof(WCHAR));
if (Result != ERROR_SUCCESS) if (Result != ERROR_SUCCESS)
{ {
WINTUN_LOGGER_LAST_ERROR(L"Failed to set NetSetupAnticipatedInstanceId"); LOG_LAST_ERROR(L"Failed to set NetSetupAnticipatedInstanceId");
goto cleanupNetDevRegKey; goto cleanupNetDevRegKey;
} }
} }
if (!SetupDiCallClassInstaller(DIF_INSTALLINTERFACES, DevInfo, &DevInfoData)) if (!SetupDiCallClassInstaller(DIF_INSTALLINTERFACES, DevInfo, &DevInfoData))
WINTUN_LOGGER_LAST_ERROR(L"Installing interfaces failed"); LOG_LAST_ERROR(L"Installing interfaces failed");
if (!SetupDiCallClassInstaller(DIF_INSTALLDEVICE, DevInfo, &DevInfoData)) if (!SetupDiCallClassInstaller(DIF_INSTALLDEVICE, DevInfo, &DevInfoData))
{ {
Result = WINTUN_LOGGER_LAST_ERROR(L"Installing device failed"); Result = LOG_LAST_ERROR(L"Installing device failed");
goto cleanupNetDevRegKey; goto cleanupNetDevRegKey;
} }
*RebootRequired = *RebootRequired || CheckReboot(DevInfo, &DevInfoData); *RebootRequired = *RebootRequired || CheckReboot(DevInfo, &DevInfoData);
@ -944,7 +944,7 @@ WintunCreateAdapter(
(const BYTE *)PoolDeviceTypeName, (const BYTE *)PoolDeviceTypeName,
(DWORD)((wcslen(PoolDeviceTypeName) + 1) * sizeof(WCHAR)))) (DWORD)((wcslen(PoolDeviceTypeName) + 1) * sizeof(WCHAR))))
{ {
Result = WINTUN_LOGGER_LAST_ERROR(L"Failed to set device description"); Result = LOG_LAST_ERROR(L"Failed to set device description");
goto cleanupNetDevRegKey; goto cleanupNetDevRegKey;
} }
@ -954,7 +954,7 @@ WintunCreateAdapter(
Result = RegistryQueryStringWait(NetDevRegKey, L"NetCfgInstanceId", WAIT_FOR_REGISTRY_TIMEOUT, &DummyStr); Result = RegistryQueryStringWait(NetDevRegKey, L"NetCfgInstanceId", WAIT_FOR_REGISTRY_TIMEOUT, &DummyStr);
if (Result != ERROR_SUCCESS) if (Result != ERROR_SUCCESS)
{ {
WINTUN_LOGGER_ERROR(L"Failed to query NetCfgInstanceId value", Result); LOG_ERROR(L"Failed to query NetCfgInstanceId value", Result);
goto cleanupNetDevRegKey; goto cleanupNetDevRegKey;
} }
HeapFree(Heap, 0, DummyStr); HeapFree(Heap, 0, DummyStr);
@ -962,20 +962,20 @@ WintunCreateAdapter(
Result = RegistryQueryDWORDWait(NetDevRegKey, L"NetLuidIndex", WAIT_FOR_REGISTRY_TIMEOUT, &DummyDWORD); Result = RegistryQueryDWORDWait(NetDevRegKey, L"NetLuidIndex", WAIT_FOR_REGISTRY_TIMEOUT, &DummyDWORD);
if (Result != ERROR_SUCCESS) if (Result != ERROR_SUCCESS)
{ {
WINTUN_LOGGER_ERROR(L"Failed to query NetLuidIndex value", Result); LOG_ERROR(L"Failed to query NetLuidIndex value", Result);
goto cleanupNetDevRegKey; goto cleanupNetDevRegKey;
} }
Result = RegistryQueryDWORDWait(NetDevRegKey, L"*IfType", WAIT_FOR_REGISTRY_TIMEOUT, &DummyDWORD); Result = RegistryQueryDWORDWait(NetDevRegKey, L"*IfType", WAIT_FOR_REGISTRY_TIMEOUT, &DummyDWORD);
if (Result != ERROR_SUCCESS) if (Result != ERROR_SUCCESS)
{ {
WINTUN_LOGGER_ERROR(L"Failed to query *IfType value", Result); LOG_ERROR(L"Failed to query *IfType value", Result);
goto cleanupNetDevRegKey; goto cleanupNetDevRegKey;
} }
Result = CreateAdapterData(Pool, DevInfo, &DevInfoData, Adapter); Result = CreateAdapterData(Pool, DevInfo, &DevInfoData, Adapter);
if (Result != ERROR_SUCCESS) if (Result != ERROR_SUCCESS)
{ {
WINTUN_LOGGER_ERROR(L"Failed to create adapter data", Result); LOG_ERROR(L"Failed to create adapter data", Result);
goto cleanupNetDevRegKey; goto cleanupNetDevRegKey;
} }
@ -990,13 +990,13 @@ WintunCreateAdapter(
&TcpipAdapterRegKey); &TcpipAdapterRegKey);
if (Result != ERROR_SUCCESS) if (Result != ERROR_SUCCESS)
{ {
WINTUN_LOGGER_ERROR(L"Failed to open adapter-specific TCP/IP adapter registry key", Result); LOG_ERROR(L"Failed to open adapter-specific TCP/IP adapter registry key", Result);
goto cleanupAdapter; goto cleanupAdapter;
} }
Result = RegistryQueryStringWait(TcpipAdapterRegKey, L"IpConfig", WAIT_FOR_REGISTRY_TIMEOUT, &DummyStr); Result = RegistryQueryStringWait(TcpipAdapterRegKey, L"IpConfig", WAIT_FOR_REGISTRY_TIMEOUT, &DummyStr);
if (Result != ERROR_SUCCESS) if (Result != ERROR_SUCCESS)
{ {
WINTUN_LOGGER_ERROR(L"Failed to query IpConfig value", Result); LOG_ERROR(L"Failed to query IpConfig value", Result);
goto cleanupTcpipAdapterRegKey; goto cleanupTcpipAdapterRegKey;
} }
HeapFree(Heap, 0, DummyStr); HeapFree(Heap, 0, DummyStr);
@ -1006,7 +1006,7 @@ WintunCreateAdapter(
Result = GetTcpipInterfaceRegPath(*Adapter, TcpipInterfaceRegPath); Result = GetTcpipInterfaceRegPath(*Adapter, TcpipInterfaceRegPath);
if (Result != ERROR_SUCCESS) if (Result != ERROR_SUCCESS)
{ {
WINTUN_LOGGER_ERROR(L"Failed to determine interface-specific TCP/IP network registry key path", Result); LOG_ERROR(L"Failed to determine interface-specific TCP/IP network registry key path", Result);
goto cleanupTcpipAdapterRegKey; goto cleanupTcpipAdapterRegKey;
} }
Result = RegistryOpenKeyWait( Result = RegistryOpenKeyWait(
@ -1017,7 +1017,7 @@ WintunCreateAdapter(
&TcpipInterfaceRegKey); &TcpipInterfaceRegKey);
if (Result != ERROR_SUCCESS) if (Result != ERROR_SUCCESS)
{ {
WINTUN_LOGGER_ERROR(L"Failed to open interface-specific TCP/IP network registry key", Result); LOG_ERROR(L"Failed to open interface-specific TCP/IP network registry key", Result);
goto cleanupTcpipAdapterRegKey; goto cleanupTcpipAdapterRegKey;
} }
@ -1025,11 +1025,11 @@ WintunCreateAdapter(
Result = RegSetKeyValueW( Result = RegSetKeyValueW(
TcpipInterfaceRegKey, NULL, L"EnableDeadGWDetect", REG_DWORD, &EnableDeadGWDetect, sizeof(EnableDeadGWDetect)); TcpipInterfaceRegKey, NULL, L"EnableDeadGWDetect", REG_DWORD, &EnableDeadGWDetect, sizeof(EnableDeadGWDetect));
if (Result != ERROR_SUCCESS) if (Result != ERROR_SUCCESS)
WINTUN_LOGGER_ERROR(L"Failed to set EnableDeadGWDetect", Result); LOG_ERROR(L"Failed to set EnableDeadGWDetect", Result);
Result = WintunSetAdapterName(*Adapter, Name); Result = WintunSetAdapterName(*Adapter, Name);
if (Result != ERROR_SUCCESS) if (Result != ERROR_SUCCESS)
WINTUN_LOGGER_ERROR(L"Failed to set adapter name", Result); LOG_ERROR(L"Failed to set adapter name", Result);
RegCloseKey(TcpipInterfaceRegKey); RegCloseKey(TcpipInterfaceRegKey);
cleanupTcpipAdapterRegKey: cleanupTcpipAdapterRegKey:
RegCloseKey(TcpipAdapterRegKey); RegCloseKey(TcpipAdapterRegKey);
@ -1079,7 +1079,7 @@ WintunDeleteAdapter(_In_ const WINTUN_ADAPTER *Adapter, _Inout_ BOOL *RebootRequ
return ERROR_SUCCESS; return ERROR_SUCCESS;
if (Result != ERROR_SUCCESS) if (Result != ERROR_SUCCESS)
{ {
WINTUN_LOGGER_ERROR(L"Failed to get device info data", Result); LOG_ERROR(L"Failed to get device info data", Result);
return Result; return Result;
} }
SetQuietInstall(DevInfo, &DevInfoData); SetQuietInstall(DevInfo, &DevInfoData);
@ -1091,7 +1091,7 @@ WintunDeleteAdapter(_In_ const WINTUN_ADAPTER *Adapter, _Inout_ BOOL *RebootRequ
SetupDiCallClassInstaller(DIF_REMOVE, DevInfo, &DevInfoData)) SetupDiCallClassInstaller(DIF_REMOVE, DevInfo, &DevInfoData))
*RebootRequired = *RebootRequired || CheckReboot(DevInfo, &DevInfoData); *RebootRequired = *RebootRequired || CheckReboot(DevInfo, &DevInfoData);
else else
Result = WINTUN_LOGGER_LAST_ERROR(L"Unable to remove existing adapter"); Result = LOG_LAST_ERROR(L"Unable to remove existing adapter");
SetupDiDestroyDeviceInfoList(DevInfo); SetupDiDestroyDeviceInfoList(DevInfo);
return Result; return Result;
} }
@ -1118,7 +1118,7 @@ WintunEnumAdapters(_In_z_count_c_(MAX_POOL) const WCHAR *Pool, _In_ WINTUN_ENUM_
HDEVINFO DevInfo = SetupDiGetClassDevsExW(&GUID_DEVCLASS_NET, NULL, NULL, DIGCF_PRESENT, NULL, NULL, NULL); HDEVINFO DevInfo = SetupDiGetClassDevsExW(&GUID_DEVCLASS_NET, NULL, NULL, DIGCF_PRESENT, NULL, NULL, NULL);
if (DevInfo == INVALID_HANDLE_VALUE) if (DevInfo == INVALID_HANDLE_VALUE)
{ {
Result = WINTUN_LOGGER_LAST_ERROR(L"Failed to get present class devices"); Result = LOG_LAST_ERROR(L"Failed to get present class devices");
goto cleanupMutex; goto cleanupMutex;
} }
HANDLE Heap = GetProcessHeap(); HANDLE Heap = GetProcessHeap();
@ -1141,7 +1141,7 @@ WintunEnumAdapters(_In_z_count_c_(MAX_POOL) const WCHAR *Pool, _In_ WINTUN_ENUM_
Result = GetDeviceRegistryMultiString(DevInfo, &DevInfoData, SPDRP_HARDWAREID, &Hwids); Result = GetDeviceRegistryMultiString(DevInfo, &DevInfoData, SPDRP_HARDWAREID, &Hwids);
if (Result != ERROR_SUCCESS) if (Result != ERROR_SUCCESS)
{ {
WINTUN_LOGGER_ERROR(L"Failed to query hardware ID", Result); LOG_ERROR(L"Failed to query hardware ID", Result);
break; break;
} }
if (!IsOurHardwareID(Hwids)) if (!IsOurHardwareID(Hwids))
@ -1158,7 +1158,7 @@ WintunEnumAdapters(_In_z_count_c_(MAX_POOL) const WCHAR *Pool, _In_ WINTUN_ENUM_
Result = IsPoolMember(Pool, DevInfo, &DevInfoData, &IsMember); Result = IsPoolMember(Pool, DevInfo, &DevInfoData, &IsMember);
if (Result != ERROR_SUCCESS) if (Result != ERROR_SUCCESS)
{ {
WINTUN_LOGGER_ERROR(L"Failed to determine pool membership", Result); LOG_ERROR(L"Failed to determine pool membership", Result);
break; break;
} }
if (!IsMember) if (!IsMember)
@ -1168,7 +1168,7 @@ WintunEnumAdapters(_In_z_count_c_(MAX_POOL) const WCHAR *Pool, _In_ WINTUN_ENUM_
Result = CreateAdapterData(Pool, DevInfo, &DevInfoData, &Adapter); Result = CreateAdapterData(Pool, DevInfo, &DevInfoData, &Adapter);
if (Result != ERROR_SUCCESS) if (Result != ERROR_SUCCESS)
{ {
WINTUN_LOGGER_ERROR(L"Failed to create adapter data", Result); LOG_ERROR(L"Failed to create adapter data", Result);
break; break;
} }
if (Func(Adapter, Param)) if (Func(Adapter, Param))

View File

@ -53,7 +53,7 @@ _Return_type_success_(return != NULL) SP_DRVINFO_DETAIL_DATA_W *DriverGetDrvInfo
HeapFree(Heap, 0, DrvInfoDetailData); HeapFree(Heap, 0, DrvInfoDetailData);
if (Result != ERROR_INSUFFICIENT_BUFFER) if (Result != ERROR_INSUFFICIENT_BUFFER)
{ {
WINTUN_LOGGER_ERROR(L"Failed", Result); LOG_ERROR(L"Failed", Result);
goto out; goto out;
} }
} }
@ -78,7 +78,7 @@ DriverIsWintunAdapter(_In_ HDEVINFO DevInfo, _In_opt_ SP_DEVINFO_DATA *DevInfoDa
BOOL Found = FALSE; BOOL Found = FALSE;
if (!SetupDiBuildDriverInfoList(DevInfo, DevInfoData, SPDIT_COMPATDRIVER)) if (!SetupDiBuildDriverInfoList(DevInfo, DevInfoData, SPDIT_COMPATDRIVER))
{ {
WINTUN_LOGGER_LAST_ERROR(L"Failed to build list of drivers"); LOG_LAST_ERROR(L"Failed to build list of drivers");
return FALSE; return FALSE;
} }
HANDLE Heap = GetProcessHeap(); HANDLE Heap = GetProcessHeap();
@ -119,7 +119,7 @@ _Return_type_success_(return != INVALID_HANDLE_VALUE) HANDLE
&InterfacesLen, (GUID *)&GUID_DEVINTERFACE_NET, (DEVINSTID_W)InstanceId, CM_GET_DEVICE_INTERFACE_LIST_PRESENT); &InterfacesLen, (GUID *)&GUID_DEVINTERFACE_NET, (DEVINSTID_W)InstanceId, CM_GET_DEVICE_INTERFACE_LIST_PRESENT);
if (Result != CR_SUCCESS) if (Result != CR_SUCCESS)
{ {
WINTUN_LOGGER(WINTUN_LOG_ERR, L"Failed to get device associated device instances size"); LOG(WINTUN_LOG_ERR, L"Failed to get device associated device instances size");
SetLastError(ERROR_GEN_FAILURE); SetLastError(ERROR_GEN_FAILURE);
return INVALID_HANDLE_VALUE; return INVALID_HANDLE_VALUE;
} }
@ -137,7 +137,7 @@ _Return_type_success_(return != INVALID_HANDLE_VALUE) HANDLE
CM_GET_DEVICE_INTERFACE_LIST_PRESENT); CM_GET_DEVICE_INTERFACE_LIST_PRESENT);
if (Result != CR_SUCCESS) if (Result != CR_SUCCESS)
{ {
WINTUN_LOGGER(WINTUN_LOG_ERR, L"Failed to get device associated device instances"); LOG(WINTUN_LOG_ERR, L"Failed to get device associated device instances");
Result = ERROR_GEN_FAILURE; Result = ERROR_GEN_FAILURE;
goto cleanupBuf; goto cleanupBuf;
} }
@ -149,7 +149,7 @@ _Return_type_success_(return != INVALID_HANDLE_VALUE) HANDLE
OPEN_EXISTING, OPEN_EXISTING,
0, 0,
NULL); NULL);
Result = Handle != INVALID_HANDLE_VALUE ? ERROR_SUCCESS : WINTUN_LOGGER_LAST_ERROR(L"Failed to connect to device"); Result = Handle != INVALID_HANDLE_VALUE ? ERROR_SUCCESS : LOG_LAST_ERROR(L"Failed to connect to device");
cleanupBuf: cleanupBuf:
HeapFree(Heap, 0, Interfaces); HeapFree(Heap, 0, Interfaces);
SetLastError(Result); SetLastError(Result);
@ -238,7 +238,7 @@ DriverGetVersion(_Out_ FILETIME *DriverDate, _Out_ DWORDLONG *DriverVersion)
DWORD SizeResource; DWORD SizeResource;
DWORD Result = ResourceGetAddress(HaveWHQL() ? L"wintun-whql.inf" : L"wintun.inf", &LockedResource, &SizeResource); DWORD Result = ResourceGetAddress(HaveWHQL() ? L"wintun-whql.inf" : L"wintun.inf", &LockedResource, &SizeResource);
if (Result != ERROR_SUCCESS) if (Result != ERROR_SUCCESS)
return WINTUN_LOGGER_ERROR(L"Failed to locate resource", Result); return LOG_ERROR(L"Failed to locate resource", Result);
enum enum
{ {
SectNone, SectNone,
@ -283,13 +283,13 @@ DriverGetVersion(_Out_ FILETIME *DriverDate, _Out_ DWORDLONG *DriverVersion)
break; break;
if (*p != '/' && *p != '-') if (*p != '/' && *p != '-')
{ {
WINTUN_LOGGER(WINTUN_LOG_ERR, L"Unexpected date delimiter"); LOG(WINTUN_LOG_ERR, L"Unexpected date delimiter");
return ERROR_INVALID_DATA; return ERROR_INVALID_DATA;
} }
} }
if (date[0] < 1 || date[0] > 12 || date[1] < 1 || date[1] > 31 || date[2] < 1601 || date[2] > 30827) if (date[0] < 1 || date[0] > 12 || date[1] < 1 || date[1] > 31 || date[2] < 1601 || date[2] > 30827)
{ {
WINTUN_LOGGER(WINTUN_LOG_ERR, L"Invalid date"); LOG(WINTUN_LOG_ERR, L"Invalid date");
return ERROR_INVALID_DATA; return ERROR_INVALID_DATA;
} }
const SYSTEMTIME st = { .wYear = (WORD)date[2], .wMonth = (WORD)date[0], .wDay = (WORD)date[1] }; const SYSTEMTIME st = { .wYear = (WORD)date[2], .wMonth = (WORD)date[0], .wDay = (WORD)date[1] };
@ -304,7 +304,7 @@ DriverGetVersion(_Out_ FILETIME *DriverDate, _Out_ DWORDLONG *DriverVersion)
version[i] = strtoul(p, &p_next, 10); version[i] = strtoul(p, &p_next, 10);
if (version[i] > 0xffff) if (version[i] > 0xffff)
{ {
WINTUN_LOGGER(WINTUN_LOG_ERR, L"Version field may not exceed 65535"); LOG(WINTUN_LOG_ERR, L"Version field may not exceed 65535");
return ERROR_INVALID_DATA; return ERROR_INVALID_DATA;
} }
p = p_next; p = p_next;
@ -312,7 +312,7 @@ DriverGetVersion(_Out_ FILETIME *DriverDate, _Out_ DWORDLONG *DriverVersion)
break; break;
if (*p != '.') if (*p != '.')
{ {
WINTUN_LOGGER(WINTUN_LOG_ERR, L"Unexpected version delimiter"); LOG(WINTUN_LOG_ERR, L"Unexpected version delimiter");
return ERROR_INVALID_DATA; return ERROR_INVALID_DATA;
} }
} }
@ -324,7 +324,7 @@ DriverGetVersion(_Out_ FILETIME *DriverDate, _Out_ DWORDLONG *DriverVersion)
} }
Inf = SkipNonLF(Inf, InfEnd); Inf = SkipNonLF(Inf, InfEnd);
} }
WINTUN_LOGGER(WINTUN_LOG_ERR, L"DriverVer not found in INF resource"); LOG(WINTUN_LOG_ERR, L"DriverVer not found in INF resource");
return ERROR_FILE_NOT_FOUND; return ERROR_FILE_NOT_FOUND;
} }
@ -400,12 +400,12 @@ static BOOL EnsureDriverUnloaded(VOID)
static WINTUN_STATUS static WINTUN_STATUS
InstallCertificate(_In_z_ const WCHAR *SignedResource) InstallCertificate(_In_z_ const WCHAR *SignedResource)
{ {
WINTUN_LOGGER(WINTUN_LOG_INFO, L"Trusting code signing certificate"); LOG(WINTUN_LOG_INFO, L"Trusting code signing certificate");
const VOID *LockedResource; const VOID *LockedResource;
DWORD SizeResource; DWORD SizeResource;
DWORD Result = ResourceGetAddress(SignedResource, &LockedResource, &SizeResource); DWORD Result = ResourceGetAddress(SignedResource, &LockedResource, &SizeResource);
if (Result != ERROR_SUCCESS) if (Result != ERROR_SUCCESS)
return WINTUN_LOGGER_ERROR("Failed to locate resource", Result); return LOG_ERROR("Failed to locate resource", Result);
const CERT_BLOB CertBlob = { .cbData = SizeResource, .pbData = (BYTE *)LockedResource }; const CERT_BLOB CertBlob = { .cbData = SizeResource, .pbData = (BYTE *)LockedResource };
HCERTSTORE QueriedStore; HCERTSTORE QueriedStore;
if (!CryptQueryObject( if (!CryptQueryObject(
@ -420,12 +420,12 @@ InstallCertificate(_In_z_ const WCHAR *SignedResource)
&QueriedStore, &QueriedStore,
0, 0,
NULL)) NULL))
return WINTUN_LOGGER_LAST_ERROR("Failed to find certificate"); return LOG_LAST_ERROR("Failed to find certificate");
HCERTSTORE TrustedStore = HCERTSTORE TrustedStore =
CertOpenStore(CERT_STORE_PROV_SYSTEM, 0, 0, CERT_SYSTEM_STORE_LOCAL_MACHINE, L"TrustedPublisher"); CertOpenStore(CERT_STORE_PROV_SYSTEM, 0, 0, CERT_SYSTEM_STORE_LOCAL_MACHINE, L"TrustedPublisher");
if (!TrustedStore) if (!TrustedStore)
{ {
Result = WINTUN_LOGGER_LAST_ERROR(L"Failed to open store"); Result = LOG_LAST_ERROR(L"Failed to open store");
goto cleanupQueriedStore; goto cleanupQueriedStore;
} }
LPSTR CodeSigningOid[] = { szOID_PKIX_KP_CODE_SIGNING }; LPSTR CodeSigningOid[] = { szOID_PKIX_KP_CODE_SIGNING };
@ -455,7 +455,7 @@ InstallCertificate(_In_z_ const WCHAR *SignedResource)
!Constraints.fCA) !Constraints.fCA)
if (!CertAddCertificateContextToStore(TrustedStore, CertContext, CERT_STORE_ADD_REPLACE_EXISTING, NULL)) if (!CertAddCertificateContextToStore(TrustedStore, CertContext, CERT_STORE_ADD_REPLACE_EXISTING, NULL))
{ {
WINTUN_LOGGER_LAST_ERROR(L"Failed to add certificate to store"); LOG_LAST_ERROR(L"Failed to add certificate to store");
Result = Result != ERROR_SUCCESS ? Result : GetLastError(); Result = Result != ERROR_SUCCESS ? Result : GetLastError();
} }
} }
@ -477,14 +477,14 @@ InstallDriver(_In_ BOOL UpdateExisting)
{ {
WCHAR WindowsDirectory[MAX_PATH]; WCHAR WindowsDirectory[MAX_PATH];
if (!GetWindowsDirectoryW(WindowsDirectory, _countof(WindowsDirectory))) if (!GetWindowsDirectoryW(WindowsDirectory, _countof(WindowsDirectory)))
return WINTUN_LOGGER_LAST_ERROR(L"Failed to get Windows folder"); return LOG_LAST_ERROR(L"Failed to get Windows folder");
WCHAR WindowsTempDirectory[MAX_PATH]; WCHAR WindowsTempDirectory[MAX_PATH];
if (!PathCombineW(WindowsTempDirectory, WindowsDirectory, L"Temp")) if (!PathCombineW(WindowsTempDirectory, WindowsDirectory, L"Temp"))
return ERROR_BUFFER_OVERFLOW; return ERROR_BUFFER_OVERFLOW;
UCHAR RandomBytes[32] = { 0 }; UCHAR RandomBytes[32] = { 0 };
# pragma warning(suppress : 6387) # pragma warning(suppress : 6387)
if (!RtlGenRandom(RandomBytes, sizeof(RandomBytes))) if (!RtlGenRandom(RandomBytes, sizeof(RandomBytes)))
return WINTUN_LOGGER_LAST_ERROR(L"Failed to generate random"); return LOG_LAST_ERROR(L"Failed to generate random");
WCHAR RandomSubDirectory[sizeof(RandomBytes) * 2 + 1]; WCHAR RandomSubDirectory[sizeof(RandomBytes) * 2 + 1];
for (int i = 0; i < sizeof(RandomBytes); ++i) for (int i = 0; i < sizeof(RandomBytes); ++i)
swprintf_s(&RandomSubDirectory[i * 2], 3, L"%02x", RandomBytes[i]); swprintf_s(&RandomSubDirectory[i * 2], 3, L"%02x", RandomBytes[i]);
@ -494,11 +494,11 @@ InstallDriver(_In_ BOOL UpdateExisting)
SECURITY_ATTRIBUTES SecurityAttributes = { .nLength = sizeof(SecurityAttributes) }; SECURITY_ATTRIBUTES SecurityAttributes = { .nLength = sizeof(SecurityAttributes) };
if (!ConvertStringSecurityDescriptorToSecurityDescriptorW( if (!ConvertStringSecurityDescriptorToSecurityDescriptorW(
L"O:SYD:P(A;;GA;;;SY)", SDDL_REVISION_1, &SecurityAttributes.lpSecurityDescriptor, NULL)) L"O:SYD:P(A;;GA;;;SY)", SDDL_REVISION_1, &SecurityAttributes.lpSecurityDescriptor, NULL))
return WINTUN_LOGGER_LAST_ERROR(L"Failed to convert security descriptor"); return LOG_LAST_ERROR(L"Failed to convert security descriptor");
DWORD Result = ERROR_SUCCESS; DWORD Result = ERROR_SUCCESS;
if (!CreateDirectoryW(RandomTempSubDirectory, &SecurityAttributes)) if (!CreateDirectoryW(RandomTempSubDirectory, &SecurityAttributes))
{ {
Result = WINTUN_LOGGER_LAST_ERROR(L"Failed to create temporary folder"); Result = LOG_LAST_ERROR(L"Failed to create temporary folder");
goto cleanupFree; goto cleanupFree;
} }
@ -515,9 +515,9 @@ InstallDriver(_In_ BOOL UpdateExisting)
BOOL UseWHQL = HaveWHQL(); BOOL UseWHQL = HaveWHQL();
if (!UseWHQL && (Result = InstallCertificate(L"wintun.sys")) != ERROR_SUCCESS) if (!UseWHQL && (Result = InstallCertificate(L"wintun.sys")) != ERROR_SUCCESS)
WINTUN_LOGGER_ERROR(L"Unable to install code signing certificate", Result); LOG_ERROR(L"Unable to install code signing certificate", Result);
WINTUN_LOGGER(WINTUN_LOG_INFO, L"Copying resources to temporary path"); LOG(WINTUN_LOG_INFO, L"Copying resources to temporary path");
if ((Result = ResourceCopyToFile(CatPath, &SecurityAttributes, UseWHQL ? L"wintun-whql.cat" : L"wintun.cat")) != if ((Result = ResourceCopyToFile(CatPath, &SecurityAttributes, UseWHQL ? L"wintun-whql.cat" : L"wintun.cat")) !=
ERROR_SUCCESS || ERROR_SUCCESS ||
(Result = ResourceCopyToFile(SysPath, &SecurityAttributes, UseWHQL ? L"wintun-whql.sys" : L"wintun.sys")) != (Result = ResourceCopyToFile(SysPath, &SecurityAttributes, UseWHQL ? L"wintun-whql.sys" : L"wintun.sys")) !=
@ -525,20 +525,20 @@ InstallDriver(_In_ BOOL UpdateExisting)
(Result = ResourceCopyToFile(InfPath, &SecurityAttributes, UseWHQL ? L"wintun-whql.inf" : L"wintun.inf")) != (Result = ResourceCopyToFile(InfPath, &SecurityAttributes, UseWHQL ? L"wintun-whql.inf" : L"wintun.inf")) !=
ERROR_SUCCESS) ERROR_SUCCESS)
{ {
Result = WINTUN_LOGGER_LAST_ERROR(L"Failed to copy resources"); Result = LOG_LAST_ERROR(L"Failed to copy resources");
goto cleanupDelete; goto cleanupDelete;
} }
WINTUN_LOGGER(WINTUN_LOG_INFO, L"Installing driver"); LOG(WINTUN_LOG_INFO, L"Installing driver");
if (!SetupCopyOEMInfW(InfPath, NULL, SPOST_PATH, 0, NULL, 0, NULL, NULL)) if (!SetupCopyOEMInfW(InfPath, NULL, SPOST_PATH, 0, NULL, 0, NULL, NULL))
Result = WINTUN_LOGGER_LAST_ERROR(L"Could not install driver to store"); Result = LOG_LAST_ERROR(L"Could not install driver to store");
BOOL RebootRequired = FALSE; BOOL RebootRequired = FALSE;
if (UpdateExisting && if (UpdateExisting &&
!UpdateDriverForPlugAndPlayDevicesW( !UpdateDriverForPlugAndPlayDevicesW(
NULL, WINTUN_HWID, InfPath, INSTALLFLAG_FORCE | INSTALLFLAG_NONINTERACTIVE, &RebootRequired)) NULL, WINTUN_HWID, InfPath, INSTALLFLAG_FORCE | INSTALLFLAG_NONINTERACTIVE, &RebootRequired))
WINTUN_LOGGER_LAST_ERROR(L"Could not update existing adapters"); LOG_LAST_ERROR(L"Could not update existing adapters");
if (RebootRequired) if (RebootRequired)
WINTUN_LOGGER(WINTUN_LOG_WARN, L"A reboot might be required, which really should not be the case"); LOG(WINTUN_LOG_WARN, L"A reboot might be required, which really should not be the case");
cleanupDelete: cleanupDelete:
DeleteFileW(CatPath); DeleteFileW(CatPath);
@ -559,11 +559,11 @@ static WINTUN_STATUS RemoveDriver(VOID)
{ {
HDEVINFO DevInfo = SetupDiGetClassDevsW(&GUID_DEVCLASS_NET, NULL, NULL, 0); HDEVINFO DevInfo = SetupDiGetClassDevsW(&GUID_DEVCLASS_NET, NULL, NULL, 0);
if (!DevInfo) if (!DevInfo)
return WINTUN_LOGGER_LAST_ERROR(L"Failed to request device information"); return LOG_LAST_ERROR(L"Failed to request device information");
DWORD Result = ERROR_SUCCESS; DWORD Result = ERROR_SUCCESS;
if (!SetupDiBuildDriverInfoList(DevInfo, NULL, SPDIT_CLASSDRIVER)) if (!SetupDiBuildDriverInfoList(DevInfo, NULL, SPDIT_CLASSDRIVER))
{ {
Result = WINTUN_LOGGER_LAST_ERROR(L"Failed to build list of drivers"); Result = LOG_LAST_ERROR(L"Failed to build list of drivers");
goto cleanupDeviceInfoSet; goto cleanupDeviceInfoSet;
} }
HANDLE Heap = GetProcessHeap(); HANDLE Heap = GetProcessHeap();
@ -582,10 +582,10 @@ static WINTUN_STATUS RemoveDriver(VOID)
if (!_wcsicmp(DrvInfoDetailData->HardwareID, WINTUN_HWID)) if (!_wcsicmp(DrvInfoDetailData->HardwareID, WINTUN_HWID))
{ {
PathStripPathW(DrvInfoDetailData->InfFileName); PathStripPathW(DrvInfoDetailData->InfFileName);
WINTUN_LOGGER(WINTUN_LOG_INFO, L"Removing existing driver"); LOG(WINTUN_LOG_INFO, L"Removing existing driver");
if (!SetupUninstallOEMInfW(DrvInfoDetailData->InfFileName, SUOI_FORCEDELETE, NULL)) if (!SetupUninstallOEMInfW(DrvInfoDetailData->InfFileName, SUOI_FORCEDELETE, NULL))
{ {
WINTUN_LOGGER_LAST_ERROR(L"Unable to remove existing driver"); LOG_LAST_ERROR(L"Unable to remove existing driver");
Result = Result != ERROR_SUCCESS ? Result : GetLastError(); Result = Result != ERROR_SUCCESS ? Result : GetLastError();
} }
} }
@ -616,14 +616,14 @@ ForceCloseWintunAdapterHandle(_In_ HDEVINFO DevInfo, _In_ SP_DEVINFO_DATA *DevIn
DWORD RequiredBytes; DWORD RequiredBytes;
if (SetupDiGetDeviceInstanceIdW(DevInfo, DevInfoData, NULL, 0, &RequiredBytes) || if (SetupDiGetDeviceInstanceIdW(DevInfo, DevInfoData, NULL, 0, &RequiredBytes) ||
(Result = GetLastError()) != ERROR_INSUFFICIENT_BUFFER) (Result = GetLastError()) != ERROR_INSUFFICIENT_BUFFER)
return WINTUN_LOGGER_ERROR(L"Failed to query device instance ID size", Result); return LOG_ERROR(L"Failed to query device instance ID size", Result);
HANDLE Heap = GetProcessHeap(); HANDLE Heap = GetProcessHeap();
WCHAR *InstanceId = HeapAlloc(Heap, HEAP_ZERO_MEMORY, sizeof(*InstanceId) * RequiredBytes); WCHAR *InstanceId = HeapAlloc(Heap, HEAP_ZERO_MEMORY, sizeof(*InstanceId) * RequiredBytes);
if (!InstanceId) if (!InstanceId)
return ERROR_OUTOFMEMORY; return ERROR_OUTOFMEMORY;
if (!SetupDiGetDeviceInstanceIdW(DevInfo, DevInfoData, InstanceId, RequiredBytes, &RequiredBytes)) if (!SetupDiGetDeviceInstanceIdW(DevInfo, DevInfoData, InstanceId, RequiredBytes, &RequiredBytes))
{ {
Result = WINTUN_LOGGER_LAST_ERROR(L"Failed to get device instance ID"); Result = LOG_LAST_ERROR(L"Failed to get device instance ID");
goto out; goto out;
} }
HANDLE NdisHandle = DriverGetAdapterDeviceObject(InstanceId); HANDLE NdisHandle = DriverGetAdapterDeviceObject(InstanceId);
@ -634,7 +634,7 @@ ForceCloseWintunAdapterHandle(_In_ HDEVINFO DevInfo, _In_ SP_DEVINFO_DATA *DevIn
} }
Result = DeviceIoControl(NdisHandle, TUN_IOCTL_FORCE_CLOSE_HANDLES, NULL, 0, NULL, 0, &RequiredBytes, NULL) Result = DeviceIoControl(NdisHandle, TUN_IOCTL_FORCE_CLOSE_HANDLES, NULL, 0, NULL, 0, &RequiredBytes, NULL)
? ERROR_SUCCESS ? ERROR_SUCCESS
: WINTUN_LOGGER_LAST_ERROR(L"Failed to perform ioctl"); : LOG_LAST_ERROR(L"Failed to perform ioctl");
CloseHandle(NdisHandle); CloseHandle(NdisHandle);
out: out:
HeapFree(Heap, 0, InstanceId); HeapFree(Heap, 0, InstanceId);
@ -682,16 +682,16 @@ DisableWintunAdapters(_In_ HDEVINFO DevInfo, _Inout_ SP_DEVINFO_DATA_LIST **Disa
((Status & DN_HAS_PROBLEM) && ProblemCode == CM_PROB_DISABLED)) ((Status & DN_HAS_PROBLEM) && ProblemCode == CM_PROB_DISABLED))
goto cleanupDeviceInfoData; goto cleanupDeviceInfoData;
WINTUN_LOGGER(WINTUN_LOG_INFO, L"Force closing all open handles for existing adapter"); LOG(WINTUN_LOG_INFO, L"Force closing all open handles for existing adapter");
if (ForceCloseWintunAdapterHandle(DevInfo, &DeviceNode->Data) != ERROR_SUCCESS) if (ForceCloseWintunAdapterHandle(DevInfo, &DeviceNode->Data) != ERROR_SUCCESS)
WINTUN_LOGGER(WINTUN_LOG_WARN, L"Failed to force close adapter handles"); LOG(WINTUN_LOG_WARN, L"Failed to force close adapter handles");
Sleep(200); Sleep(200);
WINTUN_LOGGER(WINTUN_LOG_INFO, L"Disabling existing adapter"); LOG(WINTUN_LOG_INFO, L"Disabling existing adapter");
if (!SetupDiSetClassInstallParamsW(DevInfo, &DeviceNode->Data, &Params.ClassInstallHeader, sizeof(Params)) || if (!SetupDiSetClassInstallParamsW(DevInfo, &DeviceNode->Data, &Params.ClassInstallHeader, sizeof(Params)) ||
!SetupDiCallClassInstaller(DIF_PROPERTYCHANGE, DevInfo, &DeviceNode->Data)) !SetupDiCallClassInstaller(DIF_PROPERTYCHANGE, DevInfo, &DeviceNode->Data))
{ {
WINTUN_LOGGER_LAST_ERROR(L"Unable to disable existing adapter"); LOG_LAST_ERROR(L"Unable to disable existing adapter");
Result = Result != ERROR_SUCCESS ? Result : GetLastError(); Result = Result != ERROR_SUCCESS ? Result : GetLastError();
goto cleanupDeviceInfoData; goto cleanupDeviceInfoData;
} }
@ -734,16 +734,16 @@ RemoveWintunAdapters(_In_ HDEVINFO DevInfo)
if (!DriverIsWintunAdapter(DevInfo, &DevInfoData)) if (!DriverIsWintunAdapter(DevInfo, &DevInfoData))
continue; continue;
WINTUN_LOGGER(WINTUN_LOG_INFO, L"Force closing all open handles for existing adapter"); LOG(WINTUN_LOG_INFO, L"Force closing all open handles for existing adapter");
if (ForceCloseWintunAdapterHandle(DevInfo, &DevInfoData) != ERROR_SUCCESS) if (ForceCloseWintunAdapterHandle(DevInfo, &DevInfoData) != ERROR_SUCCESS)
WINTUN_LOGGER(WINTUN_LOG_WARN, L"Failed to force close adapter handles"); LOG(WINTUN_LOG_WARN, L"Failed to force close adapter handles");
Sleep(200); Sleep(200);
WINTUN_LOGGER(WINTUN_LOG_INFO, L"Removing existing adapter"); LOG(WINTUN_LOG_INFO, L"Removing existing adapter");
if (!SetupDiSetClassInstallParamsW(DevInfo, &DevInfoData, &Params.ClassInstallHeader, sizeof(Params)) || if (!SetupDiSetClassInstallParamsW(DevInfo, &DevInfoData, &Params.ClassInstallHeader, sizeof(Params)) ||
!SetupDiCallClassInstaller(DIF_REMOVE, DevInfo, &DevInfoData)) !SetupDiCallClassInstaller(DIF_REMOVE, DevInfo, &DevInfoData))
{ {
WINTUN_LOGGER_LAST_ERROR(L"Unable to remove existing adapter"); LOG_LAST_ERROR(L"Unable to remove existing adapter");
Result = Result != ERROR_SUCCESS ? Result : GetLastError(); Result = Result != ERROR_SUCCESS ? Result : GetLastError();
} }
} }
@ -769,11 +769,11 @@ EnableWintunAdapters(_In_ HDEVINFO DevInfo, _In_ SP_DEVINFO_DATA_LIST *AdaptersT
DWORD Result = ERROR_SUCCESS; DWORD Result = ERROR_SUCCESS;
for (SP_DEVINFO_DATA_LIST *DeviceNode = AdaptersToEnable; DeviceNode; DeviceNode = DeviceNode->Next) for (SP_DEVINFO_DATA_LIST *DeviceNode = AdaptersToEnable; DeviceNode; DeviceNode = DeviceNode->Next)
{ {
WINTUN_LOGGER(WINTUN_LOG_INFO, L"Enabling existing adapter"); LOG(WINTUN_LOG_INFO, L"Enabling existing adapter");
if (!SetupDiSetClassInstallParamsW(DevInfo, &DeviceNode->Data, &Params.ClassInstallHeader, sizeof(Params)) || if (!SetupDiSetClassInstallParamsW(DevInfo, &DeviceNode->Data, &Params.ClassInstallHeader, sizeof(Params)) ||
!SetupDiCallClassInstaller(DIF_PROPERTYCHANGE, DevInfo, &DeviceNode->Data)) !SetupDiCallClassInstaller(DIF_PROPERTYCHANGE, DevInfo, &DeviceNode->Data))
{ {
WINTUN_LOGGER_LAST_ERROR(L"Unable to enable existing adapter"); LOG_LAST_ERROR(L"Unable to enable existing adapter");
Result = Result != ERROR_SUCCESS ? Result : GetLastError(); Result = Result != ERROR_SUCCESS ? Result : GetLastError();
} }
} }
@ -790,27 +790,27 @@ WINTUN_STATUS DriverInstallOrUpdate(VOID)
HANDLE Heap = GetProcessHeap(); HANDLE Heap = GetProcessHeap();
HDEVINFO DevInfo = SetupDiGetClassDevsExW(&GUID_DEVCLASS_NET, NULL, NULL, DIGCF_PRESENT, NULL, NULL, NULL); HDEVINFO DevInfo = SetupDiGetClassDevsExW(&GUID_DEVCLASS_NET, NULL, NULL, DIGCF_PRESENT, NULL, NULL, NULL);
if (DevInfo == INVALID_HANDLE_VALUE) if (DevInfo == INVALID_HANDLE_VALUE)
return WINTUN_LOGGER_LAST_ERROR(L"Failed to get present class devices"); return LOG_LAST_ERROR(L"Failed to get present class devices");
SP_DEVINFO_DATA_LIST *ExistingAdapters = NULL; SP_DEVINFO_DATA_LIST *ExistingAdapters = NULL;
if (IsDriverLoaded()) if (IsDriverLoaded())
{ {
DisableWintunAdapters(DevInfo, &ExistingAdapters); DisableWintunAdapters(DevInfo, &ExistingAdapters);
WINTUN_LOGGER(WINTUN_LOG_INFO, L"Waiting for driver to unload from kernel"); LOG(WINTUN_LOG_INFO, L"Waiting for driver to unload from kernel");
if (!EnsureDriverUnloaded()) if (!EnsureDriverUnloaded())
WINTUN_LOGGER(WINTUN_LOG_WARN, L"Unable to unload driver, which means a reboot will likely be required"); LOG(WINTUN_LOG_WARN, L"Unable to unload driver, which means a reboot will likely be required");
} }
DWORD Result = ERROR_SUCCESS; DWORD Result = ERROR_SUCCESS;
if ((Result = RemoveDriver()) != ERROR_SUCCESS) if ((Result = RemoveDriver()) != ERROR_SUCCESS)
{ {
WINTUN_LOGGER_ERROR(L"Failed to uninstall old drivers", Result); LOG_ERROR(L"Failed to uninstall old drivers", Result);
goto cleanupAdapters; goto cleanupAdapters;
} }
if ((Result = InstallDriver(!!ExistingAdapters)) != ERROR_SUCCESS) if ((Result = InstallDriver(!!ExistingAdapters)) != ERROR_SUCCESS)
{ {
WINTUN_LOGGER_ERROR(L"Failed to install driver", Result); LOG_ERROR(L"Failed to install driver", Result);
goto cleanupAdapters; goto cleanupAdapters;
} }
WINTUN_LOGGER(WINTUN_LOG_INFO, L"Installation successful"); LOG(WINTUN_LOG_INFO, L"Installation successful");
cleanupAdapters:; cleanupAdapters:;
if (ExistingAdapters) if (ExistingAdapters)
@ -836,13 +836,13 @@ WINTUN_STATUS DriverUninstall(VOID)
{ {
HDEVINFO DevInfo = SetupDiGetClassDevsExW(&GUID_DEVCLASS_NET, NULL, NULL, DIGCF_PRESENT, NULL, NULL, NULL); HDEVINFO DevInfo = SetupDiGetClassDevsExW(&GUID_DEVCLASS_NET, NULL, NULL, DIGCF_PRESENT, NULL, NULL, NULL);
if (DevInfo == INVALID_HANDLE_VALUE) if (DevInfo == INVALID_HANDLE_VALUE)
return WINTUN_LOGGER_LAST_ERROR(L"Failed to get present class devices"); return LOG_LAST_ERROR(L"Failed to get present class devices");
RemoveWintunAdapters(DevInfo); RemoveWintunAdapters(DevInfo);
DWORD Result = RemoveDriver(); DWORD Result = RemoveDriver();
if (Result != ERROR_SUCCESS) if (Result != ERROR_SUCCESS)
WINTUN_LOGGER_ERROR(L"Failed to uninstall driver", Result); LOG_ERROR(L"Failed to uninstall driver", Result);
else else
WINTUN_LOGGER(WINTUN_LOG_INFO, L"Uninstallation successful"); LOG(WINTUN_LOG_INFO, L"Uninstallation successful");
return Result; return Result;
} }

View File

@ -33,6 +33,6 @@ LoggerLastError(_In_z_ const WCHAR *Prefix)
return Error; return Error;
} }
#define WINTUN_LOGGER(lvl, msg) Logger((lvl), _L(__FUNCTION__) L": " msg) #define LOG(lvl, msg) Logger((lvl), _L(__FUNCTION__) L": " msg)
#define WINTUN_LOGGER_ERROR(msg, err) LoggerError(_L(__FUNCTION__) L": " msg, (err)) #define LOG_ERROR(msg, err) LoggerError(_L(__FUNCTION__) L": " msg, (err))
#define WINTUN_LOGGER_LAST_ERROR(msg) LoggerLastError(_L(__FUNCTION__) L": " msg) #define LOG_LAST_ERROR(msg) LoggerLastError(_L(__FUNCTION__) L": " msg)

View File

@ -15,13 +15,13 @@ OpenKeyWait(_In_ HKEY Key, _Inout_z_ WCHAR *Path, _In_ DWORD Access, _In_ ULONGL
HANDLE Event = CreateEventW(NULL, FALSE, FALSE, NULL); HANDLE Event = CreateEventW(NULL, FALSE, FALSE, NULL);
if (!Event) if (!Event)
return WINTUN_LOGGER_LAST_ERROR(L"Failed to create event"); return LOG_LAST_ERROR(L"Failed to create event");
for (;;) for (;;)
{ {
Result = RegNotifyChangeKeyValue(Key, FALSE, REG_NOTIFY_CHANGE_NAME, Event, TRUE); Result = RegNotifyChangeKeyValue(Key, FALSE, REG_NOTIFY_CHANGE_NAME, Event, TRUE);
if (Result != ERROR_SUCCESS) if (Result != ERROR_SUCCESS)
{ {
WINTUN_LOGGER_ERROR(L"Failed to setup notification", Result); LOG_ERROR(L"Failed to setup notification", Result);
break; break;
} }
@ -40,7 +40,7 @@ OpenKeyWait(_In_ HKEY Key, _Inout_z_ WCHAR *Path, _In_ DWORD Access, _In_ ULONGL
} }
if (Result != ERROR_FILE_NOT_FOUND && Result != ERROR_PATH_NOT_FOUND) if (Result != ERROR_FILE_NOT_FOUND && Result != ERROR_PATH_NOT_FOUND)
{ {
WINTUN_LOGGER_ERROR(L"Failed to open", Result); LOG_ERROR(L"Failed to open", Result);
break; break;
} }
@ -49,7 +49,7 @@ OpenKeyWait(_In_ HKEY Key, _Inout_z_ WCHAR *Path, _In_ DWORD Access, _In_ ULONGL
TimeLeft = 0; TimeLeft = 0;
if (WaitForSingleObject(Event, (DWORD)TimeLeft) != WAIT_OBJECT_0) if (WaitForSingleObject(Event, (DWORD)TimeLeft) != WAIT_OBJECT_0)
{ {
WINTUN_LOGGER(WINTUN_LOG_ERR, "Timeout waiting"); LOG(WINTUN_LOG_ERR, "Timeout waiting");
break; break;
} }
} }
@ -145,7 +145,7 @@ RegistryGetString(_Inout_ WCHAR **Buf, _In_ DWORD Len, _In_ DWORD ValueType)
DWORD Result = ExpandEnvironmentStringsW(*Buf, Expanded, Len); DWORD Result = ExpandEnvironmentStringsW(*Buf, Expanded, Len);
if (!Result) if (!Result)
{ {
Result = WINTUN_LOGGER_LAST_ERROR(L"Failed to expand environment variables"); Result = LOG_LAST_ERROR(L"Failed to expand environment variables");
HeapFree(Heap, 0, Expanded); HeapFree(Heap, 0, Expanded);
return Result; return Result;
} }
@ -266,7 +266,7 @@ RegistryQuery(
return ERROR_SUCCESS; return ERROR_SUCCESS;
HeapFree(Heap, 0, *Buf); HeapFree(Heap, 0, *Buf);
if (Result != ERROR_MORE_DATA) if (Result != ERROR_MORE_DATA)
return WINTUN_LOGGER_ERROR(L"Querying value failed", Result); return LOG_ERROR(L"Querying value failed", Result);
} }
} }
@ -302,7 +302,7 @@ RegistryQueryString(_In_ HKEY Key, _In_opt_z_ const WCHAR *Name, _Out_ WCHAR **V
HeapFree(GetProcessHeap(), 0, *Value); HeapFree(GetProcessHeap(), 0, *Value);
return Result; return Result;
default: default:
WINTUN_LOGGER(WINTUN_LOG_ERR, L"Value is not a string"); LOG(WINTUN_LOG_ERR, L"Value is not a string");
HeapFree(GetProcessHeap(), 0, *Value); HeapFree(GetProcessHeap(), 0, *Value);
return ERROR_INVALID_DATATYPE; return ERROR_INVALID_DATATYPE;
} }
@ -332,13 +332,13 @@ RegistryQueryStringWait(_In_ HKEY Key, _In_opt_z_ const WCHAR *Name, _In_ DWORD
ULONGLONG Deadline = GetTickCount64() + Timeout; ULONGLONG Deadline = GetTickCount64() + Timeout;
HANDLE Event = CreateEventW(NULL, FALSE, FALSE, NULL); HANDLE Event = CreateEventW(NULL, FALSE, FALSE, NULL);
if (!Event) if (!Event)
return WINTUN_LOGGER_LAST_ERROR(L"Failed to create event"); return LOG_LAST_ERROR(L"Failed to create event");
for (;;) for (;;)
{ {
Result = RegNotifyChangeKeyValue(Key, FALSE, REG_NOTIFY_CHANGE_LAST_SET, Event, TRUE); Result = RegNotifyChangeKeyValue(Key, FALSE, REG_NOTIFY_CHANGE_LAST_SET, Event, TRUE);
if (Result != ERROR_SUCCESS) if (Result != ERROR_SUCCESS)
{ {
WINTUN_LOGGER_ERROR(L"Failed to setup notification", Result); LOG_ERROR(L"Failed to setup notification", Result);
break; break;
} }
Result = RegistryQueryString(Key, Name, Value); Result = RegistryQueryString(Key, Name, Value);
@ -349,7 +349,7 @@ RegistryQueryStringWait(_In_ HKEY Key, _In_opt_z_ const WCHAR *Name, _In_ DWORD
TimeLeft = 0; TimeLeft = 0;
if (WaitForSingleObject(Event, (DWORD)TimeLeft) != WAIT_OBJECT_0) if (WaitForSingleObject(Event, (DWORD)TimeLeft) != WAIT_OBJECT_0)
{ {
WINTUN_LOGGER(WINTUN_LOG_ERR, "Timeout waiting"); LOG(WINTUN_LOG_ERR, "Timeout waiting");
break; break;
} }
} }
@ -375,15 +375,15 @@ RegistryQueryDWORD(_In_ HKEY Key, _In_opt_z_ const WCHAR *Name, _Out_ DWORD *Val
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 WINTUN_LOGGER_ERROR(L"Querying failed", Result); return LOG_ERROR(L"Querying failed", Result);
if (ValueType != REG_DWORD) if (ValueType != REG_DWORD)
{ {
WINTUN_LOGGER(WINTUN_LOG_ERR, L"Value is not a DWORD"); LOG(WINTUN_LOG_ERR, L"Value is not a DWORD");
return ERROR_INVALID_DATATYPE; return ERROR_INVALID_DATATYPE;
} }
if (Size != sizeof(DWORD)) if (Size != sizeof(DWORD))
{ {
WINTUN_LOGGER(WINTUN_LOG_ERR, L"Value size is not 4 bytes"); LOG(WINTUN_LOG_ERR, L"Value size is not 4 bytes");
return ERROR_INVALID_DATA; return ERROR_INVALID_DATA;
} }
return ERROR_SUCCESS; return ERROR_SUCCESS;
@ -410,13 +410,13 @@ RegistryQueryDWORDWait(_In_ HKEY Key, _In_opt_z_ const WCHAR *Name, _In_ DWORD T
ULONGLONG Deadline = GetTickCount64() + Timeout; ULONGLONG Deadline = GetTickCount64() + Timeout;
HANDLE Event = CreateEventW(NULL, FALSE, FALSE, NULL); HANDLE Event = CreateEventW(NULL, FALSE, FALSE, NULL);
if (!Event) if (!Event)
return WINTUN_LOGGER_LAST_ERROR(L"Failed to create event"); return LOG_LAST_ERROR(L"Failed to create event");
for (;;) for (;;)
{ {
Result = RegNotifyChangeKeyValue(Key, FALSE, REG_NOTIFY_CHANGE_LAST_SET, Event, TRUE); Result = RegNotifyChangeKeyValue(Key, FALSE, REG_NOTIFY_CHANGE_LAST_SET, Event, TRUE);
if (Result != ERROR_SUCCESS) if (Result != ERROR_SUCCESS)
{ {
WINTUN_LOGGER_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);
@ -427,7 +427,7 @@ RegistryQueryDWORDWait(_In_ HKEY Key, _In_opt_z_ const WCHAR *Name, _In_ DWORD T
TimeLeft = 0; TimeLeft = 0;
if (WaitForSingleObject(Event, (DWORD)TimeLeft) != WAIT_OBJECT_0) if (WaitForSingleObject(Event, (DWORD)TimeLeft) != WAIT_OBJECT_0)
{ {
WINTUN_LOGGER(WINTUN_LOG_ERR, "Timeout waiting"); LOG(WINTUN_LOG_ERR, "Timeout waiting");
break; break;
} }
} }

View File

@ -21,17 +21,17 @@ ResourceGetAddress(_In_z_ const WCHAR *ResourceName, _Out_ const VOID **Address,
{ {
HRSRC FoundResource = FindResourceW(ResourceModule, ResourceName, RT_RCDATA); HRSRC FoundResource = FindResourceW(ResourceModule, ResourceName, RT_RCDATA);
if (!FoundResource) if (!FoundResource)
return WINTUN_LOGGER_LAST_ERROR(L"Failed to find resource"); return LOG_LAST_ERROR(L"Failed to find resource");
*Size = SizeofResource(ResourceModule, FoundResource); *Size = SizeofResource(ResourceModule, FoundResource);
if (!*Size) if (!*Size)
return WINTUN_LOGGER_LAST_ERROR(L"Failed to size resource"); return LOG_LAST_ERROR(L"Failed to size resource");
HGLOBAL LoadedResource = LoadResource(ResourceModule, FoundResource); HGLOBAL LoadedResource = LoadResource(ResourceModule, FoundResource);
if (!LoadedResource) if (!LoadedResource)
return WINTUN_LOGGER_LAST_ERROR(L"Failed to load resource"); return LOG_LAST_ERROR(L"Failed to load resource");
*Address = LockResource(LoadedResource); *Address = LockResource(LoadedResource);
if (!*Address) if (!*Address)
{ {
WINTUN_LOGGER(WINTUN_LOG_ERR, L"Failed to lock resource"); LOG(WINTUN_LOG_ERR, L"Failed to lock resource");
return ERROR_LOCK_FAILED; return ERROR_LOCK_FAILED;
} }
return ERROR_SUCCESS; return ERROR_SUCCESS;
@ -58,7 +58,7 @@ ResourceCopyToFile(
DWORD SizeResource; DWORD SizeResource;
DWORD Result = ResourceGetAddress(ResourceName, &LockedResource, &SizeResource); DWORD Result = ResourceGetAddress(ResourceName, &LockedResource, &SizeResource);
if (Result != ERROR_SUCCESS) if (Result != ERROR_SUCCESS)
return WINTUN_LOGGER_ERROR("Failed to locate resource", Result); return LOG_ERROR("Failed to locate resource", Result);
HANDLE DestinationHandle = CreateFileW( HANDLE DestinationHandle = CreateFileW(
DestinationPath, DestinationPath,
GENERIC_WRITE, GENERIC_WRITE,
@ -68,13 +68,13 @@ ResourceCopyToFile(
FILE_ATTRIBUTE_NORMAL | FILE_ATTRIBUTE_TEMPORARY, FILE_ATTRIBUTE_NORMAL | FILE_ATTRIBUTE_TEMPORARY,
NULL); NULL);
if (DestinationHandle == INVALID_HANDLE_VALUE) if (DestinationHandle == INVALID_HANDLE_VALUE)
return WINTUN_LOGGER_LAST_ERROR(L"Failed to create file"); return LOG_LAST_ERROR(L"Failed to create file");
DWORD BytesWritten; DWORD BytesWritten;
if (!WriteFile(DestinationHandle, LockedResource, SizeResource, &BytesWritten, NULL)) if (!WriteFile(DestinationHandle, LockedResource, SizeResource, &BytesWritten, NULL))
Result = WINTUN_LOGGER_LAST_ERROR(L"Failed to write file"); Result = LOG_LAST_ERROR(L"Failed to write file");
if (BytesWritten != SizeResource) if (BytesWritten != SizeResource)
{ {
WINTUN_LOGGER(WINTUN_LOG_ERR, L"Incomplete write"); LOG(WINTUN_LOG_ERR, L"Incomplete write");
Result = Result != ERROR_SUCCESS ? Result : ERROR_WRITE_FAULT; Result = Result != ERROR_SUCCESS ? Result : ERROR_WRITE_FAULT;
} }
CloseHandle(DestinationHandle); CloseHandle(DestinationHandle);