/src/FreeRDP/libfreerdp/core/server.c
Line | Count | Source (jump to first uncovered line) |
1 | | /** |
2 | | * FreeRDP: A Remote Desktop Protocol Implementation |
3 | | * Server Channels |
4 | | * |
5 | | * Copyright 2014 Marc-Andre Moreau <marcandre.moreau@gmail.com> |
6 | | * Copyright 2015 Thincast Technologies GmbH |
7 | | * Copyright 2015 DI (FH) Martin Haimberger <martin.haimberger@thincast.com> |
8 | | * |
9 | | * Licensed under the Apache License, Version 2.0 (the "License"); |
10 | | * you may not use this file except in compliance with the License. |
11 | | * You may obtain a copy of the License at |
12 | | * |
13 | | * http://www.apache.org/licenses/LICENSE-2.0 |
14 | | * |
15 | | * Unless required by applicable law or agreed to in writing, software |
16 | | * distributed under the License is distributed on an "AS IS" BASIS, |
17 | | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
18 | | * See the License for the specific language governing permissions and |
19 | | * limitations under the License. |
20 | | */ |
21 | | |
22 | | #include <freerdp/config.h> |
23 | | |
24 | | #include <stdio.h> |
25 | | #include <stdlib.h> |
26 | | #include <string.h> |
27 | | #include <stdint.h> |
28 | | |
29 | | #include <winpr/wtypes.h> |
30 | | #include <winpr/crt.h> |
31 | | #include <winpr/synch.h> |
32 | | #include <winpr/stream.h> |
33 | | #include <winpr/assert.h> |
34 | | #include <winpr/cast.h> |
35 | | |
36 | | #include <freerdp/log.h> |
37 | | #include <freerdp/constants.h> |
38 | | #include <freerdp/server/channels.h> |
39 | | #include <freerdp/channels/drdynvc.h> |
40 | | #include <freerdp/utils/drdynvc.h> |
41 | | |
42 | | #include "rdp.h" |
43 | | |
44 | | #include "server.h" |
45 | | |
46 | | #define TAG FREERDP_TAG("core.server") |
47 | | #ifdef WITH_DEBUG_DVC |
48 | | #define DEBUG_DVC(...) WLog_DBG(TAG, __VA_ARGS__) |
49 | | #else |
50 | | #define DEBUG_DVC(...) \ |
51 | 0 | do \ |
52 | 0 | { \ |
53 | 0 | } while (0) |
54 | | #endif |
55 | | |
56 | 0 | #define DVC_MAX_DATA_PDU_SIZE 1600 |
57 | | |
58 | | typedef struct |
59 | | { |
60 | | UINT16 channelId; |
61 | | UINT16 reserved; |
62 | | UINT32 length; |
63 | | UINT32 offset; |
64 | | } wtsChannelMessage; |
65 | | |
66 | | static const DWORD g_err_oom = WINPR_CXX_COMPAT_CAST(DWORD, E_OUTOFMEMORY); |
67 | | |
68 | | static DWORD g_SessionId = 1; |
69 | | static wHashTable* g_ServerHandles = NULL; |
70 | | |
71 | | static rdpPeerChannel* wts_get_dvc_channel_by_id(WTSVirtualChannelManager* vcm, UINT32 ChannelId) |
72 | 0 | { |
73 | 0 | WINPR_ASSERT(vcm); |
74 | 0 | return HashTable_GetItemValue(vcm->dynamicVirtualChannels, &ChannelId); |
75 | 0 | } |
76 | | |
77 | | static BOOL wts_queue_receive_data(rdpPeerChannel* channel, const BYTE* Buffer, UINT32 Length) |
78 | 0 | { |
79 | 0 | BYTE* buffer = NULL; |
80 | 0 | wtsChannelMessage* messageCtx = NULL; |
81 | |
|
82 | 0 | WINPR_ASSERT(channel); |
83 | 0 | messageCtx = (wtsChannelMessage*)malloc(sizeof(wtsChannelMessage) + Length); |
84 | |
|
85 | 0 | if (!messageCtx) |
86 | 0 | return FALSE; |
87 | | |
88 | 0 | WINPR_ASSERT(channel->channelId <= UINT16_MAX); |
89 | 0 | messageCtx->channelId = (UINT16)channel->channelId; |
90 | 0 | messageCtx->length = Length; |
91 | 0 | messageCtx->offset = 0; |
92 | 0 | buffer = (BYTE*)(messageCtx + 1); |
93 | 0 | CopyMemory(buffer, Buffer, Length); |
94 | 0 | return MessageQueue_Post(channel->queue, messageCtx, 0, NULL, NULL); |
95 | 0 | } |
96 | | |
97 | | static BOOL wts_queue_send_item(rdpPeerChannel* channel, BYTE* Buffer, UINT32 Length) |
98 | 0 | { |
99 | 0 | BYTE* buffer = NULL; |
100 | 0 | UINT32 length = 0; |
101 | |
|
102 | 0 | WINPR_ASSERT(channel); |
103 | 0 | WINPR_ASSERT(channel->vcm); |
104 | 0 | buffer = Buffer; |
105 | 0 | length = Length; |
106 | |
|
107 | 0 | WINPR_ASSERT(channel->channelId <= UINT16_MAX); |
108 | 0 | const UINT16 channelId = (UINT16)channel->channelId; |
109 | 0 | return MessageQueue_Post(channel->vcm->queue, (void*)(UINT_PTR)channelId, 0, (void*)buffer, |
110 | 0 | (void*)(UINT_PTR)length); |
111 | 0 | } |
112 | | |
113 | | static unsigned wts_read_variable_uint(wStream* s, int cbLen, UINT32* val) |
114 | 0 | { |
115 | 0 | WINPR_ASSERT(s); |
116 | 0 | WINPR_ASSERT(val); |
117 | 0 | switch (cbLen) |
118 | 0 | { |
119 | 0 | case 0: |
120 | 0 | if (!Stream_CheckAndLogRequiredLength(TAG, s, 1)) |
121 | 0 | return 0; |
122 | | |
123 | 0 | Stream_Read_UINT8(s, *val); |
124 | 0 | return 1; |
125 | | |
126 | 0 | case 1: |
127 | 0 | if (!Stream_CheckAndLogRequiredLength(TAG, s, 2)) |
128 | 0 | return 0; |
129 | | |
130 | 0 | Stream_Read_UINT16(s, *val); |
131 | 0 | return 2; |
132 | | |
133 | 0 | case 2: |
134 | 0 | if (!Stream_CheckAndLogRequiredLength(TAG, s, 4)) |
135 | 0 | return 0; |
136 | | |
137 | 0 | Stream_Read_UINT32(s, *val); |
138 | 0 | return 4; |
139 | | |
140 | 0 | default: |
141 | 0 | WLog_ERR(TAG, "invalid wts variable uint len %d", cbLen); |
142 | 0 | return 0; |
143 | 0 | } |
144 | 0 | } |
145 | | |
146 | | static BOOL wts_read_drdynvc_capabilities_response(rdpPeerChannel* channel, UINT32 length) |
147 | 0 | { |
148 | 0 | UINT16 Version = 0; |
149 | |
|
150 | 0 | WINPR_ASSERT(channel); |
151 | 0 | WINPR_ASSERT(channel->vcm); |
152 | 0 | if (length < 3) |
153 | 0 | return FALSE; |
154 | | |
155 | 0 | Stream_Seek_UINT8(channel->receiveData); /* Pad (1 byte) */ |
156 | 0 | Stream_Read_UINT16(channel->receiveData, Version); |
157 | 0 | DEBUG_DVC("Version: %" PRIu16 "", Version); |
158 | |
|
159 | 0 | if (Version < 1) |
160 | 0 | { |
161 | 0 | WLog_ERR(TAG, "invalid version %" PRIu16 " for DRDYNVC", Version); |
162 | 0 | return FALSE; |
163 | 0 | } |
164 | | |
165 | 0 | WTSVirtualChannelManager* vcm = channel->vcm; |
166 | 0 | vcm->drdynvc_state = DRDYNVC_STATE_READY; |
167 | | |
168 | | /* we only support version 1 for now (no compression yet) */ |
169 | 0 | vcm->dvc_spoken_version = MAX(Version, 1); |
170 | |
|
171 | 0 | return SetEvent(MessageQueue_Event(vcm->queue)); |
172 | 0 | } |
173 | | |
174 | | static BOOL wts_read_drdynvc_create_response(rdpPeerChannel* channel, wStream* s, UINT32 length) |
175 | 0 | { |
176 | 0 | UINT32 CreationStatus = 0; |
177 | 0 | BOOL status = TRUE; |
178 | |
|
179 | 0 | WINPR_ASSERT(channel); |
180 | 0 | WINPR_ASSERT(s); |
181 | 0 | if (length < 4) |
182 | 0 | return FALSE; |
183 | | |
184 | 0 | Stream_Read_UINT32(s, CreationStatus); |
185 | |
|
186 | 0 | if ((INT32)CreationStatus < 0) |
187 | 0 | { |
188 | 0 | DEBUG_DVC("ChannelId %" PRIu32 " creation failed (%" PRId32 ")", channel->channelId, |
189 | 0 | (INT32)CreationStatus); |
190 | 0 | channel->dvc_open_state = DVC_OPEN_STATE_FAILED; |
191 | 0 | } |
192 | 0 | else |
193 | 0 | { |
194 | 0 | DEBUG_DVC("ChannelId %" PRIu32 " creation succeeded", channel->channelId); |
195 | 0 | channel->dvc_open_state = DVC_OPEN_STATE_SUCCEEDED; |
196 | 0 | } |
197 | |
|
198 | 0 | channel->creationStatus = (INT32)CreationStatus; |
199 | 0 | IFCALLRET(channel->vcm->dvc_creation_status, status, channel->vcm->dvc_creation_status_userdata, |
200 | 0 | channel->channelId, (INT32)CreationStatus); |
201 | 0 | if (!status) |
202 | 0 | WLog_ERR(TAG, "vcm->dvc_creation_status failed!"); |
203 | |
|
204 | 0 | return status; |
205 | 0 | } |
206 | | |
207 | | static BOOL wts_read_drdynvc_data_first(rdpPeerChannel* channel, wStream* s, int cbLen, |
208 | | UINT32 length) |
209 | 0 | { |
210 | 0 | WINPR_ASSERT(channel); |
211 | 0 | WINPR_ASSERT(s); |
212 | 0 | const UINT32 value = wts_read_variable_uint(s, cbLen, &channel->dvc_total_length); |
213 | |
|
214 | 0 | if (value == 0) |
215 | 0 | return FALSE; |
216 | 0 | if (value > length) |
217 | 0 | length = 0; |
218 | 0 | else |
219 | 0 | length -= value; |
220 | |
|
221 | 0 | if (length > channel->dvc_total_length) |
222 | 0 | return FALSE; |
223 | | |
224 | 0 | Stream_SetPosition(channel->receiveData, 0); |
225 | |
|
226 | 0 | if (!Stream_EnsureRemainingCapacity(channel->receiveData, channel->dvc_total_length)) |
227 | 0 | return FALSE; |
228 | | |
229 | 0 | Stream_Write(channel->receiveData, Stream_ConstPointer(s), length); |
230 | 0 | return TRUE; |
231 | 0 | } |
232 | | |
233 | | static BOOL wts_read_drdynvc_data(rdpPeerChannel* channel, wStream* s, UINT32 length) |
234 | 0 | { |
235 | 0 | BOOL ret = FALSE; |
236 | |
|
237 | 0 | WINPR_ASSERT(channel); |
238 | 0 | WINPR_ASSERT(s); |
239 | 0 | if (channel->dvc_total_length > 0) |
240 | 0 | { |
241 | 0 | if (Stream_GetPosition(channel->receiveData) + length > channel->dvc_total_length) |
242 | 0 | { |
243 | 0 | channel->dvc_total_length = 0; |
244 | 0 | WLog_ERR(TAG, "incorrect fragment data, discarded."); |
245 | 0 | return FALSE; |
246 | 0 | } |
247 | | |
248 | 0 | Stream_Write(channel->receiveData, Stream_ConstPointer(s), length); |
249 | |
|
250 | 0 | if (Stream_GetPosition(channel->receiveData) >= channel->dvc_total_length) |
251 | 0 | { |
252 | 0 | ret = wts_queue_receive_data(channel, Stream_Buffer(channel->receiveData), |
253 | 0 | channel->dvc_total_length); |
254 | 0 | channel->dvc_total_length = 0; |
255 | 0 | } |
256 | 0 | else |
257 | 0 | ret = TRUE; |
258 | 0 | } |
259 | 0 | else |
260 | 0 | { |
261 | 0 | ret = wts_queue_receive_data(channel, Stream_ConstPointer(s), length); |
262 | 0 | } |
263 | | |
264 | 0 | return ret; |
265 | 0 | } |
266 | | |
267 | | static void wts_read_drdynvc_close_response(rdpPeerChannel* channel) |
268 | 0 | { |
269 | 0 | WINPR_ASSERT(channel); |
270 | 0 | DEBUG_DVC("ChannelId %" PRIu32 " close response", channel->channelId); |
271 | 0 | channel->dvc_open_state = DVC_OPEN_STATE_CLOSED; |
272 | 0 | MessageQueue_PostQuit(channel->queue, 0); |
273 | 0 | } |
274 | | |
275 | | static BOOL wts_read_drdynvc_pdu(rdpPeerChannel* channel) |
276 | 0 | { |
277 | 0 | UINT8 Cmd = 0; |
278 | 0 | UINT8 Sp = 0; |
279 | 0 | UINT8 cbChId = 0; |
280 | 0 | UINT32 ChannelId = 0; |
281 | 0 | rdpPeerChannel* dvc = NULL; |
282 | |
|
283 | 0 | WINPR_ASSERT(channel); |
284 | 0 | WINPR_ASSERT(channel->vcm); |
285 | | |
286 | 0 | size_t length = Stream_GetPosition(channel->receiveData); |
287 | |
|
288 | 0 | if ((length < 1) || (length > UINT32_MAX)) |
289 | 0 | return FALSE; |
290 | | |
291 | 0 | Stream_SetPosition(channel->receiveData, 0); |
292 | 0 | const UINT8 value = Stream_Get_UINT8(channel->receiveData); |
293 | 0 | length--; |
294 | 0 | Cmd = (value & 0xf0) >> 4; |
295 | 0 | Sp = (value & 0x0c) >> 2; |
296 | 0 | cbChId = (value & 0x03) >> 0; |
297 | |
|
298 | 0 | if (Cmd == CAPABILITY_REQUEST_PDU) |
299 | 0 | return wts_read_drdynvc_capabilities_response(channel, (UINT32)length); |
300 | | |
301 | 0 | if (channel->vcm->drdynvc_state == DRDYNVC_STATE_READY) |
302 | 0 | { |
303 | 0 | BOOL haveChannelId = 0; |
304 | 0 | switch (Cmd) |
305 | 0 | { |
306 | 0 | case SOFT_SYNC_REQUEST_PDU: |
307 | 0 | case SOFT_SYNC_RESPONSE_PDU: |
308 | 0 | haveChannelId = FALSE; |
309 | 0 | break; |
310 | 0 | default: |
311 | 0 | haveChannelId = TRUE; |
312 | 0 | break; |
313 | 0 | } |
314 | | |
315 | 0 | if (haveChannelId) |
316 | 0 | { |
317 | 0 | const unsigned val = wts_read_variable_uint(channel->receiveData, cbChId, &ChannelId); |
318 | 0 | if (val == 0) |
319 | 0 | return FALSE; |
320 | | |
321 | 0 | length -= val; |
322 | |
|
323 | 0 | DEBUG_DVC("Cmd %s ChannelId %" PRIu32 " length %" PRIuz "", |
324 | 0 | drdynvc_get_packet_type(Cmd), ChannelId, length); |
325 | 0 | dvc = wts_get_dvc_channel_by_id(channel->vcm, ChannelId); |
326 | 0 | if (!dvc) |
327 | 0 | { |
328 | 0 | DEBUG_DVC("ChannelId %" PRIu32 " does not exist.", ChannelId); |
329 | 0 | return TRUE; |
330 | 0 | } |
331 | 0 | } |
332 | | |
333 | 0 | switch (Cmd) |
334 | 0 | { |
335 | 0 | case CREATE_REQUEST_PDU: |
336 | 0 | return wts_read_drdynvc_create_response(dvc, channel->receiveData, (UINT32)length); |
337 | | |
338 | 0 | case DATA_FIRST_PDU: |
339 | 0 | if (dvc->dvc_open_state != DVC_OPEN_STATE_SUCCEEDED) |
340 | 0 | { |
341 | 0 | WLog_ERR(TAG, |
342 | 0 | "ChannelId %" PRIu32 " did not open successfully. " |
343 | 0 | "Ignoring DYNVC_DATA_FIRST PDU", |
344 | 0 | ChannelId); |
345 | 0 | return TRUE; |
346 | 0 | } |
347 | | |
348 | 0 | return wts_read_drdynvc_data_first(dvc, channel->receiveData, Sp, (UINT32)length); |
349 | | |
350 | 0 | case DATA_PDU: |
351 | 0 | if (dvc->dvc_open_state != DVC_OPEN_STATE_SUCCEEDED) |
352 | 0 | { |
353 | 0 | WLog_ERR(TAG, |
354 | 0 | "ChannelId %" PRIu32 " did not open successfully. " |
355 | 0 | "Ignoring DYNVC_DATA PDU", |
356 | 0 | ChannelId); |
357 | 0 | return TRUE; |
358 | 0 | } |
359 | | |
360 | 0 | return wts_read_drdynvc_data(dvc, channel->receiveData, (UINT32)length); |
361 | | |
362 | 0 | case CLOSE_REQUEST_PDU: |
363 | 0 | wts_read_drdynvc_close_response(dvc); |
364 | 0 | break; |
365 | | |
366 | 0 | case DATA_FIRST_COMPRESSED_PDU: |
367 | 0 | case DATA_COMPRESSED_PDU: |
368 | 0 | WLog_ERR(TAG, "Compressed data not handled"); |
369 | 0 | break; |
370 | | |
371 | 0 | case SOFT_SYNC_RESPONSE_PDU: |
372 | 0 | WLog_ERR(TAG, "SoftSync response not handled yet(and rather strange to receive " |
373 | 0 | "that packet as our code doesn't send SoftSync requests"); |
374 | 0 | break; |
375 | | |
376 | 0 | case SOFT_SYNC_REQUEST_PDU: |
377 | 0 | WLog_ERR(TAG, "Not expecting a SoftSyncRequest on the server"); |
378 | 0 | return FALSE; |
379 | | |
380 | 0 | default: |
381 | 0 | WLog_ERR(TAG, "Cmd %d not recognized.", Cmd); |
382 | 0 | break; |
383 | 0 | } |
384 | 0 | } |
385 | 0 | else |
386 | 0 | { |
387 | 0 | WLog_ERR(TAG, "received Cmd %d but channel is not ready.", Cmd); |
388 | 0 | } |
389 | | |
390 | 0 | return TRUE; |
391 | 0 | } |
392 | | |
393 | | static int wts_write_variable_uint(wStream* s, UINT32 val) |
394 | 0 | { |
395 | 0 | int cb = 0; |
396 | |
|
397 | 0 | WINPR_ASSERT(s); |
398 | 0 | if (val <= 0xFF) |
399 | 0 | { |
400 | 0 | cb = 0; |
401 | 0 | Stream_Write_UINT8(s, WINPR_ASSERTING_INT_CAST(uint8_t, val)); |
402 | 0 | } |
403 | 0 | else if (val <= 0xFFFF) |
404 | 0 | { |
405 | 0 | cb = 1; |
406 | 0 | Stream_Write_UINT16(s, WINPR_ASSERTING_INT_CAST(uint16_t, val)); |
407 | 0 | } |
408 | 0 | else |
409 | 0 | { |
410 | 0 | cb = 2; |
411 | 0 | Stream_Write_UINT32(s, val); |
412 | 0 | } |
413 | | |
414 | 0 | return cb; |
415 | 0 | } |
416 | | |
417 | | static void wts_write_drdynvc_header(wStream* s, BYTE Cmd, UINT32 ChannelId) |
418 | 0 | { |
419 | 0 | BYTE* bm = NULL; |
420 | 0 | int cbChId = 0; |
421 | |
|
422 | 0 | WINPR_ASSERT(s); |
423 | | |
424 | 0 | Stream_GetPointer(s, bm); |
425 | 0 | Stream_Seek_UINT8(s); |
426 | 0 | cbChId = wts_write_variable_uint(s, ChannelId); |
427 | 0 | *bm = (((Cmd & 0x0F) << 4) | cbChId) & 0xFF; |
428 | 0 | } |
429 | | |
430 | | static BOOL wts_write_drdynvc_create_request(wStream* s, UINT32 ChannelId, const char* ChannelName) |
431 | 0 | { |
432 | 0 | size_t len = 0; |
433 | |
|
434 | 0 | WINPR_ASSERT(s); |
435 | 0 | WINPR_ASSERT(ChannelName); |
436 | | |
437 | 0 | wts_write_drdynvc_header(s, CREATE_REQUEST_PDU, ChannelId); |
438 | 0 | len = strlen(ChannelName) + 1; |
439 | |
|
440 | 0 | if (!Stream_EnsureRemainingCapacity(s, len)) |
441 | 0 | return FALSE; |
442 | | |
443 | 0 | Stream_Write(s, ChannelName, len); |
444 | 0 | return TRUE; |
445 | 0 | } |
446 | | |
447 | | static BOOL WTSProcessChannelData(rdpPeerChannel* channel, UINT16 channelId, const BYTE* data, |
448 | | size_t s, UINT32 flags, size_t t) |
449 | 0 | { |
450 | 0 | BOOL ret = TRUE; |
451 | 0 | const size_t size = s; |
452 | 0 | const size_t totalSize = t; |
453 | |
|
454 | 0 | WINPR_ASSERT(channel); |
455 | 0 | WINPR_ASSERT(channel->vcm); |
456 | 0 | WINPR_UNUSED(channelId); |
457 | |
|
458 | 0 | if (flags & CHANNEL_FLAG_FIRST) |
459 | 0 | { |
460 | 0 | Stream_SetPosition(channel->receiveData, 0); |
461 | 0 | } |
462 | |
|
463 | 0 | if (!Stream_EnsureRemainingCapacity(channel->receiveData, size)) |
464 | 0 | return FALSE; |
465 | | |
466 | 0 | Stream_Write(channel->receiveData, data, size); |
467 | |
|
468 | 0 | if (flags & CHANNEL_FLAG_LAST) |
469 | 0 | { |
470 | 0 | if (Stream_GetPosition(channel->receiveData) != totalSize) |
471 | 0 | { |
472 | 0 | WLog_ERR(TAG, "read error"); |
473 | 0 | } |
474 | |
|
475 | 0 | if (channel == channel->vcm->drdynvc_channel) |
476 | 0 | { |
477 | 0 | ret = wts_read_drdynvc_pdu(channel); |
478 | 0 | } |
479 | 0 | else |
480 | 0 | { |
481 | 0 | const size_t pos = Stream_GetPosition(channel->receiveData); |
482 | 0 | if (pos > UINT32_MAX) |
483 | 0 | ret = FALSE; |
484 | 0 | else |
485 | 0 | ret = wts_queue_receive_data(channel, Stream_Buffer(channel->receiveData), |
486 | 0 | (UINT32)pos); |
487 | 0 | } |
488 | |
|
489 | 0 | Stream_SetPosition(channel->receiveData, 0); |
490 | 0 | } |
491 | |
|
492 | 0 | return ret; |
493 | 0 | } |
494 | | |
495 | | static BOOL WTSReceiveChannelData(freerdp_peer* client, UINT16 channelId, const BYTE* data, |
496 | | size_t size, UINT32 flags, size_t totalSize) |
497 | 0 | { |
498 | 0 | rdpMcs* mcs = NULL; |
499 | |
|
500 | 0 | WINPR_ASSERT(client); |
501 | 0 | WINPR_ASSERT(client->context); |
502 | 0 | WINPR_ASSERT(client->context->rdp); |
503 | | |
504 | 0 | mcs = client->context->rdp->mcs; |
505 | 0 | WINPR_ASSERT(mcs); |
506 | | |
507 | 0 | for (UINT32 i = 0; i < mcs->channelCount; i++) |
508 | 0 | { |
509 | 0 | rdpMcsChannel* cur = &mcs->channels[i]; |
510 | 0 | if (cur->ChannelId == channelId) |
511 | 0 | { |
512 | 0 | rdpPeerChannel* channel = (rdpPeerChannel*)cur->handle; |
513 | |
|
514 | 0 | if (channel) |
515 | 0 | return WTSProcessChannelData(channel, channelId, data, size, flags, totalSize); |
516 | 0 | } |
517 | 0 | } |
518 | | |
519 | 0 | WLog_WARN(TAG, "unknown channelId %" PRIu16 " ignored", channelId); |
520 | |
|
521 | 0 | return TRUE; |
522 | 0 | } |
523 | | |
524 | | #if defined(WITH_FREERDP_DEPRECATED) |
525 | | void WTSVirtualChannelManagerGetFileDescriptor(HANDLE hServer, void** fds, int* fds_count) |
526 | | { |
527 | | void* fd = NULL; |
528 | | WTSVirtualChannelManager* vcm = (WTSVirtualChannelManager*)hServer; |
529 | | WINPR_ASSERT(vcm); |
530 | | WINPR_ASSERT(fds); |
531 | | WINPR_ASSERT(fds_count); |
532 | | |
533 | | fd = GetEventWaitObject(MessageQueue_Event(vcm->queue)); |
534 | | |
535 | | if (fd) |
536 | | { |
537 | | fds[*fds_count] = fd; |
538 | | (*fds_count)++; |
539 | | } |
540 | | |
541 | | #if 0 |
542 | | |
543 | | if (vcm->drdynvc_channel) |
544 | | { |
545 | | fd = GetEventWaitObject(vcm->drdynvc_channel->receiveEvent); |
546 | | |
547 | | if (fd) |
548 | | { |
549 | | fds[*fds_count] = fd; |
550 | | (*fds_count)++; |
551 | | } |
552 | | } |
553 | | |
554 | | #endif |
555 | | } |
556 | | #endif |
557 | | |
558 | | BOOL WTSVirtualChannelManagerOpen(HANDLE hServer) |
559 | 0 | { |
560 | 0 | WTSVirtualChannelManager* vcm = (WTSVirtualChannelManager*)hServer; |
561 | |
|
562 | 0 | if (!vcm) |
563 | 0 | return FALSE; |
564 | | |
565 | 0 | if (vcm->drdynvc_state == DRDYNVC_STATE_NONE) |
566 | 0 | { |
567 | 0 | rdpPeerChannel* channel = NULL; |
568 | | |
569 | | /* Initialize drdynvc channel once and only once. */ |
570 | 0 | vcm->drdynvc_state = DRDYNVC_STATE_INITIALIZED; |
571 | 0 | channel = (rdpPeerChannel*)WTSVirtualChannelOpen((HANDLE)vcm, WTS_CURRENT_SESSION, |
572 | 0 | DRDYNVC_SVC_CHANNEL_NAME); |
573 | |
|
574 | 0 | if (channel) |
575 | 0 | { |
576 | 0 | BYTE capaBuffer[12] = { 0 }; |
577 | 0 | wStream staticS = { 0 }; |
578 | 0 | wStream* s = Stream_StaticInit(&staticS, capaBuffer, sizeof(capaBuffer)); |
579 | |
|
580 | 0 | vcm->drdynvc_channel = channel; |
581 | 0 | vcm->dvc_spoken_version = 1; |
582 | 0 | Stream_Write_UINT8(s, 0x50); /* Cmd=5 sp=0 cbId=0 */ |
583 | 0 | Stream_Write_UINT8(s, 0x00); /* Pad */ |
584 | 0 | Stream_Write_UINT16(s, 0x0001); /* Version */ |
585 | | |
586 | | /* TODO: shall implement version 2 and 3 */ |
587 | | |
588 | 0 | const size_t pos = Stream_GetPosition(s); |
589 | 0 | WINPR_ASSERT(pos <= UINT32_MAX); |
590 | 0 | ULONG written = 0; |
591 | 0 | if (!WTSVirtualChannelWrite(channel, (PCHAR)capaBuffer, (UINT32)pos, &written)) |
592 | 0 | return FALSE; |
593 | 0 | } |
594 | 0 | } |
595 | | |
596 | 0 | return TRUE; |
597 | 0 | } |
598 | | |
599 | | BOOL WTSVirtualChannelManagerCheckFileDescriptorEx(HANDLE hServer, BOOL autoOpen) |
600 | 0 | { |
601 | 0 | wMessage message = { 0 }; |
602 | 0 | BOOL status = TRUE; |
603 | 0 | WTSVirtualChannelManager* vcm = NULL; |
604 | |
|
605 | 0 | if (!hServer || hServer == INVALID_HANDLE_VALUE) |
606 | 0 | return FALSE; |
607 | | |
608 | 0 | vcm = (WTSVirtualChannelManager*)hServer; |
609 | |
|
610 | 0 | if (autoOpen) |
611 | 0 | { |
612 | 0 | if (!WTSVirtualChannelManagerOpen(hServer)) |
613 | 0 | return FALSE; |
614 | 0 | } |
615 | | |
616 | 0 | while (MessageQueue_Peek(vcm->queue, &message, TRUE)) |
617 | 0 | { |
618 | 0 | BYTE* buffer = NULL; |
619 | 0 | UINT32 length = 0; |
620 | 0 | UINT16 channelId = 0; |
621 | 0 | channelId = (UINT16)(UINT_PTR)message.context; |
622 | 0 | buffer = (BYTE*)message.wParam; |
623 | 0 | length = (UINT32)(UINT_PTR)message.lParam; |
624 | |
|
625 | 0 | WINPR_ASSERT(vcm->client); |
626 | 0 | WINPR_ASSERT(vcm->client->SendChannelData); |
627 | 0 | if (!vcm->client->SendChannelData(vcm->client, channelId, buffer, length)) |
628 | 0 | { |
629 | 0 | status = FALSE; |
630 | 0 | } |
631 | |
|
632 | 0 | free(buffer); |
633 | |
|
634 | 0 | if (!status) |
635 | 0 | break; |
636 | 0 | } |
637 | | |
638 | 0 | return status; |
639 | 0 | } |
640 | | |
641 | | BOOL WTSVirtualChannelManagerCheckFileDescriptor(HANDLE hServer) |
642 | 0 | { |
643 | 0 | return WTSVirtualChannelManagerCheckFileDescriptorEx(hServer, TRUE); |
644 | 0 | } |
645 | | |
646 | | HANDLE WTSVirtualChannelManagerGetEventHandle(HANDLE hServer) |
647 | 0 | { |
648 | 0 | WTSVirtualChannelManager* vcm = (WTSVirtualChannelManager*)hServer; |
649 | 0 | WINPR_ASSERT(vcm); |
650 | 0 | return MessageQueue_Event(vcm->queue); |
651 | 0 | } |
652 | | |
653 | | static rdpMcsChannel* wts_get_joined_channel_by_name(rdpMcs* mcs, const char* channel_name) |
654 | 0 | { |
655 | 0 | if (!mcs || !channel_name || !strnlen(channel_name, CHANNEL_NAME_LEN + 1)) |
656 | 0 | return NULL; |
657 | | |
658 | 0 | for (UINT32 index = 0; index < mcs->channelCount; index++) |
659 | 0 | { |
660 | 0 | rdpMcsChannel* mchannel = &mcs->channels[index]; |
661 | 0 | if (mchannel->joined) |
662 | 0 | { |
663 | 0 | if (_strnicmp(mchannel->Name, channel_name, CHANNEL_NAME_LEN + 1) == 0) |
664 | 0 | return mchannel; |
665 | 0 | } |
666 | 0 | } |
667 | | |
668 | 0 | return NULL; |
669 | 0 | } |
670 | | |
671 | | static rdpMcsChannel* wts_get_joined_channel_by_id(rdpMcs* mcs, const UINT16 channel_id) |
672 | 0 | { |
673 | 0 | if (!mcs || !channel_id) |
674 | 0 | return NULL; |
675 | | |
676 | 0 | WINPR_ASSERT(mcs->channels); |
677 | 0 | for (UINT32 index = 0; index < mcs->channelCount; index++) |
678 | 0 | { |
679 | 0 | rdpMcsChannel* mchannel = &mcs->channels[index]; |
680 | 0 | if (mchannel->joined) |
681 | 0 | { |
682 | 0 | if (mchannel->ChannelId == channel_id) |
683 | 0 | return &mcs->channels[index]; |
684 | 0 | } |
685 | 0 | } |
686 | | |
687 | 0 | return NULL; |
688 | 0 | } |
689 | | |
690 | | BOOL WTSIsChannelJoinedByName(freerdp_peer* client, const char* channel_name) |
691 | 0 | { |
692 | 0 | if (!client || !client->context || !client->context->rdp) |
693 | 0 | return FALSE; |
694 | | |
695 | 0 | return wts_get_joined_channel_by_name(client->context->rdp->mcs, channel_name) == NULL ? FALSE |
696 | 0 | : TRUE; |
697 | 0 | } |
698 | | |
699 | | BOOL WTSIsChannelJoinedById(freerdp_peer* client, UINT16 channel_id) |
700 | 0 | { |
701 | 0 | if (!client || !client->context || !client->context->rdp) |
702 | 0 | return FALSE; |
703 | | |
704 | 0 | return wts_get_joined_channel_by_id(client->context->rdp->mcs, channel_id) == NULL ? FALSE |
705 | 0 | : TRUE; |
706 | 0 | } |
707 | | |
708 | | BOOL WTSVirtualChannelManagerIsChannelJoined(HANDLE hServer, const char* name) |
709 | 0 | { |
710 | 0 | WTSVirtualChannelManager* vcm = (WTSVirtualChannelManager*)hServer; |
711 | |
|
712 | 0 | if (!vcm || !vcm->rdp) |
713 | 0 | return FALSE; |
714 | | |
715 | 0 | return wts_get_joined_channel_by_name(vcm->rdp->mcs, name) == NULL ? FALSE : TRUE; |
716 | 0 | } |
717 | | |
718 | | BYTE WTSVirtualChannelManagerGetDrdynvcState(HANDLE hServer) |
719 | 0 | { |
720 | 0 | WTSVirtualChannelManager* vcm = (WTSVirtualChannelManager*)hServer; |
721 | 0 | WINPR_ASSERT(vcm); |
722 | 0 | return vcm->drdynvc_state; |
723 | 0 | } |
724 | | |
725 | | void WTSVirtualChannelManagerSetDVCCreationCallback(HANDLE hServer, psDVCCreationStatusCallback cb, |
726 | | void* userdata) |
727 | 0 | { |
728 | 0 | WTSVirtualChannelManager* vcm = hServer; |
729 | |
|
730 | 0 | WINPR_ASSERT(vcm); |
731 | | |
732 | 0 | vcm->dvc_creation_status = cb; |
733 | 0 | vcm->dvc_creation_status_userdata = userdata; |
734 | 0 | } |
735 | | |
736 | | UINT16 WTSChannelGetId(freerdp_peer* client, const char* channel_name) |
737 | 0 | { |
738 | 0 | rdpMcsChannel* channel = NULL; |
739 | |
|
740 | 0 | WINPR_ASSERT(channel_name); |
741 | 0 | if (!client || !client->context || !client->context->rdp) |
742 | 0 | return 0; |
743 | | |
744 | 0 | channel = wts_get_joined_channel_by_name(client->context->rdp->mcs, channel_name); |
745 | |
|
746 | 0 | if (!channel) |
747 | 0 | return 0; |
748 | | |
749 | 0 | return channel->ChannelId; |
750 | 0 | } |
751 | | |
752 | | UINT32 WTSChannelGetIdByHandle(HANDLE hChannelHandle) |
753 | 0 | { |
754 | 0 | rdpPeerChannel* channel = hChannelHandle; |
755 | |
|
756 | 0 | WINPR_ASSERT(channel); |
757 | | |
758 | 0 | return channel->channelId; |
759 | 0 | } |
760 | | |
761 | | BOOL WTSChannelSetHandleByName(freerdp_peer* client, const char* channel_name, void* handle) |
762 | 0 | { |
763 | 0 | rdpMcsChannel* channel = NULL; |
764 | |
|
765 | 0 | WINPR_ASSERT(channel_name); |
766 | 0 | if (!client || !client->context || !client->context->rdp) |
767 | 0 | return FALSE; |
768 | | |
769 | 0 | channel = wts_get_joined_channel_by_name(client->context->rdp->mcs, channel_name); |
770 | |
|
771 | 0 | if (!channel) |
772 | 0 | return FALSE; |
773 | | |
774 | 0 | channel->handle = handle; |
775 | 0 | return TRUE; |
776 | 0 | } |
777 | | |
778 | | BOOL WTSChannelSetHandleById(freerdp_peer* client, UINT16 channel_id, void* handle) |
779 | 0 | { |
780 | 0 | rdpMcsChannel* channel = NULL; |
781 | |
|
782 | 0 | if (!client || !client->context || !client->context->rdp) |
783 | 0 | return FALSE; |
784 | | |
785 | 0 | channel = wts_get_joined_channel_by_id(client->context->rdp->mcs, channel_id); |
786 | |
|
787 | 0 | if (!channel) |
788 | 0 | return FALSE; |
789 | | |
790 | 0 | channel->handle = handle; |
791 | 0 | return TRUE; |
792 | 0 | } |
793 | | |
794 | | void* WTSChannelGetHandleByName(freerdp_peer* client, const char* channel_name) |
795 | 0 | { |
796 | 0 | rdpMcsChannel* channel = NULL; |
797 | |
|
798 | 0 | WINPR_ASSERT(channel_name); |
799 | 0 | if (!client || !client->context || !client->context->rdp) |
800 | 0 | return NULL; |
801 | | |
802 | 0 | channel = wts_get_joined_channel_by_name(client->context->rdp->mcs, channel_name); |
803 | |
|
804 | 0 | if (!channel) |
805 | 0 | return NULL; |
806 | | |
807 | 0 | return channel->handle; |
808 | 0 | } |
809 | | |
810 | | void* WTSChannelGetHandleById(freerdp_peer* client, UINT16 channel_id) |
811 | 0 | { |
812 | 0 | rdpMcsChannel* channel = NULL; |
813 | |
|
814 | 0 | if (!client || !client->context || !client->context->rdp) |
815 | 0 | return NULL; |
816 | | |
817 | 0 | channel = wts_get_joined_channel_by_id(client->context->rdp->mcs, channel_id); |
818 | |
|
819 | 0 | if (!channel) |
820 | 0 | return NULL; |
821 | | |
822 | 0 | return channel->handle; |
823 | 0 | } |
824 | | |
825 | | const char* WTSChannelGetName(freerdp_peer* client, UINT16 channel_id) |
826 | 0 | { |
827 | 0 | rdpMcsChannel* channel = NULL; |
828 | |
|
829 | 0 | if (!client || !client->context || !client->context->rdp) |
830 | 0 | return NULL; |
831 | | |
832 | 0 | channel = wts_get_joined_channel_by_id(client->context->rdp->mcs, channel_id); |
833 | |
|
834 | 0 | if (!channel) |
835 | 0 | return NULL; |
836 | | |
837 | 0 | return (const char*)channel->Name; |
838 | 0 | } |
839 | | |
840 | | char** WTSGetAcceptedChannelNames(freerdp_peer* client, size_t* count) |
841 | 0 | { |
842 | 0 | rdpMcs* mcs = NULL; |
843 | 0 | char** names = NULL; |
844 | |
|
845 | 0 | if (!client || !client->context || !count) |
846 | 0 | return NULL; |
847 | | |
848 | 0 | WINPR_ASSERT(client->context->rdp); |
849 | 0 | mcs = client->context->rdp->mcs; |
850 | 0 | WINPR_ASSERT(mcs); |
851 | 0 | *count = mcs->channelCount; |
852 | |
|
853 | 0 | names = (char**)calloc(mcs->channelCount, sizeof(char*)); |
854 | 0 | if (!names) |
855 | 0 | return NULL; |
856 | | |
857 | 0 | for (UINT32 index = 0; index < mcs->channelCount; index++) |
858 | 0 | { |
859 | 0 | rdpMcsChannel* mchannel = &mcs->channels[index]; |
860 | 0 | names[index] = mchannel->Name; |
861 | 0 | } |
862 | |
|
863 | 0 | return names; |
864 | 0 | } |
865 | | |
866 | | INT64 WTSChannelGetOptions(freerdp_peer* client, UINT16 channel_id) |
867 | 0 | { |
868 | 0 | rdpMcsChannel* channel = NULL; |
869 | |
|
870 | 0 | if (!client || !client->context || !client->context->rdp) |
871 | 0 | return -1; |
872 | | |
873 | 0 | channel = wts_get_joined_channel_by_id(client->context->rdp->mcs, channel_id); |
874 | |
|
875 | 0 | if (!channel) |
876 | 0 | return -1; |
877 | | |
878 | 0 | return (INT64)channel->options; |
879 | 0 | } |
880 | | |
881 | | BOOL WINAPI FreeRDP_WTSStartRemoteControlSessionW(WINPR_ATTR_UNUSED LPWSTR pTargetServerName, |
882 | | WINPR_ATTR_UNUSED ULONG TargetLogonId, |
883 | | WINPR_ATTR_UNUSED BYTE HotkeyVk, |
884 | | WINPR_ATTR_UNUSED USHORT HotkeyModifiers) |
885 | 0 | { |
886 | 0 | WLog_ERR("TODO", "TODO: implement"); |
887 | 0 | return FALSE; |
888 | 0 | } |
889 | | |
890 | | BOOL WINAPI FreeRDP_WTSStartRemoteControlSessionA(WINPR_ATTR_UNUSED LPSTR pTargetServerName, |
891 | | WINPR_ATTR_UNUSED ULONG TargetLogonId, |
892 | | WINPR_ATTR_UNUSED BYTE HotkeyVk, |
893 | | WINPR_ATTR_UNUSED USHORT HotkeyModifiers) |
894 | 0 | { |
895 | 0 | WLog_ERR("TODO", "TODO: implement"); |
896 | 0 | return FALSE; |
897 | 0 | } |
898 | | |
899 | | BOOL WINAPI FreeRDP_WTSStartRemoteControlSessionExW(WINPR_ATTR_UNUSED LPWSTR pTargetServerName, |
900 | | WINPR_ATTR_UNUSED ULONG TargetLogonId, |
901 | | WINPR_ATTR_UNUSED BYTE HotkeyVk, |
902 | | WINPR_ATTR_UNUSED USHORT HotkeyModifiers, |
903 | | WINPR_ATTR_UNUSED DWORD flags) |
904 | 0 | { |
905 | 0 | WLog_ERR("TODO", "TODO: implement"); |
906 | 0 | return FALSE; |
907 | 0 | } |
908 | | |
909 | | BOOL WINAPI FreeRDP_WTSStartRemoteControlSessionExA(WINPR_ATTR_UNUSED LPSTR pTargetServerName, |
910 | | WINPR_ATTR_UNUSED ULONG TargetLogonId, |
911 | | WINPR_ATTR_UNUSED BYTE HotkeyVk, |
912 | | WINPR_ATTR_UNUSED USHORT HotkeyModifiers, |
913 | | WINPR_ATTR_UNUSED DWORD flags) |
914 | 0 | { |
915 | 0 | WLog_ERR("TODO", "TODO: implement"); |
916 | 0 | return FALSE; |
917 | 0 | } |
918 | | |
919 | | BOOL WINAPI FreeRDP_WTSStopRemoteControlSession(WINPR_ATTR_UNUSED ULONG LogonId) |
920 | 0 | { |
921 | 0 | WLog_ERR("TODO", "TODO: implement"); |
922 | 0 | return FALSE; |
923 | 0 | } |
924 | | |
925 | | BOOL WINAPI FreeRDP_WTSConnectSessionW(WINPR_ATTR_UNUSED ULONG LogonId, |
926 | | WINPR_ATTR_UNUSED ULONG TargetLogonId, |
927 | | WINPR_ATTR_UNUSED PWSTR pPassword, |
928 | | WINPR_ATTR_UNUSED BOOL bWait) |
929 | 0 | { |
930 | 0 | WLog_ERR("TODO", "TODO: implement"); |
931 | 0 | return FALSE; |
932 | 0 | } |
933 | | |
934 | | BOOL WINAPI FreeRDP_WTSConnectSessionA(WINPR_ATTR_UNUSED ULONG LogonId, |
935 | | WINPR_ATTR_UNUSED ULONG TargetLogonId, |
936 | | WINPR_ATTR_UNUSED PSTR pPassword, |
937 | | WINPR_ATTR_UNUSED BOOL bWait) |
938 | 0 | { |
939 | 0 | WLog_ERR("TODO", "TODO: implement"); |
940 | 0 | return FALSE; |
941 | 0 | } |
942 | | |
943 | | BOOL WINAPI FreeRDP_WTSEnumerateServersW(WINPR_ATTR_UNUSED LPWSTR pDomainName, |
944 | | WINPR_ATTR_UNUSED DWORD Reserved, |
945 | | WINPR_ATTR_UNUSED DWORD Version, |
946 | | WINPR_ATTR_UNUSED PWTS_SERVER_INFOW* ppServerInfo, |
947 | | WINPR_ATTR_UNUSED DWORD* pCount) |
948 | 0 | { |
949 | 0 | WLog_ERR("TODO", "TODO: implement"); |
950 | 0 | return FALSE; |
951 | 0 | } |
952 | | |
953 | | BOOL WINAPI FreeRDP_WTSEnumerateServersA(WINPR_ATTR_UNUSED LPSTR pDomainName, |
954 | | WINPR_ATTR_UNUSED DWORD Reserved, |
955 | | WINPR_ATTR_UNUSED DWORD Version, |
956 | | WINPR_ATTR_UNUSED PWTS_SERVER_INFOA* ppServerInfo, |
957 | | WINPR_ATTR_UNUSED DWORD* pCount) |
958 | 0 | { |
959 | 0 | WLog_ERR("TODO", "TODO: implement"); |
960 | 0 | return FALSE; |
961 | 0 | } |
962 | | |
963 | | HANDLE WINAPI FreeRDP_WTSOpenServerW(WINPR_ATTR_UNUSED LPWSTR pServerName) |
964 | 0 | { |
965 | 0 | WLog_ERR("TODO", "TODO: implement"); |
966 | 0 | return INVALID_HANDLE_VALUE; |
967 | 0 | } |
968 | | |
969 | | static void wts_virtual_channel_manager_free_message(void* obj) |
970 | 0 | { |
971 | 0 | wMessage* msg = (wMessage*)obj; |
972 | |
|
973 | 0 | if (msg) |
974 | 0 | { |
975 | 0 | BYTE* buffer = (BYTE*)msg->wParam; |
976 | |
|
977 | 0 | if (buffer) |
978 | 0 | free(buffer); |
979 | 0 | } |
980 | 0 | } |
981 | | |
982 | | static void channel_free(rdpPeerChannel* channel) |
983 | 0 | { |
984 | 0 | server_channel_common_free(channel); |
985 | 0 | } |
986 | | |
987 | | static void array_channel_free(void* ptr) |
988 | 0 | { |
989 | 0 | rdpPeerChannel* channel = ptr; |
990 | 0 | channel_free(channel); |
991 | 0 | } |
992 | | |
993 | | static BOOL dynChannelMatch(const void* v1, const void* v2) |
994 | 0 | { |
995 | 0 | const UINT32* p1 = (const UINT32*)v1; |
996 | 0 | const UINT32* p2 = (const UINT32*)v2; |
997 | 0 | return *p1 == *p2; |
998 | 0 | } |
999 | | |
1000 | | static UINT32 channelId_Hash(const void* key) |
1001 | 0 | { |
1002 | 0 | const UINT32* v = (const UINT32*)key; |
1003 | 0 | return *v; |
1004 | 0 | } |
1005 | | |
1006 | | HANDLE WINAPI FreeRDP_WTSOpenServerA(LPSTR pServerName) |
1007 | 0 | { |
1008 | 0 | rdpContext* context = NULL; |
1009 | 0 | freerdp_peer* client = NULL; |
1010 | 0 | WTSVirtualChannelManager* vcm = NULL; |
1011 | 0 | HANDLE hServer = INVALID_HANDLE_VALUE; |
1012 | 0 | wObject queueCallbacks = { 0 }; |
1013 | |
|
1014 | 0 | context = (rdpContext*)pServerName; |
1015 | |
|
1016 | 0 | if (!context) |
1017 | 0 | return INVALID_HANDLE_VALUE; |
1018 | | |
1019 | 0 | client = context->peer; |
1020 | |
|
1021 | 0 | if (!client) |
1022 | 0 | { |
1023 | 0 | SetLastError(ERROR_INVALID_DATA); |
1024 | 0 | return INVALID_HANDLE_VALUE; |
1025 | 0 | } |
1026 | | |
1027 | 0 | vcm = (WTSVirtualChannelManager*)calloc(1, sizeof(WTSVirtualChannelManager)); |
1028 | |
|
1029 | 0 | if (!vcm) |
1030 | 0 | goto error_vcm_alloc; |
1031 | | |
1032 | 0 | vcm->client = client; |
1033 | 0 | vcm->rdp = context->rdp; |
1034 | 0 | vcm->SessionId = g_SessionId++; |
1035 | |
|
1036 | 0 | if (!g_ServerHandles) |
1037 | 0 | { |
1038 | 0 | g_ServerHandles = HashTable_New(TRUE); |
1039 | |
|
1040 | 0 | if (!g_ServerHandles) |
1041 | 0 | goto error_free; |
1042 | 0 | } |
1043 | | |
1044 | 0 | if (!HashTable_Insert(g_ServerHandles, (void*)(UINT_PTR)vcm->SessionId, (void*)vcm)) |
1045 | 0 | goto error_free; |
1046 | | |
1047 | 0 | queueCallbacks.fnObjectFree = wts_virtual_channel_manager_free_message; |
1048 | 0 | vcm->queue = MessageQueue_New(&queueCallbacks); |
1049 | |
|
1050 | 0 | if (!vcm->queue) |
1051 | 0 | goto error_queue; |
1052 | | |
1053 | 0 | vcm->dvc_channel_id_seq = 0; |
1054 | 0 | vcm->dynamicVirtualChannels = HashTable_New(TRUE); |
1055 | |
|
1056 | 0 | if (!vcm->dynamicVirtualChannels) |
1057 | 0 | goto error_dynamicVirtualChannels; |
1058 | | |
1059 | 0 | if (!HashTable_SetHashFunction(vcm->dynamicVirtualChannels, channelId_Hash)) |
1060 | 0 | goto error_hashFunction; |
1061 | | |
1062 | 0 | { |
1063 | 0 | wObject* obj = HashTable_ValueObject(vcm->dynamicVirtualChannels); |
1064 | 0 | WINPR_ASSERT(obj); |
1065 | 0 | obj->fnObjectFree = array_channel_free; |
1066 | |
|
1067 | 0 | obj = HashTable_KeyObject(vcm->dynamicVirtualChannels); |
1068 | 0 | obj->fnObjectEquals = dynChannelMatch; |
1069 | 0 | } |
1070 | 0 | client->ReceiveChannelData = WTSReceiveChannelData; |
1071 | 0 | hServer = (HANDLE)vcm; |
1072 | 0 | return hServer; |
1073 | | |
1074 | 0 | error_hashFunction: |
1075 | 0 | HashTable_Free(vcm->dynamicVirtualChannels); |
1076 | 0 | error_dynamicVirtualChannels: |
1077 | 0 | MessageQueue_Free(vcm->queue); |
1078 | 0 | error_queue: |
1079 | 0 | HashTable_Remove(g_ServerHandles, (void*)(UINT_PTR)vcm->SessionId); |
1080 | 0 | error_free: |
1081 | 0 | free(vcm); |
1082 | 0 | error_vcm_alloc: |
1083 | 0 | SetLastError(ERROR_NOT_ENOUGH_MEMORY); |
1084 | 0 | return INVALID_HANDLE_VALUE; |
1085 | 0 | } |
1086 | | |
1087 | | HANDLE WINAPI FreeRDP_WTSOpenServerExW(WINPR_ATTR_UNUSED LPWSTR pServerName) |
1088 | 0 | { |
1089 | 0 | WLog_ERR("TODO", "TODO: implement"); |
1090 | 0 | return INVALID_HANDLE_VALUE; |
1091 | 0 | } |
1092 | | |
1093 | | HANDLE WINAPI FreeRDP_WTSOpenServerExA(LPSTR pServerName) |
1094 | 0 | { |
1095 | 0 | return FreeRDP_WTSOpenServerA(pServerName); |
1096 | 0 | } |
1097 | | |
1098 | | VOID WINAPI FreeRDP_WTSCloseServer(HANDLE hServer) |
1099 | 0 | { |
1100 | 0 | WTSVirtualChannelManager* vcm = NULL; |
1101 | 0 | vcm = (WTSVirtualChannelManager*)hServer; |
1102 | |
|
1103 | 0 | if (vcm && (vcm != INVALID_HANDLE_VALUE)) |
1104 | 0 | { |
1105 | 0 | HashTable_Remove(g_ServerHandles, (void*)(UINT_PTR)vcm->SessionId); |
1106 | |
|
1107 | 0 | HashTable_Free(vcm->dynamicVirtualChannels); |
1108 | |
|
1109 | 0 | if (vcm->drdynvc_channel) |
1110 | 0 | { |
1111 | 0 | (void)WTSVirtualChannelClose(vcm->drdynvc_channel); |
1112 | 0 | vcm->drdynvc_channel = NULL; |
1113 | 0 | } |
1114 | |
|
1115 | 0 | MessageQueue_Free(vcm->queue); |
1116 | 0 | free(vcm); |
1117 | 0 | } |
1118 | 0 | } |
1119 | | |
1120 | | BOOL WINAPI FreeRDP_WTSEnumerateSessionsW(WINPR_ATTR_UNUSED HANDLE hServer, |
1121 | | WINPR_ATTR_UNUSED DWORD Reserved, |
1122 | | WINPR_ATTR_UNUSED DWORD Version, |
1123 | | WINPR_ATTR_UNUSED PWTS_SESSION_INFOW* ppSessionInfo, |
1124 | | WINPR_ATTR_UNUSED DWORD* pCount) |
1125 | 0 | { |
1126 | 0 | WLog_ERR("TODO", "TODO: implement"); |
1127 | 0 | return FALSE; |
1128 | 0 | } |
1129 | | |
1130 | | BOOL WINAPI FreeRDP_WTSEnumerateSessionsA(WINPR_ATTR_UNUSED HANDLE hServer, |
1131 | | WINPR_ATTR_UNUSED DWORD Reserved, |
1132 | | WINPR_ATTR_UNUSED DWORD Version, |
1133 | | WINPR_ATTR_UNUSED PWTS_SESSION_INFOA* ppSessionInfo, |
1134 | | WINPR_ATTR_UNUSED DWORD* pCount) |
1135 | 0 | { |
1136 | 0 | WLog_ERR("TODO", "TODO: implement"); |
1137 | 0 | return FALSE; |
1138 | 0 | } |
1139 | | |
1140 | | BOOL WINAPI FreeRDP_WTSEnumerateSessionsExW(WINPR_ATTR_UNUSED HANDLE hServer, |
1141 | | WINPR_ATTR_UNUSED DWORD* pLevel, |
1142 | | WINPR_ATTR_UNUSED DWORD Filter, |
1143 | | WINPR_ATTR_UNUSED PWTS_SESSION_INFO_1W* ppSessionInfo, |
1144 | | WINPR_ATTR_UNUSED DWORD* pCount) |
1145 | 0 | { |
1146 | 0 | WLog_ERR("TODO", "TODO: implement"); |
1147 | 0 | return FALSE; |
1148 | 0 | } |
1149 | | |
1150 | | BOOL WINAPI FreeRDP_WTSEnumerateSessionsExA(WINPR_ATTR_UNUSED HANDLE hServer, |
1151 | | WINPR_ATTR_UNUSED DWORD* pLevel, |
1152 | | WINPR_ATTR_UNUSED DWORD Filter, |
1153 | | WINPR_ATTR_UNUSED PWTS_SESSION_INFO_1A* ppSessionInfo, |
1154 | | WINPR_ATTR_UNUSED DWORD* pCount) |
1155 | 0 | { |
1156 | 0 | WLog_ERR("TODO", "TODO: implement"); |
1157 | 0 | return FALSE; |
1158 | 0 | } |
1159 | | |
1160 | | BOOL WINAPI FreeRDP_WTSEnumerateProcessesW(WINPR_ATTR_UNUSED HANDLE hServer, |
1161 | | WINPR_ATTR_UNUSED DWORD Reserved, |
1162 | | WINPR_ATTR_UNUSED DWORD Version, |
1163 | | WINPR_ATTR_UNUSED PWTS_PROCESS_INFOW* ppProcessInfo, |
1164 | | WINPR_ATTR_UNUSED DWORD* pCount) |
1165 | 0 | { |
1166 | 0 | WLog_ERR("TODO", "TODO: implement"); |
1167 | 0 | return FALSE; |
1168 | 0 | } |
1169 | | |
1170 | | BOOL WINAPI FreeRDP_WTSEnumerateProcessesA(WINPR_ATTR_UNUSED HANDLE hServer, |
1171 | | WINPR_ATTR_UNUSED DWORD Reserved, |
1172 | | WINPR_ATTR_UNUSED DWORD Version, |
1173 | | WINPR_ATTR_UNUSED PWTS_PROCESS_INFOA* ppProcessInfo, |
1174 | | WINPR_ATTR_UNUSED DWORD* pCount) |
1175 | 0 | { |
1176 | 0 | WLog_ERR("TODO", "TODO: implement"); |
1177 | 0 | return FALSE; |
1178 | 0 | } |
1179 | | |
1180 | | BOOL WINAPI FreeRDP_WTSTerminateProcess(WINPR_ATTR_UNUSED HANDLE hServer, |
1181 | | WINPR_ATTR_UNUSED DWORD ProcessId, |
1182 | | WINPR_ATTR_UNUSED DWORD ExitCode) |
1183 | 0 | { |
1184 | 0 | WLog_ERR("TODO", "TODO: implement"); |
1185 | 0 | return FALSE; |
1186 | 0 | } |
1187 | | |
1188 | | BOOL WINAPI FreeRDP_WTSQuerySessionInformationW(WINPR_ATTR_UNUSED HANDLE hServer, |
1189 | | WINPR_ATTR_UNUSED DWORD SessionId, |
1190 | | WINPR_ATTR_UNUSED WTS_INFO_CLASS WTSInfoClass, |
1191 | | WINPR_ATTR_UNUSED LPWSTR* ppBuffer, |
1192 | | WINPR_ATTR_UNUSED DWORD* pBytesReturned) |
1193 | 0 | { |
1194 | 0 | WLog_ERR("TODO", "TODO: implement"); |
1195 | 0 | return FALSE; |
1196 | 0 | } |
1197 | | |
1198 | | BOOL WINAPI FreeRDP_WTSQuerySessionInformationA(HANDLE hServer, WINPR_ATTR_UNUSED DWORD SessionId, |
1199 | | WTS_INFO_CLASS WTSInfoClass, LPSTR* ppBuffer, |
1200 | | DWORD* pBytesReturned) |
1201 | 0 | { |
1202 | 0 | DWORD BytesReturned = 0; |
1203 | 0 | WTSVirtualChannelManager* vcm = NULL; |
1204 | 0 | vcm = (WTSVirtualChannelManager*)hServer; |
1205 | |
|
1206 | 0 | if (!vcm) |
1207 | 0 | return FALSE; |
1208 | | |
1209 | 0 | if (WTSInfoClass == WTSSessionId) |
1210 | 0 | { |
1211 | 0 | ULONG* pBuffer = NULL; |
1212 | 0 | BytesReturned = sizeof(ULONG); |
1213 | 0 | pBuffer = (ULONG*)malloc(sizeof(BytesReturned)); |
1214 | |
|
1215 | 0 | if (!pBuffer) |
1216 | 0 | { |
1217 | 0 | SetLastError(g_err_oom); |
1218 | 0 | return FALSE; |
1219 | 0 | } |
1220 | | |
1221 | 0 | *pBuffer = vcm->SessionId; |
1222 | 0 | *ppBuffer = (LPSTR)pBuffer; |
1223 | 0 | *pBytesReturned = BytesReturned; |
1224 | 0 | return TRUE; |
1225 | 0 | } |
1226 | | |
1227 | 0 | return FALSE; |
1228 | 0 | } |
1229 | | |
1230 | | BOOL WINAPI FreeRDP_WTSQueryUserConfigW(WINPR_ATTR_UNUSED LPWSTR pServerName, |
1231 | | WINPR_ATTR_UNUSED LPWSTR pUserName, |
1232 | | WINPR_ATTR_UNUSED WTS_CONFIG_CLASS WTSConfigClass, |
1233 | | WINPR_ATTR_UNUSED LPWSTR* ppBuffer, |
1234 | | WINPR_ATTR_UNUSED DWORD* pBytesReturned) |
1235 | 0 | { |
1236 | 0 | WLog_ERR("TODO", "TODO: implement"); |
1237 | 0 | return FALSE; |
1238 | 0 | } |
1239 | | |
1240 | | BOOL WINAPI FreeRDP_WTSQueryUserConfigA(WINPR_ATTR_UNUSED LPSTR pServerName, |
1241 | | WINPR_ATTR_UNUSED LPSTR pUserName, |
1242 | | WINPR_ATTR_UNUSED WTS_CONFIG_CLASS WTSConfigClass, |
1243 | | WINPR_ATTR_UNUSED LPSTR* ppBuffer, |
1244 | | WINPR_ATTR_UNUSED DWORD* pBytesReturned) |
1245 | 0 | { |
1246 | 0 | WLog_ERR("TODO", "TODO: implement"); |
1247 | 0 | return FALSE; |
1248 | 0 | } |
1249 | | |
1250 | | BOOL WINAPI FreeRDP_WTSSetUserConfigW(WINPR_ATTR_UNUSED LPWSTR pServerName, |
1251 | | WINPR_ATTR_UNUSED LPWSTR pUserName, |
1252 | | WINPR_ATTR_UNUSED WTS_CONFIG_CLASS WTSConfigClass, |
1253 | | WINPR_ATTR_UNUSED LPWSTR pBuffer, |
1254 | | WINPR_ATTR_UNUSED DWORD DataLength) |
1255 | 0 | { |
1256 | 0 | WLog_ERR("TODO", "TODO: implement"); |
1257 | 0 | return FALSE; |
1258 | 0 | } |
1259 | | |
1260 | | BOOL WINAPI FreeRDP_WTSSetUserConfigA(WINPR_ATTR_UNUSED LPSTR pServerName, |
1261 | | WINPR_ATTR_UNUSED LPSTR pUserName, |
1262 | | WINPR_ATTR_UNUSED WTS_CONFIG_CLASS WTSConfigClass, |
1263 | | WINPR_ATTR_UNUSED LPSTR pBuffer, |
1264 | | WINPR_ATTR_UNUSED DWORD DataLength) |
1265 | 0 | { |
1266 | 0 | WLog_ERR("TODO", "TODO: implement"); |
1267 | 0 | return FALSE; |
1268 | 0 | } |
1269 | | |
1270 | | BOOL WINAPI |
1271 | | FreeRDP_WTSSendMessageW(WINPR_ATTR_UNUSED HANDLE hServer, WINPR_ATTR_UNUSED DWORD SessionId, |
1272 | | WINPR_ATTR_UNUSED LPWSTR pTitle, WINPR_ATTR_UNUSED DWORD TitleLength, |
1273 | | WINPR_ATTR_UNUSED LPWSTR pMessage, WINPR_ATTR_UNUSED DWORD MessageLength, |
1274 | | WINPR_ATTR_UNUSED DWORD Style, WINPR_ATTR_UNUSED DWORD Timeout, |
1275 | | WINPR_ATTR_UNUSED DWORD* pResponse, WINPR_ATTR_UNUSED BOOL bWait) |
1276 | 0 | { |
1277 | 0 | WLog_ERR("TODO", "TODO: implement"); |
1278 | 0 | return FALSE; |
1279 | 0 | } |
1280 | | |
1281 | | BOOL WINAPI |
1282 | | FreeRDP_WTSSendMessageA(WINPR_ATTR_UNUSED HANDLE hServer, WINPR_ATTR_UNUSED DWORD SessionId, |
1283 | | WINPR_ATTR_UNUSED LPSTR pTitle, WINPR_ATTR_UNUSED DWORD TitleLength, |
1284 | | WINPR_ATTR_UNUSED LPSTR pMessage, WINPR_ATTR_UNUSED DWORD MessageLength, |
1285 | | WINPR_ATTR_UNUSED DWORD Style, WINPR_ATTR_UNUSED DWORD Timeout, |
1286 | | WINPR_ATTR_UNUSED DWORD* pResponse, WINPR_ATTR_UNUSED BOOL bWait) |
1287 | 0 | { |
1288 | 0 | WLog_ERR("TODO", "TODO: implement"); |
1289 | 0 | return FALSE; |
1290 | 0 | } |
1291 | | |
1292 | | BOOL WINAPI FreeRDP_WTSDisconnectSession(WINPR_ATTR_UNUSED HANDLE hServer, |
1293 | | WINPR_ATTR_UNUSED DWORD SessionId, |
1294 | | WINPR_ATTR_UNUSED BOOL bWait) |
1295 | 0 | { |
1296 | 0 | WLog_ERR("TODO", "TODO: implement"); |
1297 | 0 | return FALSE; |
1298 | 0 | } |
1299 | | |
1300 | | BOOL WINAPI FreeRDP_WTSLogoffSession(WINPR_ATTR_UNUSED HANDLE hServer, |
1301 | | WINPR_ATTR_UNUSED DWORD SessionId, |
1302 | | WINPR_ATTR_UNUSED BOOL bWait) |
1303 | 0 | { |
1304 | 0 | WLog_ERR("TODO", "TODO: implement"); |
1305 | 0 | return FALSE; |
1306 | 0 | } |
1307 | | |
1308 | | BOOL WINAPI FreeRDP_WTSShutdownSystem(WINPR_ATTR_UNUSED HANDLE hServer, |
1309 | | WINPR_ATTR_UNUSED DWORD ShutdownFlag) |
1310 | 0 | { |
1311 | 0 | WLog_ERR("TODO", "TODO: implement"); |
1312 | 0 | return FALSE; |
1313 | 0 | } |
1314 | | |
1315 | | BOOL WINAPI FreeRDP_WTSWaitSystemEvent(WINPR_ATTR_UNUSED HANDLE hServer, |
1316 | | WINPR_ATTR_UNUSED DWORD EventMask, |
1317 | | WINPR_ATTR_UNUSED DWORD* pEventFlags) |
1318 | 0 | { |
1319 | 0 | WLog_ERR("TODO", "TODO: implement"); |
1320 | 0 | return FALSE; |
1321 | 0 | } |
1322 | | |
1323 | | static void peer_channel_queue_free_message(void* obj) |
1324 | 0 | { |
1325 | 0 | wMessage* msg = (wMessage*)obj; |
1326 | 0 | if (!msg) |
1327 | 0 | return; |
1328 | | |
1329 | 0 | free(msg->context); |
1330 | 0 | msg->context = NULL; |
1331 | 0 | } |
1332 | | |
1333 | | static rdpPeerChannel* channel_new(WTSVirtualChannelManager* vcm, freerdp_peer* client, |
1334 | | UINT32 ChannelId, UINT16 index, UINT16 type, size_t chunkSize, |
1335 | | const char* name) |
1336 | 0 | { |
1337 | 0 | wObject queueCallbacks = { 0 }; |
1338 | 0 | queueCallbacks.fnObjectFree = peer_channel_queue_free_message; |
1339 | |
|
1340 | 0 | rdpPeerChannel* channel = |
1341 | 0 | server_channel_common_new(client, index, ChannelId, chunkSize, &queueCallbacks, name); |
1342 | |
|
1343 | 0 | WINPR_ASSERT(vcm); |
1344 | 0 | WINPR_ASSERT(client); |
1345 | | |
1346 | 0 | if (!channel) |
1347 | 0 | goto fail; |
1348 | | |
1349 | 0 | channel->vcm = vcm; |
1350 | 0 | channel->channelType = type; |
1351 | 0 | channel->creationStatus = |
1352 | 0 | (type == RDP_PEER_CHANNEL_TYPE_SVC) ? ERROR_SUCCESS : ERROR_OPERATION_IN_PROGRESS; |
1353 | |
|
1354 | 0 | return channel; |
1355 | 0 | fail: |
1356 | 0 | channel_free(channel); |
1357 | 0 | return NULL; |
1358 | 0 | } |
1359 | | |
1360 | | HANDLE WINAPI FreeRDP_WTSVirtualChannelOpen(HANDLE hServer, WINPR_ATTR_UNUSED DWORD SessionId, |
1361 | | LPSTR pVirtualName) |
1362 | 0 | { |
1363 | 0 | size_t length = 0; |
1364 | 0 | rdpMcs* mcs = NULL; |
1365 | 0 | rdpMcsChannel* joined_channel = NULL; |
1366 | 0 | freerdp_peer* client = NULL; |
1367 | 0 | rdpPeerChannel* channel = NULL; |
1368 | 0 | WTSVirtualChannelManager* vcm = NULL; |
1369 | 0 | HANDLE hChannelHandle = NULL; |
1370 | 0 | rdpContext* context = NULL; |
1371 | 0 | vcm = (WTSVirtualChannelManager*)hServer; |
1372 | |
|
1373 | 0 | if (!vcm) |
1374 | 0 | { |
1375 | 0 | SetLastError(ERROR_INVALID_DATA); |
1376 | 0 | return NULL; |
1377 | 0 | } |
1378 | | |
1379 | 0 | client = vcm->client; |
1380 | 0 | WINPR_ASSERT(client); |
1381 | | |
1382 | 0 | context = client->context; |
1383 | 0 | WINPR_ASSERT(context); |
1384 | 0 | WINPR_ASSERT(context->rdp); |
1385 | 0 | WINPR_ASSERT(context->settings); |
1386 | | |
1387 | 0 | mcs = context->rdp->mcs; |
1388 | 0 | WINPR_ASSERT(mcs); |
1389 | | |
1390 | 0 | length = strnlen(pVirtualName, CHANNEL_NAME_LEN + 1); |
1391 | |
|
1392 | 0 | if (length > CHANNEL_NAME_LEN) |
1393 | 0 | { |
1394 | 0 | SetLastError(ERROR_NOT_FOUND); |
1395 | 0 | return NULL; |
1396 | 0 | } |
1397 | | |
1398 | 0 | UINT32 index = 0; |
1399 | 0 | for (; index < mcs->channelCount; index++) |
1400 | 0 | { |
1401 | 0 | rdpMcsChannel* mchannel = &mcs->channels[index]; |
1402 | 0 | if (mchannel->joined && (strncmp(mchannel->Name, pVirtualName, length) == 0)) |
1403 | 0 | { |
1404 | 0 | joined_channel = mchannel; |
1405 | 0 | break; |
1406 | 0 | } |
1407 | 0 | } |
1408 | |
|
1409 | 0 | if (!joined_channel) |
1410 | 0 | { |
1411 | 0 | SetLastError(ERROR_NOT_FOUND); |
1412 | 0 | return NULL; |
1413 | 0 | } |
1414 | | |
1415 | 0 | channel = (rdpPeerChannel*)joined_channel->handle; |
1416 | |
|
1417 | 0 | if (!channel) |
1418 | 0 | { |
1419 | 0 | const UINT32 VCChunkSize = |
1420 | 0 | freerdp_settings_get_uint32(context->settings, FreeRDP_VCChunkSize); |
1421 | |
|
1422 | 0 | WINPR_ASSERT(index <= UINT16_MAX); |
1423 | 0 | channel = channel_new(vcm, client, joined_channel->ChannelId, (UINT16)index, |
1424 | 0 | RDP_PEER_CHANNEL_TYPE_SVC, VCChunkSize, pVirtualName); |
1425 | |
|
1426 | 0 | if (!channel) |
1427 | 0 | goto fail; |
1428 | | |
1429 | 0 | joined_channel->handle = channel; |
1430 | 0 | } |
1431 | | |
1432 | 0 | hChannelHandle = (HANDLE)channel; |
1433 | 0 | return hChannelHandle; |
1434 | 0 | fail: |
1435 | 0 | channel_free(channel); |
1436 | 0 | SetLastError(ERROR_NOT_ENOUGH_MEMORY); |
1437 | 0 | return NULL; |
1438 | 0 | } |
1439 | | |
1440 | | HANDLE WINAPI FreeRDP_WTSVirtualChannelOpenEx(DWORD SessionId, LPSTR pVirtualName, DWORD flags) |
1441 | 0 | { |
1442 | 0 | wStream* s = NULL; |
1443 | 0 | rdpMcs* mcs = NULL; |
1444 | 0 | BOOL joined = FALSE; |
1445 | 0 | freerdp_peer* client = NULL; |
1446 | 0 | rdpPeerChannel* channel = NULL; |
1447 | 0 | ULONG written = 0; |
1448 | 0 | WTSVirtualChannelManager* vcm = NULL; |
1449 | |
|
1450 | 0 | if (SessionId == WTS_CURRENT_SESSION) |
1451 | 0 | return NULL; |
1452 | | |
1453 | 0 | vcm = (WTSVirtualChannelManager*)HashTable_GetItemValue(g_ServerHandles, |
1454 | 0 | (void*)(UINT_PTR)SessionId); |
1455 | |
|
1456 | 0 | if (!vcm) |
1457 | 0 | return NULL; |
1458 | | |
1459 | 0 | if (!(flags & WTS_CHANNEL_OPTION_DYNAMIC)) |
1460 | 0 | { |
1461 | 0 | return FreeRDP_WTSVirtualChannelOpen((HANDLE)vcm, SessionId, pVirtualName); |
1462 | 0 | } |
1463 | | |
1464 | 0 | client = vcm->client; |
1465 | 0 | mcs = client->context->rdp->mcs; |
1466 | |
|
1467 | 0 | for (UINT32 index = 0; index < mcs->channelCount; index++) |
1468 | 0 | { |
1469 | 0 | rdpMcsChannel* mchannel = &mcs->channels[index]; |
1470 | 0 | if (mchannel->joined && |
1471 | 0 | (strncmp(mchannel->Name, DRDYNVC_SVC_CHANNEL_NAME, CHANNEL_NAME_LEN + 1) == 0)) |
1472 | 0 | { |
1473 | 0 | joined = TRUE; |
1474 | 0 | break; |
1475 | 0 | } |
1476 | 0 | } |
1477 | |
|
1478 | 0 | if (!joined) |
1479 | 0 | { |
1480 | 0 | SetLastError(ERROR_NOT_FOUND); |
1481 | 0 | return NULL; |
1482 | 0 | } |
1483 | | |
1484 | 0 | if (!vcm->drdynvc_channel || (vcm->drdynvc_state != DRDYNVC_STATE_READY)) |
1485 | 0 | { |
1486 | 0 | SetLastError(ERROR_NOT_READY); |
1487 | 0 | return NULL; |
1488 | 0 | } |
1489 | | |
1490 | 0 | WINPR_ASSERT(client); |
1491 | 0 | WINPR_ASSERT(client->context); |
1492 | 0 | WINPR_ASSERT(client->context->settings); |
1493 | | |
1494 | 0 | const UINT32 VCChunkSize = |
1495 | 0 | freerdp_settings_get_uint32(client->context->settings, FreeRDP_VCChunkSize); |
1496 | 0 | channel = channel_new(vcm, client, 0, 0, RDP_PEER_CHANNEL_TYPE_DVC, VCChunkSize, pVirtualName); |
1497 | |
|
1498 | 0 | if (!channel) |
1499 | 0 | { |
1500 | 0 | SetLastError(ERROR_NOT_ENOUGH_MEMORY); |
1501 | 0 | return NULL; |
1502 | 0 | } |
1503 | | |
1504 | 0 | const LONG hdl = InterlockedIncrement(&vcm->dvc_channel_id_seq); |
1505 | 0 | channel->channelId = WINPR_ASSERTING_INT_CAST(uint32_t, hdl); |
1506 | | |
1507 | 0 | if (!HashTable_Insert(vcm->dynamicVirtualChannels, &channel->channelId, channel)) |
1508 | 0 | { |
1509 | 0 | channel_free(channel); |
1510 | 0 | channel = NULL; |
1511 | 0 | goto fail; |
1512 | 0 | } |
1513 | 0 | s = Stream_New(NULL, 64); |
1514 | |
|
1515 | 0 | if (!s) |
1516 | 0 | goto fail; |
1517 | | |
1518 | 0 | if (!wts_write_drdynvc_create_request(s, channel->channelId, pVirtualName)) |
1519 | 0 | goto fail; |
1520 | | |
1521 | 0 | const size_t pos = Stream_GetPosition(s); |
1522 | 0 | WINPR_ASSERT(pos <= UINT32_MAX); |
1523 | 0 | if (!WTSVirtualChannelWrite(vcm->drdynvc_channel, Stream_BufferAs(s, char), (UINT32)pos, |
1524 | 0 | &written)) |
1525 | 0 | goto fail; |
1526 | | |
1527 | 0 | Stream_Free(s, TRUE); |
1528 | 0 | return channel; |
1529 | 0 | fail: |
1530 | 0 | Stream_Free(s, TRUE); |
1531 | 0 | if (channel) |
1532 | 0 | HashTable_Remove(vcm->dynamicVirtualChannels, &channel->channelId); |
1533 | |
|
1534 | 0 | SetLastError(ERROR_NOT_ENOUGH_MEMORY); |
1535 | 0 | return NULL; |
1536 | 0 | } |
1537 | | |
1538 | | BOOL WINAPI FreeRDP_WTSVirtualChannelClose(HANDLE hChannelHandle) |
1539 | 0 | { |
1540 | 0 | wStream* s = NULL; |
1541 | 0 | rdpMcs* mcs = NULL; |
1542 | |
|
1543 | 0 | rdpPeerChannel* channel = (rdpPeerChannel*)hChannelHandle; |
1544 | 0 | BOOL ret = TRUE; |
1545 | |
|
1546 | 0 | if (channel) |
1547 | 0 | { |
1548 | 0 | WTSVirtualChannelManager* vcm = channel->vcm; |
1549 | |
|
1550 | 0 | WINPR_ASSERT(vcm); |
1551 | 0 | WINPR_ASSERT(vcm->client); |
1552 | 0 | WINPR_ASSERT(vcm->client->context); |
1553 | 0 | WINPR_ASSERT(vcm->client->context->rdp); |
1554 | 0 | mcs = vcm->client->context->rdp->mcs; |
1555 | |
|
1556 | 0 | if (channel->channelType == RDP_PEER_CHANNEL_TYPE_SVC) |
1557 | 0 | { |
1558 | 0 | if (channel->index < mcs->channelCount) |
1559 | 0 | { |
1560 | 0 | rdpMcsChannel* cur = &mcs->channels[channel->index]; |
1561 | 0 | rdpPeerChannel* peerChannel = (rdpPeerChannel*)cur->handle; |
1562 | 0 | channel_free(peerChannel); |
1563 | 0 | cur->handle = NULL; |
1564 | 0 | } |
1565 | 0 | } |
1566 | 0 | else |
1567 | 0 | { |
1568 | 0 | if (channel->dvc_open_state == DVC_OPEN_STATE_SUCCEEDED) |
1569 | 0 | { |
1570 | 0 | ULONG written = 0; |
1571 | 0 | s = Stream_New(NULL, 8); |
1572 | |
|
1573 | 0 | if (!s) |
1574 | 0 | { |
1575 | 0 | WLog_ERR(TAG, "Stream_New failed!"); |
1576 | 0 | ret = FALSE; |
1577 | 0 | } |
1578 | 0 | else |
1579 | 0 | { |
1580 | 0 | wts_write_drdynvc_header(s, CLOSE_REQUEST_PDU, channel->channelId); |
1581 | |
|
1582 | 0 | const size_t pos = Stream_GetPosition(s); |
1583 | 0 | WINPR_ASSERT(pos <= UINT32_MAX); |
1584 | 0 | ret = WTSVirtualChannelWrite(vcm->drdynvc_channel, Stream_BufferAs(s, char), |
1585 | 0 | (UINT32)pos, &written); |
1586 | 0 | Stream_Free(s, TRUE); |
1587 | 0 | } |
1588 | 0 | } |
1589 | 0 | HashTable_Remove(vcm->dynamicVirtualChannels, &channel->channelId); |
1590 | 0 | } |
1591 | 0 | } |
1592 | | |
1593 | 0 | return ret; |
1594 | 0 | } |
1595 | | |
1596 | | BOOL WINAPI FreeRDP_WTSVirtualChannelRead(HANDLE hChannelHandle, WINPR_ATTR_UNUSED ULONG TimeOut, |
1597 | | PCHAR Buffer, ULONG BufferSize, PULONG pBytesRead) |
1598 | 0 | { |
1599 | 0 | BYTE* buffer = NULL; |
1600 | 0 | wMessage message = { 0 }; |
1601 | 0 | wtsChannelMessage* messageCtx = NULL; |
1602 | 0 | rdpPeerChannel* channel = (rdpPeerChannel*)hChannelHandle; |
1603 | |
|
1604 | 0 | WINPR_ASSERT(channel); |
1605 | | |
1606 | 0 | if (!MessageQueue_Peek(channel->queue, &message, FALSE)) |
1607 | 0 | { |
1608 | 0 | SetLastError(ERROR_NO_DATA); |
1609 | 0 | *pBytesRead = 0; |
1610 | 0 | return FALSE; |
1611 | 0 | } |
1612 | | |
1613 | 0 | messageCtx = message.context; |
1614 | |
|
1615 | 0 | if (messageCtx == NULL) |
1616 | 0 | return FALSE; |
1617 | | |
1618 | 0 | buffer = (BYTE*)(messageCtx + 1); |
1619 | 0 | *pBytesRead = messageCtx->length - messageCtx->offset; |
1620 | |
|
1621 | 0 | if (Buffer == NULL || BufferSize == 0) |
1622 | 0 | { |
1623 | 0 | return TRUE; |
1624 | 0 | } |
1625 | | |
1626 | 0 | if (*pBytesRead > BufferSize) |
1627 | 0 | *pBytesRead = BufferSize; |
1628 | |
|
1629 | 0 | CopyMemory(Buffer, buffer + messageCtx->offset, *pBytesRead); |
1630 | 0 | messageCtx->offset += *pBytesRead; |
1631 | |
|
1632 | 0 | if (messageCtx->offset >= messageCtx->length) |
1633 | 0 | { |
1634 | 0 | (void)MessageQueue_Peek(channel->queue, &message, TRUE); |
1635 | 0 | peer_channel_queue_free_message(&message); |
1636 | 0 | } |
1637 | |
|
1638 | 0 | return TRUE; |
1639 | 0 | } |
1640 | | |
1641 | | BOOL WINAPI FreeRDP_WTSVirtualChannelWrite(HANDLE hChannelHandle, PCHAR Buffer, ULONG uLength, |
1642 | | PULONG pBytesWritten) |
1643 | 0 | { |
1644 | 0 | wStream* s = NULL; |
1645 | 0 | int cbLen = 0; |
1646 | 0 | int cbChId = 0; |
1647 | 0 | int first = 0; |
1648 | 0 | BYTE* buffer = NULL; |
1649 | 0 | size_t totalWritten = 0; |
1650 | 0 | rdpPeerChannel* channel = (rdpPeerChannel*)hChannelHandle; |
1651 | 0 | BOOL ret = FALSE; |
1652 | |
|
1653 | 0 | if (!channel) |
1654 | 0 | return FALSE; |
1655 | | |
1656 | 0 | EnterCriticalSection(&channel->writeLock); |
1657 | 0 | WINPR_ASSERT(channel->vcm); |
1658 | 0 | if (channel->channelType == RDP_PEER_CHANNEL_TYPE_SVC) |
1659 | 0 | { |
1660 | 0 | buffer = (BYTE*)malloc(uLength); |
1661 | |
|
1662 | 0 | if (!buffer) |
1663 | 0 | { |
1664 | 0 | SetLastError(g_err_oom); |
1665 | 0 | goto fail; |
1666 | 0 | } |
1667 | | |
1668 | 0 | CopyMemory(buffer, Buffer, uLength); |
1669 | 0 | totalWritten = uLength; |
1670 | 0 | if (!wts_queue_send_item(channel, buffer, uLength)) |
1671 | 0 | goto fail; |
1672 | 0 | } |
1673 | 0 | else if (!channel->vcm->drdynvc_channel || (channel->vcm->drdynvc_state != DRDYNVC_STATE_READY)) |
1674 | 0 | { |
1675 | 0 | DEBUG_DVC("drdynvc not ready"); |
1676 | 0 | goto fail; |
1677 | 0 | } |
1678 | 0 | else |
1679 | 0 | { |
1680 | 0 | first = TRUE; |
1681 | |
|
1682 | 0 | size_t Length = uLength; |
1683 | 0 | while (Length > 0) |
1684 | 0 | { |
1685 | 0 | s = Stream_New(NULL, DVC_MAX_DATA_PDU_SIZE); |
1686 | |
|
1687 | 0 | if (!s) |
1688 | 0 | { |
1689 | 0 | WLog_ERR(TAG, "Stream_New failed!"); |
1690 | 0 | SetLastError(g_err_oom); |
1691 | 0 | goto fail; |
1692 | 0 | } |
1693 | | |
1694 | 0 | buffer = Stream_Buffer(s); |
1695 | 0 | Stream_Seek_UINT8(s); |
1696 | 0 | cbChId = wts_write_variable_uint(s, channel->channelId); |
1697 | |
|
1698 | 0 | if (first && (Length > Stream_GetRemainingLength(s))) |
1699 | 0 | { |
1700 | 0 | cbLen = wts_write_variable_uint(s, WINPR_ASSERTING_INT_CAST(uint32_t, Length)); |
1701 | 0 | buffer[0] = ((DATA_FIRST_PDU << 4) | (cbLen << 2) | cbChId) & 0xFF; |
1702 | 0 | } |
1703 | 0 | else |
1704 | 0 | { |
1705 | 0 | buffer[0] = ((DATA_PDU << 4) | cbChId) & 0xFF; |
1706 | 0 | } |
1707 | | |
1708 | 0 | first = FALSE; |
1709 | 0 | size_t written = Stream_GetRemainingLength(s); |
1710 | |
|
1711 | 0 | if (written > Length) |
1712 | 0 | written = Length; |
1713 | |
|
1714 | 0 | Stream_Write(s, Buffer, written); |
1715 | 0 | const size_t length = Stream_GetPosition(s); |
1716 | 0 | Stream_Free(s, FALSE); |
1717 | 0 | if (length > UINT32_MAX) |
1718 | 0 | goto fail; |
1719 | 0 | Length -= written; |
1720 | 0 | Buffer += written; |
1721 | 0 | totalWritten += written; |
1722 | 0 | if (!wts_queue_send_item(channel->vcm->drdynvc_channel, buffer, (UINT32)length)) |
1723 | 0 | goto fail; |
1724 | 0 | } |
1725 | 0 | } |
1726 | | |
1727 | 0 | if (pBytesWritten) |
1728 | 0 | *pBytesWritten = WINPR_ASSERTING_INT_CAST(uint32_t, totalWritten); |
1729 | | |
1730 | 0 | ret = TRUE; |
1731 | 0 | fail: |
1732 | 0 | LeaveCriticalSection(&channel->writeLock); |
1733 | 0 | return ret; |
1734 | 0 | } |
1735 | | |
1736 | | BOOL WINAPI FreeRDP_WTSVirtualChannelPurgeInput(WINPR_ATTR_UNUSED HANDLE hChannelHandle) |
1737 | 0 | { |
1738 | 0 | WLog_ERR("TODO", "TODO: implement"); |
1739 | 0 | return TRUE; |
1740 | 0 | } |
1741 | | |
1742 | | BOOL WINAPI FreeRDP_WTSVirtualChannelPurgeOutput(WINPR_ATTR_UNUSED HANDLE hChannelHandle) |
1743 | 0 | { |
1744 | 0 | WLog_ERR("TODO", "TODO: implement"); |
1745 | 0 | return TRUE; |
1746 | 0 | } |
1747 | | |
1748 | | BOOL WINAPI FreeRDP_WTSVirtualChannelQuery(HANDLE hChannelHandle, WTS_VIRTUAL_CLASS WtsVirtualClass, |
1749 | | PVOID* ppBuffer, DWORD* pBytesReturned) |
1750 | 0 | { |
1751 | 0 | void* pfd = NULL; |
1752 | 0 | BOOL bval = 0; |
1753 | 0 | void* fds[10] = { 0 }; |
1754 | 0 | HANDLE hEvent = NULL; |
1755 | 0 | int fds_count = 0; |
1756 | 0 | BOOL status = FALSE; |
1757 | 0 | rdpPeerChannel* channel = (rdpPeerChannel*)hChannelHandle; |
1758 | |
|
1759 | 0 | WINPR_ASSERT(channel); |
1760 | | |
1761 | 0 | switch ((UINT32)WtsVirtualClass) |
1762 | 0 | { |
1763 | 0 | case WTSVirtualFileHandle: |
1764 | 0 | hEvent = MessageQueue_Event(channel->queue); |
1765 | 0 | pfd = GetEventWaitObject(hEvent); |
1766 | |
|
1767 | 0 | if (pfd) |
1768 | 0 | { |
1769 | 0 | fds[fds_count] = pfd; |
1770 | 0 | (fds_count)++; |
1771 | 0 | } |
1772 | |
|
1773 | 0 | *ppBuffer = malloc(sizeof(void*)); |
1774 | |
|
1775 | 0 | if (!*ppBuffer) |
1776 | 0 | { |
1777 | 0 | SetLastError(g_err_oom); |
1778 | 0 | } |
1779 | 0 | else |
1780 | 0 | { |
1781 | 0 | CopyMemory(*ppBuffer, (void*)&fds[0], sizeof(void*)); |
1782 | 0 | *pBytesReturned = sizeof(void*); |
1783 | 0 | status = TRUE; |
1784 | 0 | } |
1785 | |
|
1786 | 0 | break; |
1787 | | |
1788 | 0 | case WTSVirtualEventHandle: |
1789 | 0 | hEvent = MessageQueue_Event(channel->queue); |
1790 | |
|
1791 | 0 | *ppBuffer = malloc(sizeof(HANDLE)); |
1792 | |
|
1793 | 0 | if (!*ppBuffer) |
1794 | 0 | { |
1795 | 0 | SetLastError(g_err_oom); |
1796 | 0 | } |
1797 | 0 | else |
1798 | 0 | { |
1799 | 0 | CopyMemory(*ppBuffer, (void*)&hEvent, sizeof(HANDLE)); |
1800 | 0 | *pBytesReturned = sizeof(void*); |
1801 | 0 | status = TRUE; |
1802 | 0 | } |
1803 | |
|
1804 | 0 | break; |
1805 | | |
1806 | 0 | case WTSVirtualChannelReady: |
1807 | 0 | if (channel->channelType == RDP_PEER_CHANNEL_TYPE_SVC) |
1808 | 0 | { |
1809 | 0 | bval = TRUE; |
1810 | 0 | status = TRUE; |
1811 | 0 | } |
1812 | 0 | else |
1813 | 0 | { |
1814 | 0 | switch (channel->dvc_open_state) |
1815 | 0 | { |
1816 | 0 | case DVC_OPEN_STATE_NONE: |
1817 | 0 | bval = FALSE; |
1818 | 0 | status = TRUE; |
1819 | 0 | break; |
1820 | | |
1821 | 0 | case DVC_OPEN_STATE_SUCCEEDED: |
1822 | 0 | bval = TRUE; |
1823 | 0 | status = TRUE; |
1824 | 0 | break; |
1825 | | |
1826 | 0 | default: |
1827 | 0 | *ppBuffer = NULL; |
1828 | 0 | *pBytesReturned = 0; |
1829 | 0 | return FALSE; |
1830 | 0 | } |
1831 | 0 | } |
1832 | | |
1833 | 0 | *ppBuffer = malloc(sizeof(BOOL)); |
1834 | |
|
1835 | 0 | if (!*ppBuffer) |
1836 | 0 | { |
1837 | 0 | SetLastError(g_err_oom); |
1838 | 0 | status = FALSE; |
1839 | 0 | } |
1840 | 0 | else |
1841 | 0 | { |
1842 | 0 | CopyMemory(*ppBuffer, &bval, sizeof(BOOL)); |
1843 | 0 | *pBytesReturned = sizeof(BOOL); |
1844 | 0 | } |
1845 | |
|
1846 | 0 | break; |
1847 | 0 | case WTSVirtualChannelOpenStatus: |
1848 | 0 | { |
1849 | 0 | INT32 value = channel->creationStatus; |
1850 | 0 | status = TRUE; |
1851 | |
|
1852 | 0 | *ppBuffer = malloc(sizeof(value)); |
1853 | 0 | if (!*ppBuffer) |
1854 | 0 | { |
1855 | 0 | SetLastError(g_err_oom); |
1856 | 0 | status = FALSE; |
1857 | 0 | } |
1858 | 0 | else |
1859 | 0 | { |
1860 | 0 | CopyMemory(*ppBuffer, &value, sizeof(value)); |
1861 | 0 | *pBytesReturned = sizeof(value); |
1862 | 0 | } |
1863 | 0 | break; |
1864 | 0 | } |
1865 | 0 | default: |
1866 | 0 | break; |
1867 | 0 | } |
1868 | | |
1869 | 0 | return status; |
1870 | 0 | } |
1871 | | |
1872 | | VOID WINAPI FreeRDP_WTSFreeMemory(PVOID pMemory) |
1873 | 0 | { |
1874 | 0 | free(pMemory); |
1875 | 0 | } |
1876 | | |
1877 | | BOOL WINAPI FreeRDP_WTSFreeMemoryExW(WINPR_ATTR_UNUSED WTS_TYPE_CLASS WTSTypeClass, |
1878 | | WINPR_ATTR_UNUSED PVOID pMemory, |
1879 | | WINPR_ATTR_UNUSED ULONG NumberOfEntries) |
1880 | 0 | { |
1881 | 0 | WLog_ERR("TODO", "TODO: implement"); |
1882 | 0 | return FALSE; |
1883 | 0 | } |
1884 | | |
1885 | | BOOL WINAPI FreeRDP_WTSFreeMemoryExA(WINPR_ATTR_UNUSED WTS_TYPE_CLASS WTSTypeClass, |
1886 | | WINPR_ATTR_UNUSED PVOID pMemory, |
1887 | | WINPR_ATTR_UNUSED ULONG NumberOfEntries) |
1888 | 0 | { |
1889 | 0 | WLog_ERR("TODO", "TODO: implement"); |
1890 | 0 | return FALSE; |
1891 | 0 | } |
1892 | | |
1893 | | BOOL WINAPI FreeRDP_WTSRegisterSessionNotification(WINPR_ATTR_UNUSED HWND hWnd, |
1894 | | WINPR_ATTR_UNUSED DWORD dwFlags) |
1895 | 0 | { |
1896 | 0 | WLog_ERR("TODO", "TODO: implement"); |
1897 | 0 | return FALSE; |
1898 | 0 | } |
1899 | | |
1900 | | BOOL WINAPI FreeRDP_WTSUnRegisterSessionNotification(WINPR_ATTR_UNUSED HWND hWnd) |
1901 | 0 | { |
1902 | 0 | WLog_ERR("TODO", "TODO: implement"); |
1903 | 0 | return FALSE; |
1904 | 0 | } |
1905 | | |
1906 | | BOOL WINAPI FreeRDP_WTSRegisterSessionNotificationEx(WINPR_ATTR_UNUSED HANDLE hServer, |
1907 | | WINPR_ATTR_UNUSED HWND hWnd, |
1908 | | WINPR_ATTR_UNUSED DWORD dwFlags) |
1909 | 0 | { |
1910 | 0 | WLog_ERR("TODO", "TODO: implement"); |
1911 | 0 | return FALSE; |
1912 | 0 | } |
1913 | | |
1914 | | BOOL WINAPI FreeRDP_WTSUnRegisterSessionNotificationEx(WINPR_ATTR_UNUSED HANDLE hServer, |
1915 | | WINPR_ATTR_UNUSED HWND hWnd) |
1916 | 0 | { |
1917 | 0 | WLog_ERR("TODO", "TODO: implement"); |
1918 | 0 | return FALSE; |
1919 | 0 | } |
1920 | | |
1921 | | BOOL WINAPI FreeRDP_WTSQueryUserToken(WINPR_ATTR_UNUSED ULONG SessionId, |
1922 | | WINPR_ATTR_UNUSED PHANDLE phToken) |
1923 | 0 | { |
1924 | 0 | WLog_ERR("TODO", "TODO: implement"); |
1925 | 0 | return FALSE; |
1926 | 0 | } |
1927 | | |
1928 | | BOOL WINAPI FreeRDP_WTSEnumerateProcessesExW(WINPR_ATTR_UNUSED HANDLE hServer, |
1929 | | WINPR_ATTR_UNUSED DWORD* pLevel, |
1930 | | WINPR_ATTR_UNUSED DWORD SessionId, |
1931 | | WINPR_ATTR_UNUSED LPWSTR* ppProcessInfo, |
1932 | | WINPR_ATTR_UNUSED DWORD* pCount) |
1933 | 0 | { |
1934 | 0 | WLog_ERR("TODO", "TODO: implement"); |
1935 | 0 | return FALSE; |
1936 | 0 | } |
1937 | | |
1938 | | BOOL WINAPI FreeRDP_WTSEnumerateProcessesExA(WINPR_ATTR_UNUSED HANDLE hServer, |
1939 | | WINPR_ATTR_UNUSED DWORD* pLevel, |
1940 | | WINPR_ATTR_UNUSED DWORD SessionId, |
1941 | | WINPR_ATTR_UNUSED LPSTR* ppProcessInfo, |
1942 | | WINPR_ATTR_UNUSED DWORD* pCount) |
1943 | 0 | { |
1944 | 0 | WLog_ERR("TODO", "TODO: implement"); |
1945 | 0 | return FALSE; |
1946 | 0 | } |
1947 | | |
1948 | | BOOL WINAPI FreeRDP_WTSEnumerateListenersW(WINPR_ATTR_UNUSED HANDLE hServer, |
1949 | | WINPR_ATTR_UNUSED PVOID pReserved, |
1950 | | WINPR_ATTR_UNUSED DWORD Reserved, |
1951 | | WINPR_ATTR_UNUSED PWTSLISTENERNAMEW pListeners, |
1952 | | WINPR_ATTR_UNUSED DWORD* pCount) |
1953 | 0 | { |
1954 | 0 | WLog_ERR("TODO", "TODO: implement"); |
1955 | 0 | return FALSE; |
1956 | 0 | } |
1957 | | |
1958 | | BOOL WINAPI FreeRDP_WTSEnumerateListenersA(WINPR_ATTR_UNUSED HANDLE hServer, |
1959 | | WINPR_ATTR_UNUSED PVOID pReserved, |
1960 | | WINPR_ATTR_UNUSED DWORD Reserved, |
1961 | | WINPR_ATTR_UNUSED PWTSLISTENERNAMEA pListeners, |
1962 | | WINPR_ATTR_UNUSED DWORD* pCount) |
1963 | 0 | { |
1964 | 0 | WLog_ERR("TODO", "TODO: implement"); |
1965 | 0 | return FALSE; |
1966 | 0 | } |
1967 | | |
1968 | | BOOL WINAPI FreeRDP_WTSQueryListenerConfigW(WINPR_ATTR_UNUSED HANDLE hServer, |
1969 | | WINPR_ATTR_UNUSED PVOID pReserved, |
1970 | | WINPR_ATTR_UNUSED DWORD Reserved, |
1971 | | WINPR_ATTR_UNUSED LPWSTR pListenerName, |
1972 | | WINPR_ATTR_UNUSED PWTSLISTENERCONFIGW pBuffer) |
1973 | 0 | { |
1974 | 0 | WLog_ERR("TODO", "TODO: implement"); |
1975 | 0 | return FALSE; |
1976 | 0 | } |
1977 | | |
1978 | | BOOL WINAPI FreeRDP_WTSQueryListenerConfigA(WINPR_ATTR_UNUSED HANDLE hServer, |
1979 | | WINPR_ATTR_UNUSED PVOID pReserved, |
1980 | | WINPR_ATTR_UNUSED DWORD Reserved, |
1981 | | WINPR_ATTR_UNUSED LPSTR pListenerName, |
1982 | | WINPR_ATTR_UNUSED PWTSLISTENERCONFIGA pBuffer) |
1983 | 0 | { |
1984 | 0 | WLog_ERR("TODO", "TODO: implement"); |
1985 | 0 | return FALSE; |
1986 | 0 | } |
1987 | | |
1988 | | BOOL WINAPI FreeRDP_WTSCreateListenerW(WINPR_ATTR_UNUSED HANDLE hServer, |
1989 | | WINPR_ATTR_UNUSED PVOID pReserved, |
1990 | | WINPR_ATTR_UNUSED DWORD Reserved, |
1991 | | WINPR_ATTR_UNUSED LPWSTR pListenerName, |
1992 | | WINPR_ATTR_UNUSED PWTSLISTENERCONFIGW pBuffer, |
1993 | | WINPR_ATTR_UNUSED DWORD flag) |
1994 | 0 | { |
1995 | 0 | WLog_ERR("TODO", "TODO: implement"); |
1996 | 0 | return FALSE; |
1997 | 0 | } |
1998 | | |
1999 | | BOOL WINAPI FreeRDP_WTSCreateListenerA(WINPR_ATTR_UNUSED HANDLE hServer, |
2000 | | WINPR_ATTR_UNUSED PVOID pReserved, |
2001 | | WINPR_ATTR_UNUSED DWORD Reserved, |
2002 | | WINPR_ATTR_UNUSED LPSTR pListenerName, |
2003 | | WINPR_ATTR_UNUSED PWTSLISTENERCONFIGA pBuffer, |
2004 | | WINPR_ATTR_UNUSED DWORD flag) |
2005 | 0 | { |
2006 | 0 | WLog_ERR("TODO", "TODO: implement"); |
2007 | 0 | return FALSE; |
2008 | 0 | } |
2009 | | |
2010 | | BOOL WINAPI FreeRDP_WTSSetListenerSecurityW( |
2011 | | WINPR_ATTR_UNUSED HANDLE hServer, WINPR_ATTR_UNUSED PVOID pReserved, |
2012 | | WINPR_ATTR_UNUSED DWORD Reserved, WINPR_ATTR_UNUSED LPWSTR pListenerName, |
2013 | | WINPR_ATTR_UNUSED SECURITY_INFORMATION SecurityInformation, |
2014 | | WINPR_ATTR_UNUSED PSECURITY_DESCRIPTOR pSecurityDescriptor) |
2015 | 0 | { |
2016 | 0 | WLog_ERR("TODO", "TODO: implement"); |
2017 | 0 | return FALSE; |
2018 | 0 | } |
2019 | | |
2020 | | BOOL WINAPI FreeRDP_WTSSetListenerSecurityA( |
2021 | | WINPR_ATTR_UNUSED HANDLE hServer, WINPR_ATTR_UNUSED PVOID pReserved, |
2022 | | WINPR_ATTR_UNUSED DWORD Reserved, WINPR_ATTR_UNUSED LPSTR pListenerName, |
2023 | | WINPR_ATTR_UNUSED SECURITY_INFORMATION SecurityInformation, |
2024 | | WINPR_ATTR_UNUSED PSECURITY_DESCRIPTOR pSecurityDescriptor) |
2025 | 0 | { |
2026 | 0 | WLog_ERR("TODO", "TODO: implement"); |
2027 | 0 | return FALSE; |
2028 | 0 | } |
2029 | | |
2030 | | BOOL WINAPI FreeRDP_WTSGetListenerSecurityW( |
2031 | | WINPR_ATTR_UNUSED HANDLE hServer, WINPR_ATTR_UNUSED PVOID pReserved, |
2032 | | WINPR_ATTR_UNUSED DWORD Reserved, WINPR_ATTR_UNUSED LPWSTR pListenerName, |
2033 | | WINPR_ATTR_UNUSED SECURITY_INFORMATION SecurityInformation, |
2034 | | WINPR_ATTR_UNUSED PSECURITY_DESCRIPTOR pSecurityDescriptor, WINPR_ATTR_UNUSED DWORD nLength, |
2035 | | WINPR_ATTR_UNUSED LPDWORD lpnLengthNeeded) |
2036 | 0 | { |
2037 | 0 | WLog_ERR("TODO", "TODO: implement"); |
2038 | 0 | return FALSE; |
2039 | 0 | } |
2040 | | |
2041 | | BOOL WINAPI FreeRDP_WTSGetListenerSecurityA( |
2042 | | WINPR_ATTR_UNUSED HANDLE hServer, WINPR_ATTR_UNUSED PVOID pReserved, |
2043 | | WINPR_ATTR_UNUSED DWORD Reserved, WINPR_ATTR_UNUSED LPSTR pListenerName, |
2044 | | WINPR_ATTR_UNUSED SECURITY_INFORMATION SecurityInformation, |
2045 | | WINPR_ATTR_UNUSED PSECURITY_DESCRIPTOR pSecurityDescriptor, WINPR_ATTR_UNUSED DWORD nLength, |
2046 | | WINPR_ATTR_UNUSED LPDWORD lpnLengthNeeded) |
2047 | 0 | { |
2048 | 0 | WLog_ERR("TODO", "TODO: implement"); |
2049 | 0 | return FALSE; |
2050 | 0 | } |
2051 | | |
2052 | | BOOL CDECL FreeRDP_WTSEnableChildSessions(WINPR_ATTR_UNUSED BOOL bEnable) |
2053 | 0 | { |
2054 | 0 | WLog_ERR("TODO", "TODO: implement"); |
2055 | 0 | return FALSE; |
2056 | 0 | } |
2057 | | |
2058 | | BOOL CDECL FreeRDP_WTSIsChildSessionsEnabled(WINPR_ATTR_UNUSED PBOOL pbEnabled) |
2059 | 0 | { |
2060 | 0 | WLog_ERR("TODO", "TODO: implement"); |
2061 | 0 | return FALSE; |
2062 | 0 | } |
2063 | | |
2064 | | BOOL CDECL FreeRDP_WTSGetChildSessionId(WINPR_ATTR_UNUSED PULONG pSessionId) |
2065 | 0 | { |
2066 | 0 | WLog_ERR("TODO", "TODO: implement"); |
2067 | 0 | return FALSE; |
2068 | 0 | } |
2069 | | |
2070 | | DWORD WINAPI FreeRDP_WTSGetActiveConsoleSessionId(void) |
2071 | 0 | { |
2072 | 0 | WLog_ERR("TODO", "TODO: implement"); |
2073 | 0 | return 0xFFFFFFFF; |
2074 | 0 | } |
2075 | | BOOL WINAPI FreeRDP_WTSLogoffUser(WINPR_ATTR_UNUSED HANDLE hServer) |
2076 | 0 | { |
2077 | 0 | WLog_ERR("TODO", "TODO: implement"); |
2078 | 0 | return FALSE; |
2079 | 0 | } |
2080 | | |
2081 | | BOOL WINAPI FreeRDP_WTSLogonUser(WINPR_ATTR_UNUSED HANDLE hServer, |
2082 | | WINPR_ATTR_UNUSED LPCSTR username, |
2083 | | WINPR_ATTR_UNUSED LPCSTR password, WINPR_ATTR_UNUSED LPCSTR domain) |
2084 | 0 | { |
2085 | 0 | WLog_ERR("TODO", "TODO: implement"); |
2086 | 0 | return FALSE; |
2087 | 0 | } |
2088 | | |
2089 | | void server_channel_common_free(rdpPeerChannel* channel) |
2090 | 0 | { |
2091 | 0 | if (!channel) |
2092 | 0 | return; |
2093 | 0 | MessageQueue_Free(channel->queue); |
2094 | 0 | Stream_Free(channel->receiveData, TRUE); |
2095 | 0 | DeleteCriticalSection(&channel->writeLock); |
2096 | 0 | free(channel); |
2097 | 0 | } |
2098 | | |
2099 | | rdpPeerChannel* server_channel_common_new(freerdp_peer* client, UINT16 index, UINT32 channelId, |
2100 | | size_t chunkSize, const wObject* callback, |
2101 | | const char* name) |
2102 | 0 | { |
2103 | 0 | rdpPeerChannel* channel = (rdpPeerChannel*)calloc(1, sizeof(rdpPeerChannel)); |
2104 | 0 | if (!channel) |
2105 | 0 | return NULL; |
2106 | | |
2107 | 0 | InitializeCriticalSection(&channel->writeLock); |
2108 | |
|
2109 | 0 | channel->receiveData = Stream_New(NULL, chunkSize); |
2110 | 0 | if (!channel->receiveData) |
2111 | 0 | goto fail; |
2112 | | |
2113 | 0 | channel->queue = MessageQueue_New(callback); |
2114 | 0 | if (!channel->queue) |
2115 | 0 | goto fail; |
2116 | | |
2117 | 0 | channel->index = index; |
2118 | 0 | channel->client = client; |
2119 | 0 | channel->channelId = channelId; |
2120 | 0 | strncpy(channel->channelName, name, ARRAYSIZE(channel->channelName) - 1); |
2121 | 0 | return channel; |
2122 | 0 | fail: |
2123 | 0 | WINPR_PRAGMA_DIAG_PUSH |
2124 | 0 | WINPR_PRAGMA_DIAG_IGNORED_MISMATCHED_DEALLOC |
2125 | 0 | server_channel_common_free(channel); |
2126 | 0 | WINPR_PRAGMA_DIAG_POP |
2127 | 0 | return NULL; |
2128 | 0 | } |