api: rename MAX_POOL to WINTUN_MAX_POOL

Signed-off-by: Simon Rozman <simon@rozman.si>
This commit is contained in:
Simon Rozman 2020-10-31 08:53:32 +01:00
parent 9957396dc7
commit c8004933c1
4 changed files with 36 additions and 24 deletions

View File

@ -8,7 +8,7 @@
#pragma warning(disable : 4221) /* nonstandard: address of automatic in initializer */ #pragma warning(disable : 4221) /* nonstandard: address of automatic in initializer */
#define WAIT_FOR_REGISTRY_TIMEOUT 10000 /* ms */ #define WAIT_FOR_REGISTRY_TIMEOUT 10000 /* ms */
#define MAX_POOL_DEVICE_TYPE (MAX_POOL + 8) /* Should accommodate a pool name with " Tunnel" appended */ #define MAX_POOL_DEVICE_TYPE (WINTUN_MAX_POOL + 8) /* Should accommodate a pool name with " Tunnel" appended */
#if defined(_M_IX86) #if defined(_M_IX86)
# define IMAGE_FILE_PROCESS IMAGE_FILE_MACHINE_I386 # define IMAGE_FILE_PROCESS IMAGE_FILE_MACHINE_I386
#elif defined(_M_AMD64) #elif defined(_M_AMD64)
@ -451,16 +451,16 @@ RemoveNumberedSuffix(_Inout_z_ WCHAR *Name)
} }
static WINTUN_STATUS static WINTUN_STATUS
GetPoolDeviceTypeName(_In_z_count_c_(MAX_POOL) const WCHAR *Pool, _Out_cap_c_(MAX_POOL_DEVICE_TYPE) WCHAR *Name) GetPoolDeviceTypeName(_In_z_count_c_(WINTUN_MAX_POOL) const WCHAR *Pool, _Out_cap_c_(MAX_POOL_DEVICE_TYPE) WCHAR *Name)
{ {
if (_snwprintf_s(Name, MAX_POOL_DEVICE_TYPE, _TRUNCATE, L"%.*s Tunnel", MAX_POOL, Pool) == -1) if (_snwprintf_s(Name, MAX_POOL_DEVICE_TYPE, _TRUNCATE, L"%.*s Tunnel", WINTUN_MAX_POOL, Pool) == -1)
return LOG(WINTUN_LOG_ERR, L"Pool name too long"), ERROR_INVALID_PARAMETER; return LOG(WINTUN_LOG_ERR, L"Pool name too long"), ERROR_INVALID_PARAMETER;
return ERROR_SUCCESS; return ERROR_SUCCESS;
} }
static WINTUN_STATUS static WINTUN_STATUS
IsPoolMember( IsPoolMember(
_In_z_count_c_(MAX_POOL) const WCHAR *Pool, _In_z_count_c_(WINTUN_MAX_POOL) const WCHAR *Pool,
_In_ HDEVINFO DevInfo, _In_ HDEVINFO DevInfo,
_In_ SP_DEVINFO_DATA *DevInfoData, _In_ SP_DEVINFO_DATA *DevInfoData,
_Out_ BOOL *IsMember) _Out_ BOOL *IsMember)
@ -504,7 +504,7 @@ cleanupDeviceDesc:
static WINTUN_STATUS static WINTUN_STATUS
CreateAdapterData( CreateAdapterData(
_In_z_count_c_(MAX_POOL) const WCHAR *Pool, _In_z_count_c_(WINTUN_MAX_POOL) const WCHAR *Pool,
_In_ HDEVINFO DevInfo, _In_ HDEVINFO DevInfo,
_In_ SP_DEVINFO_DATA *DevInfoData, _In_ SP_DEVINFO_DATA *DevInfoData,
_Out_ WINTUN_ADAPTER **Adapter) _Out_ WINTUN_ADAPTER **Adapter)
@ -603,7 +603,7 @@ WintunFreeAdapter(_In_ WINTUN_ADAPTER *Adapter)
WINTUN_STATUS WINAPI WINTUN_STATUS WINAPI
WintunGetAdapter( WintunGetAdapter(
_In_z_count_c_(MAX_POOL) const WCHAR *Pool, _In_z_count_c_(WINTUN_MAX_POOL) const WCHAR *Pool,
_In_z_count_c_(MAX_ADAPTER_NAME) const WCHAR *Name, _In_z_count_c_(MAX_ADAPTER_NAME) const WCHAR *Name,
_Out_ WINTUN_ADAPTER **Adapter) _Out_ WINTUN_ADAPTER **Adapter)
{ {
@ -1067,7 +1067,7 @@ static BOOL EnsureWintunUnloaded(VOID)
static WINTUN_STATUS static WINTUN_STATUS
CreateAdapter( CreateAdapter(
_In_z_count_c_(MAX_PATH) const WCHAR *InfPath, _In_z_count_c_(MAX_PATH) const WCHAR *InfPath,
_In_z_count_c_(MAX_POOL) const WCHAR *Pool, _In_z_count_c_(WINTUN_MAX_POOL) const WCHAR *Pool,
_In_z_count_c_(MAX_ADAPTER_NAME) const WCHAR *Name, _In_z_count_c_(MAX_ADAPTER_NAME) const WCHAR *Name,
_In_opt_ const GUID *RequestedGUID, _In_opt_ const GUID *RequestedGUID,
_Out_ WINTUN_ADAPTER **Adapter, _Out_ WINTUN_ADAPTER **Adapter,
@ -1585,7 +1585,10 @@ cleanupDirectory:
} }
static WINTUN_STATUS static WINTUN_STATUS
GetAdapter(_In_z_count_c_(MAX_POOL) const WCHAR *Pool, _In_ const GUID *CfgInstanceID, _Out_ WINTUN_ADAPTER **Adapter) GetAdapter(
_In_z_count_c_(WINTUN_MAX_POOL) const WCHAR *Pool,
_In_ const GUID *CfgInstanceID,
_Out_ WINTUN_ADAPTER **Adapter)
{ {
HANDLE Mutex = NamespaceTakeMutex(Pool); HANDLE Mutex = NamespaceTakeMutex(Pool);
if (!Mutex) if (!Mutex)
@ -1609,7 +1612,7 @@ cleanupMutex:
static WINTUN_STATUS static WINTUN_STATUS
CreateAdapterNatively( CreateAdapterNatively(
_In_z_count_c_(MAX_POOL) const WCHAR *Pool, _In_z_count_c_(WINTUN_MAX_POOL) const WCHAR *Pool,
_In_z_count_c_(MAX_ADAPTER_NAME) const WCHAR *Name, _In_z_count_c_(MAX_ADAPTER_NAME) const WCHAR *Name,
_In_opt_ const GUID *RequestedGUID, _In_opt_ const GUID *RequestedGUID,
_Out_ WINTUN_ADAPTER **Adapter, _Out_ WINTUN_ADAPTER **Adapter,
@ -1617,13 +1620,13 @@ CreateAdapterNatively(
{ {
LOG(WINTUN_LOG_INFO, L"Spawning native process"); LOG(WINTUN_LOG_INFO, L"Spawning native process");
WCHAR RequestedGUIDStr[MAX_GUID_STRING_LEN]; WCHAR RequestedGUIDStr[MAX_GUID_STRING_LEN];
WCHAR Arguments[15 + MAX_POOL + 3 + MAX_ADAPTER_NAME + 2 + MAX_GUID_STRING_LEN + 1]; WCHAR Arguments[15 + WINTUN_MAX_POOL + 3 + MAX_ADAPTER_NAME + 2 + MAX_GUID_STRING_LEN + 1];
if (_snwprintf_s( if (_snwprintf_s(
Arguments, Arguments,
_countof(Arguments), _countof(Arguments),
_TRUNCATE, _TRUNCATE,
RequestedGUID ? L"CreateAdapter \"%.*s\" \"%.*s\" %.*s" : L"CreateAdapter \"%.*s\" \"%.*s\"", RequestedGUID ? L"CreateAdapter \"%.*s\" \"%.*s\" %.*s" : L"CreateAdapter \"%.*s\" \"%.*s\"",
MAX_POOL, WINTUN_MAX_POOL,
Pool, Pool,
MAX_ADAPTER_NAME, MAX_ADAPTER_NAME,
Name, Name,
@ -1663,7 +1666,7 @@ cleanupArgv:
WINTUN_STATUS WINAPI WINTUN_STATUS WINAPI
WintunCreateAdapter( WintunCreateAdapter(
_In_z_count_c_(MAX_POOL) const WCHAR *Pool, _In_z_count_c_(WINTUN_MAX_POOL) const WCHAR *Pool,
_In_z_count_c_(MAX_ADAPTER_NAME) const WCHAR *Name, _In_z_count_c_(MAX_ADAPTER_NAME) const WCHAR *Name,
_In_opt_ const GUID *RequestedGUID, _In_opt_ const GUID *RequestedGUID,
_Out_ WINTUN_ADAPTER **Adapter, _Out_ WINTUN_ADAPTER **Adapter,
@ -1875,7 +1878,7 @@ cleanupToken:
} }
WINTUN_STATUS WINAPI WINTUN_STATUS WINAPI
WintunEnumAdapters(_In_z_count_c_(MAX_POOL) const WCHAR *Pool, _In_ WINTUN_ENUM_FUNC Func, _In_ LPARAM Param) WintunEnumAdapters(_In_z_count_c_(WINTUN_MAX_POOL) const WCHAR *Pool, _In_ WINTUN_ENUM_FUNC Func, _In_ LPARAM Param)
{ {
HANDLE Mutex = NamespaceTakeMutex(Pool); HANDLE Mutex = NamespaceTakeMutex(Pool);
if (!Mutex) if (!Mutex)

View File

@ -85,7 +85,7 @@ typedef struct _WINTUN_ADAPTER
WCHAR DevInstanceID[MAX_INSTANCE_ID]; WCHAR DevInstanceID[MAX_INSTANCE_ID];
DWORD LuidIndex; DWORD LuidIndex;
DWORD IfType; DWORD IfType;
WCHAR Pool[MAX_POOL]; WCHAR Pool[WINTUN_MAX_POOL];
} WINTUN_ADAPTER; } WINTUN_ADAPTER;
/** /**
@ -105,7 +105,7 @@ WintunGetAdapterDeviceObject(_In_ const WINTUN_ADAPTER *Adapter, _Out_ HANDLE *H
*/ */
WINTUN_STATUS WINAPI WINTUN_STATUS WINAPI
WintunCreateAdapter( WintunCreateAdapter(
_In_z_count_c_(MAX_POOL) const WCHAR *Pool, _In_z_count_c_(WINTUN_MAX_POOL) const WCHAR *Pool,
_In_z_count_c_(MAX_ADAPTER_NAME) const WCHAR *Name, _In_z_count_c_(MAX_ADAPTER_NAME) const WCHAR *Name,
_In_opt_ const GUID *RequestedGUID, _In_opt_ const GUID *RequestedGUID,
_Out_ WINTUN_ADAPTER **Adapter, _Out_ WINTUN_ADAPTER **Adapter,

View File

@ -83,7 +83,7 @@ VOID __stdcall CreateAdapter(HWND hwnd, HINSTANCE hinst, LPSTR lpszCmdLine, int
Init(); Init();
if (Argc < 4) if (Argc < 4)
goto cleanup; goto cleanup;
if (wcslen(Argv[2]) >= MAX_POOL) if (wcslen(Argv[2]) >= WINTUN_MAX_POOL)
goto cleanup; goto cleanup;
if (wcslen(Argv[3]) >= MAX_ADAPTER_NAME) if (wcslen(Argv[3]) >= MAX_ADAPTER_NAME)
goto cleanup; goto cleanup;
@ -125,7 +125,11 @@ VOID __stdcall DeleteAdapter(HWND hwnd, HINSTANCE hinst, LPSTR lpszCmdLine, int
if (FAILED(CLSIDFromString(Argv[3], &Adapter.CfgInstanceID))) if (FAILED(CLSIDFromString(Argv[3], &Adapter.CfgInstanceID)))
goto cleanup; goto cleanup;
BOOL RebootRequired = FALSE; BOOL RebootRequired = FALSE;
WriteFormatted(STD_OUTPUT_HANDLE, L"%1!X! %2!X!", WintunDeleteAdapter(&Adapter, ForceCloseSessions, &RebootRequired), RebootRequired); WriteFormatted(
STD_OUTPUT_HANDLE,
L"%1!X! %2!X!",
WintunDeleteAdapter(&Adapter, ForceCloseSessions, &RebootRequired),
RebootRequired);
cleanup: cleanup:
Done(); Done();

View File

@ -19,7 +19,10 @@ typedef _Return_type_success_(return == ERROR_SUCCESS) DWORD WINTUN_STATUS;
*/ */
typedef void *WINTUN_ADAPTER_HANDLE; typedef void *WINTUN_ADAPTER_HANDLE;
#define MAX_POOL 256 /**
* Maximum pool name length including zero terminator
*/
#define WINTUN_MAX_POOL 256
/** /**
* Creates a Wintun adapter. * Creates a Wintun adapter.
@ -43,7 +46,7 @@ typedef void *WINTUN_ADAPTER_HANDLE;
* @return ERROR_SUCCESS on success; Win32 error code otherwise. * @return ERROR_SUCCESS on success; Win32 error code otherwise.
*/ */
typedef WINTUN_STATUS(WINAPI *WINTUN_CREATE_ADAPTER_FUNC)( typedef WINTUN_STATUS(WINAPI *WINTUN_CREATE_ADAPTER_FUNC)(
_In_z_count_c_(MAX_POOL) const WCHAR *Pool, _In_z_count_c_(WINTUN_MAX_POOL) const WCHAR *Pool,
_In_z_count_c_(MAX_ADAPTER_NAME) const WCHAR *Name, _In_z_count_c_(MAX_ADAPTER_NAME) const WCHAR *Name,
_In_opt_ const GUID *RequestedGUID, _In_opt_ const GUID *RequestedGUID,
_Out_ WINTUN_ADAPTER_HANDLE *Adapter, _Out_ WINTUN_ADAPTER_HANDLE *Adapter,
@ -63,8 +66,10 @@ typedef WINTUN_STATUS(WINAPI *WINTUN_CREATE_ADAPTER_FUNC)(
* *
* @return ERROR_SUCCESS on success or the adapter was not found; Win32 error code otherwise. * @return ERROR_SUCCESS on success or the adapter was not found; Win32 error code otherwise.
*/ */
typedef WINTUN_STATUS( typedef WINTUN_STATUS(WINAPI *WINTUN_DELETE_ADAPTER_FUNC)(
WINAPI *WINTUN_DELETE_ADAPTER_FUNC)(_In_ WINTUN_ADAPTER_HANDLE Adapter, _In_ BOOL ForceCloseSessions, _Inout_ BOOL *RebootRequired); _In_ WINTUN_ADAPTER_HANDLE Adapter,
_In_ BOOL ForceCloseSessions,
_Inout_ BOOL *RebootRequired);
/** /**
* Called by WintunEnumAdapters for each adapter in the pool. * Called by WintunEnumAdapters for each adapter in the pool.
@ -90,7 +95,7 @@ typedef BOOL(CALLBACK *WINTUN_ENUM_FUNC)(_In_ WINTUN_ADAPTER_HANDLE Adapter, _In
* @return ERROR_SUCCESS on success; Win32 error code otherwise. * @return ERROR_SUCCESS on success; Win32 error code otherwise.
*/ */
typedef WINTUN_STATUS(WINAPI *WINTUN_ENUM_ADAPTERS_FUNC)( typedef WINTUN_STATUS(WINAPI *WINTUN_ENUM_ADAPTERS_FUNC)(
_In_z_count_c_(MAX_POOL) const WCHAR *Pool, _In_z_count_c_(WINTUN_MAX_POOL) const WCHAR *Pool,
_In_ WINTUN_ENUM_FUNC Func, _In_ WINTUN_ENUM_FUNC Func,
_In_ LPARAM Param); _In_ LPARAM Param);
@ -114,7 +119,7 @@ typedef void(WINAPI *WINTUN_FREE_ADAPTER_FUNC)(_In_ WINTUN_ADAPTER_HANDLE Adapte
* if adapter is found but not a Wintun-class or not a member of the pool; Win32 error code otherwise * if adapter is found but not a Wintun-class or not a member of the pool; Win32 error code otherwise
*/ */
typedef WINTUN_STATUS(WINAPI *WINTUN_GET_ADAPTER_FUNC)( typedef WINTUN_STATUS(WINAPI *WINTUN_GET_ADAPTER_FUNC)(
_In_z_count_c_(MAX_POOL) const WCHAR *Pool, _In_z_count_c_(WINTUN_MAX_POOL) const WCHAR *Pool,
_In_z_count_c_(MAX_ADAPTER_NAME) const WCHAR *Name, _In_z_count_c_(MAX_ADAPTER_NAME) const WCHAR *Name,
_Out_ WINTUN_ADAPTER_HANDLE *Adapter); _Out_ WINTUN_ADAPTER_HANDLE *Adapter);