Coverage Report

Created: 2026-10-15 06:31

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/FreeRDP/channels/rail/client/rail_orders.c
Line
Count
Source
1
/**
2
 * FreeRDP: A Remote Desktop Protocol Implementation
3
 * Remote Applications Integrated Locally (RAIL) Orders
4
 *
5
 * Copyright 2009 Marc-Andre Moreau <marcandre.moreau@gmail.com>
6
 * Copyright 2011 Roman Barabanov <romanbarabanov@gmail.com>
7
 * Copyright 2015 Thincast Technologies GmbH
8
 * Copyright 2015 DI (FH) Martin Haimberger <martin.haimberger@thincast.com>
9
 * Copyright 2017 Armin Novak <armin.novak@thincast.com>
10
 * Copyright 2017 Thincast Technologies GmbH
11
 *
12
 * Licensed under the Apache License, Version 2.0 (the "License");
13
 * you may not use this file except in compliance with the License.
14
 * You may obtain a copy of the License at
15
 *
16
 *     http://www.apache.org/licenses/LICENSE-2.0
17
 *
18
 * Unless required by applicable law or agreed to in writing, software
19
 * distributed under the License is distributed on an "AS IS" BASIS,
20
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21
 * See the License for the specific language governing permissions and
22
 * limitations under the License.
23
 */
24
25
#include <freerdp/config.h>
26
27
#include <winpr/crt.h>
28
#include <winpr/cast.h>
29
30
#include <freerdp/channels/log.h>
31
#include <freerdp/freerdp.h>
32
33
#include "rail_orders.h"
34
35
static BOOL rail_is_feature_supported(const rdpContext* context, UINT32 featureMask);
36
37
/**
38
 * Function description
39
 *
40
 * @return 0 on success, otherwise a Win32 error code
41
 */
42
UINT rail_send_pdu(railPlugin* rail, wStream* s, UINT16 orderType)
43
0
{
44
0
  char buffer[128] = WINPR_C_ARRAY_INIT;
45
46
0
  if (!rail || !s)
47
0
  {
48
0
    Stream_Free(s, TRUE);
49
0
    return ERROR_INVALID_PARAMETER;
50
0
  }
51
52
0
  const UINT16 orderLength = (UINT16)Stream_GetPosition(s);
53
0
  Stream_ResetPosition(s);
54
0
  if (!rail_write_pdu_header(s, orderType, orderLength))
55
0
    goto fail;
56
0
  if (!Stream_SetPosition(s, orderLength))
57
0
    goto fail;
58
0
  WLog_Print(rail->log, WLOG_DEBUG, "Sending %s PDU, length: %" PRIu16 "",
59
0
             rail_get_order_type_string_full(orderType, buffer, sizeof(buffer)), orderLength);
60
0
  return rail_send_channel_data(rail, s);
61
62
0
fail:
63
0
  Stream_Free(s, TRUE);
64
0
  return ERROR_INVALID_DATA;
65
0
}
66
67
/**
68
 * Function description
69
 *
70
 * @return 0 on success, otherwise a Win32 error code
71
 */
72
static UINT rail_read_server_exec_result_order(wStream* s, RAIL_EXEC_RESULT_ORDER* execResult)
73
193
{
74
193
  if (!s || !execResult)
75
0
    return ERROR_INVALID_PARAMETER;
76
77
193
  if (!Stream_CheckAndLogRequiredLength(TAG, s, RAIL_EXEC_RESULT_ORDER_LENGTH))
78
1
    return ERROR_INVALID_DATA;
79
80
192
  Stream_Read_UINT16(s, execResult->flags);      /* flags (2 bytes) */
81
192
  Stream_Read_UINT16(s, execResult->execResult); /* execResult (2 bytes) */
82
192
  Stream_Read_UINT32(s, execResult->rawResult);  /* rawResult (4 bytes) */
83
192
  Stream_Seek_UINT16(s);                         /* padding (2 bytes) */
84
192
  return rail_read_unicode_string(s, &execResult->exeOrFile)
85
192
             ? CHANNEL_RC_OK
86
192
             : ERROR_INTERNAL_ERROR; /* exeOrFile */
87
193
}
88
89
/**
90
 * Function description
91
 *
92
 * @return 0 on success, otherwise a Win32 error code
93
 */
94
static UINT rail_read_server_minmaxinfo_order(wStream* s, RAIL_MINMAXINFO_ORDER* minmaxinfo)
95
205
{
96
205
  if (!s || !minmaxinfo)
97
0
    return ERROR_INVALID_PARAMETER;
98
99
205
  if (!Stream_CheckAndLogRequiredLength(TAG, s, RAIL_MINMAXINFO_ORDER_LENGTH))
100
1
    return ERROR_INVALID_DATA;
101
102
204
  Stream_Read_UINT32(s, minmaxinfo->windowId);      /* windowId (4 bytes) */
103
204
  Stream_Read_INT16(s, minmaxinfo->maxWidth);       /* maxWidth (2 bytes) */
104
204
  Stream_Read_INT16(s, minmaxinfo->maxHeight);      /* maxHeight (2 bytes) */
105
204
  Stream_Read_INT16(s, minmaxinfo->maxPosX);        /* maxPosX (2 bytes) */
106
204
  Stream_Read_INT16(s, minmaxinfo->maxPosY);        /* maxPosY (2 bytes) */
107
204
  Stream_Read_INT16(s, minmaxinfo->minTrackWidth);  /* minTrackWidth (2 bytes) */
108
204
  Stream_Read_INT16(s, minmaxinfo->minTrackHeight); /* minTrackHeight (2 bytes) */
109
204
  Stream_Read_INT16(s, minmaxinfo->maxTrackWidth);  /* maxTrackWidth (2 bytes) */
110
204
  Stream_Read_INT16(s, minmaxinfo->maxTrackHeight); /* maxTrackHeight (2 bytes) */
111
204
  return CHANNEL_RC_OK;
112
205
}
113
114
/**
115
 * Function description
116
 *
117
 * @return 0 on success, otherwise a Win32 error code
118
 */
119
static UINT rail_read_server_localmovesize_order(wStream* s,
120
                                                 RAIL_LOCALMOVESIZE_ORDER* localMoveSize)
121
155
{
122
155
  UINT16 isMoveSizeStart = 0;
123
124
155
  if (!s || !localMoveSize)
125
0
    return ERROR_INVALID_PARAMETER;
126
127
155
  if (!Stream_CheckAndLogRequiredLength(TAG, s, RAIL_LOCALMOVESIZE_ORDER_LENGTH))
128
2
    return ERROR_INVALID_DATA;
129
130
153
  Stream_Read_UINT32(s, localMoveSize->windowId); /* windowId (4 bytes) */
131
153
  Stream_Read_UINT16(s, isMoveSizeStart);         /* isMoveSizeStart (2 bytes) */
132
153
  localMoveSize->isMoveSizeStart = (isMoveSizeStart != 0);
133
153
  Stream_Read_UINT16(s, localMoveSize->moveSizeType); /* moveSizeType (2 bytes) */
134
153
  Stream_Read_INT16(s, localMoveSize->posX);          /* posX (2 bytes) */
135
153
  Stream_Read_INT16(s, localMoveSize->posY);          /* posY (2 bytes) */
136
153
  return CHANNEL_RC_OK;
137
155
}
138
139
/**
140
 * Function description
141
 *
142
 * @return 0 on success, otherwise a Win32 error code
143
 */
144
static UINT rail_read_server_get_appid_resp_order(wStream* s,
145
                                                  RAIL_GET_APPID_RESP_ORDER* getAppidResp)
146
46
{
147
46
  if (!s || !getAppidResp)
148
0
    return ERROR_INVALID_PARAMETER;
149
150
46
  if (!Stream_CheckAndLogRequiredLength(TAG, s, RAIL_GET_APPID_RESP_ORDER_LENGTH))
151
3
    return ERROR_INVALID_DATA;
152
153
43
  Stream_Read_UINT32(s, getAppidResp->windowId); /* windowId (4 bytes) */
154
43
  if (!Stream_Read_UTF16_String(
155
43
          s, getAppidResp->applicationId,
156
43
          ARRAYSIZE(getAppidResp->applicationId))) /* applicationId (260 UNICODE chars) */
157
0
    return ERROR_INVALID_DATA;
158
159
43
  if (_wcsnlen(getAppidResp->applicationId, ARRAYSIZE(getAppidResp->applicationId)) >=
160
43
      ARRAYSIZE(getAppidResp->applicationId))
161
3
    return ERROR_INVALID_DATA;
162
163
40
  return CHANNEL_RC_OK;
164
43
}
165
166
/**
167
 * Function description
168
 *
169
 * @return 0 on success, otherwise a Win32 error code
170
 */
171
static UINT rail_read_langbar_info_order(wStream* s, RAIL_LANGBAR_INFO_ORDER* langbarInfo)
172
0
{
173
0
  if (!s || !langbarInfo)
174
0
    return ERROR_INVALID_PARAMETER;
175
176
0
  if (!Stream_CheckAndLogRequiredLength(TAG, s, RAIL_LANGBAR_INFO_ORDER_LENGTH))
177
0
    return ERROR_INVALID_DATA;
178
179
0
  Stream_Read_UINT32(s, langbarInfo->languageBarStatus); /* languageBarStatus (4 bytes) */
180
0
  return CHANNEL_RC_OK;
181
0
}
182
183
static UINT rail_write_client_status_order(wStream* s, const RAIL_CLIENT_STATUS_ORDER* clientStatus)
184
0
{
185
0
  if (!s || !clientStatus)
186
0
    return ERROR_INVALID_PARAMETER;
187
188
0
  Stream_Write_UINT32(s, clientStatus->flags); /* flags (4 bytes) */
189
0
  return ERROR_SUCCESS;
190
0
}
191
192
/**
193
 * Function description
194
 *
195
 * @return 0 on success, otherwise a Win32 error code
196
 */
197
static UINT rail_write_client_exec_order(wStream* s, UINT16 flags,
198
                                         const RAIL_UNICODE_STRING* exeOrFile,
199
                                         const RAIL_UNICODE_STRING* workingDir,
200
                                         const RAIL_UNICODE_STRING* arguments)
201
0
{
202
0
  UINT error = 0;
203
204
0
  if (!s || !exeOrFile || !workingDir || !arguments)
205
0
    return ERROR_INVALID_PARAMETER;
206
207
  /* [MS-RDPERP] 2.2.2.3.1 Client Execute PDU (TS_RAIL_ORDER_EXEC)
208
   * Check argument limits */
209
0
  if ((exeOrFile->length > 520) || (workingDir->length > 520) || (arguments->length > 16000))
210
0
  {
211
0
    WLog_ERR(TAG,
212
0
             "TS_RAIL_ORDER_EXEC argument limits exceeded: ExeOrFile=%" PRIu16
213
0
             " [max=520], WorkingDir=%" PRIu16 " [max=520], Arguments=%" PRIu16 " [max=16000]",
214
0
             exeOrFile->length, workingDir->length, arguments->length);
215
0
    return ERROR_BAD_ARGUMENTS;
216
0
  }
217
218
0
  Stream_Write_UINT16(s, flags);              /* flags (2 bytes) */
219
0
  Stream_Write_UINT16(s, exeOrFile->length);  /* exeOrFileLength (2 bytes) */
220
0
  Stream_Write_UINT16(s, workingDir->length); /* workingDirLength (2 bytes) */
221
0
  Stream_Write_UINT16(s, arguments->length);  /* argumentsLength (2 bytes) */
222
223
0
  if ((error = rail_write_unicode_string_value(s, exeOrFile)))
224
0
  {
225
0
    WLog_ERR(TAG, "rail_write_unicode_string_value failed with error %" PRIu32 "", error);
226
0
    return error;
227
0
  }
228
229
0
  if ((error = rail_write_unicode_string_value(s, workingDir)))
230
0
  {
231
0
    WLog_ERR(TAG, "rail_write_unicode_string_value failed with error %" PRIu32 "", error);
232
0
    return error;
233
0
  }
234
235
0
  if ((error = rail_write_unicode_string_value(s, arguments)))
236
0
  {
237
0
    WLog_ERR(TAG, "rail_write_unicode_string_value failed with error %" PRIu32 "", error);
238
0
    return error;
239
0
  }
240
241
0
  return error;
242
0
}
243
244
static UINT rail_write_client_activate_order(wStream* s, const RAIL_ACTIVATE_ORDER* activate)
245
0
{
246
0
  BYTE enabled = 0;
247
248
0
  if (!s || !activate)
249
0
    return ERROR_INVALID_PARAMETER;
250
251
0
  Stream_Write_UINT32(s, activate->windowId); /* windowId (4 bytes) */
252
0
  enabled = activate->enabled ? 1 : 0;
253
0
  Stream_Write_UINT8(s, enabled); /* enabled (1 byte) */
254
0
  return ERROR_SUCCESS;
255
0
}
256
257
static UINT rail_write_client_sysmenu_order(wStream* s, const RAIL_SYSMENU_ORDER* sysmenu)
258
0
{
259
0
  if (!s || !sysmenu)
260
0
    return ERROR_INVALID_PARAMETER;
261
262
0
  Stream_Write_UINT32(s, sysmenu->windowId); /* windowId (4 bytes) */
263
0
  Stream_Write_INT16(s, sysmenu->left);      /* left (2 bytes) */
264
0
  Stream_Write_INT16(s, sysmenu->top);       /* top (2 bytes) */
265
0
  return ERROR_SUCCESS;
266
0
}
267
268
static UINT rail_write_client_syscommand_order(wStream* s, const RAIL_SYSCOMMAND_ORDER* syscommand)
269
0
{
270
0
  if (!s || !syscommand)
271
0
    return ERROR_INVALID_PARAMETER;
272
273
0
  Stream_Write_UINT32(s, syscommand->windowId); /* windowId (4 bytes) */
274
0
  Stream_Write_UINT16(s, syscommand->command);  /* command (2 bytes) */
275
0
  return ERROR_SUCCESS;
276
0
}
277
278
static UINT rail_write_client_notify_event_order(wStream* s,
279
                                                 const RAIL_NOTIFY_EVENT_ORDER* notifyEvent)
280
0
{
281
0
  if (!s || !notifyEvent)
282
0
    return ERROR_INVALID_PARAMETER;
283
284
0
  Stream_Write_UINT32(s, notifyEvent->windowId);     /* windowId (4 bytes) */
285
0
  Stream_Write_UINT32(s, notifyEvent->notifyIconId); /* notifyIconId (4 bytes) */
286
0
  Stream_Write_UINT32(s, notifyEvent->message);      /* notifyIconId (4 bytes) */
287
0
  return ERROR_SUCCESS;
288
0
}
289
290
static UINT rail_write_client_window_move_order(wStream* s,
291
                                                const RAIL_WINDOW_MOVE_ORDER* windowMove)
292
0
{
293
0
  if (!s || !windowMove)
294
0
    return ERROR_INVALID_PARAMETER;
295
296
0
  Stream_Write_UINT32(s, windowMove->windowId); /* windowId (4 bytes) */
297
0
  Stream_Write_INT16(s, windowMove->left);      /* left (2 bytes) */
298
0
  Stream_Write_INT16(s, windowMove->top);       /* top (2 bytes) */
299
0
  Stream_Write_INT16(s, windowMove->right);     /* right (2 bytes) */
300
0
  Stream_Write_INT16(s, windowMove->bottom);    /* bottom (2 bytes) */
301
0
  return ERROR_SUCCESS;
302
0
}
303
304
static UINT rail_write_client_get_appid_req_order(wStream* s,
305
                                                  const RAIL_GET_APPID_REQ_ORDER* getAppidReq)
306
0
{
307
0
  if (!s || !getAppidReq)
308
0
    return ERROR_INVALID_PARAMETER;
309
310
0
  Stream_Write_UINT32(s, getAppidReq->windowId); /* windowId (4 bytes) */
311
0
  return ERROR_SUCCESS;
312
0
}
313
314
static UINT rail_write_langbar_info_order(wStream* s, const RAIL_LANGBAR_INFO_ORDER* langbarInfo)
315
0
{
316
0
  if (!s || !langbarInfo)
317
0
    return ERROR_INVALID_PARAMETER;
318
319
0
  Stream_Write_UINT32(s, langbarInfo->languageBarStatus); /* languageBarStatus (4 bytes) */
320
0
  return ERROR_SUCCESS;
321
0
}
322
323
static UINT rail_write_languageime_info_order(wStream* s,
324
                                              const RAIL_LANGUAGEIME_INFO_ORDER* langImeInfo)
325
0
{
326
0
  if (!s || !langImeInfo)
327
0
    return ERROR_INVALID_PARAMETER;
328
329
0
  Stream_Write_UINT32(s, langImeInfo->ProfileType);
330
0
  Stream_Write_UINT16(s, WINPR_ASSERTING_INT_CAST(UINT16, langImeInfo->LanguageID));
331
0
  Stream_Write(s, &langImeInfo->LanguageProfileCLSID, sizeof(langImeInfo->LanguageProfileCLSID));
332
0
  Stream_Write(s, &langImeInfo->ProfileGUID, sizeof(langImeInfo->ProfileGUID));
333
0
  Stream_Write_UINT32(s, langImeInfo->KeyboardLayout);
334
0
  return ERROR_SUCCESS;
335
0
}
336
337
static UINT rail_write_compartment_info_order(wStream* s,
338
                                              const RAIL_COMPARTMENT_INFO_ORDER* compartmentInfo)
339
0
{
340
0
  if (!s || !compartmentInfo)
341
0
    return ERROR_INVALID_PARAMETER;
342
343
0
  Stream_Write_UINT32(s, compartmentInfo->ImeState);
344
0
  Stream_Write_UINT32(s, compartmentInfo->ImeConvMode);
345
0
  Stream_Write_UINT32(s, compartmentInfo->ImeSentenceMode);
346
0
  Stream_Write_UINT32(s, compartmentInfo->KanaMode);
347
0
  return ERROR_SUCCESS;
348
0
}
349
350
/**
351
 * Function description
352
 *
353
 * @return 0 on success, otherwise a Win32 error code
354
 */
355
static UINT rail_recv_handshake_order(railPlugin* rail, wStream* s)
356
44
{
357
44
  RailClientContext* context = rail_get_client_interface(rail);
358
44
  RAIL_HANDSHAKE_ORDER serverHandshake = WINPR_C_ARRAY_INIT;
359
44
  UINT error = 0;
360
361
44
  if (!context || !s)
362
0
    return ERROR_INVALID_PARAMETER;
363
364
44
  if ((error = rail_read_handshake_order(s, &serverHandshake)))
365
1
  {
366
1
    WLog_ERR(TAG, "rail_read_handshake_order failed with error %" PRIu32 "!", error);
367
1
    return error;
368
1
  }
369
370
43
  rail->channelBuildNumber = serverHandshake.buildNumber;
371
372
43
  if (context->custom)
373
0
  {
374
0
    IFCALLRET(context->ServerHandshake, error, context, &serverHandshake);
375
376
0
    if (error)
377
0
      WLog_ERR(TAG, "context.ServerHandshake failed with error %" PRIu32 "", error);
378
0
  }
379
380
43
  return error;
381
44
}
382
383
static UINT rail_read_compartment_info_order(wStream* s,
384
                                             RAIL_COMPARTMENT_INFO_ORDER* compartmentInfo)
385
0
{
386
0
  if (!Stream_CheckAndLogRequiredLength(TAG, s, RAIL_COMPARTMENT_INFO_ORDER_LENGTH))
387
0
    return ERROR_INVALID_DATA;
388
389
0
  Stream_Read_UINT32(s, compartmentInfo->ImeState);        /* ImeState (4 bytes) */
390
0
  Stream_Read_UINT32(s, compartmentInfo->ImeConvMode);     /* ImeConvMode (4 bytes) */
391
0
  Stream_Read_UINT32(s, compartmentInfo->ImeSentenceMode); /* ImeSentenceMode (4 bytes) */
392
0
  Stream_Read_UINT32(s, compartmentInfo->KanaMode);        /* KANAMode (4 bytes) */
393
0
  return CHANNEL_RC_OK;
394
0
}
395
396
static UINT rail_recv_compartmentinfo_order(railPlugin* rail, wStream* s)
397
1
{
398
1
  RailClientContext* context = rail_get_client_interface(rail);
399
1
  RAIL_COMPARTMENT_INFO_ORDER pdu = WINPR_C_ARRAY_INIT;
400
1
  UINT error = 0;
401
402
1
  if (!context || !s)
403
0
    return ERROR_INVALID_PARAMETER;
404
405
1
  if (!rail_is_feature_supported(rail->rdpcontext, RAIL_LEVEL_LANGUAGE_IME_SYNC_SUPPORTED))
406
1
    return ERROR_BAD_CONFIGURATION;
407
408
0
  if ((error = rail_read_compartment_info_order(s, &pdu)))
409
0
    return error;
410
411
0
  if (context->custom)
412
0
  {
413
0
    IFCALLRET(context->ClientCompartmentInfo, error, context, &pdu);
414
415
0
    if (error)
416
0
      WLog_ERR(TAG, "context.ClientCompartmentInfo failed with error %" PRIu32 "", error);
417
0
  }
418
419
0
  return error;
420
0
}
421
422
BOOL rail_is_feature_supported(const rdpContext* context, UINT32 featureMask)
423
5
{
424
5
  UINT32 supported = 0;
425
5
  UINT32 masked = 0;
426
427
5
  if (!context || !context->settings)
428
0
    return FALSE;
429
430
5
  const UINT32 level =
431
5
      freerdp_settings_get_uint32(context->settings, FreeRDP_RemoteApplicationSupportLevel);
432
5
  const UINT32 mask =
433
5
      freerdp_settings_get_uint32(context->settings, FreeRDP_RemoteApplicationSupportMask);
434
5
  supported = level & mask;
435
5
  masked = (supported & featureMask);
436
437
5
  if (masked != featureMask)
438
5
  {
439
5
    char maskstr[256] = WINPR_C_ARRAY_INIT;
440
5
    char actualstr[256] = WINPR_C_ARRAY_INIT;
441
442
5
    WLog_WARN(TAG, "have %s, require %s",
443
5
              freerdp_rail_support_flags_to_string(supported, actualstr, sizeof(actualstr)),
444
5
              freerdp_rail_support_flags_to_string(featureMask, maskstr, sizeof(maskstr)));
445
5
    return FALSE;
446
5
  }
447
448
0
  return TRUE;
449
5
}
450
451
/**
452
 * Function description
453
 *
454
 * @return 0 on success, otherwise a Win32 error code
455
 */
456
static UINT rail_recv_handshake_ex_order(railPlugin* rail, wStream* s)
457
2
{
458
2
  RailClientContext* context = rail_get_client_interface(rail);
459
2
  RAIL_HANDSHAKE_EX_ORDER serverHandshake = WINPR_C_ARRAY_INIT;
460
2
  UINT error = 0;
461
462
2
  if (!rail || !context || !s)
463
0
    return ERROR_INVALID_PARAMETER;
464
465
2
  if (!rail_is_feature_supported(rail->rdpcontext, RAIL_LEVEL_HANDSHAKE_EX_SUPPORTED))
466
2
    return ERROR_BAD_CONFIGURATION;
467
468
0
  if ((error = rail_read_handshake_ex_order(s, &serverHandshake)))
469
0
  {
470
0
    WLog_ERR(TAG, "rail_read_handshake_ex_order failed with error %" PRIu32 "!", error);
471
0
    return error;
472
0
  }
473
474
0
  rail->channelBuildNumber = serverHandshake.buildNumber;
475
0
  rail->channelFlags = serverHandshake.railHandshakeFlags;
476
477
0
  {
478
0
    char buffer[192] = WINPR_C_ARRAY_INIT;
479
0
    WLog_DBG(TAG, "HandshakeFlags=%s [buildNumber=0x%08" PRIx32 "]",
480
0
             rail_handshake_ex_flags_to_string(rail->channelFlags, buffer, sizeof(buffer)),
481
0
             rail->channelBuildNumber);
482
0
  }
483
484
0
  if (context->custom)
485
0
  {
486
0
    IFCALLRET(context->ServerHandshakeEx, error, context, &serverHandshake);
487
488
0
    if (error)
489
0
      WLog_ERR(TAG, "context.ServerHandshakeEx failed with error %" PRIu32 "", error);
490
0
  }
491
492
0
  return error;
493
0
}
494
495
/**
496
 * Function description
497
 *
498
 * @return 0 on success, otherwise a Win32 error code
499
 */
500
static UINT rail_recv_exec_result_order(railPlugin* rail, wStream* s)
501
193
{
502
193
  RailClientContext* context = rail_get_client_interface(rail);
503
193
  RAIL_EXEC_RESULT_ORDER execResult = WINPR_C_ARRAY_INIT;
504
193
  UINT error = 0;
505
506
193
  if (!context || !s)
507
0
    return ERROR_INVALID_PARAMETER;
508
509
193
  if ((error = rail_read_server_exec_result_order(s, &execResult)))
510
112
  {
511
112
    WLog_ERR(TAG, "rail_read_server_exec_result_order failed with error %" PRIu32 "!", error);
512
112
    goto fail;
513
112
  }
514
515
81
  if (context->custom)
516
0
  {
517
0
    IFCALLRET(context->ServerExecuteResult, error, context, &execResult);
518
519
0
    if (error)
520
0
      WLog_ERR(TAG, "context.ServerExecuteResult failed with error %" PRIu32 "", error);
521
0
  }
522
523
193
fail:
524
193
  rail_unicode_string_free(&execResult.exeOrFile);
525
193
  return error;
526
81
}
527
528
/**
529
 * Function description
530
 *
531
 * @return 0 on success, otherwise a Win32 error code
532
 */
533
static UINT rail_recv_server_sysparam_order(railPlugin* rail, wStream* s)
534
309
{
535
309
  RailClientContext* context = rail_get_client_interface(rail);
536
537
309
  if (!context || !s)
538
0
    return ERROR_INVALID_PARAMETER;
539
540
309
  const BOOL extendedSpiSupported = rail_is_extended_spi_supported(rail->channelFlags);
541
309
  RAIL_SYSPARAM_ORDER sysparam = WINPR_C_ARRAY_INIT;
542
309
  UINT error = rail_read_sysparam_order(s, &sysparam, extendedSpiSupported);
543
309
  if (error)
544
84
  {
545
84
    WLog_ERR(TAG, "rail_read_sysparam_order failed with error %" PRIu32 "!", error);
546
84
    goto fail;
547
84
  }
548
549
225
  if (context->custom)
550
0
  {
551
0
    IFCALLRET(context->ServerSystemParam, error, context, &sysparam);
552
553
0
    if (error)
554
0
      WLog_ERR(TAG, "context.ServerSystemParam failed with error %" PRIu32 "", error);
555
0
  }
556
309
fail:
557
309
  rail_unicode_string_free(&sysparam.highContrast.colorScheme);
558
559
309
  return error;
560
225
}
561
562
/**
563
 * Function description
564
 *
565
 * @return 0 on success, otherwise a Win32 error code
566
 */
567
static UINT rail_recv_server_minmaxinfo_order(railPlugin* rail, wStream* s)
568
205
{
569
205
  RailClientContext* context = rail_get_client_interface(rail);
570
205
  RAIL_MINMAXINFO_ORDER minMaxInfo = WINPR_C_ARRAY_INIT;
571
205
  UINT error = 0;
572
573
205
  if (!context || !s)
574
0
    return ERROR_INVALID_PARAMETER;
575
576
205
  if ((error = rail_read_server_minmaxinfo_order(s, &minMaxInfo)))
577
1
  {
578
1
    WLog_ERR(TAG, "rail_read_server_minmaxinfo_order failed with error %" PRIu32 "!", error);
579
1
    return error;
580
1
  }
581
582
204
  if (context->custom)
583
0
  {
584
0
    IFCALLRET(context->ServerMinMaxInfo, error, context, &minMaxInfo);
585
586
0
    if (error)
587
0
      WLog_ERR(TAG, "context.ServerMinMaxInfo failed with error %" PRIu32 "", error);
588
0
  }
589
590
204
  return error;
591
205
}
592
593
/**
594
 * Function description
595
 *
596
 * @return 0 on success, otherwise a Win32 error code
597
 */
598
static UINT rail_recv_server_localmovesize_order(railPlugin* rail, wStream* s)
599
155
{
600
155
  RailClientContext* context = rail_get_client_interface(rail);
601
155
  RAIL_LOCALMOVESIZE_ORDER localMoveSize = WINPR_C_ARRAY_INIT;
602
155
  UINT error = 0;
603
604
155
  if (!context || !s)
605
0
    return ERROR_INVALID_PARAMETER;
606
607
155
  if ((error = rail_read_server_localmovesize_order(s, &localMoveSize)))
608
2
  {
609
2
    WLog_ERR(TAG, "rail_read_server_localmovesize_order failed with error %" PRIu32 "!", error);
610
2
    return error;
611
2
  }
612
613
153
  if (context->custom)
614
0
  {
615
0
    IFCALLRET(context->ServerLocalMoveSize, error, context, &localMoveSize);
616
617
0
    if (error)
618
0
      WLog_ERR(TAG, "context.ServerLocalMoveSize failed with error %" PRIu32 "", error);
619
0
  }
620
621
153
  return error;
622
155
}
623
624
/**
625
 * Function description
626
 *
627
 * @return 0 on success, otherwise a Win32 error code
628
 */
629
static UINT rail_recv_server_get_appid_resp_order(railPlugin* rail, wStream* s)
630
46
{
631
46
  RailClientContext* context = rail_get_client_interface(rail);
632
46
  RAIL_GET_APPID_RESP_ORDER getAppIdResp = WINPR_C_ARRAY_INIT;
633
46
  UINT error = 0;
634
635
46
  if (!context || !s)
636
0
    return ERROR_INVALID_PARAMETER;
637
638
46
  if ((error = rail_read_server_get_appid_resp_order(s, &getAppIdResp)))
639
6
  {
640
6
    WLog_ERR(TAG, "rail_read_server_get_appid_resp_order failed with error %" PRIu32 "!",
641
6
             error);
642
6
    return error;
643
6
  }
644
645
40
  if (context->custom)
646
0
  {
647
0
    IFCALLRET(context->ServerGetAppIdResponse, error, context, &getAppIdResp);
648
649
0
    if (error)
650
0
      WLog_ERR(TAG, "context.ServerGetAppIdResponse failed with error %" PRIu32 "", error);
651
0
  }
652
653
40
  return error;
654
46
}
655
656
/**
657
 * Function description
658
 *
659
 * @return 0 on success, otherwise a Win32 error code
660
 */
661
static UINT rail_recv_langbar_info_order(railPlugin* rail, wStream* s)
662
1
{
663
1
  RailClientContext* context = rail_get_client_interface(rail);
664
1
  RAIL_LANGBAR_INFO_ORDER langBarInfo = WINPR_C_ARRAY_INIT;
665
1
  UINT error = 0;
666
667
1
  if (!context)
668
0
    return ERROR_INVALID_PARAMETER;
669
670
1
  if (!rail_is_feature_supported(rail->rdpcontext, RAIL_LEVEL_DOCKED_LANGBAR_SUPPORTED))
671
1
    return ERROR_BAD_CONFIGURATION;
672
673
0
  if ((error = rail_read_langbar_info_order(s, &langBarInfo)))
674
0
  {
675
0
    WLog_ERR(TAG, "rail_read_langbar_info_order failed with error %" PRIu32 "!", error);
676
0
    return error;
677
0
  }
678
679
0
  if (context->custom)
680
0
  {
681
0
    IFCALLRET(context->ServerLanguageBarInfo, error, context, &langBarInfo);
682
683
0
    if (error)
684
0
      WLog_ERR(TAG, "context.ServerLanguageBarInfo failed with error %" PRIu32 "", error);
685
0
  }
686
687
0
  return error;
688
0
}
689
690
static UINT rail_read_taskbar_info_order(wStream* s, RAIL_TASKBAR_INFO_ORDER* taskbarInfo)
691
0
{
692
0
  if (!s || !taskbarInfo)
693
0
    return ERROR_INVALID_PARAMETER;
694
695
0
  if (!Stream_CheckAndLogRequiredLength(TAG, s, RAIL_TASKBAR_INFO_ORDER_LENGTH))
696
0
    return ERROR_INVALID_DATA;
697
698
0
  Stream_Read_UINT32(s, taskbarInfo->TaskbarMessage);
699
0
  Stream_Read_UINT32(s, taskbarInfo->WindowIdTab);
700
0
  Stream_Read_UINT32(s, taskbarInfo->Body);
701
0
  return CHANNEL_RC_OK;
702
0
}
703
704
static UINT rail_recv_taskbar_info_order(railPlugin* rail, wStream* s)
705
1
{
706
1
  RailClientContext* context = rail_get_client_interface(rail);
707
1
  RAIL_TASKBAR_INFO_ORDER taskBarInfo = WINPR_C_ARRAY_INIT;
708
1
  UINT error = 0;
709
710
1
  if (!context)
711
0
    return ERROR_INVALID_PARAMETER;
712
713
  /* 2.2.2.14.1 Taskbar Tab Info PDU (TS_RAIL_ORDER_TASKBARINFO)
714
   * server -> client message only supported if announced. */
715
1
  if (!rail_is_feature_supported(rail->rdpcontext, RAIL_LEVEL_SHELL_INTEGRATION_SUPPORTED))
716
1
    return ERROR_BAD_CONFIGURATION;
717
718
0
  if ((error = rail_read_taskbar_info_order(s, &taskBarInfo)))
719
0
  {
720
0
    WLog_ERR(TAG, "rail_read_langbar_info_order failed with error %" PRIu32 "!", error);
721
0
    return error;
722
0
  }
723
724
0
  if (context->custom)
725
0
  {
726
0
    IFCALLRET(context->ServerTaskBarInfo, error, context, &taskBarInfo);
727
728
0
    if (error)
729
0
      WLog_ERR(TAG, "context.ServerTaskBarInfo failed with error %" PRIu32 "", error);
730
0
  }
731
732
0
  return error;
733
0
}
734
735
static UINT rail_read_zorder_sync_order(wStream* s, RAIL_ZORDER_SYNC* zorder)
736
0
{
737
0
  if (!s || !zorder)
738
0
    return ERROR_INVALID_PARAMETER;
739
740
0
  if (!Stream_CheckAndLogRequiredLength(TAG, s, RAIL_Z_ORDER_SYNC_ORDER_LENGTH))
741
0
    return ERROR_INVALID_DATA;
742
743
0
  Stream_Read_UINT32(s, zorder->windowIdMarker);
744
0
  return CHANNEL_RC_OK;
745
0
}
746
747
static UINT rail_recv_zorder_sync_order(railPlugin* rail, wStream* s)
748
1
{
749
1
  RailClientContext* context = rail_get_client_interface(rail);
750
1
  RAIL_ZORDER_SYNC zorder = WINPR_C_ARRAY_INIT;
751
1
  UINT error = 0;
752
753
1
  if (!context)
754
0
    return ERROR_INVALID_PARAMETER;
755
756
1
  if ((rail->clientStatus.flags & TS_RAIL_CLIENTSTATUS_ZORDER_SYNC) == 0)
757
1
    return ERROR_BAD_CONFIGURATION;
758
759
0
  if ((error = rail_read_zorder_sync_order(s, &zorder)))
760
0
  {
761
0
    WLog_ERR(TAG, "rail_read_zorder_sync_order failed with error %" PRIu32 "!", error);
762
0
    return error;
763
0
  }
764
765
0
  if (context->custom)
766
0
  {
767
0
    IFCALLRET(context->ServerZOrderSync, error, context, &zorder);
768
769
0
    if (error)
770
0
      WLog_ERR(TAG, "context.ServerZOrderSync failed with error %" PRIu32 "", error);
771
0
  }
772
773
0
  return error;
774
0
}
775
776
static UINT rail_read_cloak_order(wStream* s, RAIL_CLOAK* cloak)
777
0
{
778
0
  BYTE cloaked = 0;
779
780
0
  if (!Stream_CheckAndLogRequiredLength(TAG, s, RAIL_CLOAK_ORDER_LENGTH))
781
0
    return ERROR_INVALID_DATA;
782
783
0
  Stream_Read_UINT32(s, cloak->windowId); /* WindowId (4 bytes) */
784
0
  Stream_Read_UINT8(s, cloaked);          /* Cloaked (1 byte) */
785
0
  cloak->cloak = (cloaked != 0);
786
0
  return CHANNEL_RC_OK;
787
0
}
788
789
static UINT rail_recv_cloak_order(railPlugin* rail, wStream* s)
790
1
{
791
1
  RailClientContext* context = rail_get_client_interface(rail);
792
1
  RAIL_CLOAK cloak = WINPR_C_ARRAY_INIT;
793
1
  UINT error = 0;
794
795
1
  if (!context)
796
0
    return ERROR_INVALID_PARAMETER;
797
798
  /* 2.2.2.12.1 Window Cloak State Change PDU (TS_RAIL_ORDER_CLOAK)
799
   * server -> client message only supported if announced. */
800
1
  if ((rail->clientStatus.flags & TS_RAIL_CLIENTSTATUS_BIDIRECTIONAL_CLOAK_SUPPORTED) == 0)
801
1
    return ERROR_INVALID_DATA;
802
803
0
  if ((error = rail_read_cloak_order(s, &cloak)))
804
0
  {
805
0
    WLog_ERR(TAG, "rail_read_zorder_sync_order failed with error %" PRIu32 "!", error);
806
0
    return error;
807
0
  }
808
809
0
  if (context->custom)
810
0
  {
811
0
    IFCALLRET(context->ServerCloak, error, context, &cloak);
812
813
0
    if (error)
814
0
      WLog_ERR(TAG, "context.ServerZOrderSync failed with error %" PRIu32 "", error);
815
0
  }
816
817
0
  return error;
818
0
}
819
820
static UINT rail_read_power_display_request_order(wStream* s, RAIL_POWER_DISPLAY_REQUEST* power)
821
0
{
822
0
  UINT32 active = 0;
823
824
0
  if (!s || !power)
825
0
    return ERROR_INVALID_PARAMETER;
826
827
0
  if (!Stream_CheckAndLogRequiredLength(TAG, s, RAIL_POWER_DISPLAY_REQUEST_ORDER_LENGTH))
828
0
    return ERROR_INVALID_DATA;
829
830
0
  Stream_Read_UINT32(s, active);
831
0
  power->active = active != 0;
832
0
  return CHANNEL_RC_OK;
833
0
}
834
835
static UINT rail_recv_power_display_request_order(railPlugin* rail, wStream* s)
836
1
{
837
1
  RailClientContext* context = rail_get_client_interface(rail);
838
1
  RAIL_POWER_DISPLAY_REQUEST power = WINPR_C_ARRAY_INIT;
839
1
  UINT error = 0;
840
841
1
  if (!context)
842
0
    return ERROR_INVALID_PARAMETER;
843
844
  /* 2.2.2.13.1 Power Display Request PDU(TS_RAIL_ORDER_POWER_DISPLAY_REQUEST)
845
   */
846
1
  if ((rail->clientStatus.flags & TS_RAIL_CLIENTSTATUS_POWER_DISPLAY_REQUEST_SUPPORTED) == 0)
847
1
    return ERROR_BAD_CONFIGURATION;
848
849
0
  if ((error = rail_read_power_display_request_order(s, &power)))
850
0
  {
851
0
    WLog_ERR(TAG, "rail_read_zorder_sync_order failed with error %" PRIu32 "!", error);
852
0
    return error;
853
0
  }
854
855
0
  if (context->custom)
856
0
  {
857
0
    IFCALLRET(context->ServerPowerDisplayRequest, error, context, &power);
858
859
0
    if (error)
860
0
      WLog_ERR(TAG, "context.ServerPowerDisplayRequest failed with error %" PRIu32 "", error);
861
0
  }
862
863
0
  return error;
864
0
}
865
866
static UINT rail_read_get_application_id_extended_response_order(wStream* s,
867
                                                                 RAIL_GET_APPID_RESP_EX* id)
868
120
{
869
120
  if (!s || !id)
870
0
    return ERROR_INVALID_PARAMETER;
871
872
120
  if (!Stream_CheckAndLogRequiredLength(TAG, s, 4))
873
1
    return ERROR_INVALID_DATA;
874
875
119
  Stream_Read_UINT32(s, id->windowID);
876
877
119
  if (!Stream_Read_UTF16_String(s, id->applicationID, ARRAYSIZE(id->applicationID)))
878
15
    return ERROR_INVALID_DATA;
879
880
104
  if (_wcsnlen(id->applicationID, ARRAYSIZE(id->applicationID)) >= ARRAYSIZE(id->applicationID))
881
2
    return ERROR_INVALID_DATA;
882
883
102
  if (!Stream_CheckAndLogRequiredLength(TAG, s, 4))
884
10
    return ERROR_INVALID_DATA;
885
886
92
  Stream_Read_UINT32(s, id->processId);
887
888
92
  if (!Stream_Read_UTF16_String(s, id->processImageName, ARRAYSIZE(id->processImageName)))
889
11
    return ERROR_INVALID_DATA;
890
891
81
  if (_wcsnlen(id->processImageName, ARRAYSIZE(id->processImageName)) >=
892
81
      ARRAYSIZE(id->processImageName))
893
17
    return ERROR_INVALID_DATA;
894
895
64
  return CHANNEL_RC_OK;
896
81
}
897
898
static UINT rail_recv_get_application_id_extended_response_order(railPlugin* rail, wStream* s)
899
120
{
900
120
  RailClientContext* context = rail_get_client_interface(rail);
901
120
  RAIL_GET_APPID_RESP_EX id = WINPR_C_ARRAY_INIT;
902
120
  UINT error = 0;
903
904
120
  if (!context)
905
0
    return ERROR_INVALID_PARAMETER;
906
907
120
  if ((error = rail_read_get_application_id_extended_response_order(s, &id)))
908
56
  {
909
56
    WLog_ERR(TAG,
910
56
             "rail_read_get_application_id_extended_response_order failed with error %" PRIu32
911
56
             "!",
912
56
             error);
913
56
    return error;
914
56
  }
915
916
64
  if (context->custom)
917
0
  {
918
0
    IFCALLRET(context->ServerGetAppidResponseExtended, error, context, &id);
919
920
0
    if (error)
921
0
      WLog_ERR(TAG, "context.ServerGetAppidResponseExtended failed with error %" PRIu32 "",
922
0
               error);
923
0
  }
924
925
64
  return error;
926
120
}
927
928
static UINT rail_read_textscaleinfo_order(wStream* s, UINT32* pTextScaleFactor)
929
38
{
930
38
  WINPR_ASSERT(pTextScaleFactor);
931
932
38
  if (!Stream_CheckAndLogRequiredLength(TAG, s, 4))
933
1
    return ERROR_INVALID_DATA;
934
935
37
  Stream_Read_UINT32(s, *pTextScaleFactor);
936
37
  return CHANNEL_RC_OK;
937
38
}
938
939
static UINT rail_recv_textscaleinfo_order(railPlugin* rail, wStream* s)
940
38
{
941
38
  RailClientContext* context = rail_get_client_interface(rail);
942
38
  UINT32 TextScaleFactor = 0;
943
38
  UINT error = 0;
944
945
38
  if (!context)
946
0
    return ERROR_INVALID_PARAMETER;
947
948
38
  if ((error = rail_read_textscaleinfo_order(s, &TextScaleFactor)))
949
1
    return error;
950
951
37
  if (context->custom)
952
0
  {
953
0
    IFCALLRET(context->ClientTextScale, error, context, TextScaleFactor);
954
955
0
    if (error)
956
0
      WLog_ERR(TAG, "context.ClientTextScale failed with error %" PRIu32 "", error);
957
0
  }
958
959
37
  return error;
960
38
}
961
962
static UINT rail_read_caretblinkinfo_order(wStream* s, UINT32* pCaretBlinkRate)
963
32
{
964
32
  WINPR_ASSERT(pCaretBlinkRate);
965
966
32
  if (!Stream_CheckAndLogRequiredLength(TAG, s, 4))
967
1
    return ERROR_INVALID_DATA;
968
969
31
  Stream_Read_UINT32(s, *pCaretBlinkRate);
970
31
  return CHANNEL_RC_OK;
971
32
}
972
973
static UINT rail_recv_caretblinkinfo_order(railPlugin* rail, wStream* s)
974
32
{
975
32
  RailClientContext* context = rail_get_client_interface(rail);
976
32
  UINT32 CaretBlinkRate = 0;
977
32
  UINT error = 0;
978
979
32
  if (!context)
980
0
    return ERROR_INVALID_PARAMETER;
981
32
  if ((error = rail_read_caretblinkinfo_order(s, &CaretBlinkRate)))
982
1
    return error;
983
984
31
  if (context->custom)
985
0
  {
986
0
    IFCALLRET(context->ClientCaretBlinkRate, error, context, CaretBlinkRate);
987
988
0
    if (error)
989
0
      WLog_ERR(TAG, "context.ClientCaretBlinkRate failed with error %" PRIu32 "", error);
990
0
  }
991
992
31
  return error;
993
32
}
994
995
/**
996
 * Function description
997
 *
998
 * @return 0 on success, otherwise a Win32 error code
999
 */
1000
UINT rail_order_recv(LPVOID userdata, wStream* s)
1001
1.20k
{
1002
1.20k
  char buffer[128] = WINPR_C_ARRAY_INIT;
1003
1.20k
  railPlugin* rail = userdata;
1004
1.20k
  UINT16 orderType = 0;
1005
1.20k
  UINT16 orderLength = 0;
1006
1.20k
  UINT error = CHANNEL_RC_OK;
1007
1008
1.20k
  if (!rail || !s)
1009
0
  {
1010
0
    error = ERROR_INVALID_PARAMETER;
1011
0
    goto fail;
1012
0
  }
1013
1014
1.20k
  if ((error = rail_read_pdu_header(s, &orderType, &orderLength)))
1015
43
  {
1016
43
    WLog_ERR(TAG, "rail_read_pdu_header failed with error %" PRIu32 "!", error);
1017
43
    error = ERROR_INVALID_DATA;
1018
43
    goto fail;
1019
43
  }
1020
1021
1.16k
  WLog_Print(rail->log, WLOG_DEBUG, "Received %s PDU, length:%" PRIu16 "",
1022
1.16k
             rail_get_order_type_string_full(orderType, buffer, sizeof(buffer)), orderLength);
1023
1024
1.16k
  switch (orderType)
1025
1.16k
  {
1026
44
    case TS_RAIL_ORDER_HANDSHAKE:
1027
44
      error = rail_recv_handshake_order(rail, s);
1028
44
      break;
1029
1030
1
    case TS_RAIL_ORDER_COMPARTMENTINFO:
1031
1
      error = rail_recv_compartmentinfo_order(rail, s);
1032
1
      break;
1033
1034
2
    case TS_RAIL_ORDER_HANDSHAKE_EX:
1035
2
      error = rail_recv_handshake_ex_order(rail, s);
1036
2
      break;
1037
1038
193
    case TS_RAIL_ORDER_EXEC_RESULT:
1039
193
      error = rail_recv_exec_result_order(rail, s);
1040
193
      break;
1041
1042
309
    case TS_RAIL_ORDER_SYSPARAM:
1043
309
      error = rail_recv_server_sysparam_order(rail, s);
1044
309
      break;
1045
1046
205
    case TS_RAIL_ORDER_MINMAXINFO:
1047
205
      error = rail_recv_server_minmaxinfo_order(rail, s);
1048
205
      break;
1049
1050
155
    case TS_RAIL_ORDER_LOCALMOVESIZE:
1051
155
      error = rail_recv_server_localmovesize_order(rail, s);
1052
155
      break;
1053
1054
46
    case TS_RAIL_ORDER_GET_APPID_RESP:
1055
46
      error = rail_recv_server_get_appid_resp_order(rail, s);
1056
46
      break;
1057
1058
1
    case TS_RAIL_ORDER_LANGBARINFO:
1059
1
      error = rail_recv_langbar_info_order(rail, s);
1060
1
      break;
1061
1062
1
    case TS_RAIL_ORDER_TASKBARINFO:
1063
1
      error = rail_recv_taskbar_info_order(rail, s);
1064
1
      break;
1065
1066
1
    case TS_RAIL_ORDER_ZORDER_SYNC:
1067
1
      error = rail_recv_zorder_sync_order(rail, s);
1068
1
      break;
1069
1070
1
    case TS_RAIL_ORDER_CLOAK:
1071
1
      error = rail_recv_cloak_order(rail, s);
1072
1
      break;
1073
1074
1
    case TS_RAIL_ORDER_POWER_DISPLAY_REQUEST:
1075
1
      error = rail_recv_power_display_request_order(rail, s);
1076
1
      break;
1077
1078
120
    case TS_RAIL_ORDER_GET_APPID_RESP_EX:
1079
120
      error = rail_recv_get_application_id_extended_response_order(rail, s);
1080
120
      break;
1081
1082
38
    case TS_RAIL_ORDER_TEXTSCALEINFO:
1083
38
      error = rail_recv_textscaleinfo_order(rail, s);
1084
38
      break;
1085
1086
32
    case TS_RAIL_ORDER_CARETBLINKINFO:
1087
32
      error = rail_recv_caretblinkinfo_order(rail, s);
1088
32
      break;
1089
1090
15
    default:
1091
15
      WLog_ERR(TAG, "Unknown RAIL PDU %s received.",
1092
15
               rail_get_order_type_string_full(orderType, buffer, sizeof(buffer)));
1093
15
      return ERROR_INVALID_DATA;
1094
1.16k
  }
1095
1096
1.15k
  if (error == ERROR_BAD_CONFIGURATION)
1097
7
  {
1098
7
    char ebuffer[128] = WINPR_C_ARRAY_INIT;
1099
7
    WLog_Print(rail->log, WLOG_WARN,
1100
7
               "%s - SERVER BUG: The support for this feature was not announced!",
1101
7
               rail_get_order_type_string_full(orderType, ebuffer, sizeof(ebuffer)));
1102
1103
7
    if (freerdp_settings_get_bool(rail->rdpcontext->settings,
1104
7
                                  FreeRDP_AllowUnanouncedOrdersFromServer))
1105
0
      error = CHANNEL_RC_OK;
1106
7
  }
1107
1.15k
  if (error != CHANNEL_RC_OK)
1108
272
  {
1109
272
    char ebuffer[128] = WINPR_C_ARRAY_INIT;
1110
272
    WLog_Print(rail->log, WLOG_ERROR, "Failed to process rail %s PDU, length:%" PRIu16 "",
1111
272
               rail_get_order_type_string_full(orderType, ebuffer, sizeof(ebuffer)),
1112
272
               orderLength);
1113
272
  }
1114
1115
1.19k
fail:
1116
1.19k
  Stream_Free(s, TRUE);
1117
1.19k
  return error;
1118
1.15k
}
1119
1120
/**
1121
 * Function description
1122
 *
1123
 * @return 0 on success, otherwise a Win32 error code
1124
 */
1125
UINT rail_send_handshake_order(railPlugin* rail, const RAIL_HANDSHAKE_ORDER* handshake)
1126
0
{
1127
0
  if (!rail || !handshake)
1128
0
    return ERROR_INVALID_PARAMETER;
1129
1130
0
  wStream* s = rail_pdu_init(RAIL_HANDSHAKE_ORDER_LENGTH);
1131
1132
0
  if (!s)
1133
0
  {
1134
0
    WLog_ERR(TAG, "rail_pdu_init failed!");
1135
0
    return CHANNEL_RC_NO_MEMORY;
1136
0
  }
1137
1138
0
  rail_write_handshake_order(s, handshake);
1139
0
  return rail_send_pdu(rail, s, TS_RAIL_ORDER_HANDSHAKE);
1140
0
}
1141
1142
/**
1143
 * Function description
1144
 *
1145
 * @return 0 on success, otherwise a Win32 error code
1146
 */
1147
UINT rail_send_handshake_ex_order(railPlugin* rail, const RAIL_HANDSHAKE_EX_ORDER* handshakeEx)
1148
0
{
1149
0
  if (!rail || !handshakeEx)
1150
0
    return ERROR_INVALID_PARAMETER;
1151
1152
0
  wStream* s = rail_pdu_init(RAIL_HANDSHAKE_EX_ORDER_LENGTH);
1153
1154
0
  if (!s)
1155
0
  {
1156
0
    WLog_ERR(TAG, "rail_pdu_init failed!");
1157
0
    return CHANNEL_RC_NO_MEMORY;
1158
0
  }
1159
1160
0
  rail_write_handshake_ex_order(s, handshakeEx);
1161
0
  return rail_send_pdu(rail, s, TS_RAIL_ORDER_HANDSHAKE_EX);
1162
0
}
1163
1164
/**
1165
 * Function description
1166
 *
1167
 * @return 0 on success, otherwise a Win32 error code
1168
 */
1169
UINT rail_send_client_status_order(railPlugin* rail, const RAIL_CLIENT_STATUS_ORDER* clientStatus)
1170
0
{
1171
0
  wStream* s = nullptr;
1172
0
  UINT error = 0;
1173
1174
0
  if (!rail || !clientStatus)
1175
0
    return ERROR_INVALID_PARAMETER;
1176
1177
0
  rail->clientStatus = *clientStatus;
1178
0
  s = rail_pdu_init(RAIL_CLIENT_STATUS_ORDER_LENGTH);
1179
1180
0
  if (!s)
1181
0
  {
1182
0
    WLog_ERR(TAG, "rail_pdu_init failed!");
1183
0
    return CHANNEL_RC_NO_MEMORY;
1184
0
  }
1185
1186
0
  error = rail_write_client_status_order(s, clientStatus);
1187
1188
0
  if (ERROR_SUCCESS != error)
1189
0
  {
1190
1191
0
    Stream_Free(s, TRUE);
1192
0
    return error;
1193
0
  }
1194
1195
0
  return rail_send_pdu(rail, s, TS_RAIL_ORDER_CLIENTSTATUS);
1196
0
}
1197
1198
/**
1199
 * Function description
1200
 *
1201
 * @return 0 on success, otherwise a Win32 error code
1202
 */
1203
UINT rail_send_client_exec_order(railPlugin* rail, UINT16 flags,
1204
                                 const RAIL_UNICODE_STRING* exeOrFile,
1205
                                 const RAIL_UNICODE_STRING* workingDir,
1206
                                 const RAIL_UNICODE_STRING* arguments)
1207
0
{
1208
0
  wStream* s = nullptr;
1209
0
  UINT error = 0;
1210
0
  size_t length = 0;
1211
1212
0
  if (!rail || !exeOrFile || !workingDir || !arguments)
1213
0
    return ERROR_INVALID_PARAMETER;
1214
1215
0
  length = RAIL_EXEC_ORDER_LENGTH + exeOrFile->length + workingDir->length + arguments->length;
1216
0
  s = rail_pdu_init(length);
1217
1218
0
  if (!s)
1219
0
  {
1220
0
    WLog_ERR(TAG, "rail_pdu_init failed!");
1221
0
    return CHANNEL_RC_NO_MEMORY;
1222
0
  }
1223
1224
0
  if ((error = rail_write_client_exec_order(s, flags, exeOrFile, workingDir, arguments)))
1225
0
  {
1226
0
    WLog_ERR(TAG, "rail_write_client_exec_order failed with error %" PRIu32 "!", error);
1227
0
    goto out;
1228
0
  }
1229
1230
0
  return rail_send_pdu(rail, s, TS_RAIL_ORDER_EXEC);
1231
1232
0
out:
1233
0
  Stream_Free(s, TRUE);
1234
0
  return error;
1235
0
}
1236
1237
/**
1238
 * Function description
1239
 *
1240
 * @return 0 on success, otherwise a Win32 error code
1241
 */
1242
UINT rail_send_client_activate_order(railPlugin* rail, const RAIL_ACTIVATE_ORDER* activate)
1243
0
{
1244
0
  wStream* s = nullptr;
1245
0
  UINT error = 0;
1246
1247
0
  if (!rail || !activate)
1248
0
    return ERROR_INVALID_PARAMETER;
1249
1250
0
  s = rail_pdu_init(RAIL_ACTIVATE_ORDER_LENGTH);
1251
1252
0
  if (!s)
1253
0
  {
1254
0
    WLog_ERR(TAG, "rail_pdu_init failed!");
1255
0
    return CHANNEL_RC_NO_MEMORY;
1256
0
  }
1257
1258
0
  error = rail_write_client_activate_order(s, activate);
1259
1260
0
  if (ERROR_SUCCESS != error)
1261
0
  {
1262
1263
0
    Stream_Free(s, TRUE);
1264
0
    return error;
1265
0
  }
1266
1267
0
  return rail_send_pdu(rail, s, TS_RAIL_ORDER_ACTIVATE);
1268
0
}
1269
1270
/**
1271
 * Function description
1272
 *
1273
 * @return 0 on success, otherwise a Win32 error code
1274
 */
1275
UINT rail_send_client_sysmenu_order(railPlugin* rail, const RAIL_SYSMENU_ORDER* sysmenu)
1276
0
{
1277
0
  wStream* s = nullptr;
1278
0
  UINT error = 0;
1279
1280
0
  if (!rail || !sysmenu)
1281
0
    return ERROR_INVALID_PARAMETER;
1282
1283
0
  s = rail_pdu_init(RAIL_SYSMENU_ORDER_LENGTH);
1284
1285
0
  if (!s)
1286
0
  {
1287
0
    WLog_ERR(TAG, "rail_pdu_init failed!");
1288
0
    return CHANNEL_RC_NO_MEMORY;
1289
0
  }
1290
1291
0
  error = rail_write_client_sysmenu_order(s, sysmenu);
1292
1293
0
  if (ERROR_SUCCESS != error)
1294
0
  {
1295
1296
0
    Stream_Free(s, TRUE);
1297
0
    return error;
1298
0
  }
1299
1300
0
  return rail_send_pdu(rail, s, TS_RAIL_ORDER_SYSMENU);
1301
0
}
1302
1303
/**
1304
 * Function description
1305
 *
1306
 * @return 0 on success, otherwise a Win32 error code
1307
 */
1308
UINT rail_send_client_syscommand_order(railPlugin* rail, const RAIL_SYSCOMMAND_ORDER* syscommand)
1309
0
{
1310
0
  wStream* s = nullptr;
1311
0
  UINT error = 0;
1312
1313
0
  if (!rail || !syscommand)
1314
0
    return ERROR_INVALID_PARAMETER;
1315
1316
0
  s = rail_pdu_init(RAIL_SYSCOMMAND_ORDER_LENGTH);
1317
1318
0
  if (!s)
1319
0
  {
1320
0
    WLog_ERR(TAG, "rail_pdu_init failed!");
1321
0
    return CHANNEL_RC_NO_MEMORY;
1322
0
  }
1323
1324
0
  error = rail_write_client_syscommand_order(s, syscommand);
1325
1326
0
  if (ERROR_SUCCESS != error)
1327
0
  {
1328
1329
0
    Stream_Free(s, TRUE);
1330
0
    return error;
1331
0
  }
1332
1333
0
  return rail_send_pdu(rail, s, TS_RAIL_ORDER_SYSCOMMAND);
1334
0
}
1335
1336
/**
1337
 * Function description
1338
 *
1339
 * @return 0 on success, otherwise a Win32 error code
1340
 */
1341
UINT rail_send_client_notify_event_order(railPlugin* rail,
1342
                                         const RAIL_NOTIFY_EVENT_ORDER* notifyEvent)
1343
0
{
1344
0
  wStream* s = nullptr;
1345
0
  UINT error = 0;
1346
1347
0
  if (!rail || !notifyEvent)
1348
0
    return ERROR_INVALID_PARAMETER;
1349
1350
0
  s = rail_pdu_init(RAIL_NOTIFY_EVENT_ORDER_LENGTH);
1351
1352
0
  if (!s)
1353
0
  {
1354
0
    WLog_ERR(TAG, "rail_pdu_init failed!");
1355
0
    return CHANNEL_RC_NO_MEMORY;
1356
0
  }
1357
1358
0
  error = rail_write_client_notify_event_order(s, notifyEvent);
1359
1360
0
  if (ERROR_SUCCESS != error)
1361
0
  {
1362
1363
0
    Stream_Free(s, TRUE);
1364
0
    return error;
1365
0
  }
1366
1367
0
  return rail_send_pdu(rail, s, TS_RAIL_ORDER_NOTIFY_EVENT);
1368
0
}
1369
1370
/**
1371
 * Function description
1372
 *
1373
 * @return 0 on success, otherwise a Win32 error code
1374
 */
1375
UINT rail_send_client_window_move_order(railPlugin* rail, const RAIL_WINDOW_MOVE_ORDER* windowMove)
1376
0
{
1377
0
  wStream* s = nullptr;
1378
0
  UINT error = 0;
1379
1380
0
  if (!rail || !windowMove)
1381
0
    return ERROR_INVALID_PARAMETER;
1382
1383
0
  s = rail_pdu_init(RAIL_WINDOW_MOVE_ORDER_LENGTH);
1384
1385
0
  if (!s)
1386
0
  {
1387
0
    WLog_ERR(TAG, "rail_pdu_init failed!");
1388
0
    return CHANNEL_RC_NO_MEMORY;
1389
0
  }
1390
1391
0
  error = rail_write_client_window_move_order(s, windowMove);
1392
1393
0
  if (ERROR_SUCCESS != error)
1394
0
  {
1395
1396
0
    Stream_Free(s, TRUE);
1397
0
    return error;
1398
0
  }
1399
1400
0
  return rail_send_pdu(rail, s, TS_RAIL_ORDER_WINDOWMOVE);
1401
0
}
1402
1403
/**
1404
 * Function description
1405
 *
1406
 * @return 0 on success, otherwise a Win32 error code
1407
 */
1408
UINT rail_send_client_get_appid_req_order(railPlugin* rail,
1409
                                          const RAIL_GET_APPID_REQ_ORDER* getAppIdReq)
1410
0
{
1411
0
  wStream* s = nullptr;
1412
0
  UINT error = 0;
1413
1414
0
  if (!rail || !getAppIdReq)
1415
0
    return ERROR_INVALID_PARAMETER;
1416
1417
0
  s = rail_pdu_init(RAIL_GET_APPID_REQ_ORDER_LENGTH);
1418
1419
0
  if (!s)
1420
0
  {
1421
0
    WLog_ERR(TAG, "rail_pdu_init failed!");
1422
0
    return CHANNEL_RC_NO_MEMORY;
1423
0
  }
1424
1425
0
  error = rail_write_client_get_appid_req_order(s, getAppIdReq);
1426
1427
0
  if (ERROR_SUCCESS != error)
1428
0
  {
1429
1430
0
    Stream_Free(s, TRUE);
1431
0
    return error;
1432
0
  }
1433
0
  return rail_send_pdu(rail, s, TS_RAIL_ORDER_GET_APPID_REQ);
1434
0
}
1435
1436
/**
1437
 * Function description
1438
 *
1439
 * @return 0 on success, otherwise a Win32 error code
1440
 */
1441
UINT rail_send_client_langbar_info_order(railPlugin* rail,
1442
                                         const RAIL_LANGBAR_INFO_ORDER* langBarInfo)
1443
0
{
1444
0
  wStream* s = nullptr;
1445
0
  UINT error = 0;
1446
1447
0
  if (!rail || !langBarInfo)
1448
0
    return ERROR_INVALID_PARAMETER;
1449
1450
0
  if (!rail_is_feature_supported(rail->rdpcontext, RAIL_LEVEL_DOCKED_LANGBAR_SUPPORTED))
1451
0
    return ERROR_BAD_CONFIGURATION;
1452
1453
0
  s = rail_pdu_init(RAIL_LANGBAR_INFO_ORDER_LENGTH);
1454
1455
0
  if (!s)
1456
0
  {
1457
0
    WLog_ERR(TAG, "rail_pdu_init failed!");
1458
0
    return CHANNEL_RC_NO_MEMORY;
1459
0
  }
1460
1461
0
  error = rail_write_langbar_info_order(s, langBarInfo);
1462
1463
0
  if (ERROR_SUCCESS != error)
1464
0
  {
1465
1466
0
    Stream_Free(s, TRUE);
1467
0
    return error;
1468
0
  }
1469
0
  return rail_send_pdu(rail, s, TS_RAIL_ORDER_LANGBARINFO);
1470
0
}
1471
1472
UINT rail_send_client_languageime_info_order(railPlugin* rail,
1473
                                             const RAIL_LANGUAGEIME_INFO_ORDER* langImeInfo)
1474
0
{
1475
0
  wStream* s = nullptr;
1476
0
  UINT error = 0;
1477
1478
0
  if (!rail || !langImeInfo)
1479
0
    return ERROR_INVALID_PARAMETER;
1480
1481
0
  if (!rail_is_feature_supported(rail->rdpcontext, RAIL_LEVEL_LANGUAGE_IME_SYNC_SUPPORTED))
1482
0
    return ERROR_BAD_CONFIGURATION;
1483
1484
0
  s = rail_pdu_init(RAIL_LANGUAGEIME_INFO_ORDER_LENGTH);
1485
1486
0
  if (!s)
1487
0
  {
1488
0
    WLog_ERR(TAG, "rail_pdu_init failed!");
1489
0
    return CHANNEL_RC_NO_MEMORY;
1490
0
  }
1491
1492
0
  error = rail_write_languageime_info_order(s, langImeInfo);
1493
1494
0
  if (ERROR_SUCCESS != error)
1495
0
  {
1496
1497
0
    Stream_Free(s, TRUE);
1498
0
    return error;
1499
0
  }
1500
0
  return rail_send_pdu(rail, s, TS_RAIL_ORDER_LANGUAGEIMEINFO);
1501
0
}
1502
1503
UINT rail_send_client_compartment_info_order(railPlugin* rail,
1504
                                             const RAIL_COMPARTMENT_INFO_ORDER* compartmentInfo)
1505
0
{
1506
0
  wStream* s = nullptr;
1507
0
  UINT error = 0;
1508
1509
0
  if (!rail || !compartmentInfo)
1510
0
    return ERROR_INVALID_PARAMETER;
1511
1512
0
  if (!rail_is_feature_supported(rail->rdpcontext, RAIL_LEVEL_LANGUAGE_IME_SYNC_SUPPORTED))
1513
0
    return ERROR_BAD_CONFIGURATION;
1514
1515
0
  s = rail_pdu_init(RAIL_COMPARTMENT_INFO_ORDER_LENGTH);
1516
1517
0
  if (!s)
1518
0
  {
1519
0
    WLog_ERR(TAG, "rail_pdu_init failed!");
1520
0
    return CHANNEL_RC_NO_MEMORY;
1521
0
  }
1522
1523
0
  error = rail_write_compartment_info_order(s, compartmentInfo);
1524
1525
0
  if (ERROR_SUCCESS != error)
1526
0
  {
1527
0
    Stream_Free(s, TRUE);
1528
0
    return error;
1529
0
  }
1530
0
  return rail_send_pdu(rail, s, TS_RAIL_ORDER_COMPARTMENTINFO);
1531
0
}
1532
1533
UINT rail_send_client_cloak_order(railPlugin* rail, const RAIL_CLOAK* cloak)
1534
0
{
1535
0
  if (!rail || !cloak)
1536
0
    return ERROR_INVALID_PARAMETER;
1537
1538
0
  wStream* s = rail_pdu_init(5);
1539
1540
0
  if (!s)
1541
0
  {
1542
0
    WLog_ERR(TAG, "rail_pdu_init failed!");
1543
0
    return CHANNEL_RC_NO_MEMORY;
1544
0
  }
1545
1546
0
  Stream_Write_UINT32(s, cloak->windowId);
1547
0
  Stream_Write_UINT8(s, cloak->cloak ? 1 : 0);
1548
0
  return rail_send_pdu(rail, s, TS_RAIL_ORDER_CLOAK);
1549
0
}
1550
1551
UINT rail_send_client_snap_arrange_order(railPlugin* rail, const RAIL_SNAP_ARRANGE* snap)
1552
0
{
1553
0
  if (!rail)
1554
0
    return ERROR_INVALID_PARAMETER;
1555
1556
  /* 2.2.2.7.5 Client Window Snap PDU (TS_RAIL_ORDER_SNAP_ARRANGE) */
1557
0
  if ((rail->channelFlags & TS_RAIL_ORDER_HANDSHAKE_EX_FLAGS_SNAP_ARRANGE_SUPPORTED) == 0)
1558
0
  {
1559
0
    RAIL_WINDOW_MOVE_ORDER move = WINPR_C_ARRAY_INIT;
1560
0
    move.top = snap->top;
1561
0
    move.left = snap->left;
1562
0
    move.right = snap->right;
1563
0
    move.bottom = snap->bottom;
1564
0
    move.windowId = snap->windowId;
1565
0
    return rail_send_client_window_move_order(rail, &move);
1566
0
  }
1567
1568
0
  wStream* s = rail_pdu_init(12);
1569
1570
0
  if (!s)
1571
0
  {
1572
0
    WLog_ERR(TAG, "rail_pdu_init failed!");
1573
0
    return CHANNEL_RC_NO_MEMORY;
1574
0
  }
1575
1576
0
  Stream_Write_UINT32(s, snap->windowId);
1577
0
  Stream_Write_INT16(s, snap->left);
1578
0
  Stream_Write_INT16(s, snap->top);
1579
0
  Stream_Write_INT16(s, snap->right);
1580
0
  Stream_Write_INT16(s, snap->bottom);
1581
0
  return rail_send_pdu(rail, s, TS_RAIL_ORDER_SNAP_ARRANGE);
1582
0
}
1583
1584
UINT rail_send_client_text_scale_order(railPlugin* rail, UINT32 textScale)
1585
0
{
1586
0
  if (!rail)
1587
0
    return ERROR_INVALID_PARAMETER;
1588
1589
0
  wStream* s = rail_pdu_init(4);
1590
1591
0
  if (!s)
1592
0
  {
1593
0
    WLog_ERR(TAG, "rail_pdu_init failed!");
1594
0
    return CHANNEL_RC_NO_MEMORY;
1595
0
  }
1596
1597
0
  Stream_Write_UINT32(s, textScale);
1598
0
  return rail_send_pdu(rail, s, TS_RAIL_ORDER_TEXTSCALEINFO);
1599
0
}
1600
1601
UINT rail_send_client_caret_blink_rate_order(railPlugin* rail, UINT32 rate)
1602
0
{
1603
0
  if (!rail)
1604
0
    return ERROR_INVALID_PARAMETER;
1605
1606
0
  wStream* s = rail_pdu_init(4);
1607
1608
0
  if (!s)
1609
0
  {
1610
0
    WLog_ERR(TAG, "rail_pdu_init failed!");
1611
0
    return CHANNEL_RC_NO_MEMORY;
1612
0
  }
1613
1614
0
  Stream_Write_UINT32(s, rate);
1615
0
  return rail_send_pdu(rail, s, TS_RAIL_ORDER_CARETBLINKINFO);
1616
0
}