2013-08-20 03:18:31 +04:00
|
|
|
/**
|
|
|
|
* 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>
|
2014-03-25 08:32:05 +04:00
|
|
|
#include <winpr/ini.h>
|
|
|
|
#include <winpr/path.h>
|
2013-09-17 01:10:27 +04:00
|
|
|
#include <winpr/synch.h>
|
2014-03-01 09:32:23 +04:00
|
|
|
#include <winpr/library.h>
|
2014-03-17 20:16:07 +04:00
|
|
|
#include <winpr/environment.h>
|
2013-08-20 03:18:31 +04:00
|
|
|
|
|
|
|
#include <winpr/wtsapi.h>
|
|
|
|
|
2014-03-01 09:32:23 +04:00
|
|
|
#include "wtsapi.h"
|
|
|
|
|
2013-08-20 23:22:31 +04:00
|
|
|
/**
|
|
|
|
* Remote Desktop Services API Functions:
|
|
|
|
* http://msdn.microsoft.com/en-us/library/windows/desktop/aa383464/
|
|
|
|
*/
|
|
|
|
|
2014-03-01 09:32:23 +04:00
|
|
|
void InitializeWtsApiStubs(void);
|
|
|
|
|
|
|
|
static BOOL g_Initialized = FALSE;
|
|
|
|
static HMODULE g_WtsApiModule = NULL;
|
|
|
|
|
2014-02-17 05:41:19 +04:00
|
|
|
static PWtsApiFunctionTable g_WtsApi = NULL;
|
2014-02-17 04:38:12 +04:00
|
|
|
|
2014-02-28 23:49:57 +04:00
|
|
|
BOOL WINAPI WTSStartRemoteControlSessionW(LPWSTR pTargetServerName, ULONG TargetLogonId, BYTE HotkeyVk, USHORT HotkeyModifiers)
|
2013-08-20 04:38:43 +04:00
|
|
|
{
|
2014-03-01 09:32:23 +04:00
|
|
|
WTSAPI_STUB_CALL_BOOL(StartRemoteControlSessionW, pTargetServerName, TargetLogonId, HotkeyVk, HotkeyModifiers);
|
2013-08-20 04:38:43 +04:00
|
|
|
}
|
2013-08-20 03:18:31 +04:00
|
|
|
|
2014-02-28 23:49:57 +04:00
|
|
|
BOOL WINAPI WTSStartRemoteControlSessionA(LPSTR pTargetServerName, ULONG TargetLogonId, BYTE HotkeyVk, USHORT HotkeyModifiers)
|
2013-08-20 04:38:43 +04:00
|
|
|
{
|
2014-03-01 09:32:23 +04:00
|
|
|
WTSAPI_STUB_CALL_BOOL(StartRemoteControlSessionA, pTargetServerName, TargetLogonId, HotkeyVk, HotkeyModifiers);
|
2013-08-20 04:38:43 +04:00
|
|
|
}
|
|
|
|
|
2014-02-28 23:49:57 +04:00
|
|
|
BOOL WINAPI WTSStopRemoteControlSession(ULONG LogonId)
|
2013-08-20 04:38:43 +04:00
|
|
|
{
|
2014-03-01 09:32:23 +04:00
|
|
|
WTSAPI_STUB_CALL_BOOL(StopRemoteControlSession, LogonId);
|
2013-08-20 04:38:43 +04:00
|
|
|
}
|
|
|
|
|
2014-02-28 23:49:57 +04:00
|
|
|
BOOL WINAPI WTSConnectSessionW(ULONG LogonId, ULONG TargetLogonId, PWSTR pPassword, BOOL bWait)
|
2013-08-20 04:38:43 +04:00
|
|
|
{
|
2014-03-01 09:32:23 +04:00
|
|
|
WTSAPI_STUB_CALL_BOOL(ConnectSessionW, LogonId, TargetLogonId, pPassword, bWait);
|
2013-08-20 04:38:43 +04:00
|
|
|
}
|
|
|
|
|
2014-02-28 23:49:57 +04:00
|
|
|
BOOL WINAPI WTSConnectSessionA(ULONG LogonId, ULONG TargetLogonId, PSTR pPassword, BOOL bWait)
|
2013-08-20 04:38:43 +04:00
|
|
|
{
|
2014-03-01 09:32:23 +04:00
|
|
|
WTSAPI_STUB_CALL_BOOL(ConnectSessionA, LogonId, TargetLogonId, pPassword, bWait);
|
2013-08-20 04:38:43 +04:00
|
|
|
}
|
|
|
|
|
2014-02-28 23:49:57 +04:00
|
|
|
BOOL WINAPI WTSEnumerateServersW(LPWSTR pDomainName, DWORD Reserved, DWORD Version, PWTS_SERVER_INFOW* ppServerInfo, DWORD* pCount)
|
2013-08-20 04:38:43 +04:00
|
|
|
{
|
2014-03-01 09:32:23 +04:00
|
|
|
WTSAPI_STUB_CALL_BOOL(EnumerateServersW, pDomainName, Reserved, Version, ppServerInfo, pCount);
|
2013-08-20 04:38:43 +04:00
|
|
|
}
|
|
|
|
|
2014-02-28 23:49:57 +04:00
|
|
|
BOOL WINAPI WTSEnumerateServersA(LPSTR pDomainName, DWORD Reserved, DWORD Version, PWTS_SERVER_INFOA* ppServerInfo, DWORD* pCount)
|
2013-08-20 04:38:43 +04:00
|
|
|
{
|
2014-03-01 09:32:23 +04:00
|
|
|
WTSAPI_STUB_CALL_BOOL(EnumerateServersA, pDomainName, Reserved, Version, ppServerInfo, pCount);
|
2013-08-20 04:38:43 +04:00
|
|
|
}
|
|
|
|
|
2014-02-28 23:49:57 +04:00
|
|
|
HANDLE WINAPI WTSOpenServerW(LPWSTR pServerName)
|
2013-08-20 04:38:43 +04:00
|
|
|
{
|
2014-03-01 09:32:23 +04:00
|
|
|
WTSAPI_STUB_CALL_HANDLE(OpenServerW, pServerName);
|
2013-08-20 04:38:43 +04:00
|
|
|
}
|
|
|
|
|
2014-02-28 23:49:57 +04:00
|
|
|
HANDLE WINAPI WTSOpenServerA(LPSTR pServerName)
|
2013-08-20 04:38:43 +04:00
|
|
|
{
|
2014-03-01 09:32:23 +04:00
|
|
|
WTSAPI_STUB_CALL_HANDLE(OpenServerA, pServerName);
|
2013-08-20 04:38:43 +04:00
|
|
|
}
|
|
|
|
|
2014-02-28 23:49:57 +04:00
|
|
|
HANDLE WINAPI WTSOpenServerExW(LPWSTR pServerName)
|
2013-08-20 04:38:43 +04:00
|
|
|
{
|
2014-03-01 09:32:23 +04:00
|
|
|
WTSAPI_STUB_CALL_HANDLE(OpenServerExW, pServerName);
|
2013-08-20 04:38:43 +04:00
|
|
|
}
|
|
|
|
|
2014-02-28 23:49:57 +04:00
|
|
|
HANDLE WINAPI WTSOpenServerExA(LPSTR pServerName)
|
2013-08-20 04:38:43 +04:00
|
|
|
{
|
2014-03-01 09:32:23 +04:00
|
|
|
WTSAPI_STUB_CALL_HANDLE(OpenServerExA, pServerName);
|
2013-08-20 04:38:43 +04:00
|
|
|
}
|
|
|
|
|
2014-02-28 23:49:57 +04:00
|
|
|
VOID WINAPI WTSCloseServer(HANDLE hServer)
|
2013-08-20 04:38:43 +04:00
|
|
|
{
|
2014-03-01 09:32:23 +04:00
|
|
|
WTSAPI_STUB_CALL_VOID(CloseServer, hServer);
|
2013-08-20 04:38:43 +04:00
|
|
|
}
|
|
|
|
|
2014-02-28 23:49:57 +04:00
|
|
|
BOOL WINAPI WTSEnumerateSessionsW(HANDLE hServer, DWORD Reserved, DWORD Version, PWTS_SESSION_INFOW* ppSessionInfo, DWORD* pCount)
|
2013-08-20 04:38:43 +04:00
|
|
|
{
|
2014-03-01 09:32:23 +04:00
|
|
|
WTSAPI_STUB_CALL_BOOL(EnumerateSessionsW, hServer, Reserved, Version, ppSessionInfo, pCount);
|
2013-08-20 04:38:43 +04:00
|
|
|
}
|
|
|
|
|
2014-02-28 23:49:57 +04:00
|
|
|
BOOL WINAPI WTSEnumerateSessionsA(HANDLE hServer, DWORD Reserved, DWORD Version, PWTS_SESSION_INFOA* ppSessionInfo, DWORD* pCount)
|
2013-08-20 04:38:43 +04:00
|
|
|
{
|
2014-03-01 09:32:23 +04:00
|
|
|
WTSAPI_STUB_CALL_BOOL(EnumerateSessionsA, hServer, Reserved, Version, ppSessionInfo, pCount);
|
2013-08-20 04:38:43 +04:00
|
|
|
}
|
|
|
|
|
2014-02-28 23:49:57 +04:00
|
|
|
BOOL WINAPI WTSEnumerateSessionsExW(HANDLE hServer, DWORD* pLevel, DWORD Filter, PWTS_SESSION_INFO_1W* ppSessionInfo, DWORD* pCount)
|
2013-08-20 04:38:43 +04:00
|
|
|
{
|
2014-03-01 09:32:23 +04:00
|
|
|
WTSAPI_STUB_CALL_BOOL(EnumerateSessionsExW, hServer, pLevel, Filter, ppSessionInfo, pCount);
|
2013-08-20 04:38:43 +04:00
|
|
|
}
|
|
|
|
|
2014-02-28 23:49:57 +04:00
|
|
|
BOOL WINAPI WTSEnumerateSessionsExA(HANDLE hServer, DWORD* pLevel, DWORD Filter, PWTS_SESSION_INFO_1A* ppSessionInfo, DWORD* pCount)
|
2013-08-20 04:38:43 +04:00
|
|
|
{
|
2014-03-01 09:32:23 +04:00
|
|
|
WTSAPI_STUB_CALL_BOOL(EnumerateSessionsExA, hServer, pLevel, Filter, ppSessionInfo, pCount);
|
2013-08-20 04:38:43 +04:00
|
|
|
}
|
|
|
|
|
2014-02-28 23:49:57 +04:00
|
|
|
BOOL WINAPI WTSEnumerateProcessesW(HANDLE hServer, DWORD Reserved, DWORD Version, PWTS_PROCESS_INFOW* ppProcessInfo, DWORD* pCount)
|
2013-08-20 04:38:43 +04:00
|
|
|
{
|
2014-03-01 09:32:23 +04:00
|
|
|
WTSAPI_STUB_CALL_BOOL(EnumerateProcessesW, hServer, Reserved, Version, ppProcessInfo, pCount);
|
2013-08-20 04:38:43 +04:00
|
|
|
}
|
|
|
|
|
2014-02-28 23:49:57 +04:00
|
|
|
BOOL WINAPI WTSEnumerateProcessesA(HANDLE hServer, DWORD Reserved, DWORD Version, PWTS_PROCESS_INFOA* ppProcessInfo, DWORD* pCount)
|
2013-08-20 04:38:43 +04:00
|
|
|
{
|
2014-03-01 09:32:23 +04:00
|
|
|
WTSAPI_STUB_CALL_BOOL(EnumerateProcessesA, hServer, Reserved, Version, ppProcessInfo, pCount);
|
2013-08-20 04:38:43 +04:00
|
|
|
}
|
|
|
|
|
2014-02-28 23:49:57 +04:00
|
|
|
BOOL WINAPI WTSTerminateProcess(HANDLE hServer, DWORD ProcessId, DWORD ExitCode)
|
2013-08-20 04:38:43 +04:00
|
|
|
{
|
2014-03-01 09:32:23 +04:00
|
|
|
WTSAPI_STUB_CALL_BOOL(TerminateProcess, hServer, ProcessId, ExitCode);
|
2013-08-20 04:38:43 +04:00
|
|
|
}
|
|
|
|
|
2014-02-28 23:49:57 +04:00
|
|
|
BOOL WINAPI WTSQuerySessionInformationW(HANDLE hServer, DWORD SessionId, WTS_INFO_CLASS WTSInfoClass, LPWSTR* ppBuffer, DWORD* pBytesReturned)
|
2013-08-20 04:38:43 +04:00
|
|
|
{
|
2014-03-01 09:32:23 +04:00
|
|
|
WTSAPI_STUB_CALL_BOOL(QuerySessionInformationW, hServer, SessionId, WTSInfoClass, ppBuffer, pBytesReturned);
|
2013-08-20 04:38:43 +04:00
|
|
|
}
|
|
|
|
|
2014-02-28 23:49:57 +04:00
|
|
|
BOOL WINAPI WTSQuerySessionInformationA(HANDLE hServer, DWORD SessionId, WTS_INFO_CLASS WTSInfoClass, LPSTR* ppBuffer, DWORD* pBytesReturned)
|
2013-08-20 04:38:43 +04:00
|
|
|
{
|
2014-03-01 09:32:23 +04:00
|
|
|
WTSAPI_STUB_CALL_BOOL(QuerySessionInformationA, hServer, SessionId, WTSInfoClass, ppBuffer, pBytesReturned);
|
2013-08-20 04:38:43 +04:00
|
|
|
}
|
|
|
|
|
2014-02-28 23:49:57 +04:00
|
|
|
BOOL WINAPI WTSQueryUserConfigW(LPWSTR pServerName, LPWSTR pUserName, WTS_CONFIG_CLASS WTSConfigClass, LPWSTR* ppBuffer, DWORD* pBytesReturned)
|
2013-08-20 04:38:43 +04:00
|
|
|
{
|
2014-03-01 09:32:23 +04:00
|
|
|
WTSAPI_STUB_CALL_BOOL(QueryUserConfigW, pServerName, pUserName, WTSConfigClass, ppBuffer, pBytesReturned);
|
2013-08-20 04:38:43 +04:00
|
|
|
}
|
|
|
|
|
2014-02-28 23:49:57 +04:00
|
|
|
BOOL WINAPI WTSQueryUserConfigA(LPSTR pServerName, LPSTR pUserName, WTS_CONFIG_CLASS WTSConfigClass, LPSTR* ppBuffer, DWORD* pBytesReturned)
|
2013-08-20 04:38:43 +04:00
|
|
|
{
|
2014-03-01 09:32:23 +04:00
|
|
|
WTSAPI_STUB_CALL_BOOL(QueryUserConfigA, pServerName, pUserName, WTSConfigClass, ppBuffer, pBytesReturned);
|
2013-08-20 04:38:43 +04:00
|
|
|
}
|
|
|
|
|
2014-02-28 23:49:57 +04:00
|
|
|
BOOL WINAPI WTSSetUserConfigW(LPWSTR pServerName, LPWSTR pUserName, WTS_CONFIG_CLASS WTSConfigClass, LPWSTR pBuffer, DWORD DataLength)
|
2013-08-20 04:38:43 +04:00
|
|
|
{
|
2014-03-01 09:32:23 +04:00
|
|
|
WTSAPI_STUB_CALL_BOOL(SetUserConfigW, pServerName, pUserName, WTSConfigClass, pBuffer, DataLength);
|
2013-08-20 04:38:43 +04:00
|
|
|
}
|
|
|
|
|
2014-02-28 23:49:57 +04:00
|
|
|
BOOL WINAPI WTSSetUserConfigA(LPSTR pServerName, LPSTR pUserName, WTS_CONFIG_CLASS WTSConfigClass, LPSTR pBuffer, DWORD DataLength)
|
2013-08-20 04:38:43 +04:00
|
|
|
{
|
2014-03-01 09:32:23 +04:00
|
|
|
WTSAPI_STUB_CALL_BOOL(SetUserConfigA, pServerName, pUserName, WTSConfigClass, pBuffer, DataLength);
|
2013-08-20 04:38:43 +04:00
|
|
|
}
|
|
|
|
|
2014-02-28 23:49:57 +04:00
|
|
|
BOOL WINAPI WTSSendMessageW(HANDLE hServer, DWORD SessionId, LPWSTR pTitle, DWORD TitleLength,
|
2013-08-20 04:38:43 +04:00
|
|
|
LPWSTR pMessage, DWORD MessageLength, DWORD Style, DWORD Timeout, DWORD* pResponse, BOOL bWait)
|
|
|
|
{
|
2014-03-01 09:32:23 +04:00
|
|
|
WTSAPI_STUB_CALL_BOOL(SendMessageW, hServer, SessionId, pTitle, TitleLength,
|
2013-08-23 08:06:22 +04:00
|
|
|
pMessage, MessageLength, Style, Timeout, pResponse, bWait);
|
2013-08-20 04:38:43 +04:00
|
|
|
}
|
|
|
|
|
2014-02-28 23:49:57 +04:00
|
|
|
BOOL WINAPI WTSSendMessageA(HANDLE hServer, DWORD SessionId, LPSTR pTitle, DWORD TitleLength,
|
2013-08-20 04:38:43 +04:00
|
|
|
LPSTR pMessage, DWORD MessageLength, DWORD Style, DWORD Timeout, DWORD* pResponse, BOOL bWait)
|
|
|
|
{
|
2014-03-01 09:32:23 +04:00
|
|
|
WTSAPI_STUB_CALL_BOOL(SendMessageA, hServer, SessionId, pTitle, TitleLength,
|
2014-02-17 04:38:12 +04:00
|
|
|
pMessage, MessageLength, Style, Timeout, pResponse, bWait);
|
2013-08-20 04:38:43 +04:00
|
|
|
}
|
|
|
|
|
2014-02-28 23:49:57 +04:00
|
|
|
BOOL WINAPI WTSDisconnectSession(HANDLE hServer, DWORD SessionId, BOOL bWait)
|
2013-08-20 04:38:43 +04:00
|
|
|
{
|
2014-03-01 09:32:23 +04:00
|
|
|
WTSAPI_STUB_CALL_BOOL(DisconnectSession, hServer, SessionId, bWait);
|
2013-08-20 04:38:43 +04:00
|
|
|
}
|
|
|
|
|
2014-02-28 23:49:57 +04:00
|
|
|
BOOL WINAPI WTSLogoffSession(HANDLE hServer, DWORD SessionId, BOOL bWait)
|
2013-08-20 04:38:43 +04:00
|
|
|
{
|
2014-03-01 09:32:23 +04:00
|
|
|
WTSAPI_STUB_CALL_BOOL(LogoffSession, hServer, SessionId, bWait);
|
2013-08-20 04:38:43 +04:00
|
|
|
}
|
|
|
|
|
2014-02-28 23:49:57 +04:00
|
|
|
BOOL WINAPI WTSShutdownSystem(HANDLE hServer, DWORD ShutdownFlag)
|
2013-08-20 04:38:43 +04:00
|
|
|
{
|
2014-03-01 09:32:23 +04:00
|
|
|
WTSAPI_STUB_CALL_BOOL(ShutdownSystem, hServer, ShutdownFlag);
|
2013-08-20 04:38:43 +04:00
|
|
|
}
|
|
|
|
|
2014-02-28 23:49:57 +04:00
|
|
|
BOOL WINAPI WTSWaitSystemEvent(HANDLE hServer, DWORD EventMask, DWORD* pEventFlags)
|
2013-08-20 04:38:43 +04:00
|
|
|
{
|
2014-03-01 09:32:23 +04:00
|
|
|
WTSAPI_STUB_CALL_BOOL(WaitSystemEvent, hServer, EventMask, pEventFlags);
|
2013-08-20 04:38:43 +04:00
|
|
|
}
|
|
|
|
|
2014-02-28 23:49:57 +04:00
|
|
|
HANDLE WINAPI WTSVirtualChannelOpen(HANDLE hServer, DWORD SessionId, LPSTR pVirtualName)
|
2013-08-20 04:38:43 +04:00
|
|
|
{
|
2014-03-01 09:32:23 +04:00
|
|
|
WTSAPI_STUB_CALL_HANDLE(VirtualChannelOpen, hServer, SessionId, pVirtualName);
|
2013-08-20 04:38:43 +04:00
|
|
|
}
|
|
|
|
|
2014-02-28 23:49:57 +04:00
|
|
|
HANDLE WINAPI WTSVirtualChannelOpenEx(DWORD SessionId, LPSTR pVirtualName, DWORD flags)
|
2013-08-20 04:38:43 +04:00
|
|
|
{
|
2014-03-01 09:32:23 +04:00
|
|
|
WTSAPI_STUB_CALL_HANDLE(VirtualChannelOpenEx, SessionId, pVirtualName, flags);
|
2013-08-20 04:38:43 +04:00
|
|
|
}
|
|
|
|
|
2014-02-28 23:49:57 +04:00
|
|
|
BOOL WINAPI WTSVirtualChannelClose(HANDLE hChannelHandle)
|
2013-08-20 04:38:43 +04:00
|
|
|
{
|
2014-03-01 09:32:23 +04:00
|
|
|
WTSAPI_STUB_CALL_BOOL(VirtualChannelClose, hChannelHandle);
|
2013-08-20 04:38:43 +04:00
|
|
|
}
|
|
|
|
|
2014-02-28 23:49:57 +04:00
|
|
|
BOOL WINAPI WTSVirtualChannelRead(HANDLE hChannelHandle, ULONG TimeOut, PCHAR Buffer, ULONG BufferSize, PULONG pBytesRead)
|
2013-08-20 04:38:43 +04:00
|
|
|
{
|
2014-03-01 09:32:23 +04:00
|
|
|
WTSAPI_STUB_CALL_BOOL(VirtualChannelRead, hChannelHandle, TimeOut, Buffer, BufferSize, pBytesRead);
|
2013-08-20 04:38:43 +04:00
|
|
|
}
|
|
|
|
|
2014-02-28 23:49:57 +04:00
|
|
|
BOOL WINAPI WTSVirtualChannelWrite(HANDLE hChannelHandle, PCHAR Buffer, ULONG Length, PULONG pBytesWritten)
|
2013-08-20 04:38:43 +04:00
|
|
|
{
|
2014-03-01 09:32:23 +04:00
|
|
|
WTSAPI_STUB_CALL_BOOL(VirtualChannelWrite, hChannelHandle, Buffer, Length, pBytesWritten);
|
2013-08-23 03:20:59 +04:00
|
|
|
}
|
|
|
|
|
2014-02-28 23:49:57 +04:00
|
|
|
BOOL WINAPI WTSVirtualChannelPurgeInput(HANDLE hChannelHandle)
|
2013-08-23 03:20:59 +04:00
|
|
|
{
|
2014-03-01 09:32:23 +04:00
|
|
|
WTSAPI_STUB_CALL_BOOL(VirtualChannelPurgeInput, hChannelHandle);
|
2013-08-20 04:38:43 +04:00
|
|
|
}
|
|
|
|
|
2014-02-28 23:49:57 +04:00
|
|
|
BOOL WINAPI WTSVirtualChannelPurgeOutput(HANDLE hChannelHandle)
|
2013-08-20 04:38:43 +04:00
|
|
|
{
|
2014-03-01 09:32:23 +04:00
|
|
|
WTSAPI_STUB_CALL_BOOL(VirtualChannelPurgeOutput, hChannelHandle);
|
2013-08-20 04:38:43 +04:00
|
|
|
}
|
|
|
|
|
2014-02-28 23:49:57 +04:00
|
|
|
BOOL WINAPI WTSVirtualChannelQuery(HANDLE hChannelHandle, WTS_VIRTUAL_CLASS WtsVirtualClass, PVOID* ppBuffer, DWORD* pBytesReturned)
|
2013-08-20 04:38:43 +04:00
|
|
|
{
|
2014-03-01 09:32:23 +04:00
|
|
|
WTSAPI_STUB_CALL_BOOL(VirtualChannelQuery, hChannelHandle, WtsVirtualClass, ppBuffer, pBytesReturned);
|
2013-08-20 04:38:43 +04:00
|
|
|
}
|
|
|
|
|
2014-02-28 23:49:57 +04:00
|
|
|
VOID WINAPI WTSFreeMemory(PVOID pMemory)
|
2013-08-20 04:38:43 +04:00
|
|
|
{
|
2014-03-01 09:32:23 +04:00
|
|
|
WTSAPI_STUB_CALL_VOID(FreeMemory, pMemory);
|
2013-08-20 04:38:43 +04:00
|
|
|
}
|
|
|
|
|
2014-02-28 23:49:57 +04:00
|
|
|
BOOL WINAPI WTSFreeMemoryExW(WTS_TYPE_CLASS WTSTypeClass, PVOID pMemory, ULONG NumberOfEntries)
|
2013-08-20 04:38:43 +04:00
|
|
|
{
|
2014-03-01 09:32:23 +04:00
|
|
|
WTSAPI_STUB_CALL_BOOL(FreeMemoryExW, WTSTypeClass, pMemory, NumberOfEntries);
|
2013-08-20 04:38:43 +04:00
|
|
|
}
|
|
|
|
|
2014-02-28 23:49:57 +04:00
|
|
|
BOOL WINAPI WTSFreeMemoryExA(WTS_TYPE_CLASS WTSTypeClass, PVOID pMemory, ULONG NumberOfEntries)
|
2013-08-20 04:38:43 +04:00
|
|
|
{
|
2014-03-01 09:32:23 +04:00
|
|
|
WTSAPI_STUB_CALL_BOOL(FreeMemoryExA, WTSTypeClass, pMemory, NumberOfEntries);
|
2013-08-20 04:38:43 +04:00
|
|
|
}
|
|
|
|
|
2014-02-28 23:49:57 +04:00
|
|
|
BOOL WINAPI WTSRegisterSessionNotification(HWND hWnd, DWORD dwFlags)
|
2013-08-23 08:06:22 +04:00
|
|
|
{
|
2014-03-01 09:32:23 +04:00
|
|
|
WTSAPI_STUB_CALL_BOOL(RegisterSessionNotification, hWnd, dwFlags);
|
2013-08-23 08:06:22 +04:00
|
|
|
}
|
|
|
|
|
2014-02-28 23:49:57 +04:00
|
|
|
BOOL WINAPI WTSUnRegisterSessionNotification(HWND hWnd)
|
2013-08-23 08:06:22 +04:00
|
|
|
{
|
2014-03-01 09:32:23 +04:00
|
|
|
WTSAPI_STUB_CALL_BOOL(UnRegisterSessionNotification, hWnd);
|
2013-08-23 08:06:22 +04:00
|
|
|
}
|
|
|
|
|
2014-02-28 23:49:57 +04:00
|
|
|
BOOL WINAPI WTSRegisterSessionNotificationEx(HANDLE hServer, HWND hWnd, DWORD dwFlags)
|
2013-08-23 08:06:22 +04:00
|
|
|
{
|
2014-03-01 09:32:23 +04:00
|
|
|
WTSAPI_STUB_CALL_BOOL(RegisterSessionNotificationEx, hServer, hWnd, dwFlags);
|
2013-08-23 08:06:22 +04:00
|
|
|
}
|
|
|
|
|
2014-02-28 23:49:57 +04:00
|
|
|
BOOL WINAPI WTSUnRegisterSessionNotificationEx(HANDLE hServer, HWND hWnd)
|
2013-08-23 08:06:22 +04:00
|
|
|
{
|
2014-03-01 09:32:23 +04:00
|
|
|
WTSAPI_STUB_CALL_BOOL(UnRegisterSessionNotificationEx, hServer, hWnd);
|
2013-08-23 08:06:22 +04:00
|
|
|
}
|
|
|
|
|
2014-02-28 23:49:57 +04:00
|
|
|
BOOL WINAPI WTSQueryUserToken(ULONG SessionId, PHANDLE phToken)
|
2013-08-23 08:06:22 +04:00
|
|
|
{
|
2014-03-01 09:32:23 +04:00
|
|
|
WTSAPI_STUB_CALL_BOOL(QueryUserToken, SessionId, phToken);
|
2013-08-23 08:06:22 +04:00
|
|
|
}
|
|
|
|
|
2014-02-28 23:49:57 +04:00
|
|
|
BOOL WINAPI WTSEnumerateProcessesExW(HANDLE hServer, DWORD* pLevel, DWORD SessionId, LPWSTR* ppProcessInfo, DWORD* pCount)
|
2013-08-20 04:38:43 +04:00
|
|
|
{
|
2014-03-01 09:32:23 +04:00
|
|
|
WTSAPI_STUB_CALL_BOOL(EnumerateProcessesExW, hServer, pLevel, SessionId, ppProcessInfo, pCount);
|
2013-08-20 04:38:43 +04:00
|
|
|
}
|
|
|
|
|
2014-02-28 23:49:57 +04:00
|
|
|
BOOL WINAPI WTSEnumerateProcessesExA(HANDLE hServer, DWORD* pLevel, DWORD SessionId, LPSTR* ppProcessInfo, DWORD* pCount)
|
2013-08-20 04:38:43 +04:00
|
|
|
{
|
2014-03-01 09:32:23 +04:00
|
|
|
WTSAPI_STUB_CALL_BOOL(EnumerateProcessesExA, hServer, pLevel, SessionId, ppProcessInfo, pCount);
|
2013-08-20 04:38:43 +04:00
|
|
|
}
|
|
|
|
|
2014-02-28 23:49:57 +04:00
|
|
|
BOOL WINAPI WTSEnumerateListenersW(HANDLE hServer, PVOID pReserved, DWORD Reserved, PWTSLISTENERNAMEW pListeners, DWORD* pCount)
|
2013-08-20 04:38:43 +04:00
|
|
|
{
|
2014-03-01 09:32:23 +04:00
|
|
|
WTSAPI_STUB_CALL_BOOL(EnumerateListenersW, hServer, pReserved, Reserved, pListeners, pCount);
|
2013-08-20 04:38:43 +04:00
|
|
|
}
|
|
|
|
|
2014-02-28 23:49:57 +04:00
|
|
|
BOOL WINAPI WTSEnumerateListenersA(HANDLE hServer, PVOID pReserved, DWORD Reserved, PWTSLISTENERNAMEA pListeners, DWORD* pCount)
|
2013-08-20 04:38:43 +04:00
|
|
|
{
|
2014-03-01 09:32:23 +04:00
|
|
|
WTSAPI_STUB_CALL_BOOL(EnumerateListenersA, hServer, pReserved, Reserved, pListeners, pCount);
|
2013-08-20 04:38:43 +04:00
|
|
|
}
|
|
|
|
|
2014-02-28 23:49:57 +04:00
|
|
|
BOOL WINAPI WTSQueryListenerConfigW(HANDLE hServer, PVOID pReserved, DWORD Reserved, LPWSTR pListenerName, PWTSLISTENERCONFIGW pBuffer)
|
2013-08-20 04:38:43 +04:00
|
|
|
{
|
2014-03-01 09:32:23 +04:00
|
|
|
WTSAPI_STUB_CALL_BOOL(QueryListenerConfigW, hServer, pReserved, Reserved, pListenerName, pBuffer);
|
2013-08-20 04:38:43 +04:00
|
|
|
}
|
|
|
|
|
2014-02-28 23:49:57 +04:00
|
|
|
BOOL WINAPI WTSQueryListenerConfigA(HANDLE hServer, PVOID pReserved, DWORD Reserved, LPSTR pListenerName, PWTSLISTENERCONFIGA pBuffer)
|
2013-08-20 04:38:43 +04:00
|
|
|
{
|
2014-03-01 09:32:23 +04:00
|
|
|
WTSAPI_STUB_CALL_BOOL(QueryListenerConfigA, hServer, pReserved, Reserved, pListenerName, pBuffer);
|
2013-08-20 04:38:43 +04:00
|
|
|
}
|
|
|
|
|
2014-02-28 23:49:57 +04:00
|
|
|
BOOL WINAPI WTSCreateListenerW(HANDLE hServer, PVOID pReserved, DWORD Reserved,
|
2013-08-20 04:58:42 +04:00
|
|
|
LPWSTR pListenerName, PWTSLISTENERCONFIGW pBuffer, DWORD flag)
|
2013-08-20 04:38:43 +04:00
|
|
|
{
|
2014-03-01 09:32:23 +04:00
|
|
|
WTSAPI_STUB_CALL_BOOL(CreateListenerW, hServer, pReserved, Reserved, pListenerName, pBuffer, flag);
|
2013-08-20 04:38:43 +04:00
|
|
|
}
|
|
|
|
|
2014-02-28 23:49:57 +04:00
|
|
|
BOOL WINAPI WTSCreateListenerA(HANDLE hServer, PVOID pReserved, DWORD Reserved,
|
2013-08-20 04:38:43 +04:00
|
|
|
LPSTR pListenerName, PWTSLISTENERCONFIGA pBuffer, DWORD flag)
|
|
|
|
{
|
2014-03-01 09:32:23 +04:00
|
|
|
WTSAPI_STUB_CALL_BOOL(CreateListenerA, hServer, pReserved, Reserved, pListenerName, pBuffer, flag);
|
2013-08-20 04:38:43 +04:00
|
|
|
}
|
|
|
|
|
2014-02-28 23:49:57 +04:00
|
|
|
BOOL WINAPI WTSSetListenerSecurityW(HANDLE hServer, PVOID pReserved, DWORD Reserved,
|
2013-08-20 04:38:43 +04:00
|
|
|
LPWSTR pListenerName, SECURITY_INFORMATION SecurityInformation,
|
|
|
|
PSECURITY_DESCRIPTOR pSecurityDescriptor)
|
|
|
|
{
|
2014-03-01 09:32:23 +04:00
|
|
|
WTSAPI_STUB_CALL_BOOL(SetListenerSecurityW, hServer, pReserved, Reserved,
|
2014-02-17 04:38:12 +04:00
|
|
|
pListenerName, SecurityInformation, pSecurityDescriptor);
|
2013-08-20 04:38:43 +04:00
|
|
|
}
|
|
|
|
|
2014-02-28 23:49:57 +04:00
|
|
|
BOOL WINAPI WTSSetListenerSecurityA(HANDLE hServer, PVOID pReserved, DWORD Reserved,
|
2013-08-20 04:38:43 +04:00
|
|
|
LPSTR pListenerName, SECURITY_INFORMATION SecurityInformation,
|
|
|
|
PSECURITY_DESCRIPTOR pSecurityDescriptor)
|
|
|
|
{
|
2014-03-01 09:32:23 +04:00
|
|
|
WTSAPI_STUB_CALL_BOOL(SetListenerSecurityA, hServer, pReserved, Reserved,
|
2014-02-17 04:38:12 +04:00
|
|
|
pListenerName, SecurityInformation, pSecurityDescriptor);
|
2013-08-20 04:38:43 +04:00
|
|
|
}
|
|
|
|
|
2014-02-28 23:49:57 +04:00
|
|
|
BOOL WINAPI WTSGetListenerSecurityW(HANDLE hServer, PVOID pReserved, DWORD Reserved,
|
2013-08-20 04:38:43 +04:00
|
|
|
LPWSTR pListenerName, SECURITY_INFORMATION SecurityInformation,
|
|
|
|
PSECURITY_DESCRIPTOR pSecurityDescriptor, DWORD nLength, LPDWORD lpnLengthNeeded)
|
|
|
|
{
|
2014-03-01 09:32:23 +04:00
|
|
|
WTSAPI_STUB_CALL_BOOL(GetListenerSecurityW, hServer, pReserved, Reserved, pListenerName,
|
2014-02-17 04:38:12 +04:00
|
|
|
SecurityInformation, pSecurityDescriptor, nLength, lpnLengthNeeded);
|
2013-08-20 04:38:43 +04:00
|
|
|
}
|
|
|
|
|
2014-02-28 23:49:57 +04:00
|
|
|
BOOL WINAPI WTSGetListenerSecurityA(HANDLE hServer, PVOID pReserved, DWORD Reserved,
|
2013-08-20 04:38:43 +04:00
|
|
|
LPSTR pListenerName, SECURITY_INFORMATION SecurityInformation,
|
|
|
|
PSECURITY_DESCRIPTOR pSecurityDescriptor, DWORD nLength, LPDWORD lpnLengthNeeded)
|
|
|
|
{
|
2014-03-01 09:32:23 +04:00
|
|
|
WTSAPI_STUB_CALL_BOOL(GetListenerSecurityA, hServer, pReserved, Reserved, pListenerName,
|
2014-02-17 04:38:12 +04:00
|
|
|
SecurityInformation, pSecurityDescriptor, nLength, lpnLengthNeeded);
|
2013-08-20 04:38:43 +04:00
|
|
|
}
|
|
|
|
|
2014-02-28 23:49:57 +04:00
|
|
|
BOOL CDECL WTSEnableChildSessions(BOOL bEnable)
|
2013-08-20 04:38:43 +04:00
|
|
|
{
|
2014-03-01 09:32:23 +04:00
|
|
|
WTSAPI_STUB_CALL_BOOL(EnableChildSessions, bEnable);
|
2013-08-20 04:38:43 +04:00
|
|
|
}
|
|
|
|
|
2014-02-28 23:49:57 +04:00
|
|
|
BOOL CDECL WTSIsChildSessionsEnabled(PBOOL pbEnabled)
|
2013-08-20 04:38:43 +04:00
|
|
|
{
|
2014-03-01 09:32:23 +04:00
|
|
|
WTSAPI_STUB_CALL_BOOL(IsChildSessionsEnabled, pbEnabled);
|
2013-08-20 04:38:43 +04:00
|
|
|
}
|
|
|
|
|
2014-02-28 23:49:57 +04:00
|
|
|
BOOL CDECL WTSGetChildSessionId(PULONG pSessionId)
|
2013-08-20 04:38:43 +04:00
|
|
|
{
|
2014-03-01 09:32:23 +04:00
|
|
|
WTSAPI_STUB_CALL_BOOL(GetChildSessionId, pSessionId);
|
2013-08-20 04:38:43 +04:00
|
|
|
}
|
2013-08-20 03:18:31 +04:00
|
|
|
|
2014-02-28 23:49:57 +04:00
|
|
|
#ifndef _WIN32
|
|
|
|
|
|
|
|
/**
|
|
|
|
* WTSGetActiveConsoleSessionId is declared in WinBase.h and exported by kernel32.dll
|
|
|
|
*/
|
|
|
|
|
|
|
|
DWORD WINAPI WTSGetActiveConsoleSessionId(void)
|
2014-02-17 05:12:45 +04:00
|
|
|
{
|
2014-03-01 09:32:23 +04:00
|
|
|
if (!g_Initialized)
|
|
|
|
InitializeWtsApiStubs();
|
|
|
|
|
|
|
|
if (!g_WtsApi || !g_WtsApi->pGetActiveConsoleSessionId)
|
2014-02-17 05:12:45 +04:00
|
|
|
return 0xFFFFFFFF;
|
|
|
|
|
2014-03-01 09:32:23 +04:00
|
|
|
return g_WtsApi->pGetActiveConsoleSessionId();
|
2014-02-17 05:12:45 +04:00
|
|
|
}
|
|
|
|
|
2013-08-20 03:18:31 +04:00
|
|
|
#endif
|
2014-02-17 04:38:12 +04:00
|
|
|
|
|
|
|
BOOL WTSRegisterWtsApiFunctionTable(PWtsApiFunctionTable table)
|
|
|
|
{
|
|
|
|
g_WtsApi = table;
|
|
|
|
return TRUE;
|
|
|
|
}
|
2014-03-01 09:32:23 +04:00
|
|
|
|
2014-03-25 08:32:05 +04:00
|
|
|
void InitializeWtsApiStubs_Env()
|
2014-03-01 09:32:23 +04:00
|
|
|
{
|
2014-03-17 20:16:07 +04:00
|
|
|
DWORD nSize;
|
|
|
|
char* env = NULL;
|
2014-03-01 09:32:23 +04:00
|
|
|
INIT_WTSAPI_FN pInitWtsApi;
|
|
|
|
|
|
|
|
if (g_WtsApi)
|
|
|
|
return;
|
|
|
|
|
2014-03-17 20:16:07 +04:00
|
|
|
nSize = GetEnvironmentVariableA("WTSAPI_LIBRARY", NULL, 0);
|
|
|
|
|
|
|
|
if (nSize)
|
|
|
|
{
|
|
|
|
env = (LPSTR) malloc(nSize);
|
|
|
|
nSize = GetEnvironmentVariableA("WTSAPI_LIBRARY", env, nSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (env)
|
|
|
|
g_WtsApiModule = LoadLibraryA(env);
|
2014-03-01 09:32:23 +04:00
|
|
|
|
|
|
|
if (!g_WtsApiModule)
|
|
|
|
return;
|
|
|
|
|
2014-03-19 19:52:12 +04:00
|
|
|
pInitWtsApi = (INIT_WTSAPI_FN) GetProcAddress(g_WtsApiModule, "InitWtsApi");
|
2014-03-01 09:32:23 +04:00
|
|
|
|
|
|
|
if (pInitWtsApi)
|
|
|
|
{
|
|
|
|
g_WtsApi = pInitWtsApi();
|
|
|
|
}
|
|
|
|
}
|
2014-03-25 08:32:05 +04:00
|
|
|
|
|
|
|
void InitializeWtsApiStubs_FreeRDS()
|
|
|
|
{
|
|
|
|
char* prefix;
|
|
|
|
char* libdir;
|
|
|
|
wIniFile* ini;
|
|
|
|
|
|
|
|
if (g_WtsApi)
|
|
|
|
return;
|
|
|
|
|
|
|
|
ini = IniFile_New();
|
|
|
|
|
|
|
|
if (IniFile_Parse(ini, "/var/run/freerds.instance") < 0)
|
|
|
|
{
|
|
|
|
printf("failed to parse freerds.instance\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
prefix = IniFile_GetKeyValueString(ini, "FreeRDS", "prefix");
|
|
|
|
libdir = IniFile_GetKeyValueString(ini, "FreeRDS", "libdir");
|
|
|
|
|
|
|
|
printf("FreeRDS: %s / %s\n", prefix, libdir);
|
|
|
|
|
|
|
|
if (prefix && libdir)
|
|
|
|
{
|
|
|
|
char* prefix_libdir;
|
|
|
|
char* wtsapi_library;
|
|
|
|
|
|
|
|
prefix_libdir = GetCombinedPath(prefix, libdir);
|
|
|
|
wtsapi_library = GetCombinedPath(prefix_libdir, "libfreerds-fdsapi.so");
|
|
|
|
|
|
|
|
if (wtsapi_library)
|
|
|
|
{
|
|
|
|
INIT_WTSAPI_FN pInitWtsApi;
|
|
|
|
|
|
|
|
g_WtsApiModule = LoadLibraryA(wtsapi_library);
|
|
|
|
|
|
|
|
if (g_WtsApiModule)
|
|
|
|
{
|
|
|
|
pInitWtsApi = (INIT_WTSAPI_FN) GetProcAddress(g_WtsApiModule, "InitWtsApi");
|
|
|
|
|
|
|
|
if (pInitWtsApi)
|
|
|
|
{
|
|
|
|
g_WtsApi = pInitWtsApi();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
free(prefix_libdir);
|
|
|
|
free(wtsapi_library);
|
|
|
|
}
|
|
|
|
|
|
|
|
IniFile_Free(ini);
|
|
|
|
}
|
|
|
|
|
|
|
|
void InitializeWtsApiStubs(void)
|
|
|
|
{
|
|
|
|
if (g_Initialized)
|
|
|
|
return;
|
|
|
|
|
|
|
|
g_Initialized = TRUE;
|
|
|
|
|
|
|
|
InitializeWtsApiStubs_Env();
|
|
|
|
|
|
|
|
if (!g_WtsApi)
|
|
|
|
InitializeWtsApiStubs_FreeRDS();
|
|
|
|
}
|