SocksOverRDP-Server/SocksOverRDP-Server.cpp
/*
*  Open a dynamic channel with the name given in szChannelName.
*  The output file handle can be used in ReadFile/WriteFile calls.
*/
Open a dynamic channel with the name given in szChannelName.
The output file handle can be used in ReadFile/WriteFile calls.
Open a dynamic channel with the name given in szChannelName . The output file handle can be used in ReadFile / WriteFile calls .
DWORD OpenDynamicChannel(LPCSTR szChannelName, HANDLE *phFile)
{
	HANDLE	hWTSFileHandle;
	PVOID	vcFileHandlePtr = NULL;
	DWORD	len;
	DWORD	rc = ERROR_SUCCESS;
	BOOL	fSucc;
	hWTSHandle = WTSVirtualChannelOpenEx(WTS_CURRENT_SESSION, (LPSTR)szChannelName,
		WTS_CHANNEL_OPTION_DYNAMIC | running_args.priority);
	if (NULL == hWTSHandle)
	{
		rc = GetLastError();
		goto exitpt;
	}
	fSucc = WTSVirtualChannelQuery(hWTSHandle, WTSVirtualFileHandle,
		&vcFileHandlePtr, &len);
	if (!fSucc)
	{
		rc = GetLastError();
		goto exitpt;
	}
	if (len != sizeof(HANDLE))
	{
		rc = ERROR_INVALID_PARAMETER;
		goto exitpt;
	}
	hWTSFileHandle = *(HANDLE *)vcFileHandlePtr;
	fSucc = DuplicateHandle(GetCurrentProcess(), hWTSFileHandle, 
		GetCurrentProcess(), phFile, 0, FALSE, DUPLICATE_SAME_ACCESS);
	if (!fSucc)
	{
		rc = GetLastError();
		goto exitpt;
	}
	rc = ERROR_SUCCESS;
exitpt:
	if (vcFileHandlePtr)
	{
		WTSFreeMemory(vcFileHandlePtr);
	}
	if (hWTSHandle)
	{
		WTSVirtualChannelClose(hWTSHandle);
	}
	return rc;
}
DWORD OpenDynamicChannel ( LPCSTR szChannelName , HANDLE * phFile ) { HANDLE hWTSFileHandle ; PVOID vcFileHandlePtr = NULL ; DWORD len ; DWORD rc = ERROR_SUCCESS ; BOOL fSucc ; hWTSHandle = WTSVirtualChannelOpenEx ( WTS_CURRENT_SESSION , ( LPSTR ) szChannelName , WTS_CHANNEL_OPTION_DYNAMIC | running_args . priority ) ; if ( NULL == hWTSHandle ) { rc = GetLastError ( ) ; goto exitpt ; } fSucc = WTSVirtualChannelQuery ( hWTSHandle , WTSVirtualFileHandle , & vcFileHandlePtr , & len ) ; if ( ! fSucc ) { rc = GetLastError ( ) ; goto exitpt ; } if ( len != sizeof ( HANDLE ) ) { rc = ERROR_INVALID_PARAMETER ; goto exitpt ; } hWTSFileHandle = * ( HANDLE * ) vcFileHandlePtr ; fSucc = DuplicateHandle ( GetCurrentProcess ( ) , hWTSFileHandle , GetCurrentProcess ( ) , phFile , 0 , FALSE , DUPLICATE_SAME_ACCESS ) ; if ( ! fSucc ) { rc = GetLastError ( ) ; goto exitpt ; } rc = ERROR_SUCCESS ; exitpt : if ( vcFileHandlePtr ) { WTSFreeMemory ( vcFileHandlePtr ) ; } if ( hWTSHandle ) { WTSVirtualChannelClose ( hWTSHandle ) ; } return rc ; }
Open a dynamic channel with the name given in szChannelName.
Open a dynamic channel with the name given in szChannelName .