libfreerdp-core: link against libwinpr-wtsapi, dynamically register proper WtsApi implementation in FreeRDS

This commit is contained in:
Marc-André Moreau 2014-02-16 20:41:19 -05:00
parent 1afeb448b4
commit a143a70114
10 changed files with 83 additions and 310 deletions

View File

@ -146,7 +146,7 @@ set_complex_link_libraries(VARIABLE ${MODULE_PREFIX}_LIBS
set_complex_link_libraries(VARIABLE ${MODULE_PREFIX}_LIBS
MONOLITHIC ${MONOLITHIC_BUILD}
MODULE winpr
MODULES winpr-registry winpr-utils winpr-interlocked winpr-dsparse winpr-sspi winpr-rpc winpr-handle winpr-crt)
MODULES winpr-registry winpr-utils winpr-interlocked winpr-dsparse winpr-sspi winpr-rpc winpr-wtsapi winpr-handle winpr-crt)
if(MONOLITHIC_BUILD)
set(FREERDP_LIBS ${FREERDP_LIBS} ${${MODULE_PREFIX}_LIBS} PARENT_SCOPE)

View File

@ -43,6 +43,7 @@
#include "rdp.h"
#include "client.h"
#include "server.h"
#include "channels.h"
BOOL freerdp_channel_send(rdpRdp* rdp, UINT16 channelId, BYTE* data, int size)
@ -181,15 +182,15 @@ static WtsApiFunctionTable FreeRDP_WtsApiFunctionTable =
NULL, /* LogoffSession */
NULL, /* ShutdownSystem */
NULL, /* WaitSystemEvent */
NULL, /* VirtualChannelOpen */
NULL, /* VirtualChannelOpenEx */
NULL, /* VirtualChannelClose */
NULL, /* VirtualChannelRead */
NULL, /* VirtualChannelWrite */
FreeRDP_WTSVirtualChannelOpen, /* VirtualChannelOpen */
FreeRDP_WTSVirtualChannelOpenEx, /* VirtualChannelOpenEx */
FreeRDP_WTSVirtualChannelClose, /* VirtualChannelClose */
FreeRDP_WTSVirtualChannelRead, /* VirtualChannelRead */
FreeRDP_WTSVirtualChannelWrite, /* VirtualChannelWrite */
NULL, /* VirtualChannelPurgeInput */
NULL, /* VirtualChannelPurgeOutput */
NULL, /* VirtualChannelQuery */
NULL, /* FreeMemory */
FreeRDP_WTSVirtualChannelQuery, /* VirtualChannelQuery */
FreeRDP_WTSFreeMemory, /* FreeMemory */
NULL, /* RegisterSessionNotification */
NULL, /* UnRegisterSessionNotification */
NULL, /* RegisterSessionNotificationEx */

View File

@ -34,6 +34,7 @@
#include <winpr/crt.h>
#include <winpr/stream.h>
#include <winpr/wtsapi.h>
#include <freerdp/freerdp.h>
#include <freerdp/error.h>

View File

@ -631,7 +631,7 @@ HANDLE WTSVirtualChannelManagerOpenEx(WTSVirtualChannelManager* vcm, LPSTR pVirt
return channel;
}
BOOL WTSVirtualChannelQuery(HANDLE hChannelHandle, WTS_VIRTUAL_CLASS WtsVirtualClass, PVOID* ppBuffer, DWORD* pBytesReturned)
BOOL FreeRDP_WTSVirtualChannelQuery(HANDLE hChannelHandle, WTS_VIRTUAL_CLASS WtsVirtualClass, PVOID* ppBuffer, DWORD* pBytesReturned)
{
void* pfd;
BOOL bval;
@ -707,12 +707,68 @@ BOOL WTSVirtualChannelQuery(HANDLE hChannelHandle, WTS_VIRTUAL_CLASS WtsVirtualC
return status;
}
VOID WTSFreeMemory(PVOID pMemory)
VOID FreeRDP_WTSFreeMemory(PVOID pMemory)
{
free(pMemory);
}
BOOL WTSVirtualChannelRead(HANDLE hChannelHandle, ULONG TimeOut, PCHAR Buffer, ULONG BufferSize, PULONG pBytesRead)
HANDLE FreeRDP_WTSVirtualChannelOpen(HANDLE hServer, DWORD SessionId, LPSTR pVirtualName)
{
return INVALID_HANDLE_VALUE;
}
HANDLE FreeRDP_WTSVirtualChannelOpenEx(DWORD SessionId, LPSTR pVirtualName, DWORD flags)
{
return INVALID_HANDLE_VALUE;
}
BOOL FreeRDP_WTSVirtualChannelClose(HANDLE hChannelHandle)
{
wStream* s;
rdpMcs* mcs;
WTSVirtualChannelManager* vcm;
rdpPeerChannel* channel = (rdpPeerChannel*) hChannelHandle;
if (channel)
{
vcm = channel->vcm;
mcs = vcm->client->context->rdp->mcs;
if (channel->channelType == RDP_PEER_CHANNEL_TYPE_SVC)
{
if (channel->index < mcs->channelCount)
mcs->channels[channel->index].handle = NULL;
}
else
{
ArrayList_Remove(vcm->dynamicVirtualChannels, channel);
if (channel->dvc_open_state == DVC_OPEN_STATE_SUCCEEDED)
{
s = Stream_New(NULL, 8);
wts_write_drdynvc_header(s, CLOSE_REQUEST_PDU, channel->channelId);
WTSVirtualChannelWrite(vcm->drdynvc_channel, (PCHAR) Stream_Buffer(s), Stream_GetPosition(s), NULL);
Stream_Free(s, TRUE);
}
}
if (channel->receiveData)
Stream_Free(channel->receiveData, TRUE);
if (channel->queue)
{
MessageQueue_Free(channel->queue);
channel->queue = NULL;
}
free(channel);
}
return TRUE;
}
BOOL FreeRDP_WTSVirtualChannelRead(HANDLE hChannelHandle, ULONG TimeOut, PCHAR Buffer, ULONG BufferSize, PULONG pBytesRead)
{
BYTE* buffer;
UINT32 length;
@ -741,7 +797,7 @@ BOOL WTSVirtualChannelRead(HANDLE hChannelHandle, ULONG TimeOut, PCHAR Buffer, U
return TRUE;
}
BOOL WTSVirtualChannelWrite(HANDLE hChannelHandle, PCHAR Buffer, ULONG Length, PULONG pBytesWritten)
BOOL FreeRDP_WTSVirtualChannelWrite(HANDLE hChannelHandle, PCHAR Buffer, ULONG Length, PULONG pBytesWritten)
{
wStream* s;
int cbLen;
@ -812,49 +868,3 @@ BOOL WTSVirtualChannelWrite(HANDLE hChannelHandle, PCHAR Buffer, ULONG Length, P
return TRUE;
}
BOOL WTSVirtualChannelClose(HANDLE hChannelHandle)
{
wStream* s;
rdpMcs* mcs;
WTSVirtualChannelManager* vcm;
rdpPeerChannel* channel = (rdpPeerChannel*) hChannelHandle;
if (channel)
{
vcm = channel->vcm;
mcs = vcm->client->context->rdp->mcs;
if (channel->channelType == RDP_PEER_CHANNEL_TYPE_SVC)
{
if (channel->index < mcs->channelCount)
mcs->channels[channel->index].handle = NULL;
}
else
{
ArrayList_Remove(vcm->dynamicVirtualChannels, channel);
if (channel->dvc_open_state == DVC_OPEN_STATE_SUCCEEDED)
{
s = Stream_New(NULL, 8);
wts_write_drdynvc_header(s, CLOSE_REQUEST_PDU, channel->channelId);
WTSVirtualChannelWrite(vcm->drdynvc_channel, (PCHAR) Stream_Buffer(s), Stream_GetPosition(s), NULL);
Stream_Free(s, TRUE);
}
}
if (channel->receiveData)
Stream_Free(channel->receiveData, TRUE);
if (channel->queue)
{
MessageQueue_Free(channel->queue);
channel->queue = NULL;
}
free(channel);
}
return TRUE;
}

View File

@ -90,4 +90,14 @@ struct WTSVirtualChannelManager
wArrayList* dynamicVirtualChannels;
};
BOOL FreeRDP_WTSVirtualChannelQuery(HANDLE hChannelHandle, WTS_VIRTUAL_CLASS WtsVirtualClass, PVOID* ppBuffer, DWORD* pBytesReturned);
VOID FreeRDP_WTSFreeMemory(PVOID pMemory);
HANDLE FreeRDP_WTSVirtualChannelOpen(HANDLE hServer, DWORD SessionId, LPSTR pVirtualName);
HANDLE FreeRDP_WTSVirtualChannelOpenEx(DWORD SessionId, LPSTR pVirtualName, DWORD flags);
BOOL FreeRDP_WTSVirtualChannelClose(HANDLE hChannelHandle);
BOOL FreeRDP_WTSVirtualChannelRead(HANDLE hChannelHandle, ULONG TimeOut, PCHAR Buffer, ULONG BufferSize, PULONG pBytesRead);
BOOL FreeRDP_WTSVirtualChannelWrite(HANDLE hChannelHandle, PCHAR Buffer, ULONG Length, PULONG pBytesWritten);
#endif /* FREERDP_CORE_SERVER_H */

View File

@ -505,6 +505,7 @@ DWORD WaitForMultipleObjects(DWORD nCount, const HANDLE* lpHandles, BOOL bWaitAl
if (!winpr_Handle_GetInfo(lpHandles[index], &Type, &Object))
{
fprintf(stderr, "WaitForMultipleObjects: invalid handle\n");
return WAIT_FAILED;
}

View File

@ -19,9 +19,7 @@ set(MODULE_NAME "winpr-wtsapi")
set(MODULE_PREFIX "WINPR_WTSAPI")
set(${MODULE_PREFIX}_SRCS
wtsapi.c
wtsrpc_c.c
wtsrpc_c.h)
wtsapi.c)
if(MSVC AND (NOT MONOLITHIC_BUILD))
set(${MODULE_PREFIX}_SRCS ${${MODULE_PREFIX}_SRCS} module.def)

View File

@ -31,12 +31,10 @@
* http://msdn.microsoft.com/en-us/library/windows/desktop/aa383464/
*/
static PWtsApiFunctionTable g_WtsApi;
static PWtsApiFunctionTable g_WtsApi = NULL;
#ifndef _WIN32
#include "wtsrpc_c.h"
BOOL WTSStartRemoteControlSessionW(LPWSTR pTargetServerName, ULONG TargetLogonId, BYTE HotkeyVk, USHORT HotkeyModifiers)
{
if (!g_WtsApi || !g_WtsApi->StartRemoteControlSessionW)

View File

@ -1,170 +0,0 @@
/**
* WinPR: Windows Portable Runtime
* Windows Terminal Services API
*
* Copyright 2013 Marc-Andre Moreau <marcandre.moreau@gmail.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <winpr/crt.h>
#include <winpr/wtsapi.h>
#ifndef _WIN32
#include "wtsrpc_c.h"
/**
* RPC Client Stubs
*/
BOOL RpcStartRemoteControlSession(void* context, LPWSTR pTargetServerName,
ULONG TargetLogonId, BYTE HotkeyVk, USHORT HotkeyModifiers)
{
return TRUE;
}
BOOL RpcStopRemoteControlSession(void* context, ULONG LogonId)
{
return TRUE;
}
BOOL RpcConnectSession(void* context, ULONG LogonId, ULONG TargetLogonId, PWSTR pPassword, BOOL bWait)
{
return TRUE;
}
BOOL RpcEnumerateServers(void* context, LPWSTR pDomainName, DWORD Reserved,
DWORD Version, PWTS_SERVER_INFOW* ppServerInfo, DWORD* pCount)
{
return TRUE;
}
HANDLE RpcOpenServer(void* context, LPWSTR pServerName)
{
return NULL;
}
HANDLE RpcOpenServerEx(void* context, LPWSTR pServerName)
{
return NULL;
}
VOID RpcCloseServer(void* context, HANDLE hServer)
{
}
BOOL RpcEnumerateSessions(void* context, HANDLE hServer, DWORD Reserved,
DWORD Version, PWTS_SESSION_INFOW* ppSessionInfo, DWORD* pCount)
{
return TRUE;
}
BOOL RpcEnumerateSessionsEx(void* context, HANDLE hServer, DWORD* pLevel,
DWORD Filter, PWTS_SESSION_INFO_1W* ppSessionInfo, DWORD* pCount)
{
return TRUE;
}
BOOL RpcEnumerateProcesses(void* context, HANDLE hServer, DWORD Reserved,
DWORD Version, PWTS_PROCESS_INFOW* ppProcessInfo, DWORD* pCount)
{
return TRUE;
}
BOOL RpcTerminateProcess(void* context, HANDLE hServer, DWORD ProcessId, DWORD ExitCode)
{
return TRUE;
}
BOOL RpcQuerySessionInformation(void* context, HANDLE hServer, DWORD SessionId,
WTS_INFO_CLASS WTSInfoClass, LPWSTR* ppBuffer, DWORD* pBytesReturned)
{
return TRUE;
}
BOOL RpcQueryUserConfig(void* context, LPWSTR pServerName, LPWSTR pUserName,
WTS_CONFIG_CLASS WTSConfigClass, LPWSTR* ppBuffer, DWORD* pBytesReturned)
{
return TRUE;
}
BOOL RpcSetUserConfig(void* context, LPWSTR pServerName, LPWSTR pUserName,
WTS_CONFIG_CLASS WTSConfigClass, LPWSTR pBuffer, DWORD DataLength)
{
return TRUE;
}
BOOL RpcSendMessage(void* context, HANDLE hServer, DWORD SessionId, LPWSTR pTitle, DWORD TitleLength,
LPWSTR pMessage, DWORD MessageLength, DWORD Style, DWORD Timeout, DWORD* pResponse, BOOL bWait)
{
return TRUE;
}
BOOL RpcDisconnectSession(void* context, HANDLE hServer, DWORD SessionId, BOOL bWait)
{
return TRUE;
}
BOOL RpcLogoffSession(void* context, HANDLE hServer, DWORD SessionId, BOOL bWait)
{
return TRUE;
}
BOOL RpcShutdownSystem(void* context, HANDLE hServer, DWORD ShutdownFlag)
{
return TRUE;
}
BOOL RpcRegisterSessionNotification(void* context, HWND hWnd, DWORD dwFlags)
{
return TRUE;
}
BOOL RpcUnRegisterSessionNotification(void* context, HWND hWnd)
{
return TRUE;
}
BOOL RpcRegisterSessionNotificationEx(void* context, HANDLE hServer, HWND hWnd, DWORD dwFlags)
{
return TRUE;
}
BOOL RpcUnRegisterSessionNotificationEx(void* context, HANDLE hServer, HWND hWnd)
{
return TRUE;
}
BOOL RpcEnableChildSessions(void* context, BOOL bEnable)
{
return TRUE;
}
BOOL RpcIsChildSessionsEnabled(void* context, PBOOL pbEnabled)
{
return TRUE;
}
BOOL RpcGetChildSessionId(void* context, PULONG pSessionId)
{
return TRUE;
}
#endif

View File

@ -1,76 +0,0 @@
/**
* WinPR: Windows Portable Runtime
* Windows Terminal Services API
*
* Copyright 2013 Marc-Andre Moreau <marcandre.moreau@gmail.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef WINPR_WTSAPI_RPC_CLIENT_STUBS_H
#define WINPR_WTSAPI_RPC_CLIENT_STUBS_H
/**
* RPC Client Stubs
*/
BOOL RpcStartRemoteControlSession(void* context, LPWSTR pTargetServerName,
ULONG TargetLogonId, BYTE HotkeyVk, USHORT HotkeyModifiers);
BOOL RpcStopRemoteControlSession(void* context, ULONG LogonId);
BOOL RpcConnectSession(void* context, ULONG LogonId, ULONG TargetLogonId, PWSTR pPassword, BOOL bWait);
BOOL RpcEnumerateServers(void* context, LPWSTR pDomainName, DWORD Reserved,
DWORD Version, PWTS_SERVER_INFOW* ppServerInfo, DWORD* pCount);
HANDLE RpcOpenServer(void* context, LPWSTR pServerName);
HANDLE RpcOpenServerEx(void* context, LPWSTR pServerName);
VOID RpcCloseServer(void* context, HANDLE hServer);
BOOL RpcEnumerateSessions(void* context, HANDLE hServer, DWORD Reserved,
DWORD Version, PWTS_SESSION_INFOW* ppSessionInfo, DWORD* pCount);
BOOL RpcEnumerateSessionsEx(void* context, HANDLE hServer, DWORD* pLevel,
DWORD Filter, PWTS_SESSION_INFO_1W* ppSessionInfo, DWORD* pCount);
BOOL RpcEnumerateProcesses(void* context, HANDLE hServer, DWORD Reserved,
DWORD Version, PWTS_PROCESS_INFOW* ppProcessInfo, DWORD* pCount);
BOOL RpcTerminateProcess(void* context, HANDLE hServer, DWORD ProcessId, DWORD ExitCode);
BOOL RpcQuerySessionInformation(void* context, HANDLE hServer, DWORD SessionId,
WTS_INFO_CLASS WTSInfoClass, LPWSTR* ppBuffer, DWORD* pBytesReturned);
BOOL RpcQueryUserConfig(void* context, LPWSTR pServerName, LPWSTR pUserName,
WTS_CONFIG_CLASS WTSConfigClass, LPWSTR* ppBuffer, DWORD* pBytesReturned);
BOOL RpcSetUserConfig(void* context, LPWSTR pServerName, LPWSTR pUserName,
WTS_CONFIG_CLASS WTSConfigClass, LPWSTR pBuffer, DWORD DataLength);
BOOL RpcSendMessage(void* context, HANDLE hServer, DWORD SessionId, LPWSTR pTitle, DWORD TitleLength,
LPWSTR pMessage, DWORD MessageLength, DWORD Style, DWORD Timeout, DWORD* pResponse, BOOL bWait);
BOOL RpcDisconnectSession(void* context, HANDLE hServer, DWORD SessionId, BOOL bWait);
BOOL RpcLogoffSession(void* context, HANDLE hServer, DWORD SessionId, BOOL bWait);
BOOL RpcShutdownSystem(void* context, HANDLE hServer, DWORD ShutdownFlag);
BOOL RpcRegisterSessionNotification(void* context, HWND hWnd, DWORD dwFlags);
BOOL RpcUnRegisterSessionNotification(void* context, HWND hWnd);
BOOL RpcRegisterSessionNotificationEx(void* context, HANDLE hServer, HWND hWnd, DWORD dwFlags);
BOOL RpcUnRegisterSessionNotificationEx(void* context, HANDLE hServer, HWND hWnd);
BOOL RpcEnableChildSessions(void* context, BOOL bEnable);
BOOL RpcIsChildSessionsEnabled(void* context, PBOOL pbEnabled);
BOOL RpcGetChildSessionId(void* context, PULONG pSessionId);
#endif /* WINPR_WTSAPI_RPC_CLIENT_STUBS_H */