Coverage Report

Created: 2026-09-14 06:32

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