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