Coverage Report

Created: 2026-03-04 06:17

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