/src/FreeRDP/libfreerdp/core/freerdp.c
Line | Count | Source |
1 | | /** |
2 | | * FreeRDP: A Remote Desktop Protocol Implementation |
3 | | * FreeRDP Core |
4 | | * |
5 | | * Copyright 2011 Marc-Andre Moreau <marcandre.moreau@gmail.com> |
6 | | * Copyright 2015 Thincast Technologies GmbH |
7 | | * Copyright 2015 DI (FH) Martin Haimberger <martin.haimberger@thincast.com> |
8 | | * |
9 | | * Licensed under the Apache License, Version 2.0 (the "License"); |
10 | | * you may not use this file except in compliance with the License. |
11 | | * You may obtain a copy of the License at |
12 | | * |
13 | | * http://www.apache.org/licenses/LICENSE-2.0 |
14 | | * |
15 | | * Unless required by applicable law or agreed to in writing, software |
16 | | * distributed under the License is distributed on an "AS IS" BASIS, |
17 | | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
18 | | * See the License for the specific language governing permissions and |
19 | | * limitations under the License. |
20 | | */ |
21 | | |
22 | | #include <freerdp/config.h> |
23 | | |
24 | | #include "settings.h" |
25 | | |
26 | | #include <string.h> |
27 | | #include <stdarg.h> |
28 | | #include <time.h> |
29 | | |
30 | | #include "rdp.h" |
31 | | #include "input.h" |
32 | | #include "update.h" |
33 | | #include "surface.h" |
34 | | #include "transport.h" |
35 | | #include "connection.h" |
36 | | #include "message.h" |
37 | | #include <freerdp/buildflags.h> |
38 | | #include "gateway/rpc_fault.h" |
39 | | |
40 | | #include <winpr/assert.h> |
41 | | |
42 | | #include <winpr/crt.h> |
43 | | #include <winpr/string.h> |
44 | | #include <winpr/stream.h> |
45 | | #include <winpr/wtsapi.h> |
46 | | #include <winpr/ssl.h> |
47 | | #include <winpr/debug.h> |
48 | | |
49 | | #include <freerdp/freerdp.h> |
50 | | #include <freerdp/streamdump.h> |
51 | | #include <freerdp/error.h> |
52 | | #include <freerdp/event.h> |
53 | | #include <freerdp/locale/keyboard.h> |
54 | | #include <freerdp/locale/locale.h> |
55 | | #include <freerdp/channels/channels.h> |
56 | | #include <freerdp/version.h> |
57 | | #include <freerdp/log.h> |
58 | | #include <freerdp/utils/signal.h> |
59 | | |
60 | | #include "../cache/pointer.h" |
61 | | #include "utils.h" |
62 | | |
63 | 8.11k | #define TAG FREERDP_TAG("core") |
64 | | |
65 | | static void sig_abort_connect(int signum, const char* signame, void* ctx) |
66 | 0 | { |
67 | 0 | rdpContext* context = (rdpContext*)ctx; |
68 | |
|
69 | 0 | WLog_INFO(TAG, "Signal %s [%d], terminating session %p", signame, signum, |
70 | 0 | WINPR_CXX_COMPAT_CAST(const void*, context)); |
71 | 0 | if (context) |
72 | 0 | freerdp_abort_connect_context(context); |
73 | 0 | } |
74 | | |
75 | | /** Creates a new connection based on the settings found in the "instance" parameter |
76 | | * It will use the callbacks registered on the structure to process the pre/post connect operations |
77 | | * that the caller requires. |
78 | | * @see struct rdp_freerdp in freerdp.h |
79 | | * |
80 | | * @param instance - pointer to a rdp_freerdp structure that contains base information to establish |
81 | | * the connection. On return, this function will be initialized with the new connection's settings. |
82 | | * |
83 | | * @return TRUE if successful. FALSE otherwise. |
84 | | * |
85 | | */ |
86 | | static int freerdp_connect_begin(freerdp* instance) |
87 | 0 | { |
88 | 0 | BOOL rc = 0; |
89 | 0 | rdpRdp* rdp = nullptr; |
90 | 0 | BOOL status = TRUE; |
91 | 0 | rdpSettings* settings = nullptr; |
92 | |
|
93 | 0 | if (!instance) |
94 | 0 | return -1; |
95 | | |
96 | 0 | WINPR_ASSERT(instance->context); |
97 | | |
98 | | /* We always set the return code to 0 before we start the connect sequence*/ |
99 | 0 | instance->ConnectionCallbackState = CLIENT_STATE_INITIAL; |
100 | 0 | freerdp_set_last_error_log(instance->context, FREERDP_ERROR_SUCCESS); |
101 | 0 | clearChannelError(instance->context); |
102 | 0 | if (!utils_reset_abort(instance->context->rdp)) |
103 | 0 | return -1; |
104 | | |
105 | 0 | rdp = instance->context->rdp; |
106 | 0 | WINPR_ASSERT(rdp); |
107 | |
|
108 | 0 | settings = instance->context->settings; |
109 | 0 | WINPR_ASSERT(settings); |
110 | |
|
111 | 0 | freerdp_channels_register_instance(instance->context->channels, instance); |
112 | |
|
113 | 0 | if (!freerdp_settings_set_default_order_support(settings)) |
114 | 0 | return -1; |
115 | | |
116 | 0 | if (!freerdp_add_signal_cleanup_handler(instance->context, sig_abort_connect)) |
117 | 0 | return -1; |
118 | | |
119 | 0 | IFCALLRET(instance->PreConnect, status, instance); |
120 | 0 | instance->ConnectionCallbackState = CLIENT_STATE_PRECONNECT_PASSED; |
121 | |
|
122 | 0 | freerdp_settings_print_warnings(settings); |
123 | 0 | if (status) |
124 | 0 | status = freerdp_settings_enforce_monitor_exists(settings); |
125 | |
|
126 | 0 | if (status) |
127 | 0 | status = freerdp_settings_enforce_consistency(settings); |
128 | |
|
129 | 0 | if (status) |
130 | 0 | status = freerdp_settings_check_client_after_preconnect(settings); |
131 | |
|
132 | 0 | if (status) |
133 | 0 | status = rdp_set_backup_settings(rdp); |
134 | 0 | if (status) |
135 | 0 | status = utils_reload_channels(instance->context); |
136 | |
|
137 | 0 | const UINT32 cp = freerdp_settings_get_uint32(settings, FreeRDP_KeyboardCodePage); |
138 | 0 | int64_t KeyboardLayout = freerdp_get_keyboard_default_layout_for_locale(cp); |
139 | 0 | if (KeyboardLayout == 0) |
140 | 0 | KeyboardLayout = freerdp_settings_get_uint32(settings, FreeRDP_KeyboardLayout); |
141 | |
|
142 | 0 | switch (KeyboardLayout) |
143 | 0 | { |
144 | 0 | case KBD_JAPANESE: |
145 | 0 | case KBD_JAPANESE_INPUT_SYSTEM_MS_IME2002: |
146 | 0 | { |
147 | 0 | if (!freerdp_settings_set_uint32(settings, FreeRDP_KeyboardType, |
148 | 0 | WINPR_KBD_TYPE_JAPANESE)) |
149 | 0 | return -1; |
150 | 0 | if (!freerdp_settings_set_uint32(settings, FreeRDP_KeyboardSubType, 2)) |
151 | 0 | return -1; |
152 | 0 | if (!freerdp_settings_set_uint32(settings, FreeRDP_KeyboardFunctionKey, 12)) |
153 | 0 | return -1; |
154 | 0 | } |
155 | 0 | break; |
156 | 0 | default: |
157 | 0 | break; |
158 | 0 | } |
159 | | |
160 | 0 | if (!status) |
161 | 0 | { |
162 | 0 | rdpContext* context = instance->context; |
163 | 0 | WINPR_ASSERT(context); |
164 | 0 | freerdp_set_last_error_if_not(context, FREERDP_ERROR_PRE_CONNECT_FAILED); |
165 | |
|
166 | 0 | WLog_Print(context->log, WLOG_ERROR, "freerdp_pre_connect failed: %s", |
167 | 0 | rdp_client_connection_state_string(instance->ConnectionCallbackState)); |
168 | 0 | return 0; |
169 | 0 | } |
170 | | |
171 | 0 | rc = rdp_client_connect(rdp); |
172 | | |
173 | | /* --authonly tests the connection without a UI */ |
174 | 0 | if (freerdp_settings_get_bool(rdp->settings, FreeRDP_AuthenticationOnly)) |
175 | 0 | { |
176 | 0 | rdpContext* context = rdp->context; |
177 | 0 | WINPR_ASSERT(context); |
178 | 0 | WLog_Print(context->log, WLOG_ERROR, "Authentication only, exit status %" PRId32 "", rc); |
179 | 0 | return 0; |
180 | 0 | } |
181 | | |
182 | 0 | return rc ? 1 : 0; |
183 | 0 | } |
184 | | |
185 | | BOOL freerdp_connect(freerdp* instance) |
186 | 0 | { |
187 | 0 | BOOL status = FALSE; |
188 | 0 | ConnectionResultEventArgs e = WINPR_C_ARRAY_INIT; |
189 | 0 | const int rc = freerdp_connect_begin(instance); |
190 | 0 | rdpRdp* rdp = nullptr; |
191 | 0 | UINT status2 = ERROR_INTERNAL_ERROR; |
192 | |
|
193 | 0 | WINPR_ASSERT(instance); |
194 | 0 | WINPR_ASSERT(instance->context); |
195 | |
|
196 | 0 | rdp = instance->context->rdp; |
197 | 0 | WINPR_ASSERT(rdp); |
198 | 0 | WINPR_ASSERT(rdp->settings); |
199 | |
|
200 | 0 | if (rc > 0) |
201 | | /* Pointers might have changed in between */ |
202 | 0 | { |
203 | 0 | rdp_update_internal* up = update_cast(rdp->update); |
204 | |
|
205 | 0 | if (freerdp_settings_get_bool(rdp->settings, FreeRDP_DumpRemoteFx)) |
206 | 0 | { |
207 | 0 | up->pcap_rfx = pcap_open( |
208 | 0 | freerdp_settings_get_string(rdp->settings, FreeRDP_DumpRemoteFxFile), TRUE); |
209 | |
|
210 | 0 | if (up->pcap_rfx) |
211 | 0 | up->dump_rfx = TRUE; |
212 | 0 | } |
213 | |
|
214 | 0 | pointer_cache_register_callbacks(instance->context->update); |
215 | 0 | status = IFCALLRESULT(TRUE, instance->PostConnect, instance); |
216 | 0 | instance->ConnectionCallbackState = CLIENT_STATE_POSTCONNECT_PASSED; |
217 | |
|
218 | 0 | if (status) |
219 | 0 | status2 = freerdp_channels_post_connect(instance->context->channels, instance); |
220 | 0 | } |
221 | 0 | else |
222 | 0 | { |
223 | 0 | status2 = CHANNEL_RC_OK; |
224 | 0 | if (freerdp_get_last_error(instance->context) == FREERDP_ERROR_CONNECT_TRANSPORT_FAILED) |
225 | 0 | status = freerdp_reconnect(instance); |
226 | 0 | else |
227 | 0 | goto freerdp_connect_finally; |
228 | 0 | } |
229 | | |
230 | 0 | if (!status || (status2 != CHANNEL_RC_OK) || !update_post_connect(instance->context->update)) |
231 | 0 | { |
232 | 0 | rdpContext* context = instance->context; |
233 | 0 | WINPR_ASSERT(context); |
234 | 0 | WLog_Print(context->log, WLOG_ERROR, "freerdp_post_connect failed"); |
235 | |
|
236 | 0 | freerdp_set_last_error_if_not(context, FREERDP_ERROR_POST_CONNECT_FAILED); |
237 | |
|
238 | 0 | status = FALSE; |
239 | 0 | goto freerdp_connect_finally; |
240 | 0 | } |
241 | | |
242 | 0 | if (rdp->settings->PlayRemoteFx) |
243 | 0 | { |
244 | 0 | wStream* s = nullptr; |
245 | 0 | rdp_update_internal* update = update_cast(instance->context->update); |
246 | 0 | pcap_record record = WINPR_C_ARRAY_INIT; |
247 | |
|
248 | 0 | WINPR_ASSERT(update); |
249 | 0 | update->pcap_rfx = pcap_open(rdp->settings->PlayRemoteFxFile, FALSE); |
250 | 0 | status = FALSE; |
251 | |
|
252 | 0 | if (!update->pcap_rfx) |
253 | 0 | goto freerdp_connect_finally; |
254 | 0 | else |
255 | 0 | update->play_rfx = TRUE; |
256 | | |
257 | 0 | status = TRUE; |
258 | |
|
259 | 0 | while (pcap_has_next_record(update->pcap_rfx) && status) |
260 | 0 | { |
261 | 0 | if (!pcap_get_next_record_header(update->pcap_rfx, &record)) |
262 | 0 | break; |
263 | | |
264 | 0 | s = transport_take_from_pool(rdp->transport, record.length); |
265 | 0 | if (!s) |
266 | 0 | break; |
267 | | |
268 | 0 | record.data = Stream_Buffer(s); |
269 | 0 | if (!pcap_get_next_record_content(update->pcap_rfx, &record)) |
270 | 0 | break; |
271 | 0 | if (!Stream_SetLength(s, record.length)) |
272 | 0 | { |
273 | 0 | status = FALSE; |
274 | 0 | continue; |
275 | 0 | } |
276 | 0 | Stream_ResetPosition(s); |
277 | |
|
278 | 0 | if (!update_begin_paint(&update->common)) |
279 | 0 | status = FALSE; |
280 | 0 | else |
281 | 0 | { |
282 | 0 | if (update_recv_surfcmds(&update->common, s) < 0) |
283 | 0 | status = FALSE; |
284 | |
|
285 | 0 | if (!update_end_paint(&update->common)) |
286 | 0 | status = FALSE; |
287 | 0 | } |
288 | |
|
289 | 0 | Stream_Release(s); |
290 | 0 | } |
291 | |
|
292 | 0 | pcap_close(update->pcap_rfx); |
293 | 0 | update->pcap_rfx = nullptr; |
294 | 0 | goto freerdp_connect_finally; |
295 | 0 | } |
296 | | |
297 | 0 | if (rdp->errorInfo == ERRINFO_SERVER_INSUFFICIENT_PRIVILEGES) |
298 | 0 | freerdp_set_last_error_log(instance->context, FREERDP_ERROR_INSUFFICIENT_PRIVILEGES); |
299 | |
|
300 | 0 | if (status) |
301 | 0 | status = transport_set_connected_event(rdp->transport); |
302 | |
|
303 | 0 | freerdp_connect_finally: |
304 | 0 | EventArgsInit(&e, "freerdp"); |
305 | 0 | e.result = status ? 0 : -1; |
306 | 0 | if (PubSub_OnConnectionResult(rdp->pubSub, instance->context, &e) < 0) |
307 | 0 | return FALSE; |
308 | | |
309 | 0 | if (!status) |
310 | 0 | freerdp_disconnect(instance); |
311 | |
|
312 | 0 | return status; |
313 | 0 | } |
314 | | |
315 | | #if !defined(WITHOUT_FREERDP_3x_DEPRECATED) |
316 | | BOOL freerdp_abort_connect(freerdp* instance) |
317 | 0 | { |
318 | 0 | if (!instance) |
319 | 0 | return FALSE; |
320 | | |
321 | 0 | return freerdp_abort_connect_context(instance->context); |
322 | 0 | } |
323 | | #endif |
324 | | |
325 | | BOOL freerdp_abort_connect_context(rdpContext* context) |
326 | 0 | { |
327 | 0 | if (!context) |
328 | 0 | return FALSE; |
329 | | |
330 | 0 | freerdp_set_last_error_if_not(context, FREERDP_ERROR_CONNECT_CANCELLED); |
331 | 0 | return utils_abort_connect(context->rdp); |
332 | 0 | } |
333 | | |
334 | | #if defined(WITH_FREERDP_DEPRECATED) |
335 | | BOOL freerdp_get_fds(freerdp* instance, void** rfds, int* rcount, WINPR_ATTR_UNUSED void** wfds, |
336 | | WINPR_ATTR_UNUSED int* wcount) |
337 | | { |
338 | | rdpRdp* rdp = nullptr; |
339 | | |
340 | | WINPR_ASSERT(instance); |
341 | | WINPR_ASSERT(instance->context); |
342 | | |
343 | | rdp = instance->context->rdp; |
344 | | WINPR_ASSERT(rdp); |
345 | | |
346 | | transport_get_fds(rdp->transport, rfds, rcount); |
347 | | return TRUE; |
348 | | } |
349 | | #endif |
350 | | |
351 | | BOOL freerdp_check_fds(freerdp* instance) |
352 | 0 | { |
353 | 0 | int status = 0; |
354 | 0 | rdpRdp* rdp = nullptr; |
355 | |
|
356 | 0 | if (!instance) |
357 | 0 | return FALSE; |
358 | | |
359 | 0 | if (!instance->context) |
360 | 0 | return FALSE; |
361 | | |
362 | 0 | if (!instance->context->rdp) |
363 | 0 | return FALSE; |
364 | | |
365 | 0 | rdp = instance->context->rdp; |
366 | 0 | status = rdp_check_fds(rdp); |
367 | |
|
368 | 0 | if (status < 0) |
369 | 0 | { |
370 | 0 | TerminateEventArgs e; |
371 | 0 | rdpContext* context = instance->context; |
372 | 0 | WINPR_ASSERT(context); |
373 | |
|
374 | 0 | WLog_Print(context->log, WLOG_DEBUG, "rdp_check_fds() - %i", status); |
375 | 0 | EventArgsInit(&e, "freerdp"); |
376 | 0 | e.code = 0; |
377 | 0 | if (PubSub_OnTerminate(rdp->pubSub, context, &e) < 0) |
378 | 0 | return FALSE; |
379 | 0 | return FALSE; |
380 | 0 | } |
381 | | |
382 | 0 | return TRUE; |
383 | 0 | } |
384 | | |
385 | | DWORD freerdp_get_event_handles(rdpContext* context, HANDLE* events, DWORD count) |
386 | 0 | { |
387 | 0 | DWORD nCount = 0; |
388 | |
|
389 | 0 | WINPR_ASSERT(context); |
390 | 0 | WINPR_ASSERT(context->rdp); |
391 | 0 | WINPR_ASSERT(events || (count == 0)); |
392 | |
|
393 | 0 | const size_t rrc = rdp_get_event_handles(context->rdp, &events[nCount], count - nCount); |
394 | 0 | if (rrc == 0) |
395 | 0 | return 0; |
396 | | |
397 | 0 | nCount += WINPR_ASSERTING_INT_CAST(uint32_t, rrc); |
398 | |
|
399 | 0 | if (events && (nCount < count + 2)) |
400 | 0 | { |
401 | 0 | events[nCount++] = freerdp_channels_get_event_handle(context->instance); |
402 | 0 | events[nCount++] = getChannelErrorEventHandle(context); |
403 | 0 | } |
404 | 0 | else |
405 | 0 | return 0; |
406 | | |
407 | 0 | const SSIZE_T rc = freerdp_client_channel_get_registered_event_handles( |
408 | 0 | context->channels, &events[nCount], count - nCount); |
409 | 0 | if (rc < 0) |
410 | 0 | return 0; |
411 | 0 | return nCount + (DWORD)rc; |
412 | 0 | } |
413 | | |
414 | | /* Resend mouse cursor position to prevent session lock in prevent-session-lock mode */ |
415 | | static BOOL freerdp_prevent_session_lock(rdpContext* context) |
416 | 0 | { |
417 | 0 | WINPR_ASSERT(context); |
418 | 0 | WINPR_ASSERT(context->input); |
419 | |
|
420 | 0 | rdp_input_internal* in = input_cast(context->input); |
421 | |
|
422 | 0 | UINT32 FakeMouseMotionInterval = |
423 | 0 | freerdp_settings_get_uint32(context->settings, FreeRDP_FakeMouseMotionInterval); |
424 | 0 | if (FakeMouseMotionInterval && in->lastInputTimestamp) |
425 | 0 | { |
426 | 0 | const time_t now = time(nullptr); |
427 | 0 | if (WINPR_ASSERTING_INT_CAST(size_t, now) - in->lastInputTimestamp > |
428 | 0 | FakeMouseMotionInterval) |
429 | 0 | { |
430 | 0 | WLog_Print(context->log, WLOG_DEBUG, |
431 | 0 | "fake mouse move: x=%d y=%d lastInputTimestamp=%" PRIu64 " " |
432 | 0 | "FakeMouseMotionInterval=%" PRIu32, |
433 | 0 | in->lastX, in->lastY, in->lastInputTimestamp, FakeMouseMotionInterval); |
434 | |
|
435 | 0 | BOOL status = freerdp_input_send_mouse_event(context->input, PTR_FLAGS_MOVE, in->lastX, |
436 | 0 | in->lastY); |
437 | 0 | if (!status) |
438 | 0 | { |
439 | 0 | if (freerdp_get_last_error(context) == FREERDP_ERROR_SUCCESS) |
440 | 0 | WLog_Print(context->log, WLOG_ERROR, |
441 | 0 | "freerdp_prevent_session_lock() failed - %" PRIi32 "", status); |
442 | |
|
443 | 0 | return FALSE; |
444 | 0 | } |
445 | | |
446 | 0 | return status; |
447 | 0 | } |
448 | 0 | } |
449 | | |
450 | 0 | return TRUE; |
451 | 0 | } |
452 | | |
453 | | BOOL freerdp_check_event_handles(rdpContext* context) |
454 | 0 | { |
455 | 0 | WINPR_ASSERT(context); |
456 | |
|
457 | 0 | BOOL status = freerdp_check_fds(context->instance); |
458 | |
|
459 | 0 | if (!status) |
460 | 0 | { |
461 | 0 | if (freerdp_get_last_error(context) == FREERDP_ERROR_SUCCESS) |
462 | 0 | WLog_Print(context->log, WLOG_ERROR, "freerdp_check_fds() failed - %" PRIi32 "", |
463 | 0 | status); |
464 | |
|
465 | 0 | return FALSE; |
466 | 0 | } |
467 | | |
468 | 0 | status = freerdp_channels_check_fds(context->channels, context->instance); |
469 | |
|
470 | 0 | if (!status) |
471 | 0 | { |
472 | 0 | if (freerdp_get_last_error(context) == FREERDP_ERROR_SUCCESS) |
473 | 0 | WLog_Print(context->log, WLOG_ERROR, |
474 | 0 | "freerdp_channels_check_fds() failed - %" PRIi32 "", status); |
475 | |
|
476 | 0 | return FALSE; |
477 | 0 | } |
478 | | |
479 | 0 | status = checkChannelErrorEvent(context); |
480 | |
|
481 | 0 | if (!status) |
482 | 0 | { |
483 | 0 | if (freerdp_get_last_error(context) == FREERDP_ERROR_SUCCESS) |
484 | 0 | WLog_Print(context->log, WLOG_ERROR, "checkChannelErrorEvent() failed - %" PRIi32 "", |
485 | 0 | status); |
486 | |
|
487 | 0 | return FALSE; |
488 | 0 | } |
489 | | |
490 | 0 | status = freerdp_prevent_session_lock(context); |
491 | |
|
492 | 0 | return status; |
493 | 0 | } |
494 | | |
495 | | wMessageQueue* freerdp_get_message_queue(freerdp* instance, DWORD id) |
496 | 0 | { |
497 | 0 | wMessageQueue* queue = nullptr; |
498 | |
|
499 | 0 | WINPR_ASSERT(instance); |
500 | |
|
501 | 0 | rdpContext* context = instance->context; |
502 | 0 | WINPR_ASSERT(context); |
503 | |
|
504 | 0 | switch (id) |
505 | 0 | { |
506 | 0 | case FREERDP_UPDATE_MESSAGE_QUEUE: |
507 | 0 | { |
508 | 0 | rdp_update_internal* update = update_cast(context->update); |
509 | 0 | queue = update->queue; |
510 | 0 | } |
511 | 0 | break; |
512 | | |
513 | 0 | case FREERDP_INPUT_MESSAGE_QUEUE: |
514 | 0 | { |
515 | 0 | rdp_input_internal* input = input_cast(context->input); |
516 | 0 | queue = input->queue; |
517 | 0 | } |
518 | 0 | break; |
519 | 0 | default: |
520 | 0 | break; |
521 | 0 | } |
522 | | |
523 | 0 | return queue; |
524 | 0 | } |
525 | | |
526 | | HANDLE freerdp_get_message_queue_event_handle(freerdp* instance, DWORD id) |
527 | 0 | { |
528 | 0 | HANDLE event = nullptr; |
529 | 0 | wMessageQueue* queue = freerdp_get_message_queue(instance, id); |
530 | |
|
531 | 0 | if (queue) |
532 | 0 | event = MessageQueue_Event(queue); |
533 | |
|
534 | 0 | return event; |
535 | 0 | } |
536 | | |
537 | | int freerdp_message_queue_process_message(freerdp* instance, DWORD id, wMessage* message) |
538 | 0 | { |
539 | 0 | int status = -1; |
540 | 0 | rdpContext* context = nullptr; |
541 | |
|
542 | 0 | WINPR_ASSERT(instance); |
543 | |
|
544 | 0 | context = instance->context; |
545 | 0 | WINPR_ASSERT(context); |
546 | |
|
547 | 0 | switch (id) |
548 | 0 | { |
549 | 0 | case FREERDP_UPDATE_MESSAGE_QUEUE: |
550 | 0 | status = update_message_queue_process_message(context->update, message); |
551 | 0 | break; |
552 | | |
553 | 0 | case FREERDP_INPUT_MESSAGE_QUEUE: |
554 | 0 | status = input_message_queue_process_message(context->input, message); |
555 | 0 | break; |
556 | 0 | default: |
557 | 0 | break; |
558 | 0 | } |
559 | | |
560 | 0 | return status; |
561 | 0 | } |
562 | | |
563 | | int freerdp_message_queue_process_pending_messages(freerdp* instance, DWORD id) |
564 | 0 | { |
565 | 0 | int status = -1; |
566 | 0 | rdpContext* context = nullptr; |
567 | |
|
568 | 0 | WINPR_ASSERT(instance); |
569 | |
|
570 | 0 | context = instance->context; |
571 | 0 | WINPR_ASSERT(context); |
572 | |
|
573 | 0 | switch (id) |
574 | 0 | { |
575 | 0 | case FREERDP_UPDATE_MESSAGE_QUEUE: |
576 | 0 | status = update_message_queue_process_pending_messages(context->update); |
577 | 0 | break; |
578 | | |
579 | 0 | case FREERDP_INPUT_MESSAGE_QUEUE: |
580 | 0 | status = input_message_queue_process_pending_messages(context->input); |
581 | 0 | break; |
582 | 0 | default: |
583 | 0 | break; |
584 | 0 | } |
585 | | |
586 | 0 | return status; |
587 | 0 | } |
588 | | |
589 | | static BOOL freerdp_send_channel_data(freerdp* instance, UINT16 channelId, const BYTE* data, |
590 | | size_t size) |
591 | 0 | { |
592 | 0 | WINPR_ASSERT(instance); |
593 | 0 | WINPR_ASSERT(instance->context); |
594 | 0 | WINPR_ASSERT(instance->context->rdp); |
595 | 0 | return rdp_send_channel_data(instance->context->rdp, channelId, data, size); |
596 | 0 | } |
597 | | |
598 | | static BOOL freerdp_send_channel_packet(freerdp* instance, UINT16 channelId, size_t totalSize, |
599 | | UINT32 flags, const BYTE* data, size_t chunkSize) |
600 | 0 | { |
601 | 0 | WINPR_ASSERT(instance); |
602 | 0 | WINPR_ASSERT(instance->context); |
603 | 0 | WINPR_ASSERT(instance->context->rdp); |
604 | 0 | return rdp_channel_send_packet(instance->context->rdp, channelId, totalSize, flags, data, |
605 | 0 | chunkSize); |
606 | 0 | } |
607 | | |
608 | | BOOL freerdp_disconnect(freerdp* instance) |
609 | 0 | { |
610 | 0 | BOOL rc = TRUE; |
611 | |
|
612 | 0 | if (!instance || !instance->context) |
613 | 0 | return FALSE; |
614 | | |
615 | 0 | rdpRdp* rdp = instance->context->rdp; |
616 | 0 | if (rdp) |
617 | 0 | { |
618 | | /* Try to send a [MS-RDPBCGR] 1.3.1.4.1 User-Initiated on Client PDU, we don't care about |
619 | | * success */ |
620 | 0 | if (freerdp_get_last_error(instance->context) == FREERDP_ERROR_CONNECT_CANCELLED) |
621 | 0 | { |
622 | 0 | (void)mcs_send_disconnect_provider_ultimatum(rdp->mcs, |
623 | 0 | Disconnect_Ultimatum_user_requested); |
624 | 0 | } |
625 | 0 | } |
626 | |
|
627 | 0 | utils_abort_connect(rdp); |
628 | |
|
629 | 0 | if (!rdp_client_disconnect(rdp)) |
630 | 0 | rc = FALSE; |
631 | |
|
632 | 0 | rdp_update_internal* up = nullptr; |
633 | 0 | if (rdp && rdp->update) |
634 | 0 | { |
635 | 0 | up = update_cast(rdp->update); |
636 | |
|
637 | 0 | update_post_disconnect(rdp->update); |
638 | 0 | } |
639 | |
|
640 | 0 | IFCALL(instance->PostDisconnect, instance); |
641 | |
|
642 | 0 | if (up) |
643 | 0 | { |
644 | 0 | if (up->pcap_rfx) |
645 | 0 | { |
646 | 0 | up->dump_rfx = FALSE; |
647 | 0 | pcap_close(up->pcap_rfx); |
648 | 0 | up->pcap_rfx = nullptr; |
649 | 0 | } |
650 | 0 | } |
651 | |
|
652 | 0 | if (instance->context->channels) |
653 | 0 | freerdp_channels_close(instance->context->channels, instance); |
654 | |
|
655 | 0 | IFCALL(instance->PostFinalDisconnect, instance); |
656 | |
|
657 | 0 | freerdp_del_signal_cleanup_handler(instance->context, sig_abort_connect); |
658 | 0 | return rc; |
659 | 0 | } |
660 | | |
661 | | #if !defined(WITHOUT_FREERDP_3x_DEPRECATED) |
662 | | BOOL freerdp_disconnect_before_reconnect(freerdp* instance) |
663 | 0 | { |
664 | 0 | WINPR_ASSERT(instance); |
665 | 0 | return freerdp_disconnect_before_reconnect_context(instance->context); |
666 | 0 | } |
667 | | #endif |
668 | | |
669 | | BOOL freerdp_disconnect_before_reconnect_context(rdpContext* context) |
670 | 0 | { |
671 | 0 | rdpRdp* rdp = nullptr; |
672 | |
|
673 | 0 | WINPR_ASSERT(context); |
674 | |
|
675 | 0 | rdp = context->rdp; |
676 | 0 | return rdp_client_disconnect_and_clear(rdp); |
677 | 0 | } |
678 | | |
679 | | BOOL freerdp_reconnect(freerdp* instance) |
680 | 0 | { |
681 | 0 | rdpRdp* rdp = nullptr; |
682 | |
|
683 | 0 | WINPR_ASSERT(instance); |
684 | 0 | WINPR_ASSERT(instance->context); |
685 | |
|
686 | 0 | if (freerdp_get_last_error(instance->context) == FREERDP_ERROR_CONNECT_CANCELLED) |
687 | 0 | return FALSE; |
688 | | |
689 | 0 | rdp = instance->context->rdp; |
690 | |
|
691 | 0 | if (!utils_reset_abort(instance->context->rdp)) |
692 | 0 | return FALSE; |
693 | 0 | return rdp_client_reconnect(rdp); |
694 | 0 | } |
695 | | |
696 | | #if !defined(WITHOUT_FREERDP_3x_DEPRECATED) |
697 | | BOOL freerdp_shall_disconnect(const freerdp* instance) |
698 | 0 | { |
699 | 0 | if (!instance) |
700 | 0 | return FALSE; |
701 | | |
702 | 0 | return freerdp_shall_disconnect_context(instance->context); |
703 | 0 | } |
704 | | #endif |
705 | | |
706 | | BOOL freerdp_shall_disconnect_context(const rdpContext* context) |
707 | 61 | { |
708 | 61 | if (!context) |
709 | 0 | return FALSE; |
710 | | |
711 | 61 | return utils_abort_event_is_set(context->rdp); |
712 | 61 | } |
713 | | |
714 | | BOOL freerdp_focus_required(freerdp* instance) |
715 | 0 | { |
716 | 0 | rdpRdp* rdp = nullptr; |
717 | 0 | BOOL bRetCode = FALSE; |
718 | |
|
719 | 0 | WINPR_ASSERT(instance); |
720 | 0 | WINPR_ASSERT(instance->context); |
721 | |
|
722 | 0 | rdp = instance->context->rdp; |
723 | 0 | WINPR_ASSERT(rdp); |
724 | |
|
725 | 0 | if (rdp->resendFocus) |
726 | 0 | { |
727 | 0 | bRetCode = TRUE; |
728 | 0 | rdp->resendFocus = FALSE; |
729 | 0 | } |
730 | |
|
731 | 0 | return bRetCode; |
732 | 0 | } |
733 | | |
734 | | void freerdp_set_focus(freerdp* instance) |
735 | 0 | { |
736 | 0 | rdpRdp* rdp = nullptr; |
737 | |
|
738 | 0 | WINPR_ASSERT(instance); |
739 | 0 | WINPR_ASSERT(instance->context); |
740 | |
|
741 | 0 | rdp = instance->context->rdp; |
742 | 0 | WINPR_ASSERT(rdp); |
743 | |
|
744 | 0 | rdp->resendFocus = TRUE; |
745 | 0 | } |
746 | | |
747 | | void freerdp_get_version(int* major, int* minor, int* revision) |
748 | 0 | { |
749 | 0 | if (major != nullptr) |
750 | 0 | *major = FREERDP_VERSION_MAJOR; |
751 | |
|
752 | 0 | if (minor != nullptr) |
753 | 0 | *minor = FREERDP_VERSION_MINOR; |
754 | |
|
755 | 0 | if (revision != nullptr) |
756 | 0 | *revision = FREERDP_VERSION_REVISION; |
757 | 0 | } |
758 | | |
759 | | const char* freerdp_get_version_string(void) |
760 | 0 | { |
761 | 0 | return FREERDP_VERSION_FULL; |
762 | 0 | } |
763 | | |
764 | | const char* freerdp_get_build_config(void) |
765 | 0 | { |
766 | 0 | WINPR_PRAGMA_DIAG_PUSH |
767 | 0 | WINPR_PRAGMA_DIAG_IGNORED_OVERLENGTH_STRINGS |
768 | 0 | static const char build_config[] = |
769 | 0 | "Build configuration: " FREERDP_BUILD_CONFIG "\n" |
770 | 0 | "Build type: " FREERDP_BUILD_TYPE "\n" |
771 | 0 | "CFLAGS: " FREERDP_CFLAGS "\n" |
772 | 0 | "Compiler: " FREERDP_COMPILER_ID ", " FREERDP_COMPILER_VERSION "\n" |
773 | 0 | "Target architecture: " FREERDP_TARGET_ARCH "\n"; |
774 | 0 | WINPR_PRAGMA_DIAG_POP |
775 | 0 | return build_config; |
776 | 0 | } |
777 | | |
778 | | const char* freerdp_get_build_revision(void) |
779 | 0 | { |
780 | 0 | return FREERDP_GIT_REVISION; |
781 | 0 | } |
782 | | |
783 | | static wEventType FreeRDP_Events[] = { |
784 | | DEFINE_EVENT_ENTRY(WindowStateChange), DEFINE_EVENT_ENTRY(ResizeWindow), |
785 | | DEFINE_EVENT_ENTRY(LocalResizeWindow), DEFINE_EVENT_ENTRY(EmbedWindow), |
786 | | DEFINE_EVENT_ENTRY(PanningChange), DEFINE_EVENT_ENTRY(ZoomingChange), |
787 | | DEFINE_EVENT_ENTRY(ErrorInfo), DEFINE_EVENT_ENTRY(Terminate), |
788 | | DEFINE_EVENT_ENTRY(ConnectionResult), DEFINE_EVENT_ENTRY(ChannelConnected), |
789 | | DEFINE_EVENT_ENTRY(ChannelDisconnected), DEFINE_EVENT_ENTRY(MouseEvent), |
790 | | DEFINE_EVENT_ENTRY(Activated), DEFINE_EVENT_ENTRY(Timer), |
791 | | DEFINE_EVENT_ENTRY(GraphicsReset) |
792 | | }; |
793 | | |
794 | | /** Allocator function for a rdp context. |
795 | | * The function will allocate a rdpRdp structure using rdp_new(), then copy |
796 | | * its contents to the appropriate fields in the rdp_freerdp structure given in parameters. |
797 | | * It will also initialize the 'context' field in the rdp_freerdp structure as needed. |
798 | | * If the caller has set the ContextNew callback in the 'instance' parameter, it will be called at |
799 | | * the end of the function. |
800 | | * |
801 | | * @param instance - Pointer to the rdp_freerdp structure that will be initialized with the new |
802 | | * context. |
803 | | */ |
804 | | BOOL freerdp_context_new(freerdp* instance) |
805 | 0 | { |
806 | 0 | return freerdp_context_new_ex(instance, nullptr); |
807 | 0 | } |
808 | | |
809 | | static BOOL freerdp_common_context(rdpContext* context, AccessTokenType tokenType, char** token, |
810 | | size_t count, ...) |
811 | 0 | { |
812 | 0 | BOOL rc = FALSE; |
813 | |
|
814 | 0 | WINPR_ASSERT(context); |
815 | 0 | if (!context->instance || !context->instance->GetAccessToken) |
816 | 0 | return TRUE; |
817 | | |
818 | 0 | va_list ap = WINPR_C_ARRAY_INIT; |
819 | 0 | va_start(ap, count); |
820 | 0 | switch (tokenType) |
821 | 0 | { |
822 | 0 | case ACCESS_TOKEN_TYPE_AAD: |
823 | 0 | if (count != 2) |
824 | 0 | { |
825 | 0 | WLog_ERR(TAG, |
826 | 0 | "ACCESS_TOKEN_TYPE_AAD expected 2 additional arguments, but got %" PRIuz |
827 | 0 | ", aborting", |
828 | 0 | count); |
829 | 0 | } |
830 | 0 | else |
831 | 0 | { |
832 | 0 | const char* scope = va_arg(ap, const char*); |
833 | 0 | const char* req_cnf = va_arg(ap, const char*); |
834 | 0 | rc = context->instance->GetAccessToken(context->instance, tokenType, token, count, |
835 | 0 | scope, req_cnf); |
836 | 0 | } |
837 | 0 | break; |
838 | 0 | case ACCESS_TOKEN_TYPE_AVD: |
839 | 0 | if (count != 0) |
840 | 0 | { |
841 | 0 | WLog_WARN(TAG, |
842 | 0 | "ACCESS_TOKEN_TYPE_AVD expected 0 additional arguments, but got %" PRIuz |
843 | 0 | ", ignoring", |
844 | 0 | count); |
845 | 0 | } |
846 | 0 | else |
847 | 0 | { |
848 | 0 | rc = context->instance->GetAccessToken(context->instance, tokenType, token, count); |
849 | 0 | } |
850 | 0 | break; |
851 | 0 | default: |
852 | 0 | break; |
853 | 0 | } |
854 | 0 | va_end(ap); |
855 | |
|
856 | 0 | if (!rc) |
857 | 0 | freerdp_set_last_error_if_not(context, FREERDP_ERROR_CONNECT_ACCESS_DENIED); |
858 | |
|
859 | 0 | return rc; |
860 | 0 | } |
861 | | |
862 | | BOOL freerdp_context_new_ex(freerdp* instance, rdpSettings* settings) |
863 | 8.11k | { |
864 | 8.11k | rdpRdp* rdp = nullptr; |
865 | 8.11k | rdpContext* context = nullptr; |
866 | 8.11k | BOOL ret = TRUE; |
867 | | |
868 | 8.11k | WINPR_ASSERT(instance); |
869 | | |
870 | 8.11k | instance->context = context = (rdpContext*)calloc(1, instance->ContextSize); |
871 | | |
872 | 8.11k | if (!context) |
873 | 0 | return FALSE; |
874 | | |
875 | 8.11k | context->log = WLog_Get(TAG); |
876 | 8.11k | if (!context->log) |
877 | 0 | goto fail; |
878 | | |
879 | | /* Set to external settings, prevents rdp_new from creating its own instance */ |
880 | 8.11k | context->settings = settings; |
881 | 8.11k | context->instance = instance; |
882 | 8.11k | context->ServerMode = FALSE; |
883 | 8.11k | context->disconnectUltimatum = 0; |
884 | | |
885 | 8.11k | context->metrics = metrics_new(context); |
886 | | |
887 | 8.11k | if (!context->metrics) |
888 | 0 | goto fail; |
889 | | |
890 | 8.11k | rdp = rdp_new(context); |
891 | | |
892 | 8.11k | if (!rdp) |
893 | 0 | goto fail; |
894 | | |
895 | 8.11k | context->rdp = rdp; |
896 | 8.11k | context->pubSub = rdp->pubSub; |
897 | | |
898 | 8.11k | if (!context->pubSub) |
899 | 0 | goto fail; |
900 | | |
901 | 8.11k | PubSub_AddEventTypes(rdp->pubSub, FreeRDP_Events, ARRAYSIZE(FreeRDP_Events)); |
902 | | |
903 | | #if defined(WITH_FREERDP_DEPRECATED) |
904 | | instance->input = rdp->input; |
905 | | instance->update = rdp->update; |
906 | | instance->settings = rdp->settings; |
907 | | instance->autodetect = rdp->autodetect; |
908 | | #endif |
909 | | |
910 | 8.11k | instance->heartbeat = rdp->heartbeat; |
911 | 8.11k | context->graphics = graphics_new(context); |
912 | | |
913 | 8.11k | if (!context->graphics) |
914 | 0 | goto fail; |
915 | | |
916 | 8.11k | context->input = rdp->input; |
917 | 8.11k | context->update = rdp->update; |
918 | 8.11k | context->settings = rdp->settings; |
919 | 8.11k | context->autodetect = rdp->autodetect; |
920 | | |
921 | 8.11k | if (!(context->errorDescription = calloc(1, 500))) |
922 | 0 | { |
923 | 0 | WLog_Print(context->log, WLOG_ERROR, "calloc failed!"); |
924 | 0 | goto fail; |
925 | 0 | } |
926 | | |
927 | 8.11k | if (!(context->channelErrorEvent = CreateEvent(nullptr, TRUE, FALSE, nullptr))) |
928 | 0 | { |
929 | 0 | WLog_Print(context->log, WLOG_ERROR, "CreateEvent failed!"); |
930 | 0 | goto fail; |
931 | 0 | } |
932 | | |
933 | 8.11k | update_register_client_callbacks(rdp->update); |
934 | | |
935 | 8.11k | if (!(context->channels = freerdp_channels_new(instance))) |
936 | 0 | goto fail; |
937 | | |
938 | 8.11k | context->dump = stream_dump_new(); |
939 | 8.11k | if (!context->dump) |
940 | 0 | goto fail; |
941 | | |
942 | | /* Fallback: |
943 | | * Client common library might set a function pointer to handle this, but here we provide a |
944 | | * default implementation that simply calls instance->GetAccessToken. |
945 | | */ |
946 | 8.11k | if (!freerdp_set_common_access_token(context, freerdp_common_context)) |
947 | 0 | goto fail; |
948 | | |
949 | 8.11k | IFCALLRET(instance->ContextNew, ret, instance, context); |
950 | | |
951 | 8.11k | if (!ret) |
952 | 0 | goto fail; |
953 | | |
954 | 8.11k | return TRUE; |
955 | | |
956 | 0 | fail: |
957 | 0 | freerdp_context_free(instance); |
958 | 0 | return FALSE; |
959 | 8.11k | } |
960 | | |
961 | | BOOL freerdp_context_reset(freerdp* instance) |
962 | 0 | { |
963 | 0 | if (!instance) |
964 | 0 | return FALSE; |
965 | | |
966 | 0 | WINPR_ASSERT(instance->context); |
967 | 0 | rdpRdp* rdp = instance->context->rdp; |
968 | |
|
969 | 0 | return rdp_reset_runtime_settings(rdp); |
970 | 0 | } |
971 | | |
972 | | /** Deallocator function for a rdp context. |
973 | | * The function will deallocate the resources from the 'instance' parameter that were allocated |
974 | | * from a call to freerdp_context_new(). If the ContextFree callback is set in the 'instance' |
975 | | * parameter, it will be called before deallocation occurs. |
976 | | * |
977 | | * @param instance - Pointer to the rdp_freerdp structure that was initialized by a call to |
978 | | * freerdp_context_new(). On return, the fields associated to the context are invalid. |
979 | | */ |
980 | | void freerdp_context_free(freerdp* instance) |
981 | 8.11k | { |
982 | 8.11k | rdpContext* ctx = nullptr; |
983 | | |
984 | 8.11k | if (!instance) |
985 | 0 | return; |
986 | | |
987 | 8.11k | if (!instance->context) |
988 | 0 | return; |
989 | | |
990 | 8.11k | ctx = instance->context; |
991 | | |
992 | 8.11k | IFCALL(instance->ContextFree, instance, ctx); |
993 | 8.11k | rdp_free(ctx->rdp); |
994 | 8.11k | ctx->rdp = nullptr; |
995 | 8.11k | ctx->settings = nullptr; /* owned by rdpRdp */ |
996 | | |
997 | 8.11k | graphics_free(ctx->graphics); |
998 | 8.11k | ctx->graphics = nullptr; |
999 | | |
1000 | 8.11k | metrics_free(ctx->metrics); |
1001 | 8.11k | ctx->metrics = nullptr; |
1002 | | |
1003 | 8.11k | if (ctx->channelErrorEvent) |
1004 | 8.11k | (void)CloseHandle(ctx->channelErrorEvent); |
1005 | 8.11k | ctx->channelErrorEvent = nullptr; |
1006 | | |
1007 | 8.11k | free(ctx->errorDescription); |
1008 | 8.11k | ctx->errorDescription = nullptr; |
1009 | | |
1010 | 8.11k | freerdp_channels_free(ctx->channels); |
1011 | 8.11k | ctx->channels = nullptr; |
1012 | | |
1013 | 8.11k | freerdp_client_codecs_free(ctx->codecs); |
1014 | 8.11k | ctx->codecs = nullptr; |
1015 | | |
1016 | 8.11k | stream_dump_free(ctx->dump); |
1017 | 8.11k | ctx->dump = nullptr; |
1018 | | |
1019 | 8.11k | ctx->input = nullptr; /* owned by rdpRdp */ |
1020 | 8.11k | ctx->update = nullptr; /* owned by rdpRdp */ |
1021 | 8.11k | ctx->settings = nullptr; /* owned by rdpRdp */ |
1022 | 8.11k | ctx->autodetect = nullptr; /* owned by rdpRdp */ |
1023 | | |
1024 | 8.11k | free(ctx); |
1025 | 8.11k | instance->context = nullptr; |
1026 | | #if defined(WITH_FREERDP_DEPRECATED) |
1027 | | instance->input = nullptr; /* owned by rdpRdp */ |
1028 | | instance->update = nullptr; /* owned by rdpRdp */ |
1029 | | instance->settings = nullptr; /* owned by rdpRdp */ |
1030 | | instance->autodetect = nullptr; /* owned by rdpRdp */ |
1031 | | #endif |
1032 | 8.11k | instance->heartbeat = nullptr; /* owned by rdpRdp */ |
1033 | 8.11k | } |
1034 | | |
1035 | | int freerdp_get_disconnect_ultimatum(const rdpContext* context) |
1036 | 0 | { |
1037 | 0 | WINPR_ASSERT(context); |
1038 | 0 | return context->disconnectUltimatum; |
1039 | 0 | } |
1040 | | |
1041 | | UINT32 freerdp_error_info(const freerdp* instance) |
1042 | 0 | { |
1043 | 0 | WINPR_ASSERT(instance); |
1044 | 0 | WINPR_ASSERT(instance->context); |
1045 | 0 | WINPR_ASSERT(instance->context->rdp); |
1046 | 0 | return instance->context->rdp->errorInfo; |
1047 | 0 | } |
1048 | | |
1049 | | void freerdp_set_error_info(rdpRdp* rdp, UINT32 error) |
1050 | 0 | { |
1051 | 0 | if (!rdp) |
1052 | 0 | return; |
1053 | | |
1054 | 0 | rdp_set_error_info(rdp, error); |
1055 | 0 | } |
1056 | | |
1057 | | BOOL freerdp_send_error_info(rdpRdp* rdp) |
1058 | 0 | { |
1059 | 0 | if (!rdp) |
1060 | 0 | return FALSE; |
1061 | | |
1062 | 0 | return rdp_send_error_info(rdp); |
1063 | 0 | } |
1064 | | |
1065 | | UINT32 freerdp_get_last_error(const rdpContext* context) |
1066 | 123 | { |
1067 | 123 | WINPR_ASSERT(context); |
1068 | 123 | return context->LastError; |
1069 | 123 | } |
1070 | | |
1071 | | const char* freerdp_get_last_error_name(UINT32 code) |
1072 | 1.25k | { |
1073 | 1.25k | const char* name = nullptr; |
1074 | 1.25k | const UINT32 cls = GET_FREERDP_ERROR_CLASS(code); |
1075 | 1.25k | const UINT32 type = GET_FREERDP_ERROR_TYPE(code); |
1076 | | |
1077 | 1.25k | switch (cls) |
1078 | 1.25k | { |
1079 | 0 | case FREERDP_ERROR_ERRBASE_CLASS: |
1080 | 0 | name = freerdp_get_error_base_name(type); |
1081 | 0 | break; |
1082 | | |
1083 | 781 | case FREERDP_ERROR_ERRINFO_CLASS: |
1084 | 781 | name = freerdp_get_error_info_name(type); |
1085 | 781 | break; |
1086 | | |
1087 | 305 | case FREERDP_ERROR_CONNECT_CLASS: |
1088 | 305 | name = freerdp_get_error_connect_name(type); |
1089 | 305 | break; |
1090 | | |
1091 | 173 | default: |
1092 | 173 | name = rpc_error_to_string(code); |
1093 | 173 | break; |
1094 | 1.25k | } |
1095 | | |
1096 | 1.25k | return name; |
1097 | 1.25k | } |
1098 | | |
1099 | | const char* freerdp_get_last_error_string(UINT32 code) |
1100 | 0 | { |
1101 | 0 | const char* string = nullptr; |
1102 | 0 | const UINT32 cls = GET_FREERDP_ERROR_CLASS(code); |
1103 | 0 | const UINT32 type = GET_FREERDP_ERROR_TYPE(code); |
1104 | |
|
1105 | 0 | switch (cls) |
1106 | 0 | { |
1107 | 0 | case FREERDP_ERROR_ERRBASE_CLASS: |
1108 | 0 | string = freerdp_get_error_base_string(type); |
1109 | 0 | break; |
1110 | | |
1111 | 0 | case FREERDP_ERROR_ERRINFO_CLASS: |
1112 | 0 | string = freerdp_get_error_info_string(type); |
1113 | 0 | break; |
1114 | | |
1115 | 0 | case FREERDP_ERROR_CONNECT_CLASS: |
1116 | 0 | string = freerdp_get_error_connect_string(type); |
1117 | 0 | break; |
1118 | | |
1119 | 0 | default: |
1120 | 0 | string = rpc_error_to_string(code); |
1121 | 0 | break; |
1122 | 0 | } |
1123 | | |
1124 | 0 | return string; |
1125 | 0 | } |
1126 | | |
1127 | | const char* freerdp_get_last_error_category(UINT32 code) |
1128 | 0 | { |
1129 | 0 | const char* string = nullptr; |
1130 | 0 | const UINT32 cls = GET_FREERDP_ERROR_CLASS(code); |
1131 | 0 | const UINT32 type = GET_FREERDP_ERROR_TYPE(code); |
1132 | |
|
1133 | 0 | switch (cls) |
1134 | 0 | { |
1135 | 0 | case FREERDP_ERROR_ERRBASE_CLASS: |
1136 | 0 | string = freerdp_get_error_base_category(type); |
1137 | 0 | break; |
1138 | | |
1139 | 0 | case FREERDP_ERROR_ERRINFO_CLASS: |
1140 | 0 | string = freerdp_get_error_info_category(type); |
1141 | 0 | break; |
1142 | | |
1143 | 0 | case FREERDP_ERROR_CONNECT_CLASS: |
1144 | 0 | string = freerdp_get_error_connect_category(type); |
1145 | 0 | break; |
1146 | | |
1147 | 0 | default: |
1148 | 0 | string = rpc_error_to_category(code); |
1149 | 0 | break; |
1150 | 0 | } |
1151 | | |
1152 | 0 | return string; |
1153 | 0 | } |
1154 | | |
1155 | | void freerdp_set_last_error_ex(rdpContext* context, UINT32 lastError, const char* fkt, |
1156 | | const char* file, int line) |
1157 | 1.14k | { |
1158 | 1.14k | WINPR_ASSERT(context); |
1159 | 1.14k | WINPR_ASSERT(line >= 0); |
1160 | | |
1161 | 1.14k | if (lastError) |
1162 | 1.13k | { |
1163 | 1.13k | if (WLog_IsLevelActive(context->log, WLOG_ERROR)) |
1164 | 1.13k | { |
1165 | 1.13k | WLog_PrintTextMessage(context->log, WLOG_ERROR, (size_t)line, file, fkt, |
1166 | 1.13k | "%s [0x%08" PRIX32 "]", freerdp_get_last_error_name(lastError), |
1167 | 1.13k | lastError); |
1168 | 1.13k | } |
1169 | 1.13k | } |
1170 | | |
1171 | 1.14k | if (lastError == FREERDP_ERROR_SUCCESS) |
1172 | 4 | { |
1173 | 4 | if (WLog_IsLevelActive(context->log, WLOG_DEBUG)) |
1174 | 0 | WLog_PrintTextMessage(context->log, WLOG_DEBUG, (size_t)line, file, fkt, |
1175 | 0 | "resetting error state"); |
1176 | 4 | } |
1177 | 1.13k | else if (context->LastError != FREERDP_ERROR_SUCCESS) |
1178 | 61 | { |
1179 | 61 | if (WLog_IsLevelActive(context->log, WLOG_ERROR)) |
1180 | 61 | { |
1181 | 61 | WLog_PrintTextMessage(context->log, WLOG_ERROR, (size_t)line, file, fkt, |
1182 | 61 | "TODO: Trying to set error code %s, but %s already set!", |
1183 | 61 | freerdp_get_last_error_name(lastError), |
1184 | 61 | freerdp_get_last_error_name(context->LastError)); |
1185 | 61 | } |
1186 | 61 | } |
1187 | 1.14k | context->LastError = lastError; |
1188 | 1.14k | } |
1189 | | |
1190 | | const char* freerdp_get_logon_error_info_type_ex(UINT32 type, char* buffer, size_t size) |
1191 | 0 | { |
1192 | 0 | const char* str = freerdp_get_logon_error_info_type(type); |
1193 | 0 | (void)_snprintf(buffer, size, "%s(0x%04" PRIx32 ")", str, type); |
1194 | 0 | return buffer; |
1195 | 0 | } |
1196 | | |
1197 | | const char* freerdp_get_logon_error_info_type(UINT32 type) |
1198 | 114 | { |
1199 | 114 | #define CASE_ENTRY(x) \ |
1200 | 114 | case x: \ |
1201 | 3 | return #x |
1202 | 114 | switch (type) |
1203 | 114 | { |
1204 | 0 | CASE_ENTRY(LOGON_MSG_SESSION_BUSY_OPTIONS); |
1205 | 0 | CASE_ENTRY(LOGON_MSG_DISCONNECT_REFUSED); |
1206 | 0 | CASE_ENTRY(LOGON_MSG_NO_PERMISSION); |
1207 | 0 | CASE_ENTRY(LOGON_MSG_BUMP_OPTIONS); |
1208 | 0 | CASE_ENTRY(LOGON_MSG_RECONNECT_OPTIONS); |
1209 | 0 | CASE_ENTRY(LOGON_MSG_SESSION_TERMINATE); |
1210 | 0 | CASE_ENTRY(LOGON_MSG_SESSION_CONTINUE); |
1211 | 3 | CASE_ENTRY(ERROR_CODE_ACCESS_DENIED); |
1212 | | |
1213 | 111 | default: |
1214 | 111 | return "UNKNOWN"; |
1215 | 114 | } |
1216 | 114 | #undef CASE_ENTRY |
1217 | 114 | } |
1218 | | |
1219 | | const char* freerdp_get_logon_error_info_data(UINT32 data) |
1220 | 114 | { |
1221 | 114 | switch (data) |
1222 | 114 | { |
1223 | 36 | case LOGON_FAILED_BAD_PASSWORD: |
1224 | 36 | return "LOGON_FAILED_BAD_PASSWORD"; |
1225 | | |
1226 | 0 | case LOGON_FAILED_UPDATE_PASSWORD: |
1227 | 0 | return "LOGON_FAILED_UPDATE_PASSWORD"; |
1228 | | |
1229 | 6 | case LOGON_FAILED_OTHER: |
1230 | 6 | return "LOGON_FAILED_OTHER"; |
1231 | | |
1232 | 1 | case LOGON_WARNING: |
1233 | 1 | return "LOGON_WARNING"; |
1234 | | |
1235 | 71 | default: |
1236 | 71 | return "SESSION_ID"; |
1237 | 114 | } |
1238 | 114 | } |
1239 | | |
1240 | | const char* freerdp_get_logon_error_info_data_ex(UINT32 data, char* buffer, size_t size) |
1241 | 0 | { |
1242 | 0 | const char* str = freerdp_get_logon_error_info_data(data); |
1243 | 0 | (void)_snprintf(buffer, size, "%s(0x%04" PRIx32 ")", str, data); |
1244 | 0 | return buffer; |
1245 | 0 | } |
1246 | | |
1247 | | /** Allocator function for the rdp_freerdp structure. |
1248 | | * @return an allocated structure filled with 0s. Need to be deallocated using freerdp_free() |
1249 | | */ |
1250 | | freerdp* freerdp_new(void) |
1251 | 8.11k | { |
1252 | 8.11k | freerdp* instance = nullptr; |
1253 | 8.11k | instance = (freerdp*)calloc(1, sizeof(freerdp)); |
1254 | | |
1255 | 8.11k | if (!instance) |
1256 | 0 | return nullptr; |
1257 | | |
1258 | 8.11k | instance->ContextSize = sizeof(rdpContext); |
1259 | 8.11k | instance->SendChannelData = freerdp_send_channel_data; |
1260 | 8.11k | instance->SendChannelPacket = freerdp_send_channel_packet; |
1261 | 8.11k | instance->ReceiveChannelData = freerdp_channels_data; |
1262 | 8.11k | return instance; |
1263 | 8.11k | } |
1264 | | |
1265 | | /** Deallocator function for the rdp_freerdp structure. |
1266 | | * @param instance - pointer to the rdp_freerdp structure to deallocate. |
1267 | | * On return, this pointer is not valid anymore. |
1268 | | */ |
1269 | | void freerdp_free(freerdp* instance) |
1270 | 8.11k | { |
1271 | 8.11k | free(instance); |
1272 | 8.11k | } |
1273 | | |
1274 | | ULONG freerdp_get_transport_sent(const rdpContext* context, BOOL resetCount) |
1275 | 0 | { |
1276 | 0 | WINPR_ASSERT(context); |
1277 | 0 | WINPR_ASSERT(context->rdp); |
1278 | 0 | UINT64 rc = transport_get_bytes_sent(context->rdp->transport, resetCount); |
1279 | 0 | return WINPR_CXX_COMPAT_CAST(ULONG, MIN(rc, UINT32_MAX)); |
1280 | 0 | } |
1281 | | |
1282 | | BOOL freerdp_nla_impersonate(rdpContext* context) |
1283 | 0 | { |
1284 | 0 | rdpNla* nla = nullptr; |
1285 | |
|
1286 | 0 | if (!context) |
1287 | 0 | return FALSE; |
1288 | | |
1289 | 0 | if (!context->rdp) |
1290 | 0 | return FALSE; |
1291 | | |
1292 | 0 | if (!context->rdp->transport) |
1293 | 0 | return FALSE; |
1294 | | |
1295 | 0 | nla = transport_get_nla(context->rdp->transport); |
1296 | 0 | return nla_impersonate(nla); |
1297 | 0 | } |
1298 | | |
1299 | | BOOL freerdp_nla_revert_to_self(rdpContext* context) |
1300 | 0 | { |
1301 | 0 | rdpNla* nla = nullptr; |
1302 | |
|
1303 | 0 | if (!context) |
1304 | 0 | return FALSE; |
1305 | | |
1306 | 0 | if (!context->rdp) |
1307 | 0 | return FALSE; |
1308 | | |
1309 | 0 | if (!context->rdp->transport) |
1310 | 0 | return FALSE; |
1311 | | |
1312 | 0 | nla = transport_get_nla(context->rdp->transport); |
1313 | 0 | return nla_revert_to_self(nla); |
1314 | 0 | } |
1315 | | |
1316 | | UINT32 freerdp_get_nla_sspi_error(const rdpContext* context) |
1317 | 0 | { |
1318 | 0 | WINPR_ASSERT(context); |
1319 | 0 | WINPR_ASSERT(context->rdp); |
1320 | 0 | WINPR_ASSERT(context->rdp->transport); |
1321 | |
|
1322 | 0 | rdpNla* nla = transport_get_nla(context->rdp->transport); |
1323 | 0 | return (UINT32)nla_get_sspi_error(nla); |
1324 | 0 | } |
1325 | | |
1326 | | BOOL freerdp_nla_encrypt(rdpContext* context, const SecBuffer* inBuffer, SecBuffer* outBuffer) |
1327 | 0 | { |
1328 | 0 | WINPR_ASSERT(context); |
1329 | 0 | WINPR_ASSERT(context->rdp); |
1330 | |
|
1331 | 0 | rdpNla* nla = context->rdp->nla; |
1332 | 0 | return nla_encrypt(nla, inBuffer, outBuffer); |
1333 | 0 | } |
1334 | | |
1335 | | BOOL freerdp_nla_decrypt(rdpContext* context, const SecBuffer* inBuffer, SecBuffer* outBuffer) |
1336 | 0 | { |
1337 | 0 | WINPR_ASSERT(context); |
1338 | 0 | WINPR_ASSERT(context->rdp); |
1339 | |
|
1340 | 0 | rdpNla* nla = context->rdp->nla; |
1341 | 0 | return nla_decrypt(nla, inBuffer, outBuffer); |
1342 | 0 | } |
1343 | | |
1344 | | SECURITY_STATUS freerdp_nla_QueryContextAttributes(rdpContext* context, DWORD ulAttr, PVOID pBuffer) |
1345 | 0 | { |
1346 | 0 | WINPR_ASSERT(context); |
1347 | 0 | WINPR_ASSERT(context->rdp); |
1348 | |
|
1349 | 0 | rdpNla* nla = context->rdp->nla; |
1350 | 0 | if (!nla) |
1351 | 0 | nla = transport_get_nla(context->rdp->transport); |
1352 | |
|
1353 | 0 | WINPR_ASSERT(nla); |
1354 | |
|
1355 | 0 | return nla_QueryContextAttributes(nla, ulAttr, pBuffer); |
1356 | 0 | } |
1357 | | |
1358 | | SECURITY_STATUS freerdp_nla_FreeContextBuffer(rdpContext* context, PVOID pBuffer) |
1359 | 0 | { |
1360 | 0 | WINPR_ASSERT(context); |
1361 | 0 | WINPR_ASSERT(context->rdp); |
1362 | |
|
1363 | 0 | rdpNla* nla = context->rdp->nla; |
1364 | 0 | if (!nla) |
1365 | 0 | nla = transport_get_nla(context->rdp->transport); |
1366 | |
|
1367 | 0 | WINPR_ASSERT(nla); |
1368 | |
|
1369 | 0 | return nla_FreeContextBuffer(nla, pBuffer); |
1370 | 0 | } |
1371 | | |
1372 | | HANDLE getChannelErrorEventHandle(rdpContext* context) |
1373 | 0 | { |
1374 | 0 | WINPR_ASSERT(context); |
1375 | 0 | return context->channelErrorEvent; |
1376 | 0 | } |
1377 | | |
1378 | | BOOL checkChannelErrorEvent(rdpContext* context) |
1379 | 0 | { |
1380 | 0 | WINPR_ASSERT(context); |
1381 | |
|
1382 | 0 | if (WaitForSingleObject(context->channelErrorEvent, 0) == WAIT_OBJECT_0) |
1383 | 0 | { |
1384 | 0 | WLog_Print(context->log, WLOG_ERROR, "%s. Error was %" PRIu32 "", context->errorDescription, |
1385 | 0 | context->channelErrorNum); |
1386 | 0 | return FALSE; |
1387 | 0 | } |
1388 | | |
1389 | 0 | return TRUE; |
1390 | 0 | } |
1391 | | |
1392 | | /** |
1393 | | * Function description |
1394 | | * |
1395 | | * @return 0 on success, otherwise a Win32 error code |
1396 | | */ |
1397 | | UINT getChannelError(const rdpContext* context) |
1398 | 0 | { |
1399 | 0 | WINPR_ASSERT(context); |
1400 | 0 | return context->channelErrorNum; |
1401 | 0 | } |
1402 | | |
1403 | | const char* getChannelErrorDescription(const rdpContext* context) |
1404 | 0 | { |
1405 | 0 | WINPR_ASSERT(context); |
1406 | 0 | return context->errorDescription; |
1407 | 0 | } |
1408 | | |
1409 | | void clearChannelError(rdpContext* context) |
1410 | 0 | { |
1411 | 0 | WINPR_ASSERT(context); |
1412 | 0 | context->channelErrorNum = 0; |
1413 | 0 | memset(context->errorDescription, 0, 500); |
1414 | 0 | (void)ResetEvent(context->channelErrorEvent); |
1415 | 0 | } |
1416 | | |
1417 | | WINPR_ATTR_FORMAT_ARG(3, 4) |
1418 | | void setChannelError(rdpContext* context, UINT errorNum, WINPR_FORMAT_ARG const char* format, ...) |
1419 | 0 | { |
1420 | 0 | va_list ap = WINPR_C_ARRAY_INIT; |
1421 | 0 | va_start(ap, format); |
1422 | |
|
1423 | 0 | WINPR_ASSERT(context); |
1424 | |
|
1425 | 0 | context->channelErrorNum = errorNum; |
1426 | 0 | (void)vsnprintf(context->errorDescription, 499, format, ap); |
1427 | 0 | va_end(ap); |
1428 | 0 | (void)SetEvent(context->channelErrorEvent); |
1429 | 0 | } |
1430 | | |
1431 | | const char* freerdp_nego_get_routing_token(const rdpContext* context, DWORD* length) |
1432 | 0 | { |
1433 | 0 | if (!context || !context->rdp) |
1434 | 0 | return nullptr; |
1435 | | |
1436 | 0 | return (const char*)nego_get_routing_token(context->rdp->nego, length); |
1437 | 0 | } |
1438 | | |
1439 | | BOOL freerdp_io_callback_set_event(rdpContext* context, BOOL set) |
1440 | 0 | { |
1441 | 0 | WINPR_ASSERT(context); |
1442 | 0 | return rdp_io_callback_set_event(context->rdp, set); |
1443 | 0 | } |
1444 | | |
1445 | | const rdpTransportIo* freerdp_get_io_callbacks(rdpContext* context) |
1446 | 0 | { |
1447 | 0 | WINPR_ASSERT(context); |
1448 | 0 | return rdp_get_io_callbacks(context->rdp); |
1449 | 0 | } |
1450 | | |
1451 | | BOOL freerdp_set_io_callbacks(rdpContext* context, const rdpTransportIo* io_callbacks) |
1452 | 0 | { |
1453 | 0 | WINPR_ASSERT(context); |
1454 | 0 | return rdp_set_io_callbacks(context->rdp, io_callbacks); |
1455 | 0 | } |
1456 | | |
1457 | | BOOL freerdp_set_io_callback_context(rdpContext* context, void* usercontext) |
1458 | 0 | { |
1459 | 0 | WINPR_ASSERT(context); |
1460 | 0 | return rdp_set_io_callback_context(context->rdp, usercontext); |
1461 | 0 | } |
1462 | | |
1463 | | void* freerdp_get_io_callback_context(rdpContext* context) |
1464 | 0 | { |
1465 | 0 | WINPR_ASSERT(context); |
1466 | 0 | return rdp_get_io_callback_context(context->rdp); |
1467 | 0 | } |
1468 | | |
1469 | | CONNECTION_STATE freerdp_get_state(const rdpContext* context) |
1470 | 0 | { |
1471 | 0 | WINPR_ASSERT(context); |
1472 | 0 | return rdp_get_state(context->rdp); |
1473 | 0 | } |
1474 | | |
1475 | | const char* freerdp_state_string(CONNECTION_STATE state) |
1476 | 0 | { |
1477 | 0 | return rdp_state_string(state); |
1478 | 0 | } |
1479 | | |
1480 | | BOOL freerdp_is_active_state(const rdpContext* context) |
1481 | 0 | { |
1482 | 0 | WINPR_ASSERT(context); |
1483 | 0 | return rdp_is_active_state(context->rdp); |
1484 | 0 | } |
1485 | | |
1486 | | BOOL freerdp_channels_from_mcs(rdpSettings* settings, const rdpContext* context) |
1487 | 0 | { |
1488 | 0 | WINPR_ASSERT(context); |
1489 | 0 | return rdp_channels_from_mcs(settings, context->rdp); |
1490 | 0 | } |
1491 | | |
1492 | | HANDLE freerdp_abort_event(rdpContext* context) |
1493 | 0 | { |
1494 | 0 | WINPR_ASSERT(context); |
1495 | 0 | return utils_get_abort_event(context->rdp); |
1496 | 0 | } |
1497 | | |
1498 | | static void test_mcs_free(rdpMcs* mcs) |
1499 | 30.8k | { |
1500 | 30.8k | if (!mcs) |
1501 | 0 | return; |
1502 | | |
1503 | 30.8k | if (mcs->context) |
1504 | 30.8k | { |
1505 | 30.8k | rdpSettings* settings = mcs->context->settings; |
1506 | 30.8k | freerdp_settings_free(settings); |
1507 | 30.8k | } |
1508 | 30.8k | free(mcs->context); |
1509 | | |
1510 | 30.8k | mcs_free(mcs); |
1511 | 30.8k | } |
1512 | | |
1513 | | static rdpMcs* test_mcs_new(void) |
1514 | 30.8k | { |
1515 | 30.8k | rdpSettings* settings = freerdp_settings_new(0); |
1516 | 30.8k | rdpContext* context = calloc(1, sizeof(rdpContext)); |
1517 | | |
1518 | 30.8k | if (!settings) |
1519 | 0 | goto fail; |
1520 | 30.8k | if (!freerdp_settings_set_bool(settings, FreeRDP_TransportDumpReplay, TRUE)) |
1521 | 0 | goto fail; |
1522 | | |
1523 | 30.8k | if (!context) |
1524 | 0 | goto fail; |
1525 | 30.8k | context->settings = settings; |
1526 | 30.8k | return mcs_new(context); |
1527 | | |
1528 | 0 | fail: |
1529 | 0 | free(context); |
1530 | 0 | freerdp_settings_free(settings); |
1531 | |
|
1532 | 0 | return nullptr; |
1533 | 30.8k | } |
1534 | | |
1535 | | BOOL freerdp_is_valid_mcs_create_request(const BYTE* data, size_t size) |
1536 | 15.4k | { |
1537 | | |
1538 | 15.4k | wStream sbuffer = WINPR_C_ARRAY_INIT; |
1539 | 15.4k | wStream* s = Stream_StaticConstInit(&sbuffer, data, size); |
1540 | | |
1541 | 15.4k | WINPR_ASSERT(data || (size == 0)); |
1542 | 15.4k | WINPR_ASSERT(s); |
1543 | | |
1544 | 15.4k | rdpMcs* mcs = test_mcs_new(); |
1545 | 15.4k | WINPR_ASSERT(mcs); |
1546 | | |
1547 | 15.4k | BOOL result = mcs_recv_connect_initial(mcs, s); |
1548 | 15.4k | test_mcs_free(mcs); |
1549 | 15.4k | return result; |
1550 | 15.4k | } |
1551 | | |
1552 | | BOOL freerdp_is_valid_mcs_create_response(const BYTE* data, size_t size) |
1553 | 15.4k | { |
1554 | | |
1555 | 15.4k | wStream sbuffer = WINPR_C_ARRAY_INIT; |
1556 | 15.4k | wStream* s = Stream_StaticConstInit(&sbuffer, data, size); |
1557 | | |
1558 | 15.4k | WINPR_ASSERT(data || (size == 0)); |
1559 | 15.4k | WINPR_ASSERT(s); |
1560 | | |
1561 | 15.4k | rdpMcs* mcs = test_mcs_new(); |
1562 | 15.4k | WINPR_ASSERT(mcs); |
1563 | | |
1564 | 15.4k | BOOL result = mcs_recv_connect_response(mcs, s); |
1565 | 15.4k | test_mcs_free(mcs); |
1566 | 15.4k | return result; |
1567 | 15.4k | } |
1568 | | |
1569 | | BOOL freerdp_persist_credentials(rdpContext* context) |
1570 | 0 | { |
1571 | 0 | if (!context) |
1572 | 0 | return FALSE; |
1573 | 0 | WINPR_ASSERT(context->rdp); |
1574 | 0 | return utils_persist_credentials(context->rdp->originalSettings, context->rdp->settings); |
1575 | 0 | } |
1576 | | |
1577 | | const char* freerdp_disconnect_reason_string(int reason) |
1578 | 0 | { |
1579 | 0 | switch (reason) |
1580 | 0 | { |
1581 | 0 | case Disconnect_Ultimatum_domain_disconnected: |
1582 | 0 | return "rn-domain-disconnected"; |
1583 | 0 | case Disconnect_Ultimatum_provider_initiated: |
1584 | 0 | return "rn-provider-initiated"; |
1585 | 0 | case Disconnect_Ultimatum_token_purged: |
1586 | 0 | return "rn-token-purged"; |
1587 | 0 | case Disconnect_Ultimatum_user_requested: |
1588 | 0 | return "rn-user-requested"; |
1589 | 0 | case Disconnect_Ultimatum_channel_purged: |
1590 | 0 | return "rn-channel-purged"; |
1591 | 0 | default: |
1592 | 0 | return "rn-unknown"; |
1593 | 0 | } |
1594 | 0 | } |
1595 | | |
1596 | | BOOL freerdp_set_common_access_token(rdpContext* context, |
1597 | | pGetCommonAccessToken GetCommonAccessToken) |
1598 | 8.11k | { |
1599 | 8.11k | WINPR_ASSERT(context); |
1600 | 8.11k | WINPR_ASSERT(context->rdp); |
1601 | 8.11k | context->rdp->GetCommonAccessToken = GetCommonAccessToken; |
1602 | 8.11k | return TRUE; |
1603 | 8.11k | } |
1604 | | |
1605 | | pGetCommonAccessToken freerdp_get_common_access_token(const rdpContext* context) |
1606 | 0 | { |
1607 | 0 | WINPR_ASSERT(context); |
1608 | 0 | WINPR_ASSERT(context->rdp); |
1609 | 0 | return context->rdp->GetCommonAccessToken; |
1610 | 0 | } |