1 /* Copyright 2005 Ulrich Czekalla
3 * This library is free software; you can redistribute it and/or
4 * modify it under the terms of the GNU Lesser General Public
5 * License as published by the Free Software Foundation; either
6 * version 2.1 of the License, or (at your option) any later version.
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.
13 * You should have received a copy of the GNU Lesser General Public
14 * License along with this library; if not, write to the Free Software
15 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #define WIN32_NO_STATUS
25 #include "wine/winternl.h"
27 #include "wine/debug.h"
28 #include "wine/heap.h"
30 WINE_DEFAULT_DEBUG_CHANNEL(wtsapi
);
32 #ifdef __REACTOS__ /* FIXME: Inspect */
33 #define GetCurrentProcessToken() ((HANDLE)~(ULONG_PTR)3)
36 /************************************************************
37 * WTSCloseServer (WTSAPI32.@)
39 void WINAPI
WTSCloseServer(HANDLE hServer
)
41 FIXME("Stub %p\n", hServer
);
44 /************************************************************
45 * WTSConnectSessionA (WTSAPI32.@)
47 BOOL WINAPI
WTSConnectSessionA(ULONG LogonId
, ULONG TargetLogonId
, PSTR pPassword
, BOOL bWait
)
49 FIXME("Stub %d %d (%s) %d\n", LogonId
, TargetLogonId
, debugstr_a(pPassword
), bWait
);
53 /************************************************************
54 * WTSConnectSessionW (WTSAPI32.@)
56 BOOL WINAPI
WTSConnectSessionW(ULONG LogonId
, ULONG TargetLogonId
, PWSTR pPassword
, BOOL bWait
)
58 FIXME("Stub %d %d (%s) %d\n", LogonId
, TargetLogonId
, debugstr_w(pPassword
), bWait
);
62 /************************************************************
63 * WTSDisconnectSession (WTSAPI32.@)
65 BOOL WINAPI
WTSDisconnectSession(HANDLE hServer
, DWORD SessionId
, BOOL bWait
)
67 FIXME("Stub %p 0x%08x %d\n", hServer
, SessionId
, bWait
);
71 /************************************************************
72 * WTSEnableChildSessions (WTSAPI32.@)
74 BOOL WINAPI
WTSEnableChildSessions(BOOL enable
)
76 FIXME("Stub %d\n", enable
);
80 /************************************************************
81 * WTSEnumerateProcessesA (WTSAPI32.@)
83 BOOL WINAPI
WTSEnumerateProcessesA(HANDLE hServer
, DWORD Reserved
, DWORD Version
,
84 PWTS_PROCESS_INFOA
* ppProcessInfo
, DWORD
* pCount
)
86 FIXME("Stub %p 0x%08x 0x%08x %p %p\n", hServer
, Reserved
, Version
,
87 ppProcessInfo
, pCount
);
89 if (!ppProcessInfo
|| !pCount
) return FALSE
;
92 *ppProcessInfo
= NULL
;
97 /************************************************************
98 * WTSEnumerateProcessesW (WTSAPI32.@)
100 BOOL WINAPI
WTSEnumerateProcessesW(HANDLE hServer
, DWORD Reserved
, DWORD Version
,
101 PWTS_PROCESS_INFOW
* ppProcessInfo
, DWORD
* pCount
)
103 WTS_PROCESS_INFOW
*processInfo
;
104 SYSTEM_PROCESS_INFORMATION
*spi
;
111 if (!ppProcessInfo
|| !pCount
|| Reserved
!= 0 || Version
!= 1)
113 SetLastError(ERROR_INVALID_PARAMETER
);
117 if (hServer
!= WTS_CURRENT_SERVER_HANDLE
)
119 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
126 HeapFree(GetProcessHeap(), 0, buf
);
127 buf
= HeapAlloc(GetProcessHeap(), 0, size
);
130 SetLastError(ERROR_OUTOFMEMORY
);
133 status
= NtQuerySystemInformation(SystemProcessInformation
, buf
, size
, NULL
);
135 while (status
== STATUS_INFO_LENGTH_MISMATCH
);
137 if (status
!= STATUS_SUCCESS
)
139 HeapFree(GetProcessHeap(), 0, buf
);
140 SetLastError(RtlNtStatusToDosError(status
));
148 size
+= sizeof(WTS_PROCESS_INFOW
) + spi
->ProcessName
.Length
+ sizeof(WCHAR
);
150 if (spi
->NextEntryOffset
== 0) break;
151 spi
= (SYSTEM_PROCESS_INFORMATION
*)(((PCHAR
)spi
) + spi
->NextEntryOffset
);
154 processInfo
= HeapAlloc(GetProcessHeap(), 0, size
);
157 HeapFree(GetProcessHeap(), 0, buf
);
158 SetLastError(ERROR_OUTOFMEMORY
);
161 name
= (WCHAR
*)&processInfo
[count
];
163 *ppProcessInfo
= processInfo
;
169 processInfo
->SessionId
= 0;
170 processInfo
->ProcessId
= HandleToUlong(spi
->UniqueProcessId
);
171 processInfo
->pProcessName
= name
;
172 processInfo
->pUserSid
= NULL
;
173 memcpy( name
, spi
->ProcessName
.Buffer
, spi
->ProcessName
.Length
);
174 name
[ spi
->ProcessName
.Length
/sizeof(WCHAR
) ] = 0;
177 name
+= (spi
->ProcessName
.Length
+ sizeof(WCHAR
))/sizeof(WCHAR
);
178 spi
= (SYSTEM_PROCESS_INFORMATION
*)(((PCHAR
)spi
) + spi
->NextEntryOffset
);
181 HeapFree(GetProcessHeap(), 0, buf
);
185 /************************************************************
186 * WTSEnumerateServersA (WTSAPI32.@)
188 BOOL WINAPI
WTSEnumerateServersA(LPSTR pDomainName
, DWORD Reserved
, DWORD Version
, PWTS_SERVER_INFOA
*ppServerInfo
, DWORD
*pCount
)
190 FIXME("Stub %s 0x%08x 0x%08x %p %p\n", debugstr_a(pDomainName
), Reserved
, Version
, ppServerInfo
, pCount
);
194 /************************************************************
195 * WTSEnumerateServersW (WTSAPI32.@)
197 BOOL WINAPI
WTSEnumerateServersW(LPWSTR pDomainName
, DWORD Reserved
, DWORD Version
, PWTS_SERVER_INFOW
*ppServerInfo
, DWORD
*pCount
)
199 FIXME("Stub %s 0x%08x 0x%08x %p %p\n", debugstr_w(pDomainName
), Reserved
, Version
, ppServerInfo
, pCount
);
204 /************************************************************
205 * WTSEnumerateEnumerateSessionsA (WTSAPI32.@)
207 BOOL WINAPI
WTSEnumerateSessionsA(HANDLE hServer
, DWORD Reserved
, DWORD Version
,
208 PWTS_SESSION_INFOA
* ppSessionInfo
, DWORD
* pCount
)
212 if (!once
++) FIXME("Stub %p 0x%08x 0x%08x %p %p\n", hServer
, Reserved
, Version
,
213 ppSessionInfo
, pCount
);
215 if (!ppSessionInfo
|| !pCount
) return FALSE
;
218 *ppSessionInfo
= NULL
;
223 /************************************************************
224 * WTSEnumerateEnumerateSessionsW (WTSAPI32.@)
226 BOOL WINAPI
WTSEnumerateSessionsW(HANDLE hServer
, DWORD Reserved
, DWORD Version
,
227 PWTS_SESSION_INFOW
* ppSessionInfo
, DWORD
* pCount
)
229 FIXME("Stub %p 0x%08x 0x%08x %p %p\n", hServer
, Reserved
, Version
,
230 ppSessionInfo
, pCount
);
232 if (!ppSessionInfo
|| !pCount
) return FALSE
;
235 *ppSessionInfo
= NULL
;
240 /************************************************************
241 * WTSFreeMemory (WTSAPI32.@)
243 void WINAPI
WTSFreeMemory(PVOID pMemory
)
248 /************************************************************
249 * WTSLogoffSession (WTSAPI32.@)
251 BOOL WINAPI
WTSLogoffSession(HANDLE hserver
, DWORD session_id
, BOOL bwait
)
253 FIXME("(%p, 0x%x, %d): stub\n", hserver
, session_id
, bwait
);
254 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
258 /************************************************************
259 * WTSOpenServerA (WTSAPI32.@)
261 HANDLE WINAPI
WTSOpenServerA(LPSTR pServerName
)
263 FIXME("(%s) stub\n", debugstr_a(pServerName
));
264 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
268 /************************************************************
269 * WTSOpenServerW (WTSAPI32.@)
271 HANDLE WINAPI
WTSOpenServerW(LPWSTR pServerName
)
273 FIXME("(%s) stub\n", debugstr_w(pServerName
));
274 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
278 /************************************************************
279 * WTSQuerySessionInformationA (WTSAPI32.@)
281 BOOL WINAPI
WTSQuerySessionInformationA(
284 WTS_INFO_CLASS WTSInfoClass
,
286 DWORD
* BytesReturned
)
289 const size_t wcsErrorCode
= -1;
290 LPWSTR buffer
= NULL
;
291 LPSTR ansiBuffer
= NULL
;
292 DWORD bytesReturned
= 0;
296 if (!BytesReturned
|| !Buffer
)
298 SetLastError(ERROR_INVALID_USER_BUFFER
);
302 if (!WTSQuerySessionInformationW(hServer
, SessionId
, WTSInfoClass
, &buffer
, &bytesReturned
))
304 ansiBuffer
= (LPSTR
)buffer
;
305 *Buffer
= ansiBuffer
;
306 *BytesReturned
= bytesReturned
;
310 switch (WTSInfoClass
)
312 case WTSInitialProgram
:
313 case WTSApplicationName
:
314 case WTSWorkingDirectory
:
317 case WTSWinStationName
:
320 case WTSClientDirectory
:
322 len
= wcstombs(NULL
, buffer
, 0);
323 if (len
!= wcsErrorCode
)
326 ansiBuffer
= heap_alloc_zero(len
);
327 if (ansiBuffer
&& (wcstombs(ansiBuffer
, buffer
, len
) != wcsErrorCode
))
333 WTSFreeMemory(buffer
);
340 ansiBuffer
= (LPSTR
)buffer
;
345 *Buffer
= ansiBuffer
;
346 *BytesReturned
= bytesReturned
;
350 /* FIXME: Forward request to winsta.dll::WinStationQueryInformationA */
351 FIXME("Stub %p 0x%08x %d %p %p\n", hServer
, SessionId
, WTSInfoClass
,
352 Buffer
, BytesReturned
);
358 /************************************************************
359 * WTSQuerySessionInformationW (WTSAPI32.@)
361 BOOL WINAPI
WTSQuerySessionInformationW(
364 WTS_INFO_CLASS WTSInfoClass
,
366 DWORD
* BytesReturned
)
369 if (!BytesReturned
|| !Buffer
)
371 SetLastError(ERROR_INVALID_USER_BUFFER
);
375 #if (NTDDI_VERSION >= NTDDI_WS08)
376 if (WTSInfoClass
> WTSIsRemoteSession
)
378 if (WTSInfoClass
> WTSClientProtocolType
)
381 SetLastError(ERROR_INVALID_PARAMETER
);
385 switch (WTSInfoClass
)
389 const DWORD size
= sizeof(ULONG
);
390 ULONG
* output
= heap_alloc_zero(size
);
393 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
397 *output
= NtCurrentTeb()->Peb
->SessionId
;
398 *Buffer
= (LPWSTR
)output
;
399 *BytesReturned
= size
;
408 GetUserNameW(NULL
, &count
);
409 if (GetLastError() != ERROR_INSUFFICIENT_BUFFER
)
411 username
= heap_alloc(count
* sizeof(WCHAR
));
414 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
418 GetUserNameW(username
, &count
);
420 *BytesReturned
= count
* sizeof(WCHAR
);
424 case WTSConnectState
:
426 const DWORD size
= sizeof(DWORD
);
427 WCHAR
* output
= heap_alloc_zero(size
);
430 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
435 *BytesReturned
= size
;
439 case WTSClientProtocolType
:
441 const DWORD size
= sizeof(WORD
);
442 WCHAR
* output
= heap_alloc_zero(size
);
445 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
450 *BytesReturned
= size
;
454 #if (NTDDI_VERSION >= NTDDI_WS08)
457 case WTSIncomingBytes
:
458 case WTSOutgoingBytes
:
459 case WTSIncomingFrames
:
460 case WTSOutgoingFrames
:
462 SetLastError(ERROR_NOT_SUPPORTED
);
465 #endif /* (NTDDI_VERSION >= NTDDI_WS08) */
476 /* FIXME: Forward request to winsta.dll::WinStationQueryInformationW */
477 FIXME("Stub %p 0x%08x %d %p %p\n", hServer
, SessionId
, WTSInfoClass
,
478 Buffer
, BytesReturned
);
482 /* FIXME: Forward request to winsta.dll::WinStationQueryInformationW */
483 FIXME("Stub %p 0x%08x %d %p %p\n", hServer
, SessionId
, WTSInfoClass
,
484 Buffer
, BytesReturned
);
486 if (WTSInfoClass
== WTSUserName
)
491 GetUserNameW(NULL
, &count
);
492 if (GetLastError() != ERROR_INSUFFICIENT_BUFFER
) return FALSE
;
493 if (!(username
= heap_alloc(count
* sizeof(WCHAR
)))) return FALSE
;
494 GetUserNameW(username
, &count
);
496 *BytesReturned
= count
* sizeof(WCHAR
);
503 /************************************************************
504 * WTSQueryUserToken (WTSAPI32.@)
506 BOOL WINAPI
WTSQueryUserToken(ULONG session_id
, PHANDLE token
)
508 FIXME("%u %p\n", session_id
, token
);
512 SetLastError(ERROR_INVALID_PARAMETER
);
516 return DuplicateHandle(GetCurrentProcess(), GetCurrentProcessToken(),
517 GetCurrentProcess(), token
,
518 0, FALSE
, DUPLICATE_SAME_ACCESS
);
521 /************************************************************
522 * WTSQueryUserConfigA (WTSAPI32.@)
524 BOOL WINAPI
WTSQueryUserConfigA(LPSTR pServerName
, LPSTR pUserName
, WTS_CONFIG_CLASS WTSConfigClass
, LPSTR
*ppBuffer
, DWORD
*pBytesReturned
)
526 FIXME("Stub (%s) (%s) 0x%08x %p %p\n", debugstr_a(pServerName
), debugstr_a(pUserName
), WTSConfigClass
,
527 ppBuffer
, pBytesReturned
);
531 /************************************************************
532 * WTSQueryUserConfigW (WTSAPI32.@)
534 BOOL WINAPI
WTSQueryUserConfigW(LPWSTR pServerName
, LPWSTR pUserName
, WTS_CONFIG_CLASS WTSConfigClass
, LPWSTR
*ppBuffer
, DWORD
*pBytesReturned
)
536 FIXME("Stub (%s) (%s) 0x%08x %p %p\n", debugstr_w(pServerName
), debugstr_w(pUserName
), WTSConfigClass
,
537 ppBuffer
, pBytesReturned
);
542 /************************************************************
543 * WTSRegisterSessionNotification (WTSAPI32.@)
545 BOOL WINAPI
WTSRegisterSessionNotification(HWND hWnd
, DWORD dwFlags
)
547 FIXME("Stub %p 0x%08x\n", hWnd
, dwFlags
);
551 /************************************************************
552 * WTSRegisterSessionNotificationEx (WTSAPI32.@)
554 BOOL WINAPI
WTSRegisterSessionNotificationEx(HANDLE hServer
, HWND hWnd
, DWORD dwFlags
)
556 FIXME("Stub %p %p 0x%08x\n", hServer
, hWnd
, dwFlags
);
561 /************************************************************
562 * WTSSendMessageA (WTSAPI32.@)
564 BOOL WINAPI
WTSSendMessageA(HANDLE hServer
, DWORD SessionId
, LPSTR pTitle
, DWORD TitleLength
, LPSTR pMessage
,
565 DWORD MessageLength
, DWORD Style
, DWORD Timeout
, DWORD
*pResponse
, BOOL bWait
)
567 FIXME("Stub %p 0x%08x (%s) %d (%s) %d 0x%08x %d %p %d\n", hServer
, SessionId
, debugstr_a(pTitle
), TitleLength
, debugstr_a(pMessage
), MessageLength
, Style
, Timeout
, pResponse
, bWait
);
571 /************************************************************
572 * WTSSendMessageW (WTSAPI32.@)
574 BOOL WINAPI
WTSSendMessageW(HANDLE hServer
, DWORD SessionId
, LPWSTR pTitle
, DWORD TitleLength
, LPWSTR pMessage
,
575 DWORD MessageLength
, DWORD Style
, DWORD Timeout
, DWORD
*pResponse
, BOOL bWait
)
577 FIXME("Stub %p 0x%08x (%s) %d (%s) %d 0x%08x %d %p %d\n", hServer
, SessionId
, debugstr_w(pTitle
), TitleLength
, debugstr_w(pMessage
), MessageLength
, Style
, Timeout
, pResponse
, bWait
);
581 /************************************************************
582 * WTSSetUserConfigA (WTSAPI32.@)
584 BOOL WINAPI
WTSSetUserConfigA(LPSTR pServerName
, LPSTR pUserName
, WTS_CONFIG_CLASS WTSConfigClass
, LPSTR pBuffer
, DWORD DataLength
)
586 FIXME("Stub (%s) (%s) 0x%08x %p %d\n", debugstr_a(pServerName
), debugstr_a(pUserName
), WTSConfigClass
,pBuffer
, DataLength
);
590 /************************************************************
591 * WTSSetUserConfigW (WTSAPI32.@)
593 BOOL WINAPI
WTSSetUserConfigW(LPWSTR pServerName
, LPWSTR pUserName
, WTS_CONFIG_CLASS WTSConfigClass
, LPWSTR pBuffer
, DWORD DataLength
)
595 FIXME("Stub (%s) (%s) 0x%08x %p %d\n", debugstr_w(pServerName
), debugstr_w(pUserName
), WTSConfigClass
,pBuffer
, DataLength
);
599 /************************************************************
600 * WTSShutdownSystem (WTSAPI32.@)
602 BOOL WINAPI
WTSShutdownSystem(HANDLE hServer
, DWORD ShutdownFlag
)
604 FIXME("Stub %p 0x%08x\n", hServer
,ShutdownFlag
);
608 /************************************************************
609 * WTSStartRemoteControlSessionA (WTSAPI32.@)
611 BOOL WINAPI
WTSStartRemoteControlSessionA(LPSTR pTargetServerName
, ULONG TargetLogonId
, BYTE HotkeyVk
, USHORT HotkeyModifiers
)
613 FIXME("Stub (%s) %d %d %d\n", debugstr_a(pTargetServerName
), TargetLogonId
, HotkeyVk
, HotkeyModifiers
);
617 /************************************************************
618 * WTSStartRemoteControlSessionW (WTSAPI32.@)
620 BOOL WINAPI
WTSStartRemoteControlSessionW(LPWSTR pTargetServerName
, ULONG TargetLogonId
, BYTE HotkeyVk
, USHORT HotkeyModifiers
)
622 FIXME("Stub (%s) %d %d %d\n", debugstr_w(pTargetServerName
), TargetLogonId
, HotkeyVk
, HotkeyModifiers
);
626 /************************************************************
627 * WTSStopRemoteControlSession (WTSAPI32.@)
629 BOOL WINAPI
WTSStopRemoteControlSession(ULONG LogonId
)
631 FIXME("Stub %d\n", LogonId
);
635 /************************************************************
636 * WTSTerminateProcess (WTSAPI32.@)
638 BOOL WINAPI
WTSTerminateProcess(HANDLE hServer
, DWORD ProcessId
, DWORD ExitCode
)
640 FIXME("Stub %p %d %d\n", hServer
, ProcessId
, ExitCode
);
644 /************************************************************
645 * WTSUnRegisterSessionNotification (WTSAPI32.@)
647 BOOL WINAPI
WTSUnRegisterSessionNotification(HWND hWnd
)
649 FIXME("Stub %p\n", hWnd
);
653 /************************************************************
654 * WTSUnRegisterSessionNotification (WTSAPI32.@)
656 BOOL WINAPI
WTSUnRegisterSessionNotificationEx(HANDLE hServer
, HWND hWnd
)
658 FIXME("Stub %p %p\n", hServer
, hWnd
);
663 /************************************************************
664 * WTSVirtualChannelClose (WTSAPI32.@)
666 BOOL WINAPI
WTSVirtualChannelClose(HANDLE hChannelHandle
)
668 FIXME("Stub %p\n", hChannelHandle
);
672 /************************************************************
673 * WTSVirtualChannelOpen (WTSAPI32.@)
675 HANDLE WINAPI
WTSVirtualChannelOpen(HANDLE hServer
, DWORD SessionId
, LPSTR pVirtualName
)
677 FIXME("Stub %p %d (%s)\n", hServer
, SessionId
, debugstr_a(pVirtualName
));
681 /************************************************************
682 * WTSVirtualChannelOpen (WTSAPI32.@)
684 HANDLE WINAPI
WTSVirtualChannelOpenEx(DWORD SessionId
, LPSTR pVirtualName
, DWORD flags
)
686 FIXME("Stub %d (%s) %d\n", SessionId
, debugstr_a(pVirtualName
), flags
);
690 /************************************************************
691 * WTSVirtualChannelPurgeInput (WTSAPI32.@)
693 BOOL WINAPI
WTSVirtualChannelPurgeInput(HANDLE hChannelHandle
)
695 FIXME("Stub %p\n", hChannelHandle
);
699 /************************************************************
700 * WTSVirtualChannelPurgeOutput (WTSAPI32.@)
702 BOOL WINAPI
WTSVirtualChannelPurgeOutput(HANDLE hChannelHandle
)
704 FIXME("Stub %p\n", hChannelHandle
);
709 /************************************************************
710 * WTSVirtualChannelQuery (WTSAPI32.@)
712 BOOL WINAPI
WTSVirtualChannelQuery(HANDLE hChannelHandle
, WTS_VIRTUAL_CLASS WtsVirtualClass
, PVOID
*ppBuffer
, DWORD
*pBytesReturned
)
714 FIXME("Stub %p %d %p %p\n", hChannelHandle
, WtsVirtualClass
, ppBuffer
, pBytesReturned
);
718 /************************************************************
719 * WTSVirtualChannelRead (WTSAPI32.@)
721 BOOL WINAPI
WTSVirtualChannelRead(HANDLE hChannelHandle
, ULONG TimeOut
, PCHAR Buffer
, ULONG BufferSize
, PULONG pBytesRead
)
723 FIXME("Stub %p %d %p %d %p\n", hChannelHandle
, TimeOut
, Buffer
, BufferSize
, pBytesRead
);
727 /************************************************************
728 * WTSVirtualChannelWrite (WTSAPI32.@)
730 BOOL WINAPI
WTSVirtualChannelWrite(HANDLE hChannelHandle
, PCHAR Buffer
, ULONG Length
, PULONG pBytesWritten
)
732 FIXME("Stub %p %p %d %p\n", hChannelHandle
, Buffer
, Length
, pBytesWritten
);
736 /************************************************************
737 * WTSWaitSystemEvent (WTSAPI32.@)
739 BOOL WINAPI
WTSWaitSystemEvent(HANDLE hServer
, DWORD Mask
, DWORD
* Flags
)
741 /* FIXME: Forward request to winsta.dll::WinStationWaitSystemEvent */
742 FIXME("Stub %p 0x%08x %p\n", hServer
, Mask
, Flags
);