aboutsummaryrefslogtreecommitdiffstats
path: root/api/registry.c
diff options
context:
space:
mode:
Diffstat (limited to 'api/registry.c')
-rw-r--r--api/registry.c241
1 files changed, 0 insertions, 241 deletions
diff --git a/api/registry.c b/api/registry.c
index d385d86..4f1001c 100644
--- a/api/registry.c
+++ b/api/registry.c
@@ -10,100 +10,6 @@
#include <stdlib.h>
#include <strsafe.h>
-_Must_inspect_result_
-static _Return_type_success_(return != NULL)
-_Post_maybenull_
-HKEY
-OpenKeyWait(_In_ HKEY Key, _Inout_z_ LPWSTR Path, _In_ DWORD Access, _In_ ULONGLONG Deadline)
-{
- DWORD LastError;
- LPWSTR PathNext = wcschr(Path, L'\\');
- if (PathNext)
- *PathNext = 0;
-
- HANDLE Event = CreateEventW(NULL, FALSE, FALSE, NULL);
- if (!Event)
- {
- LOG_LAST_ERROR(L"Failed to create event");
- return NULL;
- }
- for (;;)
- {
- LastError = RegNotifyChangeKeyValue(Key, FALSE, REG_NOTIFY_CHANGE_NAME, Event, TRUE);
- if (LastError != ERROR_SUCCESS)
- {
- WCHAR RegPath[MAX_REG_PATH];
- LoggerGetRegistryKeyPath(Key, RegPath);
- LOG_ERROR(LastError, L"Failed to setup registry key %.*s notification", MAX_REG_PATH, RegPath);
- break;
- }
-
- HKEY Subkey;
- LastError = RegOpenKeyExW(Key, Path, 0, PathNext ? KEY_NOTIFY : Access, &Subkey);
- if (LastError == ERROR_SUCCESS)
- {
- if (PathNext)
- {
- HKEY KeyOut = OpenKeyWait(Subkey, PathNext + 1, Access, Deadline);
- if (KeyOut)
- {
- RegCloseKey(Subkey);
- CloseHandle(Event);
- return KeyOut;
- }
- LastError = GetLastError();
- break;
- }
- else
- {
- CloseHandle(Event);
- return Subkey;
- }
- }
- if (LastError != ERROR_FILE_NOT_FOUND && LastError != ERROR_PATH_NOT_FOUND)
- {
- WCHAR RegPath[MAX_REG_PATH];
- LoggerGetRegistryKeyPath(Key, RegPath);
- LOG_ERROR(LastError, L"Failed to open registry key %.*s\\%s", MAX_REG_PATH, RegPath, Path);
- break;
- }
-
- LONGLONG TimeLeft = Deadline - GetTickCount64();
- if (TimeLeft < 0)
- TimeLeft = 0;
- DWORD Result = WaitForSingleObject(Event, (DWORD)TimeLeft);
- if (Result != WAIT_OBJECT_0)
- {
- WCHAR RegPath[MAX_REG_PATH];
- LoggerGetRegistryKeyPath(Key, RegPath);
- LOG(WINTUN_LOG_ERR,
- L"Timeout waiting for registry key %.*s\\%s (status: 0x%x)",
- MAX_REG_PATH,
- RegPath,
- Path,
- Result);
- break;
- }
- }
- CloseHandle(Event);
- SetLastError(LastError);
- return NULL;
-}
-
-_Use_decl_annotations_
-HKEY
-RegistryOpenKeyWait(HKEY Key, LPCWSTR Path, DWORD Access, DWORD Timeout)
-{
- WCHAR Buf[MAX_REG_PATH];
- if (wcsncpy_s(Buf, _countof(Buf), Path, _TRUNCATE) == STRUNCATE)
- {
- LOG(WINTUN_LOG_ERR, L"Registry path too long: %s", Path);
- SetLastError(ERROR_INVALID_PARAMETER);
- return NULL;
- }
- return OpenKeyWait(Key, Buf, Access, GetTickCount64() + Timeout);
-}
-
_Use_decl_annotations_
BOOL
RegistryGetString(LPWSTR *Buf, DWORD Len, DWORD ValueType)
@@ -150,48 +56,6 @@ RegistryGetString(LPWSTR *Buf, DWORD Len, DWORD ValueType)
}
}
-_Use_decl_annotations_
-BOOL
-RegistryGetMultiString(PZZWSTR *Buf, DWORD Len, DWORD ValueType)
-{
- if (ValueType == REG_MULTI_SZ)
- {
- for (size_t i = 0;; i += wcsnlen(*Buf + i, Len - i) + 1)
- {
- if (i > Len)
- {
- /* Missing string and list terminators. */
- PZZWSTR BufZ = ReZallocArray(*Buf, (SIZE_T)Len + 2, sizeof(*BufZ));
- if (!BufZ)
- return FALSE;
- *Buf = BufZ;
- return TRUE;
- }
- if (i == Len)
- {
- /* Missing list terminator. */
- PZZWSTR BufZ = ReZallocArray(*Buf, (SIZE_T)Len + 1, sizeof(*BufZ));
- if (!BufZ)
- return FALSE;
- *Buf = BufZ;
- return TRUE;
- }
- if (!(*Buf)[i])
- return TRUE;
- }
- }
-
- /* Sanitize REG_SZ/REG_EXPAND_SZ and append a list terminator to make a multi-string. */
- if (!RegistryGetString(Buf, Len, ValueType))
- return FALSE;
- Len = (DWORD)wcslen(*Buf) + 1;
- PZZWSTR BufZ = ReZallocArray(*Buf, (SIZE_T)Len + 1, sizeof(WCHAR));
- if (!BufZ)
- return FALSE;
- *Buf = BufZ;
- return TRUE;
-}
-
_Must_inspect_result_
static _Return_type_success_(return != NULL)
_Post_maybenull_
@@ -257,59 +121,6 @@ RegistryQueryString(HKEY Key, LPCWSTR Name, BOOL Log)
}
_Use_decl_annotations_
-LPWSTR
-RegistryQueryStringWait(HKEY Key, LPCWSTR Name, DWORD Timeout)
-{
- DWORD LastError;
- ULONGLONG Deadline = GetTickCount64() + Timeout;
- HANDLE Event = CreateEventW(NULL, FALSE, FALSE, NULL);
- if (!Event)
- {
- LOG_LAST_ERROR(L"Failed to create event");
- return NULL;
- }
- for (;;)
- {
- LastError = RegNotifyChangeKeyValue(Key, FALSE, REG_NOTIFY_CHANGE_LAST_SET, Event, TRUE);
- if (LastError != ERROR_SUCCESS)
- {
- WCHAR RegPath[MAX_REG_PATH];
- LoggerGetRegistryKeyPath(Key, RegPath);
- LOG_ERROR(LastError, L"Failed to setup registry key %.*s notification", MAX_REG_PATH, RegPath);
- break;
- }
- LPWSTR Value = RegistryQueryString(Key, Name, FALSE);
- if (Value)
- {
- CloseHandle(Event);
- return Value;
- }
- LastError = GetLastError();
- if (LastError != ERROR_FILE_NOT_FOUND && LastError != ERROR_PATH_NOT_FOUND)
- break;
- LONGLONG TimeLeft = Deadline - GetTickCount64();
- if (TimeLeft < 0)
- TimeLeft = 0;
- DWORD Result = WaitForSingleObject(Event, (DWORD)TimeLeft);
- if (Result != WAIT_OBJECT_0)
- {
- WCHAR RegPath[MAX_REG_PATH];
- LoggerGetRegistryKeyPath(Key, RegPath);
- LOG(WINTUN_LOG_ERR,
- L"Timeout waiting for registry value %.*s\\%s (status: 0x%x)",
- MAX_REG_PATH,
- RegPath,
- Name,
- Result);
- break;
- }
- }
- CloseHandle(Event);
- SetLastError(LastError);
- return NULL;
-}
-
-_Use_decl_annotations_
BOOL
RegistryQueryDWORD(HKEY Key, LPCWSTR Name, DWORD *Value, BOOL Log)
{
@@ -344,55 +155,3 @@ RegistryQueryDWORD(HKEY Key, LPCWSTR Name, DWORD *Value, BOOL Log)
}
return TRUE;
}
-
-_Use_decl_annotations_
-BOOL
-RegistryQueryDWORDWait(HKEY Key, LPCWSTR Name, DWORD Timeout, DWORD *Value)
-{
- DWORD LastError;
- ULONGLONG Deadline = GetTickCount64() + Timeout;
- HANDLE Event = CreateEventW(NULL, FALSE, FALSE, NULL);
- if (!Event)
- {
- LOG_LAST_ERROR(L"Failed to create event");
- return FALSE;
- }
- for (;;)
- {
- LastError = RegNotifyChangeKeyValue(Key, FALSE, REG_NOTIFY_CHANGE_LAST_SET, Event, TRUE);
- if (LastError != ERROR_SUCCESS)
- {
- WCHAR RegPath[MAX_REG_PATH];
- LoggerGetRegistryKeyPath(Key, RegPath);
- LOG_ERROR(LastError, L"Failed to setup registry key %.*s notification", MAX_REG_PATH, RegPath);
- break;
- }
- if (RegistryQueryDWORD(Key, Name, Value, FALSE))
- {
- CloseHandle(Event);
- return TRUE;
- }
- LastError = GetLastError();
- if (LastError != ERROR_FILE_NOT_FOUND && LastError != ERROR_PATH_NOT_FOUND)
- break;
- LONGLONG TimeLeft = Deadline - GetTickCount64();
- if (TimeLeft < 0)
- TimeLeft = 0;
- DWORD Result = WaitForSingleObject(Event, (DWORD)TimeLeft);
- if (Result != WAIT_OBJECT_0)
- {
- WCHAR RegPath[MAX_REG_PATH];
- LoggerGetRegistryKeyPath(Key, RegPath);
- LOG(WINTUN_LOG_ERR,
- L"Timeout waiting registry value %.*s\\%s (status: 0x%x)",
- MAX_REG_PATH,
- RegPath,
- Name,
- Result);
- break;
- }
- }
- CloseHandle(Event);
- SetLastError(LastError);
- return FALSE;
-}