api: install driver on demand

...and add API for uninstalling it.

Signed-off-by: Simon Rozman <simon@rozman.si>
This commit is contained in:
Simon Rozman 2020-11-02 16:28:51 +01:00 committed by Jason A. Donenfeld
parent c20e1683c2
commit 283f6c8e63
5 changed files with 587 additions and 383 deletions

File diff suppressed because it is too large Load Diff

View File

@ -13,68 +13,6 @@
#define MAX_INSTANCE_ID MAX_PATH /* TODO: Is MAX_PATH always enough? */
#define WINTUN_HWID L"Wintun"
typedef struct _SP_DEVINFO_DATA_LIST
{
SP_DEVINFO_DATA Data;
struct _SP_DEVINFO_DATA_LIST *Next;
} SP_DEVINFO_DATA_LIST;
/**
* Retrieves driver information detail for a device information set or a particular device information element in the
* device information set.
*
* @param DevInfo A handle to the device information set that contains a device information element that
* represents the device for which to retrieve driver information.
*
* @param DevInfoData A pointer to a structure that specifies the device information element in DevInfo.
*
* @param DrvInfoData A pointer to a structure that specifies the driver information element that represents the
* driver for which to retrieve details.
*
* @param DrvInfoDetailData A pointer to a structure that receives detailed information about the specified driver.
* Must be released with HeapFree(ModuleHeap, 0, *DrvInfoDetailData) after use.
*
* @return ERROR_SUCCESS on success; Win32 error code otherwise.
*/
WINTUN_STATUS
AdapterGetDrvInfoDetail(
_In_ HDEVINFO DevInfo,
_In_opt_ SP_DEVINFO_DATA *DevInfoData,
_In_ SP_DRVINFO_DATA_W *DrvInfoData,
_Out_ SP_DRVINFO_DETAIL_DATA_W **DrvInfoDetailData);
/**
* Disables all Wintun adapters.
*
* @param DevInfo A handle to the device information set.
*
* @param DisabledAdapters Output list of disabled adapters. The adapters disabled are inserted in the list head.
*
* @return ERROR_SUCCESS on success; Win32 error code otherwise.
*/
WINTUN_STATUS
AdapterDisableAllOurs(_In_ HDEVINFO DevInfo, _Inout_ SP_DEVINFO_DATA_LIST **DisabledAdapters);
/**
* Enables all adapters.
*
* @param DevInfo A handle to the device information set.
*
* @param AdaptersToEnable Input list of adapters to enable.
*
* @return ERROR_SUCCESS on success; Win32 error code otherwise.
*/
WINTUN_STATUS
AdapterEnableAll(_In_ HDEVINFO DevInfo, _In_ SP_DEVINFO_DATA_LIST *AdaptersToEnable);
/**
* Removes all Wintun adapters.
*
* @return ERROR_SUCCESS on success; Win32 error code otherwise.
*/
WINTUN_STATUS
AdapterDeleteAllOurs(void);
void
AdapterInit(void);
@ -118,3 +56,9 @@ WintunCreateAdapter(
*/
WINTUN_STATUS WINAPI
WintunDeleteAdapter(_In_ const WINTUN_ADAPTER *Adapter, _In_ BOOL ForceCloseSessions, _Out_opt_ BOOL *RebootRequired);
/**
* @copydoc WINTUN_DELETE_DRIVER_FUNC
*/
WINTUN_STATUS WINAPI
WintunDeleteDriver(void);

View File

@ -3,6 +3,7 @@ EXPORTS
WintunAllocateSendPacket
WintunCreateAdapter
WintunDeleteAdapter
WintunDeleteDriver
WintunEndSession
WintunEnumAdapters
WintunFreeAdapter

View File

@ -145,6 +145,19 @@ cleanup:
Done();
}
VOID __stdcall DeleteDriver(HWND hwnd, HINSTANCE hinst, LPSTR lpszCmdLine, int nCmdShow)
{
# pragma EXPORT
UNREFERENCED_PARAMETER(hwnd);
UNREFERENCED_PARAMETER(hinst);
UNREFERENCED_PARAMETER(lpszCmdLine);
UNREFERENCED_PARAMETER(nCmdShow);
Init();
WriteFormatted(STD_OUTPUT_HANDLE, L"%1!X!", WintunDeleteDriver());
Done();
}
#ifdef _DEBUG
VOID __stdcall DoThingsForDebugging(HWND hwnd, HINSTANCE hinst, LPSTR lpszCmdLine, int nCmdShow)
{

View File

@ -70,6 +70,13 @@ typedef WINTUN_STATUS(WINAPI *WINTUN_DELETE_ADAPTER_FUNC)(
_In_ BOOL ForceCloseSessions,
_Out_opt_ BOOL *RebootRequired);
/**
* Deletes all Wintun drivers from the driver store
*
* @return ERROR_SUCCESS on success; Win32 error code otherwise.
*/
typedef WINTUN_STATUS(WINAPI *WINTUN_DELETE_DRIVER_FUNC)(void);
/**
* Called by WintunEnumAdapters for each adapter in the pool.
*
@ -93,8 +100,10 @@ typedef BOOL(CALLBACK *WINTUN_ENUM_CALLBACK_FUNC)(_In_ WINTUN_ADAPTER_HANDLE Ada
*
* @return ERROR_SUCCESS on success; Win32 error code otherwise.
*/
typedef WINTUN_STATUS(
WINAPI *WINTUN_ENUM_ADAPTERS_FUNC)(_In_z_ const WCHAR *Pool, _In_ WINTUN_ENUM_CALLBACK_FUNC Callback, _In_ LPARAM Param);
typedef WINTUN_STATUS(WINAPI *WINTUN_ENUM_ADAPTERS_FUNC)(
_In_z_ const WCHAR *Pool,
_In_ WINTUN_ENUM_CALLBACK_FUNC Callback,
_In_ LPARAM Param);
/**
* Releases Wintun adapter resources.
@ -166,7 +175,7 @@ typedef WINTUN_STATUS(WINAPI *WINTUN_GET_ADAPTER_NAME_FUNC)(
/**
* Determines the version of the Wintun driver currently loaded.
*
* @return The version number on success, or 0 if failure.
* @return The version number on success, or 0 if failure or Wintun not loaded.
*/
typedef DWORDLONG(WINAPI *WINTUN_GET_VERSION_FUNC)(void);