Coverage Report

Created: 2026-05-30 06:46

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
  free(execResult.exeOrFile.string);
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
0
  RAIL_SYSPARAM_ORDER sysparam;
532
0
  UINT error = 0;
533
0
  BOOL extendedSpiSupported = 0;
534
535
0
  if (!context || !s)
536
0
    return ERROR_INVALID_PARAMETER;
537
538
0
  extendedSpiSupported = rail_is_extended_spi_supported(rail->channelFlags);
539
0
  if ((error = rail_read_sysparam_order(s, &sysparam, extendedSpiSupported)))
540
0
  {
541
0
    WLog_ERR(TAG, "rail_read_sysparam_order failed with error %" PRIu32 "!", error);
542
0
    return error;
543
0
  }
544
545
0
  if (context->custom)
546
0
  {
547
0
    IFCALLRET(context->ServerSystemParam, error, context, &sysparam);
548
549
0
    if (error)
550
0
      WLog_ERR(TAG, "context.ServerSystemParam failed with error %" PRIu32 "", error);
551
0
  }
552
553
0
  return error;
554
0
}
555
556
/**
557
 * Function description
558
 *
559
 * @return 0 on success, otherwise a Win32 error code
560
 */
561
static UINT rail_recv_server_minmaxinfo_order(railPlugin* rail, wStream* s)
562
0
{
563
0
  RailClientContext* context = rail_get_client_interface(rail);
564
0
  RAIL_MINMAXINFO_ORDER minMaxInfo = WINPR_C_ARRAY_INIT;
565
0
  UINT error = 0;
566
567
0
  if (!context || !s)
568
0
    return ERROR_INVALID_PARAMETER;
569
570
0
  if ((error = rail_read_server_minmaxinfo_order(s, &minMaxInfo)))
571
0
  {
572
0
    WLog_ERR(TAG, "rail_read_server_minmaxinfo_order failed with error %" PRIu32 "!", error);
573
0
    return error;
574
0
  }
575
576
0
  if (context->custom)
577
0
  {
578
0
    IFCALLRET(context->ServerMinMaxInfo, error, context, &minMaxInfo);
579
580
0
    if (error)
581
0
      WLog_ERR(TAG, "context.ServerMinMaxInfo failed with error %" PRIu32 "", error);
582
0
  }
583
584
0
  return error;
585
0
}
586
587
/**
588
 * Function description
589
 *
590
 * @return 0 on success, otherwise a Win32 error code
591
 */
592
static UINT rail_recv_server_localmovesize_order(railPlugin* rail, wStream* s)
593
0
{
594
0
  RailClientContext* context = rail_get_client_interface(rail);
595
0
  RAIL_LOCALMOVESIZE_ORDER localMoveSize = WINPR_C_ARRAY_INIT;
596
0
  UINT error = 0;
597
598
0
  if (!context || !s)
599
0
    return ERROR_INVALID_PARAMETER;
600
601
0
  if ((error = rail_read_server_localmovesize_order(s, &localMoveSize)))
602
0
  {
603
0
    WLog_ERR(TAG, "rail_read_server_localmovesize_order failed with error %" PRIu32 "!", error);
604
0
    return error;
605
0
  }
606
607
0
  if (context->custom)
608
0
  {
609
0
    IFCALLRET(context->ServerLocalMoveSize, error, context, &localMoveSize);
610
611
0
    if (error)
612
0
      WLog_ERR(TAG, "context.ServerLocalMoveSize failed with error %" PRIu32 "", error);
613
0
  }
614
615
0
  return error;
616
0
}
617
618
/**
619
 * Function description
620
 *
621
 * @return 0 on success, otherwise a Win32 error code
622
 */
623
static UINT rail_recv_server_get_appid_resp_order(railPlugin* rail, wStream* s)
624
0
{
625
0
  RailClientContext* context = rail_get_client_interface(rail);
626
0
  RAIL_GET_APPID_RESP_ORDER getAppIdResp = WINPR_C_ARRAY_INIT;
627
0
  UINT error = 0;
628
629
0
  if (!context || !s)
630
0
    return ERROR_INVALID_PARAMETER;
631
632
0
  if ((error = rail_read_server_get_appid_resp_order(s, &getAppIdResp)))
633
0
  {
634
0
    WLog_ERR(TAG, "rail_read_server_get_appid_resp_order failed with error %" PRIu32 "!",
635
0
             error);
636
0
    return error;
637
0
  }
638
639
0
  if (context->custom)
640
0
  {
641
0
    IFCALLRET(context->ServerGetAppIdResponse, error, context, &getAppIdResp);
642
643
0
    if (error)
644
0
      WLog_ERR(TAG, "context.ServerGetAppIdResponse failed with error %" PRIu32 "", error);
645
0
  }
646
647
0
  return error;
648
0
}
649
650
/**
651
 * Function description
652
 *
653
 * @return 0 on success, otherwise a Win32 error code
654
 */
655
static UINT rail_recv_langbar_info_order(railPlugin* rail, wStream* s)
656
0
{
657
0
  RailClientContext* context = rail_get_client_interface(rail);
658
0
  RAIL_LANGBAR_INFO_ORDER langBarInfo = WINPR_C_ARRAY_INIT;
659
0
  UINT error = 0;
660
661
0
  if (!context)
662
0
    return ERROR_INVALID_PARAMETER;
663
664
0
  if (!rail_is_feature_supported(rail->rdpcontext, RAIL_LEVEL_DOCKED_LANGBAR_SUPPORTED))
665
0
    return ERROR_BAD_CONFIGURATION;
666
667
0
  if ((error = rail_read_langbar_info_order(s, &langBarInfo)))
668
0
  {
669
0
    WLog_ERR(TAG, "rail_read_langbar_info_order failed with error %" PRIu32 "!", error);
670
0
    return error;
671
0
  }
672
673
0
  if (context->custom)
674
0
  {
675
0
    IFCALLRET(context->ServerLanguageBarInfo, error, context, &langBarInfo);
676
677
0
    if (error)
678
0
      WLog_ERR(TAG, "context.ServerLanguageBarInfo failed with error %" PRIu32 "", error);
679
0
  }
680
681
0
  return error;
682
0
}
683
684
static UINT rail_read_taskbar_info_order(wStream* s, RAIL_TASKBAR_INFO_ORDER* taskbarInfo)
685
0
{
686
0
  if (!s || !taskbarInfo)
687
0
    return ERROR_INVALID_PARAMETER;
688
689
0
  if (!Stream_CheckAndLogRequiredLength(TAG, s, RAIL_TASKBAR_INFO_ORDER_LENGTH))
690
0
    return ERROR_INVALID_DATA;
691
692
0
  Stream_Read_UINT32(s, taskbarInfo->TaskbarMessage);
693
0
  Stream_Read_UINT32(s, taskbarInfo->WindowIdTab);
694
0
  Stream_Read_UINT32(s, taskbarInfo->Body);
695
0
  return CHANNEL_RC_OK;
696
0
}
697
698
static UINT rail_recv_taskbar_info_order(railPlugin* rail, wStream* s)
699
0
{
700
0
  RailClientContext* context = rail_get_client_interface(rail);
701
0
  RAIL_TASKBAR_INFO_ORDER taskBarInfo = WINPR_C_ARRAY_INIT;
702
0
  UINT error = 0;
703
704
0
  if (!context)
705
0
    return ERROR_INVALID_PARAMETER;
706
707
  /* 2.2.2.14.1 Taskbar Tab Info PDU (TS_RAIL_ORDER_TASKBARINFO)
708
   * server -> client message only supported if announced. */
709
0
  if (!rail_is_feature_supported(rail->rdpcontext, RAIL_LEVEL_SHELL_INTEGRATION_SUPPORTED))
710
0
    return ERROR_BAD_CONFIGURATION;
711
712
0
  if ((error = rail_read_taskbar_info_order(s, &taskBarInfo)))
713
0
  {
714
0
    WLog_ERR(TAG, "rail_read_langbar_info_order failed with error %" PRIu32 "!", error);
715
0
    return error;
716
0
  }
717
718
0
  if (context->custom)
719
0
  {
720
0
    IFCALLRET(context->ServerTaskBarInfo, error, context, &taskBarInfo);
721
722
0
    if (error)
723
0
      WLog_ERR(TAG, "context.ServerTaskBarInfo failed with error %" PRIu32 "", error);
724
0
  }
725
726
0
  return error;
727
0
}
728
729
static UINT rail_read_zorder_sync_order(wStream* s, RAIL_ZORDER_SYNC* zorder)
730
0
{
731
0
  if (!s || !zorder)
732
0
    return ERROR_INVALID_PARAMETER;
733
734
0
  if (!Stream_CheckAndLogRequiredLength(TAG, s, RAIL_Z_ORDER_SYNC_ORDER_LENGTH))
735
0
    return ERROR_INVALID_DATA;
736
737
0
  Stream_Read_UINT32(s, zorder->windowIdMarker);
738
0
  return CHANNEL_RC_OK;
739
0
}
740
741
static UINT rail_recv_zorder_sync_order(railPlugin* rail, wStream* s)
742
0
{
743
0
  RailClientContext* context = rail_get_client_interface(rail);
744
0
  RAIL_ZORDER_SYNC zorder = WINPR_C_ARRAY_INIT;
745
0
  UINT error = 0;
746
747
0
  if (!context)
748
0
    return ERROR_INVALID_PARAMETER;
749
750
0
  if ((rail->clientStatus.flags & TS_RAIL_CLIENTSTATUS_ZORDER_SYNC) == 0)
751
0
    return ERROR_INVALID_DATA;
752
753
0
  if ((error = rail_read_zorder_sync_order(s, &zorder)))
754
0
  {
755
0
    WLog_ERR(TAG, "rail_read_zorder_sync_order failed with error %" PRIu32 "!", error);
756
0
    return error;
757
0
  }
758
759
0
  if (context->custom)
760
0
  {
761
0
    IFCALLRET(context->ServerZOrderSync, error, context, &zorder);
762
763
0
    if (error)
764
0
      WLog_ERR(TAG, "context.ServerZOrderSync failed with error %" PRIu32 "", error);
765
0
  }
766
767
0
  return error;
768
0
}
769
770
static UINT rail_read_cloak_order(wStream* s, RAIL_CLOAK* cloak)
771
0
{
772
0
  BYTE cloaked = 0;
773
774
0
  if (!Stream_CheckAndLogRequiredLength(TAG, s, RAIL_CLOAK_ORDER_LENGTH))
775
0
    return ERROR_INVALID_DATA;
776
777
0
  Stream_Read_UINT32(s, cloak->windowId); /* WindowId (4 bytes) */
778
0
  Stream_Read_UINT8(s, cloaked);          /* Cloaked (1 byte) */
779
0
  cloak->cloak = (cloaked != 0);
780
0
  return CHANNEL_RC_OK;
781
0
}
782
783
static UINT rail_recv_cloak_order(railPlugin* rail, wStream* s)
784
0
{
785
0
  RailClientContext* context = rail_get_client_interface(rail);
786
0
  RAIL_CLOAK cloak = WINPR_C_ARRAY_INIT;
787
0
  UINT error = 0;
788
789
0
  if (!context)
790
0
    return ERROR_INVALID_PARAMETER;
791
792
  /* 2.2.2.12.1 Window Cloak State Change PDU (TS_RAIL_ORDER_CLOAK)
793
   * server -> client message only supported if announced. */
794
0
  if ((rail->clientStatus.flags & TS_RAIL_CLIENTSTATUS_BIDIRECTIONAL_CLOAK_SUPPORTED) == 0)
795
0
    return ERROR_INVALID_DATA;
796
797
0
  if ((error = rail_read_cloak_order(s, &cloak)))
798
0
  {
799
0
    WLog_ERR(TAG, "rail_read_zorder_sync_order failed with error %" PRIu32 "!", error);
800
0
    return error;
801
0
  }
802
803
0
  if (context->custom)
804
0
  {
805
0
    IFCALLRET(context->ServerCloak, error, context, &cloak);
806
807
0
    if (error)
808
0
      WLog_ERR(TAG, "context.ServerZOrderSync failed with error %" PRIu32 "", error);
809
0
  }
810
811
0
  return error;
812
0
}
813
814
static UINT rail_read_power_display_request_order(wStream* s, RAIL_POWER_DISPLAY_REQUEST* power)
815
0
{
816
0
  UINT32 active = 0;
817
818
0
  if (!s || !power)
819
0
    return ERROR_INVALID_PARAMETER;
820
821
0
  if (!Stream_CheckAndLogRequiredLength(TAG, s, RAIL_POWER_DISPLAY_REQUEST_ORDER_LENGTH))
822
0
    return ERROR_INVALID_DATA;
823
824
0
  Stream_Read_UINT32(s, active);
825
0
  power->active = active != 0;
826
0
  return CHANNEL_RC_OK;
827
0
}
828
829
static UINT rail_recv_power_display_request_order(railPlugin* rail, wStream* s)
830
0
{
831
0
  RailClientContext* context = rail_get_client_interface(rail);
832
0
  RAIL_POWER_DISPLAY_REQUEST power = WINPR_C_ARRAY_INIT;
833
0
  UINT error = 0;
834
835
0
  if (!context)
836
0
    return ERROR_INVALID_PARAMETER;
837
838
  /* 2.2.2.13.1 Power Display Request PDU(TS_RAIL_ORDER_POWER_DISPLAY_REQUEST)
839
   */
840
0
  if ((rail->clientStatus.flags & TS_RAIL_CLIENTSTATUS_POWER_DISPLAY_REQUEST_SUPPORTED) == 0)
841
0
    return ERROR_INVALID_DATA;
842
843
0
  if ((error = rail_read_power_display_request_order(s, &power)))
844
0
  {
845
0
    WLog_ERR(TAG, "rail_read_zorder_sync_order failed with error %" PRIu32 "!", error);
846
0
    return error;
847
0
  }
848
849
0
  if (context->custom)
850
0
  {
851
0
    IFCALLRET(context->ServerPowerDisplayRequest, error, context, &power);
852
853
0
    if (error)
854
0
      WLog_ERR(TAG, "context.ServerPowerDisplayRequest failed with error %" PRIu32 "", error);
855
0
  }
856
857
0
  return error;
858
0
}
859
860
static UINT rail_read_get_application_id_extended_response_order(wStream* s,
861
                                                                 RAIL_GET_APPID_RESP_EX* id)
862
0
{
863
0
  if (!s || !id)
864
0
    return ERROR_INVALID_PARAMETER;
865
866
0
  if (!Stream_CheckAndLogRequiredLength(TAG, s, 4))
867
0
    return ERROR_INVALID_DATA;
868
869
0
  Stream_Read_UINT32(s, id->windowID);
870
871
0
  if (!Stream_Read_UTF16_String(s, id->applicationID, ARRAYSIZE(id->applicationID)))
872
0
    return ERROR_INVALID_DATA;
873
874
0
  if (_wcsnlen(id->applicationID, ARRAYSIZE(id->applicationID)) >= ARRAYSIZE(id->applicationID))
875
0
    return ERROR_INVALID_DATA;
876
877
0
  if (!Stream_CheckAndLogRequiredLength(TAG, s, 4))
878
0
    return ERROR_INVALID_DATA;
879
880
0
  Stream_Read_UINT32(s, id->processId);
881
882
0
  if (!Stream_Read_UTF16_String(s, id->processImageName, ARRAYSIZE(id->processImageName)))
883
0
    return ERROR_INVALID_DATA;
884
885
0
  if (_wcsnlen(id->applicationID, ARRAYSIZE(id->processImageName)) >=
886
0
      ARRAYSIZE(id->processImageName))
887
0
    return ERROR_INVALID_DATA;
888
889
0
  return CHANNEL_RC_OK;
890
0
}
891
892
static UINT rail_recv_get_application_id_extended_response_order(railPlugin* rail, wStream* s)
893
0
{
894
0
  RailClientContext* context = rail_get_client_interface(rail);
895
0
  RAIL_GET_APPID_RESP_EX id = WINPR_C_ARRAY_INIT;
896
0
  UINT error = 0;
897
898
0
  if (!context)
899
0
    return ERROR_INVALID_PARAMETER;
900
901
0
  if ((error = rail_read_get_application_id_extended_response_order(s, &id)))
902
0
  {
903
0
    WLog_ERR(TAG,
904
0
             "rail_read_get_application_id_extended_response_order failed with error %" PRIu32
905
0
             "!",
906
0
             error);
907
0
    return error;
908
0
  }
909
910
0
  if (context->custom)
911
0
  {
912
0
    IFCALLRET(context->ServerGetAppidResponseExtended, error, context, &id);
913
914
0
    if (error)
915
0
      WLog_ERR(TAG, "context.ServerGetAppidResponseExtended failed with error %" PRIu32 "",
916
0
               error);
917
0
  }
918
919
0
  return error;
920
0
}
921
922
static UINT rail_read_textscaleinfo_order(wStream* s, UINT32* pTextScaleFactor)
923
0
{
924
0
  WINPR_ASSERT(pTextScaleFactor);
925
926
0
  if (!Stream_CheckAndLogRequiredLength(TAG, s, 4))
927
0
    return ERROR_INVALID_DATA;
928
929
0
  Stream_Read_UINT32(s, *pTextScaleFactor);
930
0
  return CHANNEL_RC_OK;
931
0
}
932
933
static UINT rail_recv_textscaleinfo_order(railPlugin* rail, wStream* s)
934
0
{
935
0
  RailClientContext* context = rail_get_client_interface(rail);
936
0
  UINT32 TextScaleFactor = 0;
937
0
  UINT error = 0;
938
939
0
  if (!context)
940
0
    return ERROR_INVALID_PARAMETER;
941
942
0
  if ((error = rail_read_textscaleinfo_order(s, &TextScaleFactor)))
943
0
    return error;
944
945
0
  if (context->custom)
946
0
  {
947
0
    IFCALLRET(context->ClientTextScale, error, context, TextScaleFactor);
948
949
0
    if (error)
950
0
      WLog_ERR(TAG, "context.ClientTextScale failed with error %" PRIu32 "", error);
951
0
  }
952
953
0
  return error;
954
0
}
955
956
static UINT rail_read_caretblinkinfo_order(wStream* s, UINT32* pCaretBlinkRate)
957
0
{
958
0
  WINPR_ASSERT(pCaretBlinkRate);
959
960
0
  if (!Stream_CheckAndLogRequiredLength(TAG, s, 4))
961
0
    return ERROR_INVALID_DATA;
962
963
0
  Stream_Read_UINT32(s, *pCaretBlinkRate);
964
0
  return CHANNEL_RC_OK;
965
0
}
966
967
static UINT rail_recv_caretblinkinfo_order(railPlugin* rail, wStream* s)
968
0
{
969
0
  RailClientContext* context = rail_get_client_interface(rail);
970
0
  UINT32 CaretBlinkRate = 0;
971
0
  UINT error = 0;
972
973
0
  if (!context)
974
0
    return ERROR_INVALID_PARAMETER;
975
0
  if ((error = rail_read_caretblinkinfo_order(s, &CaretBlinkRate)))
976
0
    return error;
977
978
0
  if (context->custom)
979
0
  {
980
0
    IFCALLRET(context->ClientCaretBlinkRate, error, context, CaretBlinkRate);
981
982
0
    if (error)
983
0
      WLog_ERR(TAG, "context.ClientCaretBlinkRate failed with error %" PRIu32 "", error);
984
0
  }
985
986
0
  return error;
987
0
}
988
989
/**
990
 * Function description
991
 *
992
 * @return 0 on success, otherwise a Win32 error code
993
 */
994
UINT rail_order_recv(LPVOID userdata, wStream* s)
995
0
{
996
0
  char buffer[128] = WINPR_C_ARRAY_INIT;
997
0
  railPlugin* rail = userdata;
998
0
  UINT16 orderType = 0;
999
0
  UINT16 orderLength = 0;
1000
0
  UINT error = CHANNEL_RC_OK;
1001
1002
0
  if (!rail || !s)
1003
0
    return ERROR_INVALID_PARAMETER;
1004
1005
0
  if ((error = rail_read_pdu_header(s, &orderType, &orderLength)))
1006
0
  {
1007
0
    WLog_ERR(TAG, "rail_read_pdu_header failed with error %" PRIu32 "!", error);
1008
0
    return error;
1009
0
  }
1010
1011
0
  WLog_Print(rail->log, WLOG_DEBUG, "Received %s PDU, length:%" PRIu16 "",
1012
0
             rail_get_order_type_string_full(orderType, buffer, sizeof(buffer)), orderLength);
1013
1014
0
  switch (orderType)
1015
0
  {
1016
0
    case TS_RAIL_ORDER_HANDSHAKE:
1017
0
      error = rail_recv_handshake_order(rail, s);
1018
0
      break;
1019
1020
0
    case TS_RAIL_ORDER_COMPARTMENTINFO:
1021
0
      error = rail_recv_compartmentinfo_order(rail, s);
1022
0
      break;
1023
1024
0
    case TS_RAIL_ORDER_HANDSHAKE_EX:
1025
0
      error = rail_recv_handshake_ex_order(rail, s);
1026
0
      break;
1027
1028
0
    case TS_RAIL_ORDER_EXEC_RESULT:
1029
0
      error = rail_recv_exec_result_order(rail, s);
1030
0
      break;
1031
1032
0
    case TS_RAIL_ORDER_SYSPARAM:
1033
0
      error = rail_recv_server_sysparam_order(rail, s);
1034
0
      break;
1035
1036
0
    case TS_RAIL_ORDER_MINMAXINFO:
1037
0
      error = rail_recv_server_minmaxinfo_order(rail, s);
1038
0
      break;
1039
1040
0
    case TS_RAIL_ORDER_LOCALMOVESIZE:
1041
0
      error = rail_recv_server_localmovesize_order(rail, s);
1042
0
      break;
1043
1044
0
    case TS_RAIL_ORDER_GET_APPID_RESP:
1045
0
      error = rail_recv_server_get_appid_resp_order(rail, s);
1046
0
      break;
1047
1048
0
    case TS_RAIL_ORDER_LANGBARINFO:
1049
0
      error = rail_recv_langbar_info_order(rail, s);
1050
0
      break;
1051
1052
0
    case TS_RAIL_ORDER_TASKBARINFO:
1053
0
      error = rail_recv_taskbar_info_order(rail, s);
1054
0
      break;
1055
1056
0
    case TS_RAIL_ORDER_ZORDER_SYNC:
1057
0
      error = rail_recv_zorder_sync_order(rail, s);
1058
0
      break;
1059
1060
0
    case TS_RAIL_ORDER_CLOAK:
1061
0
      error = rail_recv_cloak_order(rail, s);
1062
0
      break;
1063
1064
0
    case TS_RAIL_ORDER_POWER_DISPLAY_REQUEST:
1065
0
      error = rail_recv_power_display_request_order(rail, s);
1066
0
      break;
1067
1068
0
    case TS_RAIL_ORDER_GET_APPID_RESP_EX:
1069
0
      error = rail_recv_get_application_id_extended_response_order(rail, s);
1070
0
      break;
1071
1072
0
    case TS_RAIL_ORDER_TEXTSCALEINFO:
1073
0
      error = rail_recv_textscaleinfo_order(rail, s);
1074
0
      break;
1075
1076
0
    case TS_RAIL_ORDER_CARETBLINKINFO:
1077
0
      error = rail_recv_caretblinkinfo_order(rail, s);
1078
0
      break;
1079
1080
0
    default:
1081
0
      WLog_ERR(TAG, "Unknown RAIL PDU %s received.",
1082
0
               rail_get_order_type_string_full(orderType, buffer, sizeof(buffer)));
1083
0
      return ERROR_INVALID_DATA;
1084
0
  }
1085
1086
0
  if (error != CHANNEL_RC_OK)
1087
0
  {
1088
0
    char ebuffer[128] = WINPR_C_ARRAY_INIT;
1089
0
    WLog_Print(rail->log, WLOG_ERROR, "Failed to process rail %s PDU, length:%" PRIu16 "",
1090
0
               rail_get_order_type_string_full(orderType, ebuffer, sizeof(ebuffer)),
1091
0
               orderLength);
1092
0
  }
1093
1094
0
  Stream_Free(s, TRUE);
1095
0
  return error;
1096
0
}
1097
1098
/**
1099
 * Function description
1100
 *
1101
 * @return 0 on success, otherwise a Win32 error code
1102
 */
1103
UINT rail_send_handshake_order(railPlugin* rail, const RAIL_HANDSHAKE_ORDER* handshake)
1104
0
{
1105
0
  if (!rail || !handshake)
1106
0
    return ERROR_INVALID_PARAMETER;
1107
1108
0
  wStream* s = rail_pdu_init(RAIL_HANDSHAKE_ORDER_LENGTH);
1109
1110
0
  if (!s)
1111
0
  {
1112
0
    WLog_ERR(TAG, "rail_pdu_init failed!");
1113
0
    return CHANNEL_RC_NO_MEMORY;
1114
0
  }
1115
1116
0
  rail_write_handshake_order(s, handshake);
1117
0
  return rail_send_pdu(rail, s, TS_RAIL_ORDER_HANDSHAKE);
1118
0
}
1119
1120
/**
1121
 * Function description
1122
 *
1123
 * @return 0 on success, otherwise a Win32 error code
1124
 */
1125
UINT rail_send_handshake_ex_order(railPlugin* rail, const RAIL_HANDSHAKE_EX_ORDER* handshakeEx)
1126
0
{
1127
0
  if (!rail || !handshakeEx)
1128
0
    return ERROR_INVALID_PARAMETER;
1129
1130
0
  wStream* s = rail_pdu_init(RAIL_HANDSHAKE_EX_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_ex_order(s, handshakeEx);
1139
0
  return rail_send_pdu(rail, s, TS_RAIL_ORDER_HANDSHAKE_EX);
1140
0
}
1141
1142
/**
1143
 * Function description
1144
 *
1145
 * @return 0 on success, otherwise a Win32 error code
1146
 */
1147
UINT rail_send_client_status_order(railPlugin* rail, const RAIL_CLIENT_STATUS_ORDER* clientStatus)
1148
0
{
1149
0
  wStream* s = nullptr;
1150
0
  UINT error = 0;
1151
1152
0
  if (!rail || !clientStatus)
1153
0
    return ERROR_INVALID_PARAMETER;
1154
1155
0
  rail->clientStatus = *clientStatus;
1156
0
  s = rail_pdu_init(RAIL_CLIENT_STATUS_ORDER_LENGTH);
1157
1158
0
  if (!s)
1159
0
  {
1160
0
    WLog_ERR(TAG, "rail_pdu_init failed!");
1161
0
    return CHANNEL_RC_NO_MEMORY;
1162
0
  }
1163
1164
0
  error = rail_write_client_status_order(s, clientStatus);
1165
1166
0
  if (ERROR_SUCCESS != error)
1167
0
  {
1168
1169
0
    Stream_Free(s, TRUE);
1170
0
    return error;
1171
0
  }
1172
1173
0
  return rail_send_pdu(rail, s, TS_RAIL_ORDER_CLIENTSTATUS);
1174
0
}
1175
1176
/**
1177
 * Function description
1178
 *
1179
 * @return 0 on success, otherwise a Win32 error code
1180
 */
1181
UINT rail_send_client_exec_order(railPlugin* rail, UINT16 flags,
1182
                                 const RAIL_UNICODE_STRING* exeOrFile,
1183
                                 const RAIL_UNICODE_STRING* workingDir,
1184
                                 const RAIL_UNICODE_STRING* arguments)
1185
0
{
1186
0
  wStream* s = nullptr;
1187
0
  UINT error = 0;
1188
0
  size_t length = 0;
1189
1190
0
  if (!rail || !exeOrFile || !workingDir || !arguments)
1191
0
    return ERROR_INVALID_PARAMETER;
1192
1193
0
  length = RAIL_EXEC_ORDER_LENGTH + exeOrFile->length + workingDir->length + arguments->length;
1194
0
  s = rail_pdu_init(length);
1195
1196
0
  if (!s)
1197
0
  {
1198
0
    WLog_ERR(TAG, "rail_pdu_init failed!");
1199
0
    return CHANNEL_RC_NO_MEMORY;
1200
0
  }
1201
1202
0
  if ((error = rail_write_client_exec_order(s, flags, exeOrFile, workingDir, arguments)))
1203
0
  {
1204
0
    WLog_ERR(TAG, "rail_write_client_exec_order failed with error %" PRIu32 "!", error);
1205
0
    goto out;
1206
0
  }
1207
1208
0
  return rail_send_pdu(rail, s, TS_RAIL_ORDER_EXEC);
1209
1210
0
out:
1211
0
  Stream_Free(s, TRUE);
1212
0
  return error;
1213
0
}
1214
1215
/**
1216
 * Function description
1217
 *
1218
 * @return 0 on success, otherwise a Win32 error code
1219
 */
1220
UINT rail_send_client_activate_order(railPlugin* rail, const RAIL_ACTIVATE_ORDER* activate)
1221
0
{
1222
0
  wStream* s = nullptr;
1223
0
  UINT error = 0;
1224
1225
0
  if (!rail || !activate)
1226
0
    return ERROR_INVALID_PARAMETER;
1227
1228
0
  s = rail_pdu_init(RAIL_ACTIVATE_ORDER_LENGTH);
1229
1230
0
  if (!s)
1231
0
  {
1232
0
    WLog_ERR(TAG, "rail_pdu_init failed!");
1233
0
    return CHANNEL_RC_NO_MEMORY;
1234
0
  }
1235
1236
0
  error = rail_write_client_activate_order(s, activate);
1237
1238
0
  if (ERROR_SUCCESS != error)
1239
0
  {
1240
1241
0
    Stream_Free(s, TRUE);
1242
0
    return error;
1243
0
  }
1244
1245
0
  return rail_send_pdu(rail, s, TS_RAIL_ORDER_ACTIVATE);
1246
0
}
1247
1248
/**
1249
 * Function description
1250
 *
1251
 * @return 0 on success, otherwise a Win32 error code
1252
 */
1253
UINT rail_send_client_sysmenu_order(railPlugin* rail, const RAIL_SYSMENU_ORDER* sysmenu)
1254
0
{
1255
0
  wStream* s = nullptr;
1256
0
  UINT error = 0;
1257
1258
0
  if (!rail || !sysmenu)
1259
0
    return ERROR_INVALID_PARAMETER;
1260
1261
0
  s = rail_pdu_init(RAIL_SYSMENU_ORDER_LENGTH);
1262
1263
0
  if (!s)
1264
0
  {
1265
0
    WLog_ERR(TAG, "rail_pdu_init failed!");
1266
0
    return CHANNEL_RC_NO_MEMORY;
1267
0
  }
1268
1269
0
  error = rail_write_client_sysmenu_order(s, sysmenu);
1270
1271
0
  if (ERROR_SUCCESS != error)
1272
0
  {
1273
1274
0
    Stream_Free(s, TRUE);
1275
0
    return error;
1276
0
  }
1277
1278
0
  return rail_send_pdu(rail, s, TS_RAIL_ORDER_SYSMENU);
1279
0
}
1280
1281
/**
1282
 * Function description
1283
 *
1284
 * @return 0 on success, otherwise a Win32 error code
1285
 */
1286
UINT rail_send_client_syscommand_order(railPlugin* rail, const RAIL_SYSCOMMAND_ORDER* syscommand)
1287
0
{
1288
0
  wStream* s = nullptr;
1289
0
  UINT error = 0;
1290
1291
0
  if (!rail || !syscommand)
1292
0
    return ERROR_INVALID_PARAMETER;
1293
1294
0
  s = rail_pdu_init(RAIL_SYSCOMMAND_ORDER_LENGTH);
1295
1296
0
  if (!s)
1297
0
  {
1298
0
    WLog_ERR(TAG, "rail_pdu_init failed!");
1299
0
    return CHANNEL_RC_NO_MEMORY;
1300
0
  }
1301
1302
0
  error = rail_write_client_syscommand_order(s, syscommand);
1303
1304
0
  if (ERROR_SUCCESS != error)
1305
0
  {
1306
1307
0
    Stream_Free(s, TRUE);
1308
0
    return error;
1309
0
  }
1310
1311
0
  return rail_send_pdu(rail, s, TS_RAIL_ORDER_SYSCOMMAND);
1312
0
}
1313
1314
/**
1315
 * Function description
1316
 *
1317
 * @return 0 on success, otherwise a Win32 error code
1318
 */
1319
UINT rail_send_client_notify_event_order(railPlugin* rail,
1320
                                         const RAIL_NOTIFY_EVENT_ORDER* notifyEvent)
1321
0
{
1322
0
  wStream* s = nullptr;
1323
0
  UINT error = 0;
1324
1325
0
  if (!rail || !notifyEvent)
1326
0
    return ERROR_INVALID_PARAMETER;
1327
1328
0
  s = rail_pdu_init(RAIL_NOTIFY_EVENT_ORDER_LENGTH);
1329
1330
0
  if (!s)
1331
0
  {
1332
0
    WLog_ERR(TAG, "rail_pdu_init failed!");
1333
0
    return CHANNEL_RC_NO_MEMORY;
1334
0
  }
1335
1336
0
  error = rail_write_client_notify_event_order(s, notifyEvent);
1337
1338
0
  if (ERROR_SUCCESS != error)
1339
0
  {
1340
1341
0
    Stream_Free(s, TRUE);
1342
0
    return error;
1343
0
  }
1344
1345
0
  return rail_send_pdu(rail, s, TS_RAIL_ORDER_NOTIFY_EVENT);
1346
0
}
1347
1348
/**
1349
 * Function description
1350
 *
1351
 * @return 0 on success, otherwise a Win32 error code
1352
 */
1353
UINT rail_send_client_window_move_order(railPlugin* rail, const RAIL_WINDOW_MOVE_ORDER* windowMove)
1354
0
{
1355
0
  wStream* s = nullptr;
1356
0
  UINT error = 0;
1357
1358
0
  if (!rail || !windowMove)
1359
0
    return ERROR_INVALID_PARAMETER;
1360
1361
0
  s = rail_pdu_init(RAIL_WINDOW_MOVE_ORDER_LENGTH);
1362
1363
0
  if (!s)
1364
0
  {
1365
0
    WLog_ERR(TAG, "rail_pdu_init failed!");
1366
0
    return CHANNEL_RC_NO_MEMORY;
1367
0
  }
1368
1369
0
  error = rail_write_client_window_move_order(s, windowMove);
1370
1371
0
  if (ERROR_SUCCESS != error)
1372
0
  {
1373
1374
0
    Stream_Free(s, TRUE);
1375
0
    return error;
1376
0
  }
1377
1378
0
  return rail_send_pdu(rail, s, TS_RAIL_ORDER_WINDOWMOVE);
1379
0
}
1380
1381
/**
1382
 * Function description
1383
 *
1384
 * @return 0 on success, otherwise a Win32 error code
1385
 */
1386
UINT rail_send_client_get_appid_req_order(railPlugin* rail,
1387
                                          const RAIL_GET_APPID_REQ_ORDER* getAppIdReq)
1388
0
{
1389
0
  wStream* s = nullptr;
1390
0
  UINT error = 0;
1391
1392
0
  if (!rail || !getAppIdReq)
1393
0
    return ERROR_INVALID_PARAMETER;
1394
1395
0
  s = rail_pdu_init(RAIL_GET_APPID_REQ_ORDER_LENGTH);
1396
1397
0
  if (!s)
1398
0
  {
1399
0
    WLog_ERR(TAG, "rail_pdu_init failed!");
1400
0
    return CHANNEL_RC_NO_MEMORY;
1401
0
  }
1402
1403
0
  error = rail_write_client_get_appid_req_order(s, getAppIdReq);
1404
1405
0
  if (ERROR_SUCCESS != error)
1406
0
  {
1407
1408
0
    Stream_Free(s, TRUE);
1409
0
    return error;
1410
0
  }
1411
0
  return rail_send_pdu(rail, s, TS_RAIL_ORDER_GET_APPID_REQ);
1412
0
}
1413
1414
/**
1415
 * Function description
1416
 *
1417
 * @return 0 on success, otherwise a Win32 error code
1418
 */
1419
UINT rail_send_client_langbar_info_order(railPlugin* rail,
1420
                                         const RAIL_LANGBAR_INFO_ORDER* langBarInfo)
1421
0
{
1422
0
  wStream* s = nullptr;
1423
0
  UINT error = 0;
1424
1425
0
  if (!rail || !langBarInfo)
1426
0
    return ERROR_INVALID_PARAMETER;
1427
1428
0
  if (!rail_is_feature_supported(rail->rdpcontext, RAIL_LEVEL_DOCKED_LANGBAR_SUPPORTED))
1429
0
    return ERROR_BAD_CONFIGURATION;
1430
1431
0
  s = rail_pdu_init(RAIL_LANGBAR_INFO_ORDER_LENGTH);
1432
1433
0
  if (!s)
1434
0
  {
1435
0
    WLog_ERR(TAG, "rail_pdu_init failed!");
1436
0
    return CHANNEL_RC_NO_MEMORY;
1437
0
  }
1438
1439
0
  error = rail_write_langbar_info_order(s, langBarInfo);
1440
1441
0
  if (ERROR_SUCCESS != error)
1442
0
  {
1443
1444
0
    Stream_Free(s, TRUE);
1445
0
    return error;
1446
0
  }
1447
0
  return rail_send_pdu(rail, s, TS_RAIL_ORDER_LANGBARINFO);
1448
0
}
1449
1450
UINT rail_send_client_languageime_info_order(railPlugin* rail,
1451
                                             const RAIL_LANGUAGEIME_INFO_ORDER* langImeInfo)
1452
0
{
1453
0
  wStream* s = nullptr;
1454
0
  UINT error = 0;
1455
1456
0
  if (!rail || !langImeInfo)
1457
0
    return ERROR_INVALID_PARAMETER;
1458
1459
0
  if (!rail_is_feature_supported(rail->rdpcontext, RAIL_LEVEL_LANGUAGE_IME_SYNC_SUPPORTED))
1460
0
    return ERROR_BAD_CONFIGURATION;
1461
1462
0
  s = rail_pdu_init(RAIL_LANGUAGEIME_INFO_ORDER_LENGTH);
1463
1464
0
  if (!s)
1465
0
  {
1466
0
    WLog_ERR(TAG, "rail_pdu_init failed!");
1467
0
    return CHANNEL_RC_NO_MEMORY;
1468
0
  }
1469
1470
0
  error = rail_write_languageime_info_order(s, langImeInfo);
1471
1472
0
  if (ERROR_SUCCESS != error)
1473
0
  {
1474
1475
0
    Stream_Free(s, TRUE);
1476
0
    return error;
1477
0
  }
1478
0
  return rail_send_pdu(rail, s, TS_RAIL_ORDER_LANGUAGEIMEINFO);
1479
0
}
1480
1481
UINT rail_send_client_compartment_info_order(railPlugin* rail,
1482
                                             const RAIL_COMPARTMENT_INFO_ORDER* compartmentInfo)
1483
0
{
1484
0
  wStream* s = nullptr;
1485
0
  UINT error = 0;
1486
1487
0
  if (!rail || !compartmentInfo)
1488
0
    return ERROR_INVALID_PARAMETER;
1489
1490
0
  if (!rail_is_feature_supported(rail->rdpcontext, RAIL_LEVEL_LANGUAGE_IME_SYNC_SUPPORTED))
1491
0
    return ERROR_BAD_CONFIGURATION;
1492
1493
0
  s = rail_pdu_init(RAIL_COMPARTMENT_INFO_ORDER_LENGTH);
1494
1495
0
  if (!s)
1496
0
  {
1497
0
    WLog_ERR(TAG, "rail_pdu_init failed!");
1498
0
    return CHANNEL_RC_NO_MEMORY;
1499
0
  }
1500
1501
0
  error = rail_write_compartment_info_order(s, compartmentInfo);
1502
1503
0
  if (ERROR_SUCCESS != error)
1504
0
  {
1505
0
    Stream_Free(s, TRUE);
1506
0
    return error;
1507
0
  }
1508
0
  return rail_send_pdu(rail, s, TS_RAIL_ORDER_COMPARTMENTINFO);
1509
0
}
1510
1511
UINT rail_send_client_cloak_order(railPlugin* rail, const RAIL_CLOAK* cloak)
1512
0
{
1513
0
  if (!rail || !cloak)
1514
0
    return ERROR_INVALID_PARAMETER;
1515
1516
0
  wStream* s = rail_pdu_init(5);
1517
1518
0
  if (!s)
1519
0
  {
1520
0
    WLog_ERR(TAG, "rail_pdu_init failed!");
1521
0
    return CHANNEL_RC_NO_MEMORY;
1522
0
  }
1523
1524
0
  Stream_Write_UINT32(s, cloak->windowId);
1525
0
  Stream_Write_UINT8(s, cloak->cloak ? 1 : 0);
1526
0
  return rail_send_pdu(rail, s, TS_RAIL_ORDER_CLOAK);
1527
0
}
1528
1529
UINT rail_send_client_snap_arrange_order(railPlugin* rail, const RAIL_SNAP_ARRANGE* snap)
1530
0
{
1531
0
  if (!rail)
1532
0
    return ERROR_INVALID_PARAMETER;
1533
1534
  /* 2.2.2.7.5 Client Window Snap PDU (TS_RAIL_ORDER_SNAP_ARRANGE) */
1535
0
  if ((rail->channelFlags & TS_RAIL_ORDER_HANDSHAKE_EX_FLAGS_SNAP_ARRANGE_SUPPORTED) == 0)
1536
0
  {
1537
0
    RAIL_WINDOW_MOVE_ORDER move = WINPR_C_ARRAY_INIT;
1538
0
    move.top = snap->top;
1539
0
    move.left = snap->left;
1540
0
    move.right = snap->right;
1541
0
    move.bottom = snap->bottom;
1542
0
    move.windowId = snap->windowId;
1543
0
    return rail_send_client_window_move_order(rail, &move);
1544
0
  }
1545
1546
0
  wStream* s = rail_pdu_init(12);
1547
1548
0
  if (!s)
1549
0
  {
1550
0
    WLog_ERR(TAG, "rail_pdu_init failed!");
1551
0
    return CHANNEL_RC_NO_MEMORY;
1552
0
  }
1553
1554
0
  Stream_Write_UINT32(s, snap->windowId);
1555
0
  Stream_Write_INT16(s, snap->left);
1556
0
  Stream_Write_INT16(s, snap->top);
1557
0
  Stream_Write_INT16(s, snap->right);
1558
0
  Stream_Write_INT16(s, snap->bottom);
1559
0
  return rail_send_pdu(rail, s, TS_RAIL_ORDER_SNAP_ARRANGE);
1560
0
}
1561
1562
UINT rail_send_client_text_scale_order(railPlugin* rail, UINT32 textScale)
1563
0
{
1564
0
  if (!rail)
1565
0
    return ERROR_INVALID_PARAMETER;
1566
1567
0
  wStream* s = rail_pdu_init(4);
1568
1569
0
  if (!s)
1570
0
  {
1571
0
    WLog_ERR(TAG, "rail_pdu_init failed!");
1572
0
    return CHANNEL_RC_NO_MEMORY;
1573
0
  }
1574
1575
0
  Stream_Write_UINT32(s, textScale);
1576
0
  return rail_send_pdu(rail, s, TS_RAIL_ORDER_TEXTSCALEINFO);
1577
0
}
1578
1579
UINT rail_send_client_caret_blink_rate_order(railPlugin* rail, UINT32 rate)
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, rate);
1593
0
  return rail_send_pdu(rail, s, TS_RAIL_ORDER_CARETBLINKINFO);
1594
0
}