[WTSAPI32] Sync with Wine Staging 3.3. CORE-14434
[reactos.git] / dll / win32 / wtsapi32 / wtsapi32.c
1 /* Copyright 2005 Ulrich Czekalla
2 *
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.
7 *
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.
12 *
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
16 */
17
18 #include "config.h"
19 #include <stdarg.h>
20 #include <stdlib.h>
21 #include "ntstatus.h"
22 #define WIN32_NO_STATUS
23 #include "windef.h"
24 #include "winbase.h"
25 #include "wine/winternl.h"
26 #include "wtsapi32.h"
27 #include "wine/debug.h"
28
29 WINE_DEFAULT_DEBUG_CHANNEL(wtsapi);
30
31 #ifdef __REACTOS__ /* FIXME: Inspect */
32 #define GetCurrentProcessToken() ((HANDLE)~(ULONG_PTR)3)
33 #endif
34
35 /************************************************************
36 * WTSCloseServer (WTSAPI32.@)
37 */
38 void WINAPI WTSCloseServer(HANDLE hServer)
39 {
40 FIXME("Stub %p\n", hServer);
41 }
42
43 /************************************************************
44 * WTSConnectSessionA (WTSAPI32.@)
45 */
46 BOOL WINAPI WTSConnectSessionA(ULONG LogonId, ULONG TargetLogonId, PSTR pPassword, BOOL bWait)
47 {
48 FIXME("Stub %d %d (%s) %d\n", LogonId, TargetLogonId, debugstr_a(pPassword), bWait);
49 return TRUE;
50 }
51
52 /************************************************************
53 * WTSConnectSessionW (WTSAPI32.@)
54 */
55 BOOL WINAPI WTSConnectSessionW(ULONG LogonId, ULONG TargetLogonId, PWSTR pPassword, BOOL bWait)
56 {
57 FIXME("Stub %d %d (%s) %d\n", LogonId, TargetLogonId, debugstr_w(pPassword), bWait);
58 return TRUE;
59 }
60
61 /************************************************************
62 * WTSDisconnectSession (WTSAPI32.@)
63 */
64 BOOL WINAPI WTSDisconnectSession(HANDLE hServer, DWORD SessionId, BOOL bWait)
65 {
66 FIXME("Stub %p 0x%08x %d\n", hServer, SessionId, bWait);
67 return TRUE;
68 }
69
70 /************************************************************
71 * WTSEnableChildSessions (WTSAPI32.@)
72 */
73 BOOL WINAPI WTSEnableChildSessions(BOOL enable)
74 {
75 FIXME("Stub %d\n", enable);
76 return TRUE;
77 }
78
79 /************************************************************
80 * WTSEnumerateProcessesA (WTSAPI32.@)
81 */
82 BOOL WINAPI WTSEnumerateProcessesA(HANDLE hServer, DWORD Reserved, DWORD Version,
83 PWTS_PROCESS_INFOA* ppProcessInfo, DWORD* pCount)
84 {
85 FIXME("Stub %p 0x%08x 0x%08x %p %p\n", hServer, Reserved, Version,
86 ppProcessInfo, pCount);
87
88 if (!ppProcessInfo || !pCount) return FALSE;
89
90 *pCount = 0;
91 *ppProcessInfo = NULL;
92
93 return TRUE;
94 }
95
96 /************************************************************
97 * WTSEnumerateProcessesW (WTSAPI32.@)
98 */
99 BOOL WINAPI WTSEnumerateProcessesW(HANDLE hServer, DWORD Reserved, DWORD Version,
100 PWTS_PROCESS_INFOW* ppProcessInfo, DWORD* pCount)
101 {
102 WTS_PROCESS_INFOW *processInfo;
103 SYSTEM_PROCESS_INFORMATION *spi;
104 ULONG size = 0x4000;
105 void *buf = NULL;
106 NTSTATUS status;
107 DWORD count;
108 WCHAR *name;
109
110 if (!ppProcessInfo || !pCount || Reserved != 0 || Version != 1)
111 {
112 SetLastError(ERROR_INVALID_PARAMETER);
113 return FALSE;
114 }
115
116 if (hServer != WTS_CURRENT_SERVER_HANDLE)
117 {
118 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
119 return FALSE;
120 }
121
122 do
123 {
124 size *= 2;
125 HeapFree(GetProcessHeap(), 0, buf);
126 buf = HeapAlloc(GetProcessHeap(), 0, size);
127 if (!buf)
128 {
129 SetLastError(ERROR_OUTOFMEMORY);
130 return FALSE;
131 }
132 status = NtQuerySystemInformation(SystemProcessInformation, buf, size, NULL);
133 }
134 while (status == STATUS_INFO_LENGTH_MISMATCH);
135
136 if (status != STATUS_SUCCESS)
137 {
138 HeapFree(GetProcessHeap(), 0, buf);
139 SetLastError(RtlNtStatusToDosError(status));
140 return FALSE;
141 }
142
143 spi = buf;
144 count = size = 0;
145 for (;;)
146 {
147 size += sizeof(WTS_PROCESS_INFOW) + spi->ProcessName.Length + sizeof(WCHAR);
148 count++;
149 if (spi->NextEntryOffset == 0) break;
150 spi = (SYSTEM_PROCESS_INFORMATION *)(((PCHAR)spi) + spi->NextEntryOffset);
151 }
152
153 processInfo = HeapAlloc(GetProcessHeap(), 0, size);
154 if (!processInfo)
155 {
156 HeapFree(GetProcessHeap(), 0, buf);
157 SetLastError(ERROR_OUTOFMEMORY);
158 return FALSE;
159 }
160 name = (WCHAR *)&processInfo[count];
161
162 *ppProcessInfo = processInfo;
163 *pCount = count;
164
165 spi = buf;
166 while (count--)
167 {
168 processInfo->SessionId = 0;
169 processInfo->ProcessId = HandleToUlong(spi->UniqueProcessId);
170 processInfo->pProcessName = name;
171 processInfo->pUserSid = NULL;
172 memcpy( name, spi->ProcessName.Buffer, spi->ProcessName.Length );
173 name[ spi->ProcessName.Length/sizeof(WCHAR) ] = 0;
174
175 processInfo++;
176 name += (spi->ProcessName.Length + sizeof(WCHAR))/sizeof(WCHAR);
177 spi = (SYSTEM_PROCESS_INFORMATION *)(((PCHAR)spi) + spi->NextEntryOffset);
178 }
179
180 HeapFree(GetProcessHeap(), 0, buf);
181 return TRUE;
182 }
183
184 /************************************************************
185 * WTSEnumerateServersA (WTSAPI32.@)
186 */
187 BOOL WINAPI WTSEnumerateServersA(LPSTR pDomainName, DWORD Reserved, DWORD Version, PWTS_SERVER_INFOA *ppServerInfo, DWORD *pCount)
188 {
189 FIXME("Stub %s 0x%08x 0x%08x %p %p\n", debugstr_a(pDomainName), Reserved, Version, ppServerInfo, pCount);
190 return FALSE;
191 }
192
193 /************************************************************
194 * WTSEnumerateServersW (WTSAPI32.@)
195 */
196 BOOL WINAPI WTSEnumerateServersW(LPWSTR pDomainName, DWORD Reserved, DWORD Version, PWTS_SERVER_INFOW *ppServerInfo, DWORD *pCount)
197 {
198 FIXME("Stub %s 0x%08x 0x%08x %p %p\n", debugstr_w(pDomainName), Reserved, Version, ppServerInfo, pCount);
199 return FALSE;
200 }
201
202
203 /************************************************************
204 * WTSEnumerateEnumerateSessionsA (WTSAPI32.@)
205 */
206 BOOL WINAPI WTSEnumerateSessionsA(HANDLE hServer, DWORD Reserved, DWORD Version,
207 PWTS_SESSION_INFOA* ppSessionInfo, DWORD* pCount)
208 {
209 static int once;
210
211 if (!once++) FIXME("Stub %p 0x%08x 0x%08x %p %p\n", hServer, Reserved, Version,
212 ppSessionInfo, pCount);
213
214 if (!ppSessionInfo || !pCount) return FALSE;
215
216 *pCount = 0;
217 *ppSessionInfo = NULL;
218
219 return TRUE;
220 }
221
222 /************************************************************
223 * WTSEnumerateEnumerateSessionsW (WTSAPI32.@)
224 */
225 BOOL WINAPI WTSEnumerateSessionsW(HANDLE hServer, DWORD Reserved, DWORD Version,
226 PWTS_SESSION_INFOW* ppSessionInfo, DWORD* pCount)
227 {
228 FIXME("Stub %p 0x%08x 0x%08x %p %p\n", hServer, Reserved, Version,
229 ppSessionInfo, pCount);
230
231 if (!ppSessionInfo || !pCount) return FALSE;
232
233 *pCount = 0;
234 *ppSessionInfo = NULL;
235
236 return TRUE;
237 }
238
239 /************************************************************
240 * WTSFreeMemory (WTSAPI32.@)
241 */
242 void WINAPI WTSFreeMemory(PVOID pMemory)
243 {
244 HeapFree(GetProcessHeap(), 0, pMemory);
245 }
246
247 /************************************************************
248 * WTSLogoffSession (WTSAPI32.@)
249 */
250 BOOL WINAPI WTSLogoffSession(HANDLE hserver, DWORD session_id, BOOL bwait)
251 {
252 FIXME("(%p, 0x%x, %d): stub\n", hserver, session_id, bwait);
253 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
254 return FALSE;
255 }
256
257 /************************************************************
258 * WTSOpenServerA (WTSAPI32.@)
259 */
260 HANDLE WINAPI WTSOpenServerA(LPSTR pServerName)
261 {
262 FIXME("(%s) stub\n", debugstr_a(pServerName));
263 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
264 return NULL;
265 }
266
267 /************************************************************
268 * WTSOpenServerW (WTSAPI32.@)
269 */
270 HANDLE WINAPI WTSOpenServerW(LPWSTR pServerName)
271 {
272 FIXME("(%s) stub\n", debugstr_w(pServerName));
273 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
274 return NULL;
275 }
276
277 /************************************************************
278 * WTSQuerySessionInformationA (WTSAPI32.@)
279 */
280 BOOL WINAPI WTSQuerySessionInformationA(
281 HANDLE hServer,
282 DWORD SessionId,
283 WTS_INFO_CLASS WTSInfoClass,
284 LPSTR* Buffer,
285 DWORD* BytesReturned)
286 {
287 /* FIXME: Forward request to winsta.dll::WinStationQueryInformationA */
288 FIXME("Stub %p 0x%08x %d %p %p\n", hServer, SessionId, WTSInfoClass,
289 Buffer, BytesReturned);
290
291 return FALSE;
292 }
293
294 /************************************************************
295 * WTSQuerySessionInformationW (WTSAPI32.@)
296 */
297 BOOL WINAPI WTSQuerySessionInformationW(
298 HANDLE hServer,
299 DWORD SessionId,
300 WTS_INFO_CLASS WTSInfoClass,
301 LPWSTR* Buffer,
302 DWORD* BytesReturned)
303 {
304 /* FIXME: Forward request to winsta.dll::WinStationQueryInformationW */
305 FIXME("Stub %p 0x%08x %d %p %p\n", hServer, SessionId, WTSInfoClass,
306 Buffer, BytesReturned);
307
308 return FALSE;
309 }
310
311 /************************************************************
312 * WTSQueryUserToken (WTSAPI32.@)
313 */
314 BOOL WINAPI WTSQueryUserToken(ULONG session_id, PHANDLE token)
315 {
316 FIXME("%u %p\n", session_id, token);
317
318 if (!token)
319 {
320 SetLastError(ERROR_INVALID_PARAMETER);
321 return FALSE;
322 }
323
324 return DuplicateHandle(GetCurrentProcess(), GetCurrentProcessToken(),
325 GetCurrentProcess(), token,
326 0, FALSE, DUPLICATE_SAME_ACCESS);
327 }
328
329 /************************************************************
330 * WTSQueryUserConfigA (WTSAPI32.@)
331 */
332 BOOL WINAPI WTSQueryUserConfigA(LPSTR pServerName, LPSTR pUserName, WTS_CONFIG_CLASS WTSConfigClass, LPSTR *ppBuffer, DWORD *pBytesReturned)
333 {
334 FIXME("Stub (%s) (%s) 0x%08x %p %p\n", debugstr_a(pServerName), debugstr_a(pUserName), WTSConfigClass,
335 ppBuffer, pBytesReturned);
336 return FALSE;
337 }
338
339 /************************************************************
340 * WTSQueryUserConfigW (WTSAPI32.@)
341 */
342 BOOL WINAPI WTSQueryUserConfigW(LPWSTR pServerName, LPWSTR pUserName, WTS_CONFIG_CLASS WTSConfigClass, LPWSTR *ppBuffer, DWORD *pBytesReturned)
343 {
344 FIXME("Stub (%s) (%s) 0x%08x %p %p\n", debugstr_w(pServerName), debugstr_w(pUserName), WTSConfigClass,
345 ppBuffer, pBytesReturned);
346 return FALSE;
347 }
348
349
350 /************************************************************
351 * WTSRegisterSessionNotification (WTSAPI32.@)
352 */
353 BOOL WINAPI WTSRegisterSessionNotification(HWND hWnd, DWORD dwFlags)
354 {
355 FIXME("Stub %p 0x%08x\n", hWnd, dwFlags);
356 return TRUE;
357 }
358
359 /************************************************************
360 * WTSRegisterSessionNotificationEx (WTSAPI32.@)
361 */
362 BOOL WINAPI WTSRegisterSessionNotificationEx(HANDLE hServer, HWND hWnd, DWORD dwFlags)
363 {
364 FIXME("Stub %p %p 0x%08x\n", hServer, hWnd, dwFlags);
365 return FALSE;
366 }
367
368
369 /************************************************************
370 * WTSSendMessageA (WTSAPI32.@)
371 */
372 BOOL WINAPI WTSSendMessageA(HANDLE hServer, DWORD SessionId, LPSTR pTitle, DWORD TitleLength, LPSTR pMessage,
373 DWORD MessageLength, DWORD Style, DWORD Timeout, DWORD *pResponse, BOOL bWait)
374 {
375 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);
376 return FALSE;
377 }
378
379 /************************************************************
380 * WTSSendMessageW (WTSAPI32.@)
381 */
382 BOOL WINAPI WTSSendMessageW(HANDLE hServer, DWORD SessionId, LPWSTR pTitle, DWORD TitleLength, LPWSTR pMessage,
383 DWORD MessageLength, DWORD Style, DWORD Timeout, DWORD *pResponse, BOOL bWait)
384 {
385 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);
386 return FALSE;
387 }
388
389 /************************************************************
390 * WTSSetUserConfigA (WTSAPI32.@)
391 */
392 BOOL WINAPI WTSSetUserConfigA(LPSTR pServerName, LPSTR pUserName, WTS_CONFIG_CLASS WTSConfigClass, LPSTR pBuffer, DWORD DataLength)
393 {
394 FIXME("Stub (%s) (%s) 0x%08x %p %d\n", debugstr_a(pServerName), debugstr_a(pUserName), WTSConfigClass,pBuffer, DataLength);
395 return FALSE;
396 }
397
398 /************************************************************
399 * WTSSetUserConfigW (WTSAPI32.@)
400 */
401 BOOL WINAPI WTSSetUserConfigW(LPWSTR pServerName, LPWSTR pUserName, WTS_CONFIG_CLASS WTSConfigClass, LPWSTR pBuffer, DWORD DataLength)
402 {
403 FIXME("Stub (%s) (%s) 0x%08x %p %d\n", debugstr_w(pServerName), debugstr_w(pUserName), WTSConfigClass,pBuffer, DataLength);
404 return FALSE;
405 }
406
407 /************************************************************
408 * WTSShutdownSystem (WTSAPI32.@)
409 */
410 BOOL WINAPI WTSShutdownSystem(HANDLE hServer, DWORD ShutdownFlag)
411 {
412 FIXME("Stub %p 0x%08x\n", hServer,ShutdownFlag);
413 return FALSE;
414 }
415
416 /************************************************************
417 * WTSStartRemoteControlSessionA (WTSAPI32.@)
418 */
419 BOOL WINAPI WTSStartRemoteControlSessionA(LPSTR pTargetServerName, ULONG TargetLogonId, BYTE HotkeyVk, USHORT HotkeyModifiers)
420 {
421 FIXME("Stub (%s) %d %d %d\n", debugstr_a(pTargetServerName), TargetLogonId, HotkeyVk, HotkeyModifiers);
422 return FALSE;
423 }
424
425 /************************************************************
426 * WTSStartRemoteControlSessionW (WTSAPI32.@)
427 */
428 BOOL WINAPI WTSStartRemoteControlSessionW(LPWSTR pTargetServerName, ULONG TargetLogonId, BYTE HotkeyVk, USHORT HotkeyModifiers)
429 {
430 FIXME("Stub (%s) %d %d %d\n", debugstr_w(pTargetServerName), TargetLogonId, HotkeyVk, HotkeyModifiers);
431 return FALSE;
432 }
433
434 /************************************************************
435 * WTSStopRemoteControlSession (WTSAPI32.@)
436 */
437 BOOL WINAPI WTSStopRemoteControlSession(ULONG LogonId)
438 {
439 FIXME("Stub %d\n", LogonId);
440 return FALSE;
441 }
442
443 /************************************************************
444 * WTSTerminateProcess (WTSAPI32.@)
445 */
446 BOOL WINAPI WTSTerminateProcess(HANDLE hServer, DWORD ProcessId, DWORD ExitCode)
447 {
448 FIXME("Stub %p %d %d\n", hServer, ProcessId, ExitCode);
449 return FALSE;
450 }
451
452 /************************************************************
453 * WTSUnRegisterSessionNotification (WTSAPI32.@)
454 */
455 BOOL WINAPI WTSUnRegisterSessionNotification(HWND hWnd)
456 {
457 FIXME("Stub %p\n", hWnd);
458 return FALSE;
459 }
460
461 /************************************************************
462 * WTSUnRegisterSessionNotification (WTSAPI32.@)
463 */
464 BOOL WINAPI WTSUnRegisterSessionNotificationEx(HANDLE hServer, HWND hWnd)
465 {
466 FIXME("Stub %p %p\n", hServer, hWnd);
467 return FALSE;
468 }
469
470
471 /************************************************************
472 * WTSVirtualChannelClose (WTSAPI32.@)
473 */
474 BOOL WINAPI WTSVirtualChannelClose(HANDLE hChannelHandle)
475 {
476 FIXME("Stub %p\n", hChannelHandle);
477 return FALSE;
478 }
479
480 /************************************************************
481 * WTSVirtualChannelOpen (WTSAPI32.@)
482 */
483 HANDLE WINAPI WTSVirtualChannelOpen(HANDLE hServer, DWORD SessionId, LPSTR pVirtualName)
484 {
485 FIXME("Stub %p %d (%s)\n", hServer, SessionId, debugstr_a(pVirtualName));
486 return NULL;
487 }
488
489 /************************************************************
490 * WTSVirtualChannelOpen (WTSAPI32.@)
491 */
492 HANDLE WINAPI WTSVirtualChannelOpenEx(DWORD SessionId, LPSTR pVirtualName, DWORD flags)
493 {
494 FIXME("Stub %d (%s) %d\n", SessionId, debugstr_a(pVirtualName), flags);
495 return NULL;
496 }
497
498 /************************************************************
499 * WTSVirtualChannelPurgeInput (WTSAPI32.@)
500 */
501 BOOL WINAPI WTSVirtualChannelPurgeInput(HANDLE hChannelHandle)
502 {
503 FIXME("Stub %p\n", hChannelHandle);
504 return FALSE;
505 }
506
507 /************************************************************
508 * WTSVirtualChannelPurgeOutput (WTSAPI32.@)
509 */
510 BOOL WINAPI WTSVirtualChannelPurgeOutput(HANDLE hChannelHandle)
511 {
512 FIXME("Stub %p\n", hChannelHandle);
513 return FALSE;
514 }
515
516
517 /************************************************************
518 * WTSVirtualChannelQuery (WTSAPI32.@)
519 */
520 BOOL WINAPI WTSVirtualChannelQuery(HANDLE hChannelHandle, WTS_VIRTUAL_CLASS WtsVirtualClass, PVOID *ppBuffer, DWORD *pBytesReturned)
521 {
522 FIXME("Stub %p %d %p %p\n", hChannelHandle, WtsVirtualClass, ppBuffer, pBytesReturned);
523 return FALSE;
524 }
525
526 /************************************************************
527 * WTSVirtualChannelRead (WTSAPI32.@)
528 */
529 BOOL WINAPI WTSVirtualChannelRead(HANDLE hChannelHandle, ULONG TimeOut, PCHAR Buffer, ULONG BufferSize, PULONG pBytesRead)
530 {
531 FIXME("Stub %p %d %p %d %p\n", hChannelHandle, TimeOut, Buffer, BufferSize, pBytesRead);
532 return FALSE;
533 }
534
535 /************************************************************
536 * WTSVirtualChannelWrite (WTSAPI32.@)
537 */
538 BOOL WINAPI WTSVirtualChannelWrite(HANDLE hChannelHandle, PCHAR Buffer, ULONG Length, PULONG pBytesWritten)
539 {
540 FIXME("Stub %p %p %d %p\n", hChannelHandle, Buffer, Length, pBytesWritten);
541 return FALSE;
542 }
543
544 /************************************************************
545 * WTSWaitSystemEvent (WTSAPI32.@)
546 */
547 BOOL WINAPI WTSWaitSystemEvent(HANDLE hServer, DWORD Mask, DWORD* Flags)
548 {
549 /* FIXME: Forward request to winsta.dll::WinStationWaitSystemEvent */
550 FIXME("Stub %p 0x%08x %p\n", hServer, Mask, Flags);
551 return FALSE;
552 }