Coverage Report

Created: 2024-09-08 06:20

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