aboutsummaryrefslogtreecommitdiffstats
path: root/example/example.c
diff options
context:
space:
mode:
authorSimon Rozman <simon@rozman.si>2021-03-08 13:48:29 +0100
committerSimon Rozman <simon@rozman.si>2021-03-08 13:48:29 +0100
commitcef79225560bd454cb5c49d8d2b0cfac869de8d3 (patch)
tree9196e23668f0ae06498442b73a6797f7d4fe52d8 /example/example.c
parentapi: upgrade logging (diff)
downloadwintun-cef79225560bd454cb5c49d8d2b0cfac869de8d3.tar.xz
wintun-cef79225560bd454cb5c49d8d2b0cfac869de8d3.zip
api: elevate to SYSTEM in WintunEnumAdapters()
The WintunEnumAdapters() requires namespace mutex. However, NamespaceTakePoolMutex() works as SYSTEM user only. WireGuard is using the WintunEnumAdapters() in its manager service to cleanup stale adapters. As the WireGuard manager service is running as SYSTEM, this requirement was not apparent before. This commit also extends the example project to list its existing adapters at start. Signed-off-by: Simon Rozman <simon@rozman.si>
Diffstat (limited to '')
-rw-r--r--example/example.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/example/example.c b/example/example.c
index d36c2d4..9e5f2e8 100644
--- a/example/example.c
+++ b/example/example.c
@@ -293,6 +293,16 @@ SendPackets(_Inout_ DWORD_PTR SessionPtr)
return ERROR_SUCCESS;
}
+static BOOL CALLBACK
+PrintAdapter(_In_ WINTUN_ADAPTER_HANDLE Adapter, _In_ LPARAM Param)
+{
+ UNREFERENCED_PARAMETER(Param);
+ WCHAR szAdapterName[MAX_ADAPTER_NAME];
+ if (WintunGetAdapterName(Adapter, szAdapterName))
+ Log(WINTUN_LOG_INFO, L"Existing Wintun adapter: %s", szAdapterName);
+ return TRUE;
+}
+
int
main(void)
{
@@ -301,6 +311,7 @@ main(void)
return LogError(L"Failed to initialize Wintun", GetLastError());
WintunSetLogger(ConsoleLogger);
Log(WINTUN_LOG_INFO, L"Wintun library loaded");
+ WintunEnumAdapters(L"Example", PrintAdapter, 0);
DWORD LastError;
HaveQuit = FALSE;