/src/FreeRDP/libfreerdp/core/mcs.c
Line | Count | Source |
1 | | /** |
2 | | * FreeRDP: A Remote Desktop Protocol Implementation |
3 | | * T.125 Multipoint Communication Service (MCS) Protocol |
4 | | * |
5 | | * Copyright 2011 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 | | * Copyright 2017 Armin Novak <armin.novak@thincast.com> |
9 | | * Copyright 2017 Thincast Technologies GmbH |
10 | | * |
11 | | * Licensed under the Apache License, Version 2.0 (the "License"); |
12 | | * you may not use this file except in compliance with the License. |
13 | | * You may obtain a copy of the License at |
14 | | * |
15 | | * http://www.apache.org/licenses/LICENSE-2.0 |
16 | | * |
17 | | * Unless required by applicable law or agreed to in writing, software |
18 | | * distributed under the License is distributed on an "AS IS" BASIS, |
19 | | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
20 | | * See the License for the specific language governing permissions and |
21 | | * limitations under the License. |
22 | | */ |
23 | | |
24 | | #include <freerdp/config.h> |
25 | | |
26 | | #include <winpr/crt.h> |
27 | | #include <winpr/assert.h> |
28 | | #include <freerdp/log.h> |
29 | | |
30 | | #include "gcc.h" |
31 | | |
32 | | #include "mcs.h" |
33 | | #include "tpdu.h" |
34 | | #include "tpkt.h" |
35 | | #include "client.h" |
36 | | #include "connection.h" |
37 | | |
38 | 43.2k | #define MCS_TAG FREERDP_TAG("core") |
39 | | |
40 | | /** |
41 | | * T.125 MCS is defined in: |
42 | | * |
43 | | * http://www.itu.int/rec/T-REC-T.125-199802-I/ |
44 | | * ITU-T T.125 Multipoint Communication Service Protocol Specification |
45 | | */ |
46 | | |
47 | | /** |
48 | | * Connect-Initial ::= [APPLICATION 101] IMPLICIT SEQUENCE |
49 | | * { |
50 | | * callingDomainSelector OCTET_STRING, |
51 | | * calledDomainSelector OCTET_STRING, |
52 | | * upwardFlag BOOLEAN, |
53 | | * targetParameters DomainParameters, |
54 | | * minimumParameters DomainParameters, |
55 | | * maximumParameters DomainParameters, |
56 | | * userData OCTET_STRING |
57 | | * } |
58 | | * |
59 | | * DomainParameters ::= SEQUENCE |
60 | | * { |
61 | | * maxChannelIds INTEGER (0..MAX), |
62 | | * maxUserIds INTEGER (0..MAX), |
63 | | * maxTokenIds INTEGER (0..MAX), |
64 | | * numPriorities INTEGER (0..MAX), |
65 | | * minThroughput INTEGER (0..MAX), |
66 | | * maxHeight INTEGER (0..MAX), |
67 | | * maxMCSPDUsize INTEGER (0..MAX), |
68 | | * protocolVersion INTEGER (0..MAX) |
69 | | * } |
70 | | * |
71 | | * Connect-Response ::= [APPLICATION 102] IMPLICIT SEQUENCE |
72 | | * { |
73 | | * result Result, |
74 | | * calledConnectId INTEGER (0..MAX), |
75 | | * domainParameters DomainParameters, |
76 | | * userData OCTET_STRING |
77 | | * } |
78 | | * |
79 | | * Result ::= ENUMERATED |
80 | | * { |
81 | | * rt-successful (0), |
82 | | * rt-domain-merging (1), |
83 | | * rt-domain-not-hierarchical (2), |
84 | | * rt-no-such-channel (3), |
85 | | * rt-no-such-domain (4), |
86 | | * rt-no-such-user (5), |
87 | | * rt-not-admitted (6), |
88 | | * rt-other-user-id (7), |
89 | | * rt-parameters-unacceptable (8), |
90 | | * rt-token-not-available (9), |
91 | | * rt-token-not-possessed (10), |
92 | | * rt-too-many-channels (11), |
93 | | * rt-too-many-tokens (12), |
94 | | * rt-too-many-users (13), |
95 | | * rt-unspecified-failure (14), |
96 | | * rt-user-rejected (15) |
97 | | * } |
98 | | * |
99 | | * ErectDomainRequest ::= [APPLICATION 1] IMPLICIT SEQUENCE |
100 | | * { |
101 | | * subHeight INTEGER (0..MAX), |
102 | | * subInterval INTEGER (0..MAX) |
103 | | * } |
104 | | * |
105 | | * AttachUserRequest ::= [APPLICATION 10] IMPLICIT SEQUENCE |
106 | | * { |
107 | | * } |
108 | | * |
109 | | * AttachUserConfirm ::= [APPLICATION 11] IMPLICIT SEQUENCE |
110 | | * { |
111 | | * result Result, |
112 | | * initiator UserId OPTIONAL |
113 | | * } |
114 | | * |
115 | | * ChannelJoinRequest ::= [APPLICATION 14] IMPLICIT SEQUENCE |
116 | | * { |
117 | | * initiator UserId, |
118 | | * channelId ChannelId |
119 | | * } |
120 | | * |
121 | | * ChannelJoinConfirm ::= [APPLICATION 15] IMPLICIT SEQUENCE |
122 | | * { |
123 | | * result Result, |
124 | | * initiator UserId, |
125 | | * requested ChannelId, |
126 | | * channelId ChannelId OPTIONAL |
127 | | * } |
128 | | * |
129 | | * SendDataRequest ::= [APPLICATION 25] IMPLICIT SEQUENCE |
130 | | * { |
131 | | * initiator UserId, |
132 | | * channelId ChannelId, |
133 | | * dataPriority DataPriority, |
134 | | * segmentation Segmentation, |
135 | | * userData OCTET_STRING |
136 | | * } |
137 | | * |
138 | | * DataPriority ::= CHOICE |
139 | | * { |
140 | | * top NULL, |
141 | | * high NULL, |
142 | | * medium NULL, |
143 | | * low NULL, |
144 | | * ... |
145 | | * } |
146 | | * |
147 | | * Segmentation ::= BIT_STRING |
148 | | * { |
149 | | * begin (0), |
150 | | * end (1) |
151 | | * } (SIZE(2)) |
152 | | * |
153 | | * SendDataIndication ::= SEQUENCE |
154 | | * { |
155 | | * initiator UserId, |
156 | | * channelId ChannelId, |
157 | | * reliability BOOLEAN, |
158 | | * domainReferenceID INTEGER (0..65535) OPTIONAL, |
159 | | * dataPriority DataPriority, |
160 | | * segmentation Segmentation, |
161 | | * userData OCTET_STRING, |
162 | | * totalDataSize INTEGER OPTIONAL, |
163 | | * nonStandard SEQUENCE OF NonStandardParameter OPTIONAL, |
164 | | * ... |
165 | | * } |
166 | | * |
167 | | */ |
168 | | |
169 | | static const BYTE callingDomainSelector[1] = { 0x01 }; |
170 | | static const BYTE calledDomainSelector[1] = { 0x01 }; |
171 | | |
172 | | /* |
173 | | static const char* const mcs_result_enumerated[] = |
174 | | { |
175 | | "rt-successful", |
176 | | "rt-domain-merging", |
177 | | "rt-domain-not-hierarchical", |
178 | | "rt-no-such-channel", |
179 | | "rt-no-such-domain", |
180 | | "rt-no-such-user", |
181 | | "rt-not-admitted", |
182 | | "rt-other-user-id", |
183 | | "rt-parameters-unacceptable", |
184 | | "rt-token-not-available", |
185 | | "rt-token-not-possessed", |
186 | | "rt-too-many-channels", |
187 | | "rt-too-many-tokens", |
188 | | "rt-too-many-users", |
189 | | "rt-unspecified-failure", |
190 | | "rt-user-rejected" |
191 | | }; |
192 | | */ |
193 | | |
194 | | const char* mcs_domain_pdu_string(DomainMCSPDU pdu) |
195 | 110 | { |
196 | 110 | switch (pdu) |
197 | 110 | { |
198 | 7 | case DomainMCSPDU_PlumbDomainIndication: |
199 | 7 | return "DomainMCSPDU_PlumbDomainIndication"; |
200 | 1 | case DomainMCSPDU_ErectDomainRequest: |
201 | 1 | return "DomainMCSPDU_ErectDomainRequest"; |
202 | 1 | case DomainMCSPDU_MergeChannelsRequest: |
203 | 1 | return "DomainMCSPDU_MergeChannelsRequest"; |
204 | 1 | case DomainMCSPDU_MergeChannelsConfirm: |
205 | 1 | return "DomainMCSPDU_MergeChannelsConfirm"; |
206 | 1 | case DomainMCSPDU_PurgeChannelsIndication: |
207 | 1 | return "DomainMCSPDU_PurgeChannelsIndication"; |
208 | 1 | case DomainMCSPDU_MergeTokensRequest: |
209 | 1 | return "DomainMCSPDU_MergeTokensRequest"; |
210 | 0 | case DomainMCSPDU_MergeTokensConfirm: |
211 | 0 | return "DomainMCSPDU_MergeTokensConfirm"; |
212 | 0 | case DomainMCSPDU_PurgeTokensIndication: |
213 | 0 | return "DomainMCSPDU_PurgeTokensIndication"; |
214 | 0 | case DomainMCSPDU_DisconnectProviderUltimatum: |
215 | 0 | return "DomainMCSPDU_DisconnectProviderUltimatum"; |
216 | 0 | case DomainMCSPDU_RejectMCSPDUUltimatum: |
217 | 0 | return "DomainMCSPDU_RejectMCSPDUUltimatum"; |
218 | 1 | case DomainMCSPDU_AttachUserRequest: |
219 | 1 | return "DomainMCSPDU_AttachUserRequest"; |
220 | 0 | case DomainMCSPDU_AttachUserConfirm: |
221 | 0 | return "DomainMCSPDU_AttachUserConfirm"; |
222 | 2 | case DomainMCSPDU_DetachUserRequest: |
223 | 2 | return "DomainMCSPDU_DetachUserRequest"; |
224 | 0 | case DomainMCSPDU_DetachUserIndication: |
225 | 0 | return "DomainMCSPDU_DetachUserIndication"; |
226 | 0 | case DomainMCSPDU_ChannelJoinRequest: |
227 | 0 | return "DomainMCSPDU_ChannelJoinRequest"; |
228 | 0 | case DomainMCSPDU_ChannelJoinConfirm: |
229 | 0 | return "DomainMCSPDU_ChannelJoinConfirm"; |
230 | 0 | case DomainMCSPDU_ChannelLeaveRequest: |
231 | 0 | return "DomainMCSPDU_ChannelLeaveRequest"; |
232 | 0 | case DomainMCSPDU_ChannelConveneRequest: |
233 | 0 | return "DomainMCSPDU_ChannelConveneRequest"; |
234 | 0 | case DomainMCSPDU_ChannelConveneConfirm: |
235 | 0 | return "DomainMCSPDU_ChannelConveneConfirm"; |
236 | 0 | case DomainMCSPDU_ChannelDisbandRequest: |
237 | 0 | return "DomainMCSPDU_ChannelDisbandRequest"; |
238 | 0 | case DomainMCSPDU_ChannelDisbandIndication: |
239 | 0 | return "DomainMCSPDU_ChannelDisbandIndication"; |
240 | 0 | case DomainMCSPDU_ChannelAdmitRequest: |
241 | 0 | return "DomainMCSPDU_ChannelAdmitRequest"; |
242 | 0 | case DomainMCSPDU_ChannelAdmitIndication: |
243 | 0 | return "DomainMCSPDU_ChannelAdmitIndication"; |
244 | 1 | case DomainMCSPDU_ChannelExpelRequest: |
245 | 1 | return "DomainMCSPDU_ChannelExpelRequest"; |
246 | 1 | case DomainMCSPDU_ChannelExpelIndication: |
247 | 1 | return "DomainMCSPDU_ChannelExpelIndication"; |
248 | 21 | case DomainMCSPDU_SendDataRequest: |
249 | 21 | return "DomainMCSPDU_SendDataRequest"; |
250 | 34 | case DomainMCSPDU_SendDataIndication: |
251 | 34 | return "DomainMCSPDU_SendDataIndication"; |
252 | 0 | case DomainMCSPDU_UniformSendDataRequest: |
253 | 0 | return "DomainMCSPDU_UniformSendDataRequest"; |
254 | 0 | case DomainMCSPDU_UniformSendDataIndication: |
255 | 0 | return "DomainMCSPDU_UniformSendDataIndication"; |
256 | 0 | case DomainMCSPDU_TokenGrabRequest: |
257 | 0 | return "DomainMCSPDU_TokenGrabRequest"; |
258 | 0 | case DomainMCSPDU_TokenGrabConfirm: |
259 | 0 | return "DomainMCSPDU_TokenGrabConfirm"; |
260 | 17 | case DomainMCSPDU_TokenInhibitRequest: |
261 | 17 | return "DomainMCSPDU_TokenInhibitRequest"; |
262 | 0 | case DomainMCSPDU_TokenInhibitConfirm: |
263 | 0 | return "DomainMCSPDU_TokenInhibitConfirm"; |
264 | 0 | case DomainMCSPDU_TokenGiveRequest: |
265 | 0 | return "DomainMCSPDU_TokenGiveRequest"; |
266 | 0 | case DomainMCSPDU_TokenGiveIndication: |
267 | 0 | return "DomainMCSPDU_TokenGiveIndication"; |
268 | 0 | case DomainMCSPDU_TokenGiveResponse: |
269 | 0 | return "DomainMCSPDU_TokenGiveResponse"; |
270 | 1 | case DomainMCSPDU_TokenGiveConfirm: |
271 | 1 | return "DomainMCSPDU_TokenGiveConfirm"; |
272 | 0 | case DomainMCSPDU_TokenPleaseRequest: |
273 | 0 | return "DomainMCSPDU_TokenPleaseRequest"; |
274 | 0 | case DomainMCSPDU_TokenPleaseConfirm: |
275 | 0 | return "DomainMCSPDU_TokenPleaseConfirm"; |
276 | 1 | case DomainMCSPDU_TokenReleaseRequest: |
277 | 1 | return "DomainMCSPDU_TokenReleaseRequest"; |
278 | 1 | case DomainMCSPDU_TokenReleaseConfirm: |
279 | 1 | return "DomainMCSPDU_TokenReleaseConfirm"; |
280 | 1 | case DomainMCSPDU_TokenTestRequest: |
281 | 1 | return "DomainMCSPDU_TokenTestRequest"; |
282 | 0 | case DomainMCSPDU_TokenTestConfirm: |
283 | 0 | return "DomainMCSPDU_TokenTestConfirm"; |
284 | 0 | case DomainMCSPDU_enum_length: |
285 | 0 | return "DomainMCSPDU_enum_length"; |
286 | 17 | default: |
287 | 17 | return "DomainMCSPDU_UNKNOWN"; |
288 | 110 | } |
289 | 110 | } |
290 | | |
291 | | static BOOL mcs_merge_domain_parameters(wLog* log, DomainParameters* targetParameters, |
292 | | DomainParameters* minimumParameters, |
293 | | DomainParameters* maximumParameters, |
294 | | DomainParameters* pOutParameters); |
295 | | |
296 | | static BOOL mcs_write_connect_initial(wStream* s, rdpMcs* mcs, wStream* userData); |
297 | | static BOOL mcs_write_connect_response(wStream* s, rdpMcs* mcs, wStream* userData); |
298 | | static BOOL mcs_read_domain_mcspdu_header(wLog* log, wStream* s, DomainMCSPDU domainMCSPDU, |
299 | | UINT16* length, DomainMCSPDU* actual); |
300 | | |
301 | | static int mcs_initialize_client_channels(rdpMcs* mcs, const rdpSettings* settings) |
302 | 0 | { |
303 | 0 | if (!mcs || !settings) |
304 | 0 | return -1; |
305 | | |
306 | 0 | mcs->channelCount = freerdp_settings_get_uint32(settings, FreeRDP_ChannelCount); |
307 | |
|
308 | 0 | if (mcs->channelCount > mcs->channelMaxCount) |
309 | 0 | mcs->channelCount = mcs->channelMaxCount; |
310 | |
|
311 | 0 | ZeroMemory(mcs->channels, sizeof(rdpMcsChannel) * mcs->channelMaxCount); |
312 | |
|
313 | 0 | for (UINT32 index = 0; index < mcs->channelCount; index++) |
314 | 0 | { |
315 | 0 | const CHANNEL_DEF* defchannel = |
316 | 0 | freerdp_settings_get_pointer_array(settings, FreeRDP_ChannelDefArray, index); |
317 | 0 | rdpMcsChannel* cur = &mcs->channels[index]; |
318 | 0 | WINPR_ASSERT(defchannel); |
319 | 0 | CopyMemory(cur->Name, defchannel->name, CHANNEL_NAME_LEN); |
320 | 0 | cur->options = defchannel->options; |
321 | 0 | } |
322 | |
|
323 | 0 | return 0; |
324 | 0 | } |
325 | | |
326 | | /** |
327 | | * Read a DomainMCSPDU header. |
328 | | * @param s stream |
329 | | * @param domainMCSPDU DomainMCSPDU type |
330 | | * @param length TPKT length |
331 | | * |
332 | | * @return \b TRUE for success, \b FALSE otherwise |
333 | | */ |
334 | | |
335 | | BOOL mcs_read_domain_mcspdu_header(wLog* log, wStream* s, DomainMCSPDU domainMCSPDU, UINT16* length, |
336 | | DomainMCSPDU* actual) |
337 | 0 | { |
338 | 0 | UINT16 li = 0; |
339 | 0 | BYTE choice = 0; |
340 | |
|
341 | 0 | if (actual) |
342 | 0 | *actual = DomainMCSPDU_invalid; |
343 | |
|
344 | 0 | WINPR_ASSERT(s); |
345 | 0 | WINPR_ASSERT(domainMCSPDU); |
346 | 0 | WINPR_ASSERT(length); |
347 | |
|
348 | 0 | if (!tpkt_read_header(s, length)) |
349 | 0 | return FALSE; |
350 | | |
351 | 0 | if (!tpdu_read_data(s, &li, *length)) |
352 | 0 | return FALSE; |
353 | | |
354 | 0 | if (!per_read_choice(s, &choice)) |
355 | 0 | return FALSE; |
356 | | |
357 | 0 | const BYTE val = choice >> 2; |
358 | 0 | const DomainMCSPDU MCSPDU = |
359 | 0 | (val > DomainMCSPDU_enum_length) ? DomainMCSPDU_invalid : (DomainMCSPDU)(val); |
360 | 0 | if (actual) |
361 | 0 | *actual = MCSPDU; |
362 | |
|
363 | 0 | if (domainMCSPDU != MCSPDU) |
364 | 0 | { |
365 | 0 | WLog_Print(log, WLOG_ERROR, "Expected MCS %s, got %s", mcs_domain_pdu_string(domainMCSPDU), |
366 | 0 | mcs_domain_pdu_string(MCSPDU)); |
367 | 0 | return FALSE; |
368 | 0 | } |
369 | | |
370 | 0 | return TRUE; |
371 | 0 | } |
372 | | |
373 | | /** |
374 | | * Write a DomainMCSPDU header. |
375 | | * @param s stream |
376 | | * @param domainMCSPDU DomainMCSPDU type |
377 | | * @param length TPKT length |
378 | | */ |
379 | | |
380 | | BOOL mcs_write_domain_mcspdu_header(wStream* s, DomainMCSPDU domainMCSPDU, UINT16 length, |
381 | | BYTE options) |
382 | 2.57k | { |
383 | 2.57k | WINPR_ASSERT(s); |
384 | 2.57k | WINPR_ASSERT((options & ~0x03) == 0); |
385 | 2.57k | WINPR_ASSERT((domainMCSPDU & ~0x3F) == 0); |
386 | | |
387 | 2.57k | if (!tpkt_write_header(s, length)) |
388 | 0 | return FALSE; |
389 | 2.57k | if (!tpdu_write_data(s)) |
390 | 0 | return FALSE; |
391 | 2.57k | return per_write_choice(s, (BYTE)((domainMCSPDU << 2) | options)); |
392 | 2.57k | } |
393 | | |
394 | | /** |
395 | | * Initialize MCS Domain Parameters. |
396 | | * @param domainParameters domain parameters |
397 | | * @param maxChannelIds max channel ids |
398 | | * @param maxUserIds max user ids |
399 | | * @param maxTokenIds max token ids |
400 | | * @param maxMCSPDUsize max MCS PDU size |
401 | | */ |
402 | | |
403 | | static BOOL mcs_init_domain_parameters(DomainParameters* domainParameters, UINT32 maxChannelIds, |
404 | | UINT32 maxUserIds, UINT32 maxTokenIds, UINT32 maxMCSPDUsize) |
405 | 173k | { |
406 | 173k | if (!domainParameters) |
407 | 0 | return FALSE; |
408 | | |
409 | 173k | domainParameters->maxChannelIds = maxChannelIds; |
410 | 173k | domainParameters->maxUserIds = maxUserIds; |
411 | 173k | domainParameters->maxTokenIds = maxTokenIds; |
412 | 173k | domainParameters->maxMCSPDUsize = maxMCSPDUsize; |
413 | 173k | domainParameters->numPriorities = 1; |
414 | 173k | domainParameters->minThroughput = 0; |
415 | 173k | domainParameters->maxHeight = 1; |
416 | 173k | domainParameters->protocolVersion = 2; |
417 | 173k | return TRUE; |
418 | 173k | } |
419 | | |
420 | | /** |
421 | | * Read MCS Domain Parameters. |
422 | | * @param s stream |
423 | | * @param domainParameters domain parameters |
424 | | */ |
425 | | |
426 | | static BOOL mcs_read_domain_parameters(wStream* s, DomainParameters* domainParameters) |
427 | 4.95k | { |
428 | 4.95k | size_t length = 0; |
429 | | |
430 | 4.95k | if (!s || !domainParameters) |
431 | 0 | return FALSE; |
432 | | |
433 | 4.95k | return ber_read_sequence_tag(s, &length) && |
434 | 4.89k | ber_read_integer(s, &(domainParameters->maxChannelIds)) && |
435 | 4.87k | ber_read_integer(s, &(domainParameters->maxUserIds)) && |
436 | 4.84k | ber_read_integer(s, &(domainParameters->maxTokenIds)) && |
437 | 4.79k | ber_read_integer(s, &(domainParameters->numPriorities)) && |
438 | 4.74k | ber_read_integer(s, &(domainParameters->minThroughput)) && |
439 | 4.72k | ber_read_integer(s, &(domainParameters->maxHeight)) && |
440 | 4.71k | ber_read_integer(s, &(domainParameters->maxMCSPDUsize)) && |
441 | 4.67k | ber_read_integer(s, &(domainParameters->protocolVersion)); |
442 | 4.95k | } |
443 | | |
444 | | /** |
445 | | * Write MCS Domain Parameters. |
446 | | * @param s stream |
447 | | * @param domainParameters domain parameters |
448 | | */ |
449 | | |
450 | | static BOOL mcs_write_domain_parameters(wLog* log, wStream* s, DomainParameters* domainParameters) |
451 | 0 | { |
452 | 0 | BOOL rc = FALSE; |
453 | 0 | size_t length = 0; |
454 | |
|
455 | 0 | if (!s || !domainParameters) |
456 | 0 | return FALSE; |
457 | | |
458 | 0 | wStream* tmps = Stream_New(NULL, Stream_Capacity(s)); |
459 | |
|
460 | 0 | if (!tmps) |
461 | 0 | { |
462 | 0 | WLog_Print(log, WLOG_ERROR, "Stream_New failed!"); |
463 | 0 | return FALSE; |
464 | 0 | } |
465 | | |
466 | 0 | if (!ber_write_integer(tmps, domainParameters->maxChannelIds)) |
467 | 0 | goto fail; |
468 | 0 | if (!ber_write_integer(tmps, domainParameters->maxUserIds)) |
469 | 0 | goto fail; |
470 | 0 | if (!ber_write_integer(tmps, domainParameters->maxTokenIds)) |
471 | 0 | goto fail; |
472 | 0 | if (!ber_write_integer(tmps, domainParameters->numPriorities)) |
473 | 0 | goto fail; |
474 | 0 | if (!ber_write_integer(tmps, domainParameters->minThroughput)) |
475 | 0 | goto fail; |
476 | 0 | if (!ber_write_integer(tmps, domainParameters->maxHeight)) |
477 | 0 | goto fail; |
478 | 0 | if (!ber_write_integer(tmps, domainParameters->maxMCSPDUsize)) |
479 | 0 | goto fail; |
480 | 0 | if (!ber_write_integer(tmps, domainParameters->protocolVersion)) |
481 | 0 | goto fail; |
482 | 0 | length = Stream_GetPosition(tmps); |
483 | 0 | if (!ber_write_sequence_tag(s, length)) |
484 | 0 | goto fail; |
485 | 0 | Stream_Write(s, Stream_Buffer(tmps), length); |
486 | |
|
487 | 0 | rc = TRUE; |
488 | 0 | fail: |
489 | 0 | Stream_Free(tmps, TRUE); |
490 | 0 | return rc; |
491 | 0 | } |
492 | | |
493 | | #ifdef DEBUG_MCS |
494 | | /** |
495 | | * Print MCS Domain Parameters. |
496 | | * @param domainParameters domain parameters |
497 | | */ |
498 | | |
499 | | static void mcs_print_domain_parameters(DomainParameters* domainParameters) |
500 | | { |
501 | | WLog_INFO(TAG, "DomainParameters {"); |
502 | | |
503 | | if (domainParameters) |
504 | | { |
505 | | WLog_INFO(TAG, "\tmaxChannelIds:%" PRIu32 "", domainParameters->maxChannelIds); |
506 | | WLog_INFO(TAG, "\tmaxUserIds:%" PRIu32 "", domainParameters->maxUserIds); |
507 | | WLog_INFO(TAG, "\tmaxTokenIds:%" PRIu32 "", domainParameters->maxTokenIds); |
508 | | WLog_INFO(TAG, "\tnumPriorities:%" PRIu32 "", domainParameters->numPriorities); |
509 | | WLog_INFO(TAG, "\tminThroughput:%" PRIu32 "", domainParameters->minThroughput); |
510 | | WLog_INFO(TAG, "\tmaxHeight:%" PRIu32 "", domainParameters->maxHeight); |
511 | | WLog_INFO(TAG, "\tmaxMCSPDUsize:%" PRIu32 "", domainParameters->maxMCSPDUsize); |
512 | | WLog_INFO(TAG, "\tprotocolVersion:%" PRIu32 "", domainParameters->protocolVersion); |
513 | | } |
514 | | else |
515 | | WLog_INFO(TAG, "\tdomainParameters=%p", domainParameters); |
516 | | |
517 | | WLog_INFO(TAG, "}"); |
518 | | } |
519 | | #endif |
520 | | |
521 | | /** |
522 | | * Merge MCS Domain Parameters. |
523 | | * @param targetParameters target parameters |
524 | | * @param minimumParameters minimum parameters |
525 | | * @param maximumParameters maximum parameters |
526 | | * @param pOutParameters output parameters |
527 | | * |
528 | | * @return \b TRUE for success, \b FALSE otherwise |
529 | | */ |
530 | | |
531 | | BOOL mcs_merge_domain_parameters(wLog* log, DomainParameters* targetParameters, |
532 | | DomainParameters* minimumParameters, |
533 | | DomainParameters* maximumParameters, |
534 | | DomainParameters* pOutParameters) |
535 | 390 | { |
536 | | /* maxChannelIds */ |
537 | 390 | if (!targetParameters || !minimumParameters || !maximumParameters || !pOutParameters) |
538 | 0 | return FALSE; |
539 | | |
540 | 390 | if (targetParameters->maxChannelIds >= 4) |
541 | 350 | { |
542 | 350 | pOutParameters->maxChannelIds = targetParameters->maxChannelIds; |
543 | 350 | } |
544 | 40 | else if (maximumParameters->maxChannelIds >= 4) |
545 | 37 | { |
546 | 37 | pOutParameters->maxChannelIds = 4; |
547 | 37 | } |
548 | 3 | else |
549 | 3 | { |
550 | 3 | WLog_Print(log, WLOG_ERROR, "invalid maxChannelIds [%" PRIu32 ", %" PRIu32 "]", |
551 | 3 | targetParameters->maxChannelIds, maximumParameters->maxChannelIds); |
552 | 3 | return FALSE; |
553 | 3 | } |
554 | | |
555 | | /* maxUserIds */ |
556 | | |
557 | 387 | if (targetParameters->maxUserIds >= 3) |
558 | 375 | { |
559 | 375 | pOutParameters->maxUserIds = targetParameters->maxUserIds; |
560 | 375 | } |
561 | 12 | else if (maximumParameters->maxUserIds >= 3) |
562 | 10 | { |
563 | 10 | pOutParameters->maxUserIds = 3; |
564 | 10 | } |
565 | 2 | else |
566 | 2 | { |
567 | 2 | WLog_Print(log, WLOG_ERROR, "invalid maxUserIds [%" PRIu32 ", %" PRIu32 "]", |
568 | 2 | targetParameters->maxUserIds, maximumParameters->maxUserIds); |
569 | 2 | return FALSE; |
570 | 2 | } |
571 | | |
572 | | /* maxTokenIds */ |
573 | 385 | pOutParameters->maxTokenIds = targetParameters->maxTokenIds; |
574 | | |
575 | | /* numPriorities */ |
576 | | |
577 | 385 | if (minimumParameters->numPriorities <= 1) |
578 | 61 | { |
579 | 61 | pOutParameters->numPriorities = 1; |
580 | 61 | } |
581 | 324 | else |
582 | 324 | { |
583 | 324 | WLog_Print(log, WLOG_ERROR, "invalid numPriorities [%" PRIu32 "]", |
584 | 324 | maximumParameters->numPriorities); |
585 | 324 | return FALSE; |
586 | 324 | } |
587 | | |
588 | | /* minThroughput */ |
589 | 61 | pOutParameters->minThroughput = targetParameters->minThroughput; |
590 | | |
591 | | /* maxHeight */ |
592 | | |
593 | 61 | if ((targetParameters->maxHeight == 1) || (minimumParameters->maxHeight <= 1)) |
594 | 59 | { |
595 | 59 | pOutParameters->maxHeight = 1; |
596 | 59 | } |
597 | 2 | else |
598 | 2 | { |
599 | 2 | WLog_Print(log, WLOG_ERROR, "invalid maxHeight [%" PRIu32 ", %" PRIu32 "]", |
600 | 2 | targetParameters->maxHeight, minimumParameters->maxHeight); |
601 | 2 | return FALSE; |
602 | 2 | } |
603 | | |
604 | | /* maxMCSPDUsize */ |
605 | | |
606 | 59 | if (targetParameters->maxMCSPDUsize >= 1024) |
607 | 43 | { |
608 | 43 | if (targetParameters->maxMCSPDUsize <= 65528) |
609 | 13 | { |
610 | 13 | pOutParameters->maxMCSPDUsize = targetParameters->maxMCSPDUsize; |
611 | 13 | } |
612 | 30 | else if ((minimumParameters->maxMCSPDUsize >= 124) && |
613 | 30 | (minimumParameters->maxMCSPDUsize <= 65528)) |
614 | 2 | { |
615 | 2 | pOutParameters->maxMCSPDUsize = 65528; |
616 | 2 | } |
617 | 28 | else |
618 | 28 | { |
619 | 28 | WLog_Print(log, WLOG_ERROR, "invalid maxMCSPDUsize [%" PRIu32 ", %" PRIu32 "]", |
620 | 28 | targetParameters->maxMCSPDUsize, minimumParameters->maxMCSPDUsize); |
621 | 28 | return FALSE; |
622 | 28 | } |
623 | 43 | } |
624 | 16 | else |
625 | 16 | { |
626 | 16 | if (maximumParameters->maxMCSPDUsize >= 124) |
627 | 15 | { |
628 | 15 | pOutParameters->maxMCSPDUsize = maximumParameters->maxMCSPDUsize; |
629 | 15 | } |
630 | 1 | else |
631 | 1 | { |
632 | 1 | WLog_Print(log, WLOG_ERROR, "invalid maxMCSPDUsize [%" PRIu32 "]", |
633 | 1 | maximumParameters->maxMCSPDUsize); |
634 | 1 | return FALSE; |
635 | 1 | } |
636 | 16 | } |
637 | | |
638 | | /* protocolVersion */ |
639 | | |
640 | 30 | if ((targetParameters->protocolVersion == 2) || |
641 | 28 | ((minimumParameters->protocolVersion <= 2) && (maximumParameters->protocolVersion >= 2))) |
642 | 3 | { |
643 | 3 | pOutParameters->protocolVersion = 2; |
644 | 3 | } |
645 | 27 | else |
646 | 27 | { |
647 | 27 | WLog_Print(log, WLOG_ERROR, |
648 | 27 | "invalid protocolVersion [%" PRIu32 ", %" PRIu32 ", %" PRIu32 "]", |
649 | 27 | targetParameters->protocolVersion, minimumParameters->protocolVersion, |
650 | 27 | maximumParameters->protocolVersion); |
651 | 27 | return FALSE; |
652 | 27 | } |
653 | | |
654 | 3 | return TRUE; |
655 | 30 | } |
656 | | |
657 | | /** |
658 | | * Read an MCS Connect Initial PDU. |
659 | | * msdn{cc240508} |
660 | | * @param mcs MCS module |
661 | | * @param s stream |
662 | | */ |
663 | | |
664 | | BOOL mcs_recv_connect_initial(rdpMcs* mcs, wStream* s) |
665 | 14.4k | { |
666 | 14.4k | UINT16 li = 0; |
667 | 14.4k | size_t length = 0; |
668 | 14.4k | BOOL upwardFlag = FALSE; |
669 | 14.4k | UINT16 tlength = 0; |
670 | | |
671 | 14.4k | WINPR_ASSERT(mcs); |
672 | 14.4k | WINPR_ASSERT(s); |
673 | | |
674 | 14.4k | if (!tpkt_read_header(s, &tlength)) |
675 | 363 | return FALSE; |
676 | | |
677 | 14.0k | if (!tpdu_read_data(s, &li, tlength)) |
678 | 11.1k | return FALSE; |
679 | | |
680 | 2.91k | if (!ber_read_application_tag(s, MCS_TYPE_CONNECT_INITIAL, &length)) |
681 | 1.60k | return FALSE; |
682 | | |
683 | | /* callingDomainSelector (OCTET_STRING) */ |
684 | 1.30k | if (!ber_read_octet_string_tag(s, &length) || |
685 | 1.29k | (!Stream_CheckAndLogRequiredLengthWLog(mcs->log, s, length))) |
686 | 19 | return FALSE; |
687 | | |
688 | 1.29k | Stream_Seek(s, length); |
689 | | |
690 | | /* calledDomainSelector (OCTET_STRING) */ |
691 | 1.29k | if (!ber_read_octet_string_tag(s, &length) || |
692 | 1.27k | (!Stream_CheckAndLogRequiredLengthWLog(mcs->log, s, length))) |
693 | 16 | return FALSE; |
694 | | |
695 | 1.27k | Stream_Seek(s, length); |
696 | | |
697 | | /* upwardFlag (BOOLEAN) */ |
698 | 1.27k | if (!ber_read_BOOL(s, &upwardFlag)) |
699 | 26 | return FALSE; |
700 | | |
701 | | /* targetParameters (DomainParameters) */ |
702 | 1.24k | if (!mcs_read_domain_parameters(s, &mcs->targetParameters)) |
703 | 99 | return FALSE; |
704 | | |
705 | | /* minimumParameters (DomainParameters) */ |
706 | 1.14k | if (!mcs_read_domain_parameters(s, &mcs->minimumParameters)) |
707 | 63 | return FALSE; |
708 | | |
709 | | /* maximumParameters (DomainParameters) */ |
710 | 1.08k | if (!mcs_read_domain_parameters(s, &mcs->maximumParameters)) |
711 | 19 | return FALSE; |
712 | | |
713 | 1.06k | if (!ber_read_octet_string_tag(s, &length) || |
714 | 1.06k | (!Stream_CheckAndLogRequiredLengthWLog(mcs->log, s, length))) |
715 | 5 | return FALSE; |
716 | | |
717 | 1.06k | if (!gcc_read_conference_create_request(s, mcs)) |
718 | 672 | return FALSE; |
719 | | |
720 | 390 | if (!mcs_merge_domain_parameters(mcs->log, &mcs->targetParameters, &mcs->minimumParameters, |
721 | 390 | &mcs->maximumParameters, &mcs->domainParameters)) |
722 | 387 | return FALSE; |
723 | | |
724 | 3 | return tpkt_ensure_stream_consumed(mcs->log, s, tlength); |
725 | 390 | } |
726 | | |
727 | | /** |
728 | | * Write an MCS Connect Initial PDU. |
729 | | * msdn{cc240508} |
730 | | * @param s stream |
731 | | * @param mcs MCS module |
732 | | * @param userData GCC Conference Create Request |
733 | | */ |
734 | | |
735 | | BOOL mcs_write_connect_initial(wStream* s, rdpMcs* mcs, wStream* userData) |
736 | 0 | { |
737 | 0 | size_t length = 0; |
738 | 0 | wStream* tmps = NULL; |
739 | 0 | BOOL ret = FALSE; |
740 | |
|
741 | 0 | if (!s || !mcs || !userData) |
742 | 0 | return FALSE; |
743 | | |
744 | 0 | tmps = Stream_New(NULL, Stream_Capacity(s)); |
745 | |
|
746 | 0 | if (!tmps) |
747 | 0 | { |
748 | 0 | WLog_Print(mcs->log, WLOG_ERROR, "Stream_New failed!"); |
749 | 0 | return FALSE; |
750 | 0 | } |
751 | | |
752 | | /* callingDomainSelector (OCTET_STRING) */ |
753 | 0 | if (!ber_write_octet_string(tmps, callingDomainSelector, sizeof(callingDomainSelector))) |
754 | 0 | goto out; |
755 | | /* calledDomainSelector (OCTET_STRING) */ |
756 | 0 | if (!ber_write_octet_string(tmps, calledDomainSelector, sizeof(calledDomainSelector))) |
757 | 0 | goto out; |
758 | | /* upwardFlag (BOOLEAN) */ |
759 | 0 | ber_write_BOOL(tmps, TRUE); |
760 | | |
761 | | /* targetParameters (DomainParameters) */ |
762 | 0 | if (!mcs_write_domain_parameters(mcs->log, tmps, &mcs->targetParameters)) |
763 | 0 | goto out; |
764 | | |
765 | | /* minimumParameters (DomainParameters) */ |
766 | 0 | if (!mcs_write_domain_parameters(mcs->log, tmps, &mcs->minimumParameters)) |
767 | 0 | goto out; |
768 | | |
769 | | /* maximumParameters (DomainParameters) */ |
770 | 0 | if (!mcs_write_domain_parameters(mcs->log, tmps, &mcs->maximumParameters)) |
771 | 0 | goto out; |
772 | | |
773 | | /* userData (OCTET_STRING) */ |
774 | 0 | if (!ber_write_octet_string(tmps, Stream_Buffer(userData), Stream_GetPosition(userData))) |
775 | 0 | goto out; |
776 | 0 | length = Stream_GetPosition(tmps); |
777 | | /* Connect-Initial (APPLICATION 101, IMPLICIT SEQUENCE) */ |
778 | 0 | ber_write_application_tag(s, MCS_TYPE_CONNECT_INITIAL, length); |
779 | 0 | Stream_Write(s, Stream_Buffer(tmps), length); |
780 | 0 | ret = TRUE; |
781 | 0 | out: |
782 | 0 | Stream_Free(tmps, TRUE); |
783 | 0 | return ret; |
784 | 0 | } |
785 | | |
786 | | /** |
787 | | * Write an MCS Connect Response PDU. |
788 | | * msdn{cc240508} |
789 | | * @param s stream |
790 | | * @param mcs MCS module |
791 | | * @param userData GCC Conference Create Response |
792 | | * |
793 | | * @return \b TRUE for success, \b FALSE otherwise |
794 | | */ |
795 | | |
796 | | BOOL mcs_write_connect_response(wStream* s, rdpMcs* mcs, wStream* userData) |
797 | 0 | { |
798 | 0 | size_t length = 0; |
799 | 0 | wStream* tmps = NULL; |
800 | 0 | BOOL ret = FALSE; |
801 | |
|
802 | 0 | if (!s || !mcs || !userData) |
803 | 0 | return FALSE; |
804 | | |
805 | 0 | tmps = Stream_New(NULL, Stream_Capacity(s)); |
806 | |
|
807 | 0 | if (!tmps) |
808 | 0 | { |
809 | 0 | WLog_Print(mcs->log, WLOG_ERROR, "Stream_New failed!"); |
810 | 0 | return FALSE; |
811 | 0 | } |
812 | | |
813 | 0 | ber_write_enumerated(tmps, 0, MCS_Result_enum_length); |
814 | 0 | if (!ber_write_integer(tmps, 0)) /* calledConnectId */ |
815 | 0 | goto out; |
816 | | |
817 | 0 | if (!mcs_write_domain_parameters(mcs->log, tmps, &(mcs->domainParameters))) |
818 | 0 | goto out; |
819 | | |
820 | | /* userData (OCTET_STRING) */ |
821 | 0 | if (!ber_write_octet_string(tmps, Stream_Buffer(userData), Stream_GetPosition(userData))) |
822 | 0 | goto out; |
823 | 0 | length = Stream_GetPosition(tmps); |
824 | 0 | ber_write_application_tag(s, MCS_TYPE_CONNECT_RESPONSE, length); |
825 | 0 | Stream_Write(s, Stream_Buffer(tmps), length); |
826 | 0 | ret = TRUE; |
827 | 0 | out: |
828 | 0 | Stream_Free(tmps, TRUE); |
829 | 0 | return ret; |
830 | 0 | } |
831 | | |
832 | | /** |
833 | | * Send MCS Connect Initial. |
834 | | * msdn{cc240508} |
835 | | * @param mcs mcs module |
836 | | */ |
837 | | |
838 | | static BOOL mcs_send_connect_initial(rdpMcs* mcs) |
839 | 0 | { |
840 | 0 | int status = -1; |
841 | 0 | size_t length = 0; |
842 | 0 | wStream* s = NULL; |
843 | 0 | size_t bm = 0; |
844 | 0 | size_t em = 0; |
845 | 0 | wStream* gcc_CCrq = NULL; |
846 | |
|
847 | 0 | if (!mcs || !mcs->context) |
848 | 0 | return FALSE; |
849 | | |
850 | 0 | mcs_initialize_client_channels(mcs, mcs->context->settings); |
851 | 0 | wStream* client_data = Stream_New(NULL, 512); |
852 | |
|
853 | 0 | if (!client_data) |
854 | 0 | { |
855 | 0 | WLog_Print(mcs->log, WLOG_ERROR, "Stream_New failed!"); |
856 | 0 | return FALSE; |
857 | 0 | } |
858 | | |
859 | 0 | if (!gcc_write_client_data_blocks(client_data, mcs)) |
860 | 0 | goto out; |
861 | 0 | gcc_CCrq = Stream_New(NULL, 1024); |
862 | |
|
863 | 0 | if (!gcc_CCrq) |
864 | 0 | { |
865 | 0 | WLog_Print(mcs->log, WLOG_ERROR, "Stream_New failed!"); |
866 | 0 | goto out; |
867 | 0 | } |
868 | | |
869 | 0 | if (!gcc_write_conference_create_request(gcc_CCrq, client_data)) |
870 | 0 | goto out; |
871 | 0 | length = Stream_GetPosition(gcc_CCrq) + 7; |
872 | 0 | s = Stream_New(NULL, 1024 + length); |
873 | |
|
874 | 0 | if (!s) |
875 | 0 | { |
876 | 0 | WLog_Print(mcs->log, WLOG_ERROR, "Stream_New failed!"); |
877 | 0 | goto out; |
878 | 0 | } |
879 | | |
880 | 0 | bm = Stream_GetPosition(s); |
881 | 0 | Stream_Seek(s, 7); |
882 | |
|
883 | 0 | if (!mcs_write_connect_initial(s, mcs, gcc_CCrq)) |
884 | 0 | { |
885 | 0 | WLog_Print(mcs->log, WLOG_ERROR, "mcs_write_connect_initial failed!"); |
886 | 0 | goto out; |
887 | 0 | } |
888 | | |
889 | 0 | em = Stream_GetPosition(s); |
890 | 0 | length = (em - bm); |
891 | 0 | if (length > UINT16_MAX) |
892 | 0 | goto out; |
893 | 0 | Stream_SetPosition(s, bm); |
894 | 0 | if (!tpkt_write_header(s, (UINT16)length)) |
895 | 0 | goto out; |
896 | 0 | if (!tpdu_write_data(s)) |
897 | 0 | goto out; |
898 | 0 | Stream_SetPosition(s, em); |
899 | 0 | Stream_SealLength(s); |
900 | |
|
901 | 0 | { |
902 | 0 | rdpTransport* transport = freerdp_get_transport(mcs->context); |
903 | 0 | status = transport_write(transport, s); |
904 | 0 | } |
905 | |
|
906 | 0 | out: |
907 | 0 | Stream_Free(s, TRUE); |
908 | 0 | Stream_Free(gcc_CCrq, TRUE); |
909 | 0 | Stream_Free(client_data, TRUE); |
910 | 0 | return (status < 0 ? FALSE : TRUE); |
911 | 0 | } |
912 | | |
913 | | /** |
914 | | * Read MCS Connect Response. |
915 | | * msdn{cc240501} |
916 | | * @param mcs mcs module |
917 | | */ |
918 | | |
919 | | BOOL mcs_recv_connect_response(rdpMcs* mcs, wStream* s) |
920 | 14.4k | { |
921 | 14.4k | size_t length = 0; |
922 | 14.4k | UINT16 tlength = 0; |
923 | 14.4k | BYTE result = 0; |
924 | 14.4k | UINT16 li = 0; |
925 | 14.4k | UINT32 calledConnectId = 0; |
926 | | |
927 | 14.4k | if (!mcs || !s) |
928 | 0 | return FALSE; |
929 | | |
930 | 14.4k | if (!tpkt_read_header(s, &tlength)) |
931 | 363 | return FALSE; |
932 | | |
933 | 14.0k | if (!tpdu_read_data(s, &li, tlength)) |
934 | 11.1k | return FALSE; |
935 | | |
936 | 2.91k | if (!ber_read_application_tag(s, MCS_TYPE_CONNECT_RESPONSE, &length) || |
937 | 1.54k | !ber_read_enumerated(s, &result, MCS_Result_enum_length) || |
938 | 1.50k | !ber_read_integer(s, &calledConnectId) || |
939 | 1.47k | !mcs_read_domain_parameters(s, &(mcs->domainParameters)) || |
940 | 1.36k | !ber_read_octet_string_tag(s, &length)) |
941 | 1.55k | { |
942 | 1.55k | return FALSE; |
943 | 1.55k | } |
944 | | |
945 | 1.35k | if (!gcc_read_conference_create_response(s, mcs)) |
946 | 1.23k | { |
947 | 1.23k | WLog_Print(mcs->log, WLOG_ERROR, "gcc_read_conference_create_response failed"); |
948 | 1.23k | return FALSE; |
949 | 1.23k | } |
950 | | |
951 | 122 | return tpkt_ensure_stream_consumed(mcs->log, s, tlength); |
952 | 1.35k | } |
953 | | |
954 | | /** |
955 | | * Send MCS Connect Response. |
956 | | * msdn{cc240501} |
957 | | * @param mcs mcs module |
958 | | */ |
959 | | |
960 | | BOOL mcs_send_connect_response(rdpMcs* mcs) |
961 | 0 | { |
962 | 0 | size_t length = 0; |
963 | 0 | int status = -1; |
964 | 0 | wStream* s = NULL; |
965 | 0 | size_t bm = 0; |
966 | 0 | size_t em = 0; |
967 | 0 | wStream* gcc_CCrsp = NULL; |
968 | |
|
969 | 0 | if (!mcs) |
970 | 0 | return FALSE; |
971 | | |
972 | 0 | wStream* server_data = Stream_New(NULL, 512); |
973 | |
|
974 | 0 | if (!server_data) |
975 | 0 | { |
976 | 0 | WLog_Print(mcs->log, WLOG_ERROR, "Stream_New failed!"); |
977 | 0 | return FALSE; |
978 | 0 | } |
979 | | |
980 | 0 | if (!gcc_write_server_data_blocks(server_data, mcs)) |
981 | 0 | goto out; |
982 | | |
983 | 0 | gcc_CCrsp = Stream_New(NULL, 512 + Stream_Capacity(server_data)); |
984 | |
|
985 | 0 | if (!gcc_CCrsp) |
986 | 0 | { |
987 | 0 | WLog_Print(mcs->log, WLOG_ERROR, "Stream_New failed!"); |
988 | 0 | goto out; |
989 | 0 | } |
990 | | |
991 | 0 | if (!gcc_write_conference_create_response(gcc_CCrsp, server_data)) |
992 | 0 | goto out; |
993 | 0 | length = Stream_GetPosition(gcc_CCrsp) + 7; |
994 | 0 | s = Stream_New(NULL, length + 1024); |
995 | |
|
996 | 0 | if (!s) |
997 | 0 | { |
998 | 0 | WLog_Print(mcs->log, WLOG_ERROR, "Stream_New failed!"); |
999 | 0 | goto out; |
1000 | 0 | } |
1001 | | |
1002 | 0 | bm = Stream_GetPosition(s); |
1003 | 0 | Stream_Seek(s, 7); |
1004 | |
|
1005 | 0 | if (!mcs_write_connect_response(s, mcs, gcc_CCrsp)) |
1006 | 0 | goto out; |
1007 | | |
1008 | 0 | em = Stream_GetPosition(s); |
1009 | 0 | length = (em - bm); |
1010 | 0 | if (length > UINT16_MAX) |
1011 | 0 | goto out; |
1012 | 0 | Stream_SetPosition(s, bm); |
1013 | 0 | if (!tpkt_write_header(s, (UINT16)length)) |
1014 | 0 | goto out; |
1015 | 0 | if (!tpdu_write_data(s)) |
1016 | 0 | goto out; |
1017 | 0 | Stream_SetPosition(s, em); |
1018 | 0 | Stream_SealLength(s); |
1019 | |
|
1020 | 0 | { |
1021 | 0 | rdpTransport* transport = freerdp_get_transport(mcs->context); |
1022 | 0 | status = transport_write(transport, s); |
1023 | 0 | } |
1024 | |
|
1025 | 0 | out: |
1026 | 0 | Stream_Free(s, TRUE); |
1027 | 0 | Stream_Free(gcc_CCrsp, TRUE); |
1028 | 0 | Stream_Free(server_data, TRUE); |
1029 | 0 | return (status < 0) ? FALSE : TRUE; |
1030 | 0 | } |
1031 | | |
1032 | | /** |
1033 | | * Read MCS Erect Domain Request. |
1034 | | * msdn{cc240523} |
1035 | | * @param mcs MCS module to use |
1036 | | * @param s stream |
1037 | | */ |
1038 | | |
1039 | | BOOL mcs_recv_erect_domain_request(rdpMcs* mcs, wStream* s) |
1040 | 0 | { |
1041 | 0 | UINT16 length = 0; |
1042 | 0 | UINT32 subHeight = 0; |
1043 | 0 | UINT32 subInterval = 0; |
1044 | |
|
1045 | 0 | WINPR_ASSERT(mcs); |
1046 | 0 | WINPR_ASSERT(s); |
1047 | |
|
1048 | 0 | if (!mcs_read_domain_mcspdu_header(mcs->log, s, DomainMCSPDU_ErectDomainRequest, &length, NULL)) |
1049 | 0 | return FALSE; |
1050 | | |
1051 | 0 | if (!per_read_integer(s, &subHeight)) /* subHeight (INTEGER) */ |
1052 | 0 | return FALSE; |
1053 | | |
1054 | 0 | if (!per_read_integer(s, &subInterval)) /* subInterval (INTEGER) */ |
1055 | 0 | return FALSE; |
1056 | | |
1057 | 0 | return tpkt_ensure_stream_consumed(mcs->log, s, length); |
1058 | 0 | } |
1059 | | |
1060 | | /** |
1061 | | * Send MCS Erect Domain Request. |
1062 | | * msdn{cc240523} |
1063 | | * @param mcs MCS module to use |
1064 | | */ |
1065 | | |
1066 | | BOOL mcs_send_erect_domain_request(rdpMcs* mcs) |
1067 | 0 | { |
1068 | 0 | int status = -1; |
1069 | 0 | UINT16 length = 12; |
1070 | |
|
1071 | 0 | if (!mcs) |
1072 | 0 | return FALSE; |
1073 | | |
1074 | 0 | wStream* s = Stream_New(NULL, length); |
1075 | |
|
1076 | 0 | if (!s) |
1077 | 0 | { |
1078 | 0 | WLog_Print(mcs->log, WLOG_ERROR, "Stream_New failed!"); |
1079 | 0 | return FALSE; |
1080 | 0 | } |
1081 | | |
1082 | 0 | if (!mcs_write_domain_mcspdu_header(s, DomainMCSPDU_ErectDomainRequest, length, 0)) |
1083 | 0 | goto out; |
1084 | 0 | if (!per_write_integer(s, 0)) /* subHeight (INTEGER) */ |
1085 | 0 | goto out; |
1086 | 0 | if (!per_write_integer(s, 0)) /* subInterval (INTEGER) */ |
1087 | 0 | goto out; |
1088 | 0 | Stream_SealLength(s); |
1089 | |
|
1090 | 0 | rdpTransport* transport = freerdp_get_transport(mcs->context); |
1091 | 0 | status = transport_write(transport, s); |
1092 | 0 | out: |
1093 | 0 | Stream_Free(s, TRUE); |
1094 | 0 | return (status < 0) ? FALSE : TRUE; |
1095 | 0 | } |
1096 | | |
1097 | | /** |
1098 | | * Read MCS Attach User Request. |
1099 | | * msdn{cc240524} |
1100 | | * @param mcs mcs module |
1101 | | * @param s stream |
1102 | | */ |
1103 | | |
1104 | | BOOL mcs_recv_attach_user_request(rdpMcs* mcs, wStream* s) |
1105 | 0 | { |
1106 | 0 | UINT16 length = 0; |
1107 | |
|
1108 | 0 | if (!mcs || !s) |
1109 | 0 | return FALSE; |
1110 | | |
1111 | 0 | if (!mcs_read_domain_mcspdu_header(mcs->log, s, DomainMCSPDU_AttachUserRequest, &length, NULL)) |
1112 | 0 | return FALSE; |
1113 | 0 | return tpkt_ensure_stream_consumed(mcs->log, s, length); |
1114 | 0 | } |
1115 | | |
1116 | | /** |
1117 | | * Send MCS Attach User Request. |
1118 | | * msdn{cc240524} |
1119 | | * @param mcs mcs module |
1120 | | */ |
1121 | | |
1122 | | BOOL mcs_send_attach_user_request(rdpMcs* mcs) |
1123 | 0 | { |
1124 | 0 | int status = -1; |
1125 | 0 | UINT16 length = 8; |
1126 | |
|
1127 | 0 | if (!mcs) |
1128 | 0 | return FALSE; |
1129 | | |
1130 | 0 | wStream* s = Stream_New(NULL, length); |
1131 | |
|
1132 | 0 | if (!s) |
1133 | 0 | { |
1134 | 0 | WLog_Print(mcs->log, WLOG_ERROR, "Stream_New failed!"); |
1135 | 0 | return FALSE; |
1136 | 0 | } |
1137 | | |
1138 | 0 | if (!mcs_write_domain_mcspdu_header(s, DomainMCSPDU_AttachUserRequest, length, 0)) |
1139 | 0 | goto fail; |
1140 | | |
1141 | 0 | Stream_SealLength(s); |
1142 | |
|
1143 | 0 | rdpTransport* transport = freerdp_get_transport(mcs->context); |
1144 | 0 | status = transport_write(transport, s); |
1145 | |
|
1146 | 0 | fail: |
1147 | 0 | Stream_Free(s, TRUE); |
1148 | 0 | return (status < 0) ? FALSE : TRUE; |
1149 | 0 | } |
1150 | | |
1151 | | /** |
1152 | | * Read MCS Attach User Confirm. |
1153 | | * msdn{cc240525} |
1154 | | * @param mcs mcs module |
1155 | | */ |
1156 | | |
1157 | | BOOL mcs_recv_attach_user_confirm(rdpMcs* mcs, wStream* s) |
1158 | 0 | { |
1159 | 0 | BYTE result = 0; |
1160 | 0 | UINT16 length = 0; |
1161 | |
|
1162 | 0 | if (!mcs || !s) |
1163 | 0 | return FALSE; |
1164 | | |
1165 | 0 | if (!mcs_read_domain_mcspdu_header(mcs->log, s, DomainMCSPDU_AttachUserConfirm, &length, NULL)) |
1166 | 0 | return FALSE; |
1167 | 0 | if (!per_read_enumerated(s, &result, MCS_Result_enum_length)) /* result */ |
1168 | 0 | return FALSE; |
1169 | 0 | if (!per_read_integer16(s, &(mcs->userId), MCS_BASE_CHANNEL_ID)) /* initiator (UserId) */ |
1170 | 0 | return FALSE; |
1171 | 0 | return tpkt_ensure_stream_consumed(mcs->log, s, length); |
1172 | 0 | } |
1173 | | |
1174 | | /** |
1175 | | * Send MCS Attach User Confirm. |
1176 | | * msdn{cc240525} |
1177 | | * @param mcs mcs module |
1178 | | */ |
1179 | | |
1180 | | BOOL mcs_send_attach_user_confirm(rdpMcs* mcs) |
1181 | 0 | { |
1182 | 0 | int status = -1; |
1183 | 0 | UINT16 length = 11; |
1184 | |
|
1185 | 0 | if (!mcs) |
1186 | 0 | return FALSE; |
1187 | | |
1188 | 0 | wStream* s = Stream_New(NULL, length); |
1189 | |
|
1190 | 0 | if (!s) |
1191 | 0 | { |
1192 | 0 | WLog_Print(mcs->log, WLOG_ERROR, "Stream_New failed!"); |
1193 | 0 | return FALSE; |
1194 | 0 | } |
1195 | | |
1196 | 0 | mcs->userId = mcs->baseChannelId++; |
1197 | 0 | if (!mcs_write_domain_mcspdu_header(s, DomainMCSPDU_AttachUserConfirm, length, 2)) |
1198 | 0 | goto out; |
1199 | 0 | if (!per_write_enumerated(s, 0, MCS_Result_enum_length)) /* result */ |
1200 | 0 | goto out; |
1201 | 0 | if (!per_write_integer16(s, mcs->userId, MCS_BASE_CHANNEL_ID)) /* initiator (UserId) */ |
1202 | 0 | goto out; |
1203 | 0 | Stream_SealLength(s); |
1204 | |
|
1205 | 0 | rdpTransport* transport = freerdp_get_transport(mcs->context); |
1206 | 0 | status = transport_write(transport, s); |
1207 | 0 | out: |
1208 | 0 | Stream_Free(s, TRUE); |
1209 | 0 | return (status < 0) ? FALSE : TRUE; |
1210 | 0 | } |
1211 | | |
1212 | | /** |
1213 | | * Read MCS Channel Join Request. |
1214 | | * msdn{cc240526} |
1215 | | * @param mcs mcs module |
1216 | | * @param s stream |
1217 | | */ |
1218 | | |
1219 | | BOOL mcs_recv_channel_join_request(rdpMcs* mcs, const rdpSettings* settings, wStream* s, |
1220 | | UINT16* channelId) |
1221 | 0 | { |
1222 | 0 | UINT16 length = 0; |
1223 | 0 | UINT16 userId = 0; |
1224 | |
|
1225 | 0 | if (!mcs || !s || !channelId) |
1226 | 0 | return FALSE; |
1227 | | |
1228 | 0 | if (!mcs_read_domain_mcspdu_header(mcs->log, s, DomainMCSPDU_ChannelJoinRequest, &length, NULL)) |
1229 | 0 | return FALSE; |
1230 | | |
1231 | 0 | if (!per_read_integer16(s, &userId, MCS_BASE_CHANNEL_ID)) |
1232 | 0 | return FALSE; |
1233 | 0 | if (userId != mcs->userId) |
1234 | 0 | { |
1235 | 0 | if (freerdp_settings_get_bool(settings, FreeRDP_TransportDumpReplay)) |
1236 | 0 | mcs->userId = userId; |
1237 | 0 | else |
1238 | 0 | return FALSE; |
1239 | 0 | } |
1240 | 0 | if (!per_read_integer16(s, channelId, 0)) |
1241 | 0 | return FALSE; |
1242 | | |
1243 | 0 | return tpkt_ensure_stream_consumed(mcs->log, s, length); |
1244 | 0 | } |
1245 | | |
1246 | | /** |
1247 | | * Send MCS Channel Join Request. |
1248 | | * msdn{cc240526} |
1249 | | * |
1250 | | * @param mcs mcs module |
1251 | | * @param channelId channel id |
1252 | | * |
1253 | | * @return \b TRUE for success, \b FALSE otherwise |
1254 | | */ |
1255 | | |
1256 | | BOOL mcs_send_channel_join_request(rdpMcs* mcs, UINT16 channelId) |
1257 | 0 | { |
1258 | 0 | int status = -1; |
1259 | 0 | UINT16 length = 12; |
1260 | |
|
1261 | 0 | WINPR_ASSERT(mcs); |
1262 | |
|
1263 | 0 | wStream* s = Stream_New(NULL, length); |
1264 | |
|
1265 | 0 | if (!s) |
1266 | 0 | { |
1267 | 0 | WLog_Print(mcs->log, WLOG_ERROR, "Stream_New failed!"); |
1268 | 0 | return FALSE; |
1269 | 0 | } |
1270 | | |
1271 | 0 | if (!mcs_write_domain_mcspdu_header(s, DomainMCSPDU_ChannelJoinRequest, length, 0)) |
1272 | 0 | goto out; |
1273 | 0 | if (!per_write_integer16(s, mcs->userId, MCS_BASE_CHANNEL_ID)) |
1274 | 0 | goto out; |
1275 | 0 | if (!per_write_integer16(s, channelId, 0)) |
1276 | 0 | goto out; |
1277 | 0 | Stream_SealLength(s); |
1278 | |
|
1279 | 0 | rdpTransport* transport = freerdp_get_transport(mcs->context); |
1280 | 0 | status = transport_write(transport, s); |
1281 | |
|
1282 | 0 | out: |
1283 | 0 | Stream_Free(s, TRUE); |
1284 | 0 | return (status < 0) ? FALSE : TRUE; |
1285 | 0 | } |
1286 | | |
1287 | | /** |
1288 | | * Read MCS Channel Join Confirm. |
1289 | | * msdn{cc240527} |
1290 | | * @param mcs mcs module |
1291 | | */ |
1292 | | |
1293 | | BOOL mcs_recv_channel_join_confirm(rdpMcs* mcs, wStream* s, UINT16* channelId) |
1294 | 0 | { |
1295 | 0 | UINT16 length = 0; |
1296 | 0 | BYTE result = 0; |
1297 | 0 | UINT16 initiator = 0; |
1298 | 0 | UINT16 requested = 0; |
1299 | |
|
1300 | 0 | WINPR_ASSERT(mcs); |
1301 | 0 | WINPR_ASSERT(channelId); |
1302 | |
|
1303 | 0 | if (!mcs_read_domain_mcspdu_header(mcs->log, s, DomainMCSPDU_ChannelJoinConfirm, &length, NULL)) |
1304 | 0 | return FALSE; |
1305 | | |
1306 | 0 | if (!per_read_enumerated(s, &result, MCS_Result_enum_length)) /* result */ |
1307 | 0 | return FALSE; |
1308 | 0 | if (!per_read_integer16(s, &initiator, MCS_BASE_CHANNEL_ID)) /* initiator (UserId) */ |
1309 | 0 | return FALSE; |
1310 | 0 | if (!per_read_integer16(s, &requested, 0)) /* requested (ChannelId) */ |
1311 | 0 | return FALSE; |
1312 | 0 | if (!per_read_integer16(s, channelId, 0)) /* channelId */ |
1313 | 0 | return FALSE; |
1314 | 0 | return tpkt_ensure_stream_consumed(mcs->log, s, length); |
1315 | 0 | } |
1316 | | |
1317 | | /** |
1318 | | * Send MCS Channel Join Confirm. |
1319 | | * msdn{cc240527} |
1320 | | * @param mcs mcs module |
1321 | | */ |
1322 | | |
1323 | | BOOL mcs_send_channel_join_confirm(rdpMcs* mcs, UINT16 channelId) |
1324 | 0 | { |
1325 | 0 | int status = -1; |
1326 | 0 | UINT16 length = 15; |
1327 | |
|
1328 | 0 | if (!mcs) |
1329 | 0 | return FALSE; |
1330 | | |
1331 | 0 | wStream* s = Stream_New(NULL, length); |
1332 | |
|
1333 | 0 | if (!s) |
1334 | 0 | { |
1335 | 0 | WLog_Print(mcs->log, WLOG_ERROR, "Stream_New failed!"); |
1336 | 0 | return FALSE; |
1337 | 0 | } |
1338 | | |
1339 | 0 | if (!mcs_write_domain_mcspdu_header(s, DomainMCSPDU_ChannelJoinConfirm, length, 2)) |
1340 | 0 | goto fail; |
1341 | 0 | if (!per_write_enumerated(s, 0, MCS_Result_enum_length)) /* result */ |
1342 | 0 | goto fail; |
1343 | 0 | if (!per_write_integer16(s, mcs->userId, MCS_BASE_CHANNEL_ID)) /* initiator (UserId) */ |
1344 | 0 | goto fail; |
1345 | 0 | if (!per_write_integer16(s, channelId, 0)) /* requested (ChannelId) */ |
1346 | 0 | goto fail; |
1347 | 0 | if (!per_write_integer16(s, channelId, 0)) /* channelId */ |
1348 | 0 | goto fail; |
1349 | 0 | Stream_SealLength(s); |
1350 | |
|
1351 | 0 | { |
1352 | 0 | rdpTransport* transport = freerdp_get_transport(mcs->context); |
1353 | 0 | status = transport_write(transport, s); |
1354 | 0 | } |
1355 | |
|
1356 | 0 | fail: |
1357 | 0 | Stream_Free(s, TRUE); |
1358 | 0 | return (status < 0) ? FALSE : TRUE; |
1359 | 0 | } |
1360 | | |
1361 | | /** |
1362 | | * Receive MCS Disconnect Provider Ultimatum PDU. |
1363 | | * @param mcs mcs module |
1364 | | */ |
1365 | | |
1366 | | BOOL mcs_recv_disconnect_provider_ultimatum(WINPR_ATTR_UNUSED rdpMcs* mcs, wStream* s, int* reason) |
1367 | 820 | { |
1368 | 820 | BYTE b1 = 0; |
1369 | 820 | BYTE b2 = 0; |
1370 | | |
1371 | 820 | WINPR_ASSERT(mcs); |
1372 | 820 | WINPR_ASSERT(s); |
1373 | 820 | WINPR_ASSERT(reason); |
1374 | | |
1375 | | /* |
1376 | | * http://msdn.microsoft.com/en-us/library/cc240872.aspx: |
1377 | | * |
1378 | | * PER encoded (ALIGNED variant of BASIC-PER) PDU contents: |
1379 | | * 21 80 |
1380 | | * |
1381 | | * 0x21: |
1382 | | * 0 - --\ |
1383 | | * 0 - | |
1384 | | * 1 - | CHOICE: From DomainMCSPDU select disconnectProviderUltimatum (8) |
1385 | | * 0 - | of type DisconnectProviderUltimatum |
1386 | | * 0 - | |
1387 | | * 0 - --/ |
1388 | | * 0 - --\ |
1389 | | * 1 - | |
1390 | | * | DisconnectProviderUltimatum::reason = rn-user-requested (3) |
1391 | | * 0x80: | |
1392 | | * 1 - --/ |
1393 | | * 0 - padding |
1394 | | * 0 - padding |
1395 | | * 0 - padding |
1396 | | * 0 - padding |
1397 | | * 0 - padding |
1398 | | * 0 - padding |
1399 | | * 0 - padding |
1400 | | */ |
1401 | | |
1402 | 820 | if (!Stream_CheckAndLogRequiredLengthWLog(mcs->log, s, 1)) |
1403 | 2 | return FALSE; |
1404 | | |
1405 | 818 | Stream_Rewind_UINT8(s); |
1406 | 818 | Stream_Read_UINT8(s, b1); |
1407 | 818 | Stream_Read_UINT8(s, b2); |
1408 | 818 | *reason = ((b1 & 0x01) << 1) | (b2 >> 7); |
1409 | 818 | return TRUE; |
1410 | 820 | } |
1411 | | |
1412 | | /** |
1413 | | * Send MCS Disconnect Provider Ultimatum PDU. |
1414 | | * @param mcs mcs module |
1415 | | */ |
1416 | | |
1417 | | BOOL mcs_send_disconnect_provider_ultimatum(rdpMcs* mcs, enum Disconnect_Ultimatum reason) |
1418 | 0 | { |
1419 | 0 | int status = -1; |
1420 | 0 | UINT16 length = 9; |
1421 | |
|
1422 | 0 | WINPR_ASSERT(mcs); |
1423 | |
|
1424 | 0 | wStream* s = Stream_New(NULL, length); |
1425 | |
|
1426 | 0 | if (!s) |
1427 | 0 | goto fail; |
1428 | | |
1429 | 0 | if (!mcs_write_domain_mcspdu_header(s, DomainMCSPDU_DisconnectProviderUltimatum, length, 1)) |
1430 | 0 | goto fail; |
1431 | | |
1432 | 0 | if (!per_write_enumerated(s, 0x80, WINPR_ASSERTING_INT_CAST(BYTE, reason))) |
1433 | 0 | goto fail; |
1434 | | |
1435 | 0 | { |
1436 | 0 | rdpTransport* transport = freerdp_get_transport(mcs->context); |
1437 | 0 | status = transport_write(transport, s); |
1438 | 0 | } |
1439 | |
|
1440 | 0 | fail: |
1441 | 0 | WLog_Print(mcs->log, WLOG_DEBUG, "sending DisconnectProviderUltimatum(%s)", |
1442 | 0 | freerdp_disconnect_reason_string((int)reason)); |
1443 | 0 | Stream_Free(s, TRUE); |
1444 | 0 | return (status < 0) ? FALSE : TRUE; |
1445 | 0 | } |
1446 | | |
1447 | | BOOL mcs_client_begin(rdpMcs* mcs) |
1448 | 0 | { |
1449 | 0 | if (!mcs || !mcs->context) |
1450 | 0 | return FALSE; |
1451 | | |
1452 | | /* First transition state, we need this to trigger session recording */ |
1453 | 0 | if (!mcs_send_connect_initial(mcs)) |
1454 | 0 | { |
1455 | 0 | freerdp_set_last_error_if_not(mcs->context, FREERDP_ERROR_MCS_CONNECT_INITIAL_ERROR); |
1456 | |
|
1457 | 0 | WLog_Print(mcs->log, WLOG_ERROR, "Error: unable to send MCS Connect Initial"); |
1458 | 0 | return FALSE; |
1459 | 0 | } |
1460 | | |
1461 | 0 | return TRUE; |
1462 | 0 | } |
1463 | | |
1464 | | /** |
1465 | | * Instantiate new MCS module. |
1466 | | * @param context rdpContext to use |
1467 | | * @return new MCS module |
1468 | | */ |
1469 | | |
1470 | | rdpMcs* mcs_new(rdpContext* context) |
1471 | 43.2k | { |
1472 | 43.2k | rdpMcs* mcs = (rdpMcs*)calloc(1, sizeof(rdpMcs)); |
1473 | | |
1474 | 43.2k | if (!mcs) |
1475 | 0 | return NULL; |
1476 | 43.2k | mcs->log = WLog_Get(MCS_TAG); |
1477 | 43.2k | WINPR_ASSERT(mcs->log); |
1478 | | |
1479 | 43.2k | mcs->context = context; |
1480 | 43.2k | mcs_init_domain_parameters(&mcs->targetParameters, 34, 2, 0, 0xFFFF); |
1481 | 43.2k | mcs_init_domain_parameters(&mcs->minimumParameters, 1, 1, 1, 0x420); |
1482 | 43.2k | mcs_init_domain_parameters(&mcs->maximumParameters, 0xFFFF, 0xFC17, 0xFFFF, 0xFFFF); |
1483 | 43.2k | mcs_init_domain_parameters(&mcs->domainParameters, 0, 0, 0, 0xFFFF); |
1484 | 43.2k | mcs->channelCount = 0; |
1485 | 43.2k | mcs->channelMaxCount = CHANNEL_MAX_COUNT; |
1486 | 43.2k | mcs->baseChannelId = MCS_GLOBAL_CHANNEL_ID + 1; |
1487 | 43.2k | mcs->channels = (rdpMcsChannel*)calloc(mcs->channelMaxCount, sizeof(rdpMcsChannel)); |
1488 | | |
1489 | 43.2k | if (!mcs->channels) |
1490 | 0 | goto out_free; |
1491 | | |
1492 | 43.2k | return mcs; |
1493 | 0 | out_free: |
1494 | 0 | free(mcs); |
1495 | 0 | return NULL; |
1496 | 43.2k | } |
1497 | | |
1498 | | /** |
1499 | | * Free MCS module. |
1500 | | * @param mcs MCS module to be freed |
1501 | | */ |
1502 | | |
1503 | | void mcs_free(rdpMcs* mcs) |
1504 | 43.2k | { |
1505 | 43.2k | if (mcs) |
1506 | 43.2k | { |
1507 | 43.2k | free(mcs->channels); |
1508 | 43.2k | free(mcs); |
1509 | 43.2k | } |
1510 | 43.2k | } |
1511 | | |
1512 | | BOOL mcs_server_apply_to_settings(const rdpMcs* mcs, rdpSettings* settings) |
1513 | 0 | { |
1514 | 0 | BOOL rc = FALSE; |
1515 | |
|
1516 | 0 | WINPR_ASSERT(mcs); |
1517 | 0 | WINPR_ASSERT(settings); |
1518 | |
|
1519 | 0 | if (!freerdp_settings_set_uint32(settings, FreeRDP_ChannelCount, mcs->channelCount)) |
1520 | 0 | goto fail; |
1521 | | |
1522 | 0 | for (UINT32 x = 0; x < mcs->channelCount; x++) |
1523 | 0 | { |
1524 | 0 | const rdpMcsChannel* current = &mcs->channels[x]; |
1525 | 0 | CHANNEL_DEF def = WINPR_C_ARRAY_INIT; |
1526 | 0 | def.options = current->options; |
1527 | 0 | memcpy(def.name, current->Name, sizeof(def.name)); |
1528 | 0 | if (!freerdp_settings_set_pointer_array(settings, FreeRDP_ChannelDefArray, x, &def)) |
1529 | 0 | goto fail; |
1530 | 0 | } |
1531 | | |
1532 | 0 | rc = TRUE; |
1533 | 0 | fail: |
1534 | 0 | if (!rc) |
1535 | 0 | WLog_Print(mcs->log, WLOG_WARN, "failed to apply settings"); |
1536 | |
|
1537 | 0 | return rc; |
1538 | 0 | } |