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