| 1 | /** |
| 2 | * FreeRDP: A Remote Desktop Protocol Implementation |
| 3 | * Smartcard Device Service Virtual Channel |
| 4 | * |
| 5 | * Copyright 2011 O.S. Systems Software Ltda. |
| 6 | * Copyright 2011 Eduardo Fiss Beloni <[email protected]> |
| 7 | * Copyright 2011 Anthony Tong <[email protected]> |
| 8 | * Copyright 2015 Thincast Technologies GmbH |
| 9 | * Copyright 2015 DI (FH) Martin Haimberger <[email protected]> |
| 10 | * Copyright 2016 David PHAM-VAN <[email protected]> |
| 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>cxx . . $ `<file>/build/include/freerdp/config.h`/ |
| 26 | |
| 27 | #include <winpr/crt.h>cxx . . $ `<file>/winpr/include/winpr/crt.h`/ |
| 28 | #include <winpr/smartcard.h>cxx . . $ `<file>/winpr/include/winpr/smartcard.h`/ |
| 29 | #include <winpr/environment.h>cxx . . $ `<file>/winpr/include/winpr/environment.h`/ |
| 30 | |
| 31 | #include <freerdp/freerdp.h>cxx . . $ `<file>/include/freerdp/freerdp.h`/ |
| 32 | #include <freerdp/channels/rdpdr.h>cxx . . $ `<file>/include/freerdp/channels/rdpdr.h`/ |
| 33 | #include <freerdp/channels/scard.h>cxx . . $ `<file>/include/freerdp/channels/scard.h`/ |
| 34 | #include <freerdp/utils/smartcard_call.h>cxx . . $ `<file>/include/freerdp/utils/smartcard_call.h`/ |
| 35 | #include <freerdp/utils/smartcard_operations.h>cxx . . $ `<file>/include/freerdp/utils/smartcard_operations.h`/ |
| 36 | #include <freerdp/utils/rdpdr_utils.h>cxx . . $ `<file>/include/freerdp/utils/rdpdr_utils.h`/ |
| 37 | |
| 38 | #include "smartcard_main.h"cxx . . $ `<file>/channels/smartcard/client/smartcard_main.h`/ |
| 39 | |
| 40 | #define CAST_FROM_DEVICEcxx . . $ `channels/smartcard/client/smartcard_main.c:40:9`!(device) cast_device_from(device, __func__, __FILE__, __LINE__) |
| 41 | |
| 42 | typedef structcxx . . $ $anonymous_type_4358fb7d6ed44e57_0# |
| 43 | { |
| 44 | SMARTCARD_OPERATIONcxx . . $ SMARTCARD_OPERATION# operationcxx . . $ $anonymous_type_4358fb7d6ed44e57_0#operation.; |
| 45 | IRPcxx . . $ IRP#* irpcxx . . $ $anonymous_type_4358fb7d6ed44e57_0#irp.; |
| 46 | } scard_irp_queue_elementcxx . . $ scard_irp_queue_element#; |
| 47 | |
| 48 | static void smartcard_context_freecxx . . $ smartcard_context_free(5d22bdacc48458e8).(void* pCtx); |
| 49 | |
| 50 | static UINTcxx . . $ UINT# smartcard_complete_irpcxx . . $ smartcard_complete_irp(7a9f2d5612c5c231).(SMARTCARD_DEVICEcxx . . $ SMARTCARD_DEVICE#* smartcard, IRPcxx . . $ IRP#* irp, BOOLcxx . . $ BOOL#* handled); |
| 51 | |
| 52 | static SMARTCARD_DEVICEcxx . . $ SMARTCARD_DEVICE#* cast_device_fromcxx . . $ cast_device_from(33b11288b058ca2).(DEVICEcxx . . $ DEVICE#* device, const char* fkt, const char* file, |
| 53 | size_t line) |
| 54 | { |
| 55 | if (!device) |
| 56 | { |
| 57 | WLog_ERRcxx . . $ `winpr/include/winpr/wlog.h:347:9`!(TAGcxx . . $ `channels/smartcard/client/smartcard_main.h:38:9`!, "%s [%s:%" PRIuzcxx . . $ `winpr/include/winpr/wtypes.h:485:9`! "] Called smartcard channel with nullptr device", fkt, file, |
| 58 | line); |
| 59 | return nullptrcxx . . $ `winpr/include/winpr/platform.h:88:9`!; |
| 60 | } |
| 61 | |
| 62 | if (device->typecxx . . $ S_DEVICE#type. != RDPDR_DTYP_SMARTCARDcxx . . $ RDPDR_DTYP_SMARTCARD.) |
| 63 | { |
| 64 | WLog_ERRcxx . . $ `winpr/include/winpr/wlog.h:347:9`!(TAGcxx . . $ `channels/smartcard/client/smartcard_main.h:38:9`!, |
| 65 | "%s [%s:%" PRIuzcxx . . $ `winpr/include/winpr/wtypes.h:485:9`! "] Called smartcard channel with invalid device of type %" PRIx32cxx . . $ `<external>/15933738808807975373/inttypes.h:125:10`!, |
| 66 | fkt, file, line, device->type); |
| 67 | return nullptrcxx . . $ `winpr/include/winpr/platform.h:88:9`!; |
| 68 | } |
| 69 | |
| 70 | return (SMARTCARD_DEVICEcxx . . $ SMARTCARD_DEVICE#*)device; |
| 71 | } |
| 72 | |
| 73 | static DWORDcxx . . $ DWORD# WINAPIcxx . . $ `winpr/include/winpr/wtypes.h:84:9`! smartcard_context_threadcxx . . $ smartcard_context_thread(6769d0e399bf81e3).(LPVOIDcxx . . $ LPVOID# arg) |
| 74 | { |
| 75 | SMARTCARD_CONTEXTcxx . . $ SMARTCARD_CONTEXT#* pContext = (SMARTCARD_CONTEXTcxx . . $ SMARTCARD_CONTEXT#*)arg; |
| 76 | DWORDcxx . . $ DWORD# nCount = 0; |
| 77 | DWORDcxx . . $ DWORD# waitStatus = 0; |
| 78 | HANDLEcxx . . $ HANDLE# hEvents[2] = WINPR_C_ARRAY_INITcxx . . $ `winpr/include/winpr/platform.h:87:9`!; |
| 79 | wMessagecxx . . $ wMessage# message = WINPR_C_ARRAY_INITcxx . . $ `winpr/include/winpr/platform.h:87:9`!; |
| 80 | SMARTCARD_DEVICEcxx . . $ SMARTCARD_DEVICE#* smartcard = nullptrcxx . . $ `winpr/include/winpr/platform.h:88:9`!; |
| 81 | UINTcxx . . $ UINT# error = CHANNEL_RC_OKcxx . . $ `winpr/include/winpr/wtsapi.h:159:9`!; |
| 82 | smartcard = pContext->smartcardcxx . . $ $anonymous_type_4711dac392aa0bc9_1#smartcard.; |
| 83 | |
| 84 | hEvents[nCount++] = MessageQueue_Eventcxx . . $ MessageQueue_Event(10aff47038be4cd0).(pContext->IrpQueuecxx . . $ $anonymous_type_4711dac392aa0bc9_1#IrpQueue.); |
| 85 | |
| 86 | while (1) |
| 87 | { |
| 88 | waitStatus = WaitForMultipleObjectscxx . . $ WaitForMultipleObjects(b9c7375e997c2ab5).(nCount, hEvents, FALSEcxx . . $ `winpr/include/winpr/wtypes.h:122:9`!, INFINITEcxx . . $ `winpr/include/winpr/synch.h:212:9`!); |
| 89 | |
| 90 | if (waitStatus == WAIT_FAILEDcxx . . $ `winpr/include/winpr/synch.h:222:9`!) |
| 91 | { |
| 92 | error = GetLastErrorcxx . . $ GetLastError(db52760e79bf9054).(); |
| 93 | WLog_ERRcxx . . $ `winpr/include/winpr/wlog.h:347:9`!(TAGcxx . . $ `channels/smartcard/client/smartcard_main.h:38:9`!, "WaitForMultipleObjects failed with error %" PRIu32cxx . . $ `<external>/15933738808807975373/inttypes.h:109:10`! "!", error); |
| 94 | break; |
| 95 | } |
| 96 | |
| 97 | waitStatus = WaitForSingleObjectcxx . . $ WaitForSingleObject(35feec062aeef876).(MessageQueue_Eventcxx . . $ MessageQueue_Event(10aff47038be4cd0).(pContext->IrpQueuecxx . . $ $anonymous_type_4711dac392aa0bc9_1#IrpQueue.), 0); |
| 98 | |
| 99 | if (waitStatus == WAIT_FAILEDcxx . . $ `winpr/include/winpr/synch.h:222:9`!) |
| 100 | { |
| 101 | error = GetLastErrorcxx . . $ GetLastError(db52760e79bf9054).(); |
| 102 | WLog_ERRcxx . . $ `winpr/include/winpr/wlog.h:347:9`!(TAGcxx . . $ `channels/smartcard/client/smartcard_main.h:38:9`!, "WaitForSingleObject failed with error %" PRIu32cxx . . $ `<external>/15933738808807975373/inttypes.h:109:10`! "!", error); |
| 103 | break; |
| 104 | } |
| 105 | |
| 106 | if (waitStatus == WAIT_OBJECT_0cxx . . $ `winpr/include/winpr/synch.h:214:9`!) |
| 107 | { |
| 108 | scard_irp_queue_elementcxx . . $ scard_irp_queue_element#* element = nullptrcxx . . $ `winpr/include/winpr/platform.h:88:9`!; |
| 109 | |
| 110 | if (!MessageQueue_Peekcxx . . $ MessageQueue_Peek(86df90ae267cd1ca).(pContext->IrpQueuecxx . . $ $anonymous_type_4711dac392aa0bc9_1#IrpQueue., &message, TRUEcxx . . $ `winpr/include/winpr/wtypes.h:126:9`!)) |
| 111 | { |
| 112 | WLog_ERRcxx . . $ `winpr/include/winpr/wlog.h:347:9`!(TAGcxx . . $ `channels/smartcard/client/smartcard_main.h:38:9`!, "MessageQueue_Peek failed!"); |
| 113 | error = ERROR_INTERNAL_ERRORcxx . . $ `winpr/include/winpr/error.h:985:9`!; |
| 114 | break; |
| 115 | } |
| 116 | |
| 117 | if (message.idcxx . . $ s_wMessage#id. == WMQ_QUITcxx . . $ `winpr/include/winpr/collections.h:845:9`!) |
| 118 | break; |
| 119 | |
| 120 | element = (scard_irp_queue_elementcxx . . $ scard_irp_queue_element#*)message.wParamcxx . . $ s_wMessage#wParam.; |
| 121 | |
| 122 | if (element) |
| 123 | { |
| 124 | BOOLcxx . . $ BOOL# handled = FALSEcxx . . $ `winpr/include/winpr/wtypes.h:122:9`!; |
| 125 | WINPR_ASSERTcxx . . $ `winpr/include/winpr/assert-api.h:76:9`!(smartcard); |
| 126 | |
| 127 | const LONGcxx . . $ LONG# status = |
| 128 | smartcard_irp_device_control_callcxx . . $ smartcard_irp_device_control_call(e30547e481ee7662).(smartcard->callctxcxx . . $ $anonymous_type_4711dac392aa0bc9_0#callctx., element->irpcxx . . $ $anonymous_type_4358fb7d6ed44e57_0#irp.->outputcxx . . $ S_IRP#output., |
| 129 | &element->irpcxx . . $ $anonymous_type_4358fb7d6ed44e57_0#irp.->IoStatuscxx . . $ S_IRP#IoStatus., &element->operationcxx . . $ $anonymous_type_4358fb7d6ed44e57_0#operation.); |
| 130 | if (status) |
| 131 | { |
| 132 | element->irpcxx . . $ $anonymous_type_4358fb7d6ed44e57_0#irp.->Discardcxx . . $ S_IRP#Discard.(element->irpcxx . . $ $anonymous_type_4358fb7d6ed44e57_0#irp.); |
| 133 | smartcard_operation_freecxx . . $ smartcard_operation_free(cdae1d5aef0ee276).(&element->operationcxx . . $ $anonymous_type_4358fb7d6ed44e57_0#operation., TRUEcxx . . $ `winpr/include/winpr/wtypes.h:126:9`!); |
| 134 | WLog_ERRcxx . . $ `winpr/include/winpr/wlog.h:347:9`!(TAGcxx . . $ `channels/smartcard/client/smartcard_main.h:38:9`!, |
| 135 | "smartcard_irp_device_control_call failed with error %s [%" PRId32cxx . . $ `<external>/15933738808807975373/inttypes.h:61:10`! "]", |
| 136 | NtStatus2Tag(status), status); |
| 137 | error = (UINTcxx . . $ UINT#)status; |
| 138 | break; |
| 139 | } |
| 140 | |
| 141 | error = smartcard_complete_irpcxx . . $ smartcard_complete_irp(7a9f2d5612c5c231).(smartcard, element->irpcxx . . $ $anonymous_type_4358fb7d6ed44e57_0#irp., &handled); |
| 142 | if (!handled) |
| 143 | element->irpcxx . . $ $anonymous_type_4358fb7d6ed44e57_0#irp.->Discardcxx . . $ S_IRP#Discard.(element->irpcxx . . $ $anonymous_type_4358fb7d6ed44e57_0#irp.); |
| 144 | smartcard_operation_freecxx . . $ smartcard_operation_free(cdae1d5aef0ee276).(&element->operationcxx . . $ $anonymous_type_4358fb7d6ed44e57_0#operation., TRUEcxx . . $ `winpr/include/winpr/wtypes.h:126:9`!); |
| 145 | |
| 146 | if (error) |
| 147 | { |
| 148 | WLog_ERRcxx . . $ `winpr/include/winpr/wlog.h:347:9`!(TAGcxx . . $ `channels/smartcard/client/smartcard_main.h:38:9`!, "smartcard_complete_irp failed with %s [%" PRIu32cxx . . $ `<external>/15933738808807975373/inttypes.h:109:10`! "]", |
| 149 | WTSErrorToString(error), error); |
| 150 | break; |
| 151 | } |
| 152 | } |
| 153 | } |
| 154 | } |
| 155 | |
| 156 | if (error && smartcard->rdpcontextcxx . . $ $anonymous_type_4711dac392aa0bc9_0#rdpcontext.) |
| 157 | setChannelErrorcxx . . $ setChannelError(5de635fef11cc662).(smartcard->rdpcontextcxx . . $ $anonymous_type_4711dac392aa0bc9_0#rdpcontext., error, "smartcard_context_thread reported an error"); |
| 158 | |
| 159 | ExitThreadcxx . . $ ExitThread(cb2f890c2fdad230).(error); |
| 160 | return error; |
| 161 | } |
| 162 | |
| 163 | static void smartcard_operation_queue_freecxx . . $ smartcard_operation_queue_free(5d22bdacc48458e8).(void* obj) |
| 164 | { |
| 165 | wMessagecxx . . $ wMessage#* msg = obj; |
| 166 | if (!msg) |
| 167 | return; |
| 168 | if (msg->idcxx . . $ s_wMessage#id. != 0) |
| 169 | return; |
| 170 | |
| 171 | scard_irp_queue_elementcxx . . $ scard_irp_queue_element#* element = (scard_irp_queue_elementcxx . . $ scard_irp_queue_element#*)msg->wParamcxx . . $ s_wMessage#wParam.; |
| 172 | if (!element) |
| 173 | return; |
| 174 | WINPR_ASSERTcxx . . $ `winpr/include/winpr/assert-api.h:76:9`!(element->irp); |
| 175 | WINPR_ASSERTcxx . . $ `winpr/include/winpr/assert-api.h:76:9`!(element->irp->Discard); |
| 176 | element->irpcxx . . $ $anonymous_type_4358fb7d6ed44e57_0#irp.->Discardcxx . . $ S_IRP#Discard.(element->irpcxx . . $ $anonymous_type_4358fb7d6ed44e57_0#irp.); |
| 177 | smartcard_operation_freecxx . . $ smartcard_operation_free(cdae1d5aef0ee276).(&element->operationcxx . . $ $anonymous_type_4358fb7d6ed44e57_0#operation., TRUEcxx . . $ `winpr/include/winpr/wtypes.h:126:9`!); |
| 178 | } |
| 179 | |
| 180 | static void* smartcard_context_newcxx . . $ smartcard_context_new(417ab160f6baadc6).(void* smartcard, SCARDCONTEXTcxx . . $ SCARDCONTEXT# hContext) |
| 181 | { |
| 182 | SMARTCARD_CONTEXTcxx . . $ SMARTCARD_CONTEXT#* pContext = (SMARTCARD_CONTEXTcxx . . $ SMARTCARD_CONTEXT#*)calloccxx . . $ calloc(63a7bf2941bfcd7a).(1, sizeof(SMARTCARD_CONTEXTcxx . . $ SMARTCARD_CONTEXT#)); |
| 183 | |
| 184 | WLog_VRBcxx . . $ `winpr/include/winpr/wlog.h:339:9`!(TAGcxx . . $ `channels/smartcard/client/smartcard_main.h:38:9`!, "smartcard context create %p", (const void*)pContext); |
| 185 | if (!pContext) |
| 186 | { |
| 187 | WLog_ERRcxx . . $ `winpr/include/winpr/wlog.h:347:9`!(TAGcxx . . $ `channels/smartcard/client/smartcard_main.h:38:9`!, "calloc failed!"); |
| 188 | return pContext; |
| 189 | } |
| 190 | |
| 191 | pContext->smartcardcxx . . $ $anonymous_type_4711dac392aa0bc9_1#smartcard. = smartcard; |
| 192 | pContext->hContextcxx . . $ $anonymous_type_4711dac392aa0bc9_1#hContext. = hContext; |
| 193 | pContext->IrpQueuecxx . . $ $anonymous_type_4711dac392aa0bc9_1#IrpQueue. = MessageQueue_Newcxx . . $ MessageQueue_New(16a3a0bf8651d5f6).(nullptrcxx . . $ `winpr/include/winpr/platform.h:88:9`!); |
| 194 | |
| 195 | if (!pContext->IrpQueuecxx . . $ $anonymous_type_4711dac392aa0bc9_1#IrpQueue.) |
| 196 | { |
| 197 | WLog_ERRcxx . . $ `winpr/include/winpr/wlog.h:347:9`!(TAGcxx . . $ `channels/smartcard/client/smartcard_main.h:38:9`!, "MessageQueue_New failed!"); |
| 198 | goto fail; |
| 199 | } |
| 200 | |
| 201 | { |
| 202 | wObjectcxx . . $ wObject#* obj = MessageQueue_Objectcxx . . $ MessageQueue_Object(cd23635037a4f9b3).(pContext->IrpQueuecxx . . $ $anonymous_type_4711dac392aa0bc9_1#IrpQueue.); |
| 203 | WINPR_ASSERTcxx . . $ `winpr/include/winpr/assert-api.h:76:9`!(obj); |
| 204 | obj->fnObjectFreecxx . . $ $anonymous_type_ae1bcafa0ded638f_0#fnObjectFree. = smartcard_operation_queue_freecxx . . $ smartcard_operation_queue_free(5d22bdacc48458e8).; |
| 205 | } |
| 206 | |
| 207 | pContext->threadcxx . . $ $anonymous_type_4711dac392aa0bc9_1#thread. = CreateThreadcxx . . $ CreateThread(b708535bf8f563fd).(nullptrcxx . . $ `winpr/include/winpr/platform.h:88:9`!, 0, smartcard_context_threadcxx . . $ smartcard_context_thread(6769d0e399bf81e3)., pContext, 0, nullptrcxx . . $ `winpr/include/winpr/platform.h:88:9`!); |
| 208 | |
| 209 | if (!pContext->threadcxx . . $ $anonymous_type_4711dac392aa0bc9_1#thread.) |
| 210 | { |
| 211 | WLog_ERRcxx . . $ `winpr/include/winpr/wlog.h:347:9`!(TAGcxx . . $ `channels/smartcard/client/smartcard_main.h:38:9`!, "CreateThread failed!"); |
| 212 | goto fail; |
| 213 | } |
| 214 | |
| 215 | return pContext; |
| 216 | fail: |
| 217 | smartcard_context_freecxx . . $ smartcard_context_free(5d22bdacc48458e8).(pContext); |
| 218 | return nullptrcxx . . $ `winpr/include/winpr/platform.h:88:9`!; |
| 219 | } |
| 220 | |
| 221 | void smartcard_context_freecxx . . $ smartcard_context_free(5d22bdacc48458e8).(void* pCtx) |
| 222 | { |
| 223 | SMARTCARD_CONTEXTcxx . . $ SMARTCARD_CONTEXT#* pContext = pCtx; |
| 224 | |
| 225 | WLog_VRBcxx . . $ `winpr/include/winpr/wlog.h:339:9`!(TAGcxx . . $ `channels/smartcard/client/smartcard_main.h:38:9`!, "smartcard context destroy %p", pCtx); |
| 226 | if (!pContext) |
| 227 | return; |
| 228 | |
| 229 | /* cancel blocking calls like SCardGetStatusChange */ |
| 230 | WINPR_ASSERTcxx . . $ `winpr/include/winpr/assert-api.h:76:9`!(pContext->smartcard); |
| 231 | smartcard_call_cancel_contextcxx . . $ smartcard_call_cancel_context(ad90f1ff42fe14d8).(pContext->smartcardcxx . . $ $anonymous_type_4711dac392aa0bc9_1#smartcard.->callctxcxx . . $ $anonymous_type_4711dac392aa0bc9_0#callctx., pContext->hContextcxx . . $ $anonymous_type_4711dac392aa0bc9_1#hContext.); |
| 232 | |
| 233 | if (pContext->IrpQueuecxx . . $ $anonymous_type_4711dac392aa0bc9_1#IrpQueue.) |
| 234 | { |
| 235 | if (MessageQueue_PostQuitcxx . . $ MessageQueue_PostQuit(57e0bc29cc47719f).(pContext->IrpQueuecxx . . $ $anonymous_type_4711dac392aa0bc9_1#IrpQueue., 0)) |
| 236 | { |
| 237 | if (WaitForSingleObjectcxx . . $ WaitForSingleObject(35feec062aeef876).(pContext->threadcxx . . $ $anonymous_type_4711dac392aa0bc9_1#thread., INFINITEcxx . . $ `winpr/include/winpr/synch.h:212:9`!) == WAIT_FAILEDcxx . . $ `winpr/include/winpr/synch.h:222:9`!) |
| 238 | WLog_ERRcxx . . $ `winpr/include/winpr/wlog.h:347:9`!(TAGcxx . . $ `channels/smartcard/client/smartcard_main.h:38:9`!, "WaitForSingleObject failed with error %" PRIu32cxx . . $ `<external>/15933738808807975373/inttypes.h:109:10`! "!", GetLastError()); |
| 239 | |
| 240 | (void)CloseHandlecxx . . $ CloseHandle(dedf1e9b1c614a07).(pContext->threadcxx . . $ $anonymous_type_4711dac392aa0bc9_1#thread.); |
| 241 | } |
| 242 | MessageQueue_Freecxx . . $ MessageQueue_Free(d46f1ef4c8e02876).(pContext->IrpQueuecxx . . $ $anonymous_type_4711dac392aa0bc9_1#IrpQueue.); |
| 243 | } |
| 244 | smartcard_call_release_contextcxx . . $ smartcard_call_release_context(ad90f1ff42fe14d8).(pContext->smartcardcxx . . $ $anonymous_type_4711dac392aa0bc9_1#smartcard.->callctxcxx . . $ $anonymous_type_4711dac392aa0bc9_0#callctx., pContext->hContextcxx . . $ $anonymous_type_4711dac392aa0bc9_1#hContext.); |
| 245 | freecxx . . $ free(5d22bdacc48458e8).(pContext); |
| 246 | } |
| 247 | |
| 248 | static UINTcxx . . $ UINT# smartcard_free_cxx . . $ smartcard_free_(cb14c3e65898bc6a).(SMARTCARD_DEVICEcxx . . $ SMARTCARD_DEVICE#* smartcard) |
| 249 | { |
| 250 | if (!smartcard) |
| 251 | return CHANNEL_RC_OKcxx . . $ `winpr/include/winpr/wtsapi.h:159:9`!; |
| 252 | |
| 253 | if (smartcard->IrpQueuecxx . . $ $anonymous_type_4711dac392aa0bc9_0#IrpQueue.) |
| 254 | { |
| 255 | MessageQueue_Freecxx . . $ MessageQueue_Free(d46f1ef4c8e02876).(smartcard->IrpQueuecxx . . $ $anonymous_type_4711dac392aa0bc9_0#IrpQueue.); |
| 256 | (void)CloseHandlecxx . . $ CloseHandle(dedf1e9b1c614a07).(smartcard->threadcxx . . $ $anonymous_type_4711dac392aa0bc9_0#thread.); |
| 257 | } |
| 258 | |
| 259 | Stream_Freecxx . . $ Stream_Free(31813de2214206e2).(smartcard->devicecxx . . $ $anonymous_type_4711dac392aa0bc9_0#device..datacxx . . $ S_DEVICE#data., TRUEcxx . . $ `winpr/include/winpr/wtypes.h:126:9`!); |
| 260 | ListDictionary_Freecxx . . $ ListDictionary_Free(eeb79f4afedc5610).(smartcard->rgOutstandingMessagescxx . . $ $anonymous_type_4711dac392aa0bc9_0#rgOutstandingMessages.); |
| 261 | |
| 262 | smartcard_call_context_freecxx . . $ smartcard_call_context_free(647a04e221dc8925).(smartcard->callctxcxx . . $ $anonymous_type_4711dac392aa0bc9_0#callctx.); |
| 263 | |
| 264 | freecxx . . $ free(5d22bdacc48458e8).(smartcard); |
| 265 | return CHANNEL_RC_OKcxx . . $ `winpr/include/winpr/wtsapi.h:159:9`!; |
| 266 | } |
| 267 | /** |
| 268 | * Function description |
| 269 | * |
| 270 | * @return 0 on success, otherwise a Win32 error code |
| 271 | */ |
| 272 | static UINTcxx . . $ UINT# smartcard_freecxx . . $ smartcard_free(deb90cd3bde539e2).(DEVICEcxx . . $ DEVICE#* device) |
| 273 | { |
| 274 | SMARTCARD_DEVICEcxx . . $ SMARTCARD_DEVICE#* smartcard = CAST_FROM_DEVICEcxx . . $ `channels/smartcard/client/smartcard_main.c:40:9`!(device); |
| 275 | |
| 276 | WLog_VRBcxx . . $ `winpr/include/winpr/wlog.h:339:9`!(TAGcxx . . $ `channels/smartcard/client/smartcard_main.h:38:9`!, "smartcard device destroy: %p", (const void*)smartcard); |
| 277 | if (!smartcard) |
| 278 | return ERROR_INVALID_PARAMETERcxx . . $ `winpr/include/winpr/error.h:252:9`!; |
| 279 | |
| 280 | /** |
| 281 | * Calling smartcard_release_all_contexts to unblock all operations waiting for transactions |
| 282 | * to unlock. |
| 283 | */ |
| 284 | smartcard_call_cancel_all_contextcxx . . $ smartcard_call_cancel_all_context(c91c7d6742113e16).(smartcard->callctxcxx . . $ $anonymous_type_4711dac392aa0bc9_0#callctx.); |
| 285 | |
| 286 | /* Stopping all threads and cancelling all IRPs */ |
| 287 | |
| 288 | if (smartcard->IrpQueuecxx . . $ $anonymous_type_4711dac392aa0bc9_0#IrpQueue.) |
| 289 | { |
| 290 | if (MessageQueue_PostQuitcxx . . $ MessageQueue_PostQuit(57e0bc29cc47719f).(smartcard->IrpQueuecxx . . $ $anonymous_type_4711dac392aa0bc9_0#IrpQueue., 0) && |
| 291 | (WaitForSingleObjectcxx . . $ WaitForSingleObject(35feec062aeef876).(smartcard->threadcxx . . $ $anonymous_type_4711dac392aa0bc9_0#thread., INFINITEcxx . . $ `winpr/include/winpr/synch.h:212:9`!) == WAIT_FAILEDcxx . . $ `winpr/include/winpr/synch.h:222:9`!)) |
| 292 | { |
| 293 | DWORDcxx . . $ DWORD# error = GetLastErrorcxx . . $ GetLastError(db52760e79bf9054).(); |
| 294 | WLog_ERRcxx . . $ `winpr/include/winpr/wlog.h:347:9`!(TAGcxx . . $ `channels/smartcard/client/smartcard_main.h:38:9`!, "WaitForSingleObject failed with error %" PRIu32cxx . . $ `<external>/15933738808807975373/inttypes.h:109:10`! "!", error); |
| 295 | return error; |
| 296 | } |
| 297 | } |
| 298 | |
| 299 | return smartcard_free_cxx . . $ smartcard_free_(cb14c3e65898bc6a).(smartcard); |
| 300 | } |
| 301 | |
| 302 | /** |
| 303 | * Initialization occurs when the protocol server sends a device announce message. |
| 304 | * At that time, we need to cancel all outstanding IRPs. |
| 305 | */ |
| 306 | |
| 307 | /** |
| 308 | * Function description |
| 309 | * |
| 310 | * @return 0 on success, otherwise a Win32 error code |
| 311 | */ |
| 312 | static UINTcxx . . $ UINT# smartcard_initcxx . . $ smartcard_init(deb90cd3bde539e2).(DEVICEcxx . . $ DEVICE#* device) |
| 313 | { |
| 314 | SMARTCARD_DEVICEcxx . . $ SMARTCARD_DEVICE#* smartcard = CAST_FROM_DEVICEcxx . . $ `channels/smartcard/client/smartcard_main.c:40:9`!(device); |
| 315 | |
| 316 | WLog_VRBcxx . . $ `winpr/include/winpr/wlog.h:339:9`!(TAGcxx . . $ `channels/smartcard/client/smartcard_main.h:38:9`!, "smartcard device init %p", (const void*)smartcard); |
| 317 | if (!smartcard) |
| 318 | return ERROR_INVALID_PARAMETERcxx . . $ `winpr/include/winpr/error.h:252:9`!; |
| 319 | |
| 320 | smartcard_call_cancel_all_contextcxx . . $ smartcard_call_cancel_all_context(c91c7d6742113e16).(smartcard->callctxcxx . . $ $anonymous_type_4711dac392aa0bc9_0#callctx.); |
| 321 | return CHANNEL_RC_OKcxx . . $ `winpr/include/winpr/wtsapi.h:159:9`!; |
| 322 | } |
| 323 | |
| 324 | /** |
| 325 | * Function description |
| 326 | * |
| 327 | * @return 0 on success, otherwise a Win32 error code |
| 328 | */ |
| 329 | UINTcxx . . $ UINT# smartcard_complete_irpcxx . . $ smartcard_complete_irp(7a9f2d5612c5c231).(SMARTCARD_DEVICEcxx . . $ SMARTCARD_DEVICE#* smartcard, IRPcxx . . $ IRP#* irp, BOOLcxx . . $ BOOL#* handled) |
| 330 | { |
| 331 | WINPR_ASSERTcxx . . $ `winpr/include/winpr/assert-api.h:76:9`!(smartcard); |
| 332 | WINPR_ASSERTcxx . . $ `winpr/include/winpr/assert-api.h:76:9`!(irp); |
| 333 | WINPR_ASSERTcxx . . $ `winpr/include/winpr/assert-api.h:76:9`!(handled); |
| 334 | |
| 335 | uintptr_tcxx . . $ uintptr_t# key = (uintptr_tcxx . . $ uintptr_t#)irp->CompletionIdcxx . . $ S_IRP#CompletionId. + 1; |
| 336 | ListDictionary_Removecxx . . $ ListDictionary_Remove(1052719f28577513).(smartcard->rgOutstandingMessagescxx . . $ $anonymous_type_4711dac392aa0bc9_0#rgOutstandingMessages., (void*)key); |
| 337 | |
| 338 | WINPR_ASSERTcxx . . $ `winpr/include/winpr/assert-api.h:76:9`!(irp->Complete); |
| 339 | *handled = TRUEcxx . . $ `winpr/include/winpr/wtypes.h:126:9`!; |
| 340 | return irp->Completecxx . . $ S_IRP#Complete.(irp); |
| 341 | } |
| 342 | |
| 343 | /** |
| 344 | * Multiple threads and SCardGetStatusChange: |
| 345 | * http://musclecard.996296.n3.nabble.com/Multiple-threads-and-SCardGetStatusChange-td4430.html |
| 346 | */ |
| 347 | |
| 348 | /** |
| 349 | * Function description |
| 350 | * |
| 351 | * @return 0 on success, otherwise a Win32 error code |
| 352 | */ |
| 353 | static UINTcxx . . $ UINT# smartcard_process_irpcxx . . $ smartcard_process_irp(7a9f2d5612c5c231).(SMARTCARD_DEVICEcxx . . $ SMARTCARD_DEVICE#* smartcard, IRPcxx . . $ IRP#* irp, BOOLcxx . . $ BOOL#* handled) |
| 354 | { |
| 355 | LONGcxx . . $ LONG# status = 0; |
| 356 | BOOLcxx . . $ BOOL# asyncIrp = FALSEcxx . . $ `winpr/include/winpr/wtypes.h:122:9`!; |
| 357 | SMARTCARD_CONTEXTcxx . . $ SMARTCARD_CONTEXT#* pContext = nullptrcxx . . $ `winpr/include/winpr/platform.h:88:9`!; |
| 358 | |
| 359 | WINPR_ASSERTcxx . . $ `winpr/include/winpr/assert-api.h:76:9`!(smartcard); |
| 360 | WINPR_ASSERTcxx . . $ `winpr/include/winpr/assert-api.h:76:9`!(handled); |
| 361 | WINPR_ASSERTcxx . . $ `winpr/include/winpr/assert-api.h:76:9`!(irp); |
| 362 | WINPR_ASSERTcxx . . $ `winpr/include/winpr/assert-api.h:76:9`!(irp->Complete); |
| 363 | |
| 364 | uintptr_tcxx . . $ uintptr_t# key = (uintptr_tcxx . . $ uintptr_t#)irp->CompletionIdcxx . . $ S_IRP#CompletionId. + 1; |
| 365 | |
| 366 | if (!ListDictionary_Addcxx . . $ ListDictionary_Add(3b1ed64cb1e2c79b).(smartcard->rgOutstandingMessagescxx . . $ $anonymous_type_4711dac392aa0bc9_0#rgOutstandingMessages., (void*)key, irp)) |
| 367 | { |
| 368 | WLog_ERRcxx . . $ `winpr/include/winpr/wlog.h:347:9`!(TAGcxx . . $ `channels/smartcard/client/smartcard_main.h:38:9`!, "ListDictionary_Add failed!"); |
| 369 | return ERROR_INTERNAL_ERRORcxx . . $ `winpr/include/winpr/error.h:985:9`!; |
| 370 | } |
| 371 | |
| 372 | if (irp->MajorFunctioncxx . . $ S_IRP#MajorFunction. == IRP_MJ_DEVICE_CONTROLcxx . . $ IRP_MJ_DEVICE_CONTROL.) |
| 373 | { |
| 374 | scard_irp_queue_elementcxx . . $ scard_irp_queue_element#* element = calloccxx . . $ calloc(63a7bf2941bfcd7a).(1, sizeof(scard_irp_queue_elementcxx . . $ scard_irp_queue_element#)); |
| 375 | if (!element) |
| 376 | return ERROR_OUTOFMEMORYcxx . . $ `winpr/include/winpr/error.h:199:9`!; |
| 377 | |
| 378 | element->irpcxx . . $ $anonymous_type_4358fb7d6ed44e57_0#irp. = irp; |
| 379 | element->operationcxx . . $ $anonymous_type_4358fb7d6ed44e57_0#operation..completionIDcxx . . $ $anonymous_type_d64b37066b3195f2_0#completionID. = irp->CompletionIdcxx . . $ S_IRP#CompletionId.; |
| 380 | |
| 381 | status = smartcard_irp_device_control_decode_requestcxx . . $ smartcard_irp_device_control_decode_request(5435fa91527925cd).(irp->inputcxx . . $ S_IRP#input., irp->CompletionIdcxx . . $ S_IRP#CompletionId., |
| 382 | irp->FileIdcxx . . $ S_IRP#FileId., &element->operationcxx . . $ $anonymous_type_4358fb7d6ed44e57_0#operation.); |
| 383 | |
| 384 | if (status != SCARD_S_SUCCESScxx . . $ `winpr/include/winpr/smartcard.h:44:9`!) |
| 385 | { |
| 386 | UINTcxx . . $ UINT# error = 0; |
| 387 | |
| 388 | smartcard_operation_freecxx . . $ smartcard_operation_free(cdae1d5aef0ee276).(&element->operationcxx . . $ $anonymous_type_4358fb7d6ed44e57_0#operation., TRUEcxx . . $ `winpr/include/winpr/wtypes.h:126:9`!); |
| 389 | irp->IoStatuscxx . . $ S_IRP#IoStatus. = STATUS_UNSUCCESSFULcxx . . $ `winpr/include/winpr/nt.h:289:9`!; |
| 390 | |
| 391 | if ((error = smartcard_complete_irpcxx . . $ smartcard_complete_irp(7a9f2d5612c5c231).(smartcard, irp, handled))) |
| 392 | { |
| 393 | WLog_ERRcxx . . $ `winpr/include/winpr/wlog.h:347:9`!(TAGcxx . . $ `channels/smartcard/client/smartcard_main.h:38:9`!, "Queue_Enqueue failed!"); |
| 394 | return error; |
| 395 | } |
| 396 | |
| 397 | return CHANNEL_RC_OKcxx . . $ `winpr/include/winpr/wtsapi.h:159:9`!; |
| 398 | } |
| 399 | |
| 400 | asyncIrp = TRUEcxx . . $ `winpr/include/winpr/wtypes.h:126:9`!; |
| 401 | |
| 402 | switch (element->operationcxx . . $ $anonymous_type_4358fb7d6ed44e57_0#operation..ioControlCodecxx . . $ $anonymous_type_d64b37066b3195f2_0#ioControlCode.) |
| 403 | { |
| 404 | case SCARD_IOCTL_ESTABLISHCONTEXTcxx . . $ `include/freerdp/channels/scard.h:35:9`!: |
| 405 | case SCARD_IOCTL_RELEASECONTEXTcxx . . $ `include/freerdp/channels/scard.h:36:9`!: |
| 406 | case SCARD_IOCTL_ISVALIDCONTEXTcxx . . $ `include/freerdp/channels/scard.h:37:9`!: |
| 407 | case SCARD_IOCTL_CANCELcxx . . $ `include/freerdp/channels/scard.h:62:9`!: |
| 408 | case SCARD_IOCTL_ACCESSSTARTEDEVENTcxx . . $ `include/freerdp/channels/scard.h:76:9`!: |
| 409 | case SCARD_IOCTL_RELEASETARTEDEVENTcxx . . $ `include/freerdp/channels/scard.h:77:9`!: |
| 410 | asyncIrp = FALSEcxx . . $ `winpr/include/winpr/wtypes.h:122:9`!; |
| 411 | break; |
| 412 | |
| 413 | case SCARD_IOCTL_LISTREADERGROUPSAcxx . . $ `include/freerdp/channels/scard.h:38:9`!: |
| 414 | case SCARD_IOCTL_LISTREADERGROUPSWcxx . . $ `include/freerdp/channels/scard.h:39:9`!: |
| 415 | case SCARD_IOCTL_LISTREADERSAcxx . . $ `include/freerdp/channels/scard.h:40:9`!: |
| 416 | case SCARD_IOCTL_LISTREADERSWcxx . . $ `include/freerdp/channels/scard.h:41:9`!: |
| 417 | case SCARD_IOCTL_INTRODUCEREADERGROUPAcxx . . $ `include/freerdp/channels/scard.h:42:9`!: |
| 418 | case SCARD_IOCTL_INTRODUCEREADERGROUPWcxx . . $ `include/freerdp/channels/scard.h:43:9`!: |
| 419 | case SCARD_IOCTL_FORGETREADERGROUPAcxx . . $ `include/freerdp/channels/scard.h:44:9`!: |
| 420 | case SCARD_IOCTL_FORGETREADERGROUPWcxx . . $ `include/freerdp/channels/scard.h:45:9`!: |
| 421 | case SCARD_IOCTL_INTRODUCEREADERAcxx . . $ `include/freerdp/channels/scard.h:46:9`!: |
| 422 | case SCARD_IOCTL_INTRODUCEREADERWcxx . . $ `include/freerdp/channels/scard.h:47:9`!: |
| 423 | case SCARD_IOCTL_FORGETREADERAcxx . . $ `include/freerdp/channels/scard.h:48:9`!: |
| 424 | case SCARD_IOCTL_FORGETREADERWcxx . . $ `include/freerdp/channels/scard.h:49:9`!: |
| 425 | case SCARD_IOCTL_ADDREADERTOGROUPAcxx . . $ `include/freerdp/channels/scard.h:50:9`!: |
| 426 | case SCARD_IOCTL_ADDREADERTOGROUPWcxx . . $ `include/freerdp/channels/scard.h:51:9`!: |
| 427 | case SCARD_IOCTL_REMOVEREADERFROMGROUPAcxx . . $ `include/freerdp/channels/scard.h:52:9`!: |
| 428 | case SCARD_IOCTL_REMOVEREADERFROMGROUPWcxx . . $ `include/freerdp/channels/scard.h:55:9`!: |
| 429 | case SCARD_IOCTL_LOCATECARDSAcxx . . $ `include/freerdp/channels/scard.h:58:9`!: |
| 430 | case SCARD_IOCTL_LOCATECARDSWcxx . . $ `include/freerdp/channels/scard.h:59:9`!: |
| 431 | case SCARD_IOCTL_LOCATECARDSBYATRAcxx . . $ `include/freerdp/channels/scard.h:78:9`!: |
| 432 | case SCARD_IOCTL_LOCATECARDSBYATRWcxx . . $ `include/freerdp/channels/scard.h:79:9`!: |
| 433 | case SCARD_IOCTL_READCACHEAcxx . . $ `include/freerdp/channels/scard.h:80:9`!: |
| 434 | case SCARD_IOCTL_READCACHEWcxx . . $ `include/freerdp/channels/scard.h:81:9`!: |
| 435 | case SCARD_IOCTL_WRITECACHEAcxx . . $ `include/freerdp/channels/scard.h:82:9`!: |
| 436 | case SCARD_IOCTL_WRITECACHEWcxx . . $ `include/freerdp/channels/scard.h:83:9`!: |
| 437 | case SCARD_IOCTL_GETREADERICONcxx . . $ `include/freerdp/channels/scard.h:85:9`!: |
| 438 | case SCARD_IOCTL_GETDEVICETYPEIDcxx . . $ `include/freerdp/channels/scard.h:86:9`!: |
| 439 | case SCARD_IOCTL_GETSTATUSCHANGEAcxx . . $ `include/freerdp/channels/scard.h:60:9`!: |
| 440 | case SCARD_IOCTL_GETSTATUSCHANGEWcxx . . $ `include/freerdp/channels/scard.h:61:9`!: |
| 441 | case SCARD_IOCTL_CONNECTAcxx . . $ `include/freerdp/channels/scard.h:63:9`!: |
| 442 | case SCARD_IOCTL_CONNECTWcxx . . $ `include/freerdp/channels/scard.h:64:9`!: |
| 443 | case SCARD_IOCTL_RECONNECTcxx . . $ `include/freerdp/channels/scard.h:65:9`!: |
| 444 | case SCARD_IOCTL_DISCONNECTcxx . . $ `include/freerdp/channels/scard.h:66:9`!: |
| 445 | case SCARD_IOCTL_BEGINTRANSACTIONcxx . . $ `include/freerdp/channels/scard.h:67:9`!: |
| 446 | case SCARD_IOCTL_ENDTRANSACTIONcxx . . $ `include/freerdp/channels/scard.h:68:9`!: |
| 447 | case SCARD_IOCTL_STATEcxx . . $ `include/freerdp/channels/scard.h:69:9`!: |
| 448 | case SCARD_IOCTL_STATUSAcxx . . $ `include/freerdp/channels/scard.h:70:9`!: |
| 449 | case SCARD_IOCTL_STATUSWcxx . . $ `include/freerdp/channels/scard.h:71:9`!: |
| 450 | case SCARD_IOCTL_TRANSMITcxx . . $ `include/freerdp/channels/scard.h:72:9`!: |
| 451 | case SCARD_IOCTL_CONTROLcxx . . $ `include/freerdp/channels/scard.h:73:9`!: |
| 452 | case SCARD_IOCTL_GETATTRIBcxx . . $ `include/freerdp/channels/scard.h:74:9`!: |
| 453 | case SCARD_IOCTL_SETATTRIBcxx . . $ `include/freerdp/channels/scard.h:75:9`!: |
| 454 | case SCARD_IOCTL_GETTRANSMITCOUNTcxx . . $ `include/freerdp/channels/scard.h:84:9`!: |
| 455 | asyncIrp = TRUEcxx . . $ `winpr/include/winpr/wtypes.h:126:9`!; |
| 456 | break; |
| 457 | default: |
| 458 | break; |
| 459 | } |
| 460 | |
| 461 | pContext = smartcard_call_get_contextcxx . . $ smartcard_call_get_context(4cbeddcfb86e3010).(smartcard->callctxcxx . . $ $anonymous_type_4711dac392aa0bc9_0#callctx., element->operationcxx . . $ $anonymous_type_4358fb7d6ed44e57_0#operation..hContextcxx . . $ $anonymous_type_d64b37066b3195f2_0#hContext.); |
| 462 | |
| 463 | if (!pContext) |
| 464 | asyncIrp = FALSEcxx . . $ `winpr/include/winpr/wtypes.h:122:9`!; |
| 465 | |
| 466 | if (!asyncIrp) |
| 467 | { |
| 468 | UINTcxx . . $ UINT# error = 0; |
| 469 | |
| 470 | status = |
| 471 | smartcard_irp_device_control_callcxx . . $ smartcard_irp_device_control_call(e30547e481ee7662).(smartcard->callctxcxx . . $ $anonymous_type_4711dac392aa0bc9_0#callctx., element->irpcxx . . $ $anonymous_type_4358fb7d6ed44e57_0#irp.->outputcxx . . $ S_IRP#output., |
| 472 | &element->irpcxx . . $ $anonymous_type_4358fb7d6ed44e57_0#irp.->IoStatuscxx . . $ S_IRP#IoStatus., &element->operationcxx . . $ $anonymous_type_4358fb7d6ed44e57_0#operation.); |
| 473 | smartcard_operation_freecxx . . $ smartcard_operation_free(cdae1d5aef0ee276).(&element->operationcxx . . $ $anonymous_type_4358fb7d6ed44e57_0#operation., TRUEcxx . . $ `winpr/include/winpr/wtypes.h:126:9`!); |
| 474 | |
| 475 | if (status) |
| 476 | { |
| 477 | WLog_ERRcxx . . $ `winpr/include/winpr/wlog.h:347:9`!(TAGcxx . . $ `channels/smartcard/client/smartcard_main.h:38:9`!, "smartcard_irp_device_control_call failed with error %" PRId32cxx . . $ `<external>/15933738808807975373/inttypes.h:61:10`! "!", |
| 478 | status); |
| 479 | return (UINT32cxx . . $ UINT32#)status; |
| 480 | } |
| 481 | |
| 482 | if ((error = smartcard_complete_irpcxx . . $ smartcard_complete_irp(7a9f2d5612c5c231).(smartcard, irp, handled))) |
| 483 | { |
| 484 | WLog_ERRcxx . . $ `winpr/include/winpr/wlog.h:347:9`!(TAGcxx . . $ `channels/smartcard/client/smartcard_main.h:38:9`!, "Queue_Enqueue failed!"); |
| 485 | return error; |
| 486 | } |
| 487 | } |
| 488 | else |
| 489 | { |
| 490 | if (pContext) |
| 491 | { |
| 492 | if (!MessageQueue_Postcxx . . $ MessageQueue_Post(d228958df36e3ed0).(pContext->IrpQueuecxx . . $ $anonymous_type_4711dac392aa0bc9_1#IrpQueue., nullptrcxx . . $ `winpr/include/winpr/platform.h:88:9`!, 0, (void*)element, nullptrcxx . . $ `winpr/include/winpr/platform.h:88:9`!)) |
| 493 | { |
| 494 | smartcard_operation_freecxx . . $ smartcard_operation_free(cdae1d5aef0ee276).(&element->operationcxx . . $ $anonymous_type_4358fb7d6ed44e57_0#operation., TRUEcxx . . $ `winpr/include/winpr/wtypes.h:126:9`!); |
| 495 | WLog_ERRcxx . . $ `winpr/include/winpr/wlog.h:347:9`!(TAGcxx . . $ `channels/smartcard/client/smartcard_main.h:38:9`!, "MessageQueue_Post failed!"); |
| 496 | return ERROR_INTERNAL_ERRORcxx . . $ `winpr/include/winpr/error.h:985:9`!; |
| 497 | } |
| 498 | *handled = TRUEcxx . . $ `winpr/include/winpr/wtypes.h:126:9`!; |
| 499 | } |
| 500 | } |
| 501 | } |
| 502 | else |
| 503 | { |
| 504 | UINTcxx . . $ UINT# ustatus = 0; |
| 505 | WLog_ERRcxx . . $ `winpr/include/winpr/wlog.h:347:9`!(TAGcxx . . $ `channels/smartcard/client/smartcard_main.h:38:9`!, "Unexpected SmartCard IRP: MajorFunction %s, MinorFunction: 0x%08" PRIX32cxx . . $ `<external>/15933738808807975373/inttypes.h:141:10`! "", |
| 506 | rdpdr_irp_string(irp->MajorFunction), irp->MinorFunction); |
| 507 | irp->IoStatuscxx . . $ S_IRP#IoStatus. = STATUS_NOT_SUPPORTEDcxx . . $ `winpr/include/winpr/nt.h:478:9`!; |
| 508 | |
| 509 | if ((ustatus = smartcard_complete_irpcxx . . $ smartcard_complete_irp(7a9f2d5612c5c231).(smartcard, irp, handled))) |
| 510 | { |
| 511 | WLog_ERRcxx . . $ `winpr/include/winpr/wlog.h:347:9`!(TAGcxx . . $ `channels/smartcard/client/smartcard_main.h:38:9`!, "Queue_Enqueue failed!"); |
| 512 | return ustatus; |
| 513 | } |
| 514 | } |
| 515 | |
| 516 | return CHANNEL_RC_OKcxx . . $ `winpr/include/winpr/wtsapi.h:159:9`!; |
| 517 | } |
| 518 | |
| 519 | static DWORDcxx . . $ DWORD# WINAPIcxx . . $ `winpr/include/winpr/wtypes.h:84:9`! smartcard_thread_funccxx . . $ smartcard_thread_func(6769d0e399bf81e3).(LPVOIDcxx . . $ LPVOID# arg) |
| 520 | { |
| 521 | IRPcxx . . $ IRP#* irp = nullptrcxx . . $ `winpr/include/winpr/platform.h:88:9`!; |
| 522 | DWORDcxx . . $ DWORD# nCount = 0; |
| 523 | DWORDcxx . . $ DWORD# status = 0; |
| 524 | HANDLEcxx . . $ HANDLE# hEvents[1] = WINPR_C_ARRAY_INITcxx . . $ `winpr/include/winpr/platform.h:87:9`!; |
| 525 | wMessagecxx . . $ wMessage# message = WINPR_C_ARRAY_INITcxx . . $ `winpr/include/winpr/platform.h:87:9`!; |
| 526 | UINTcxx . . $ UINT# error = CHANNEL_RC_OKcxx . . $ `winpr/include/winpr/wtsapi.h:159:9`!; |
| 527 | SMARTCARD_DEVICEcxx . . $ SMARTCARD_DEVICE#* smartcard = CAST_FROM_DEVICEcxx . . $ `channels/smartcard/client/smartcard_main.c:40:9`!(arg); |
| 528 | |
| 529 | if (!smartcard) |
| 530 | return ERROR_INVALID_PARAMETERcxx . . $ `winpr/include/winpr/error.h:252:9`!; |
| 531 | |
| 532 | hEvents[nCount++] = MessageQueue_Eventcxx . . $ MessageQueue_Event(10aff47038be4cd0).(smartcard->IrpQueuecxx . . $ $anonymous_type_4711dac392aa0bc9_0#IrpQueue.); |
| 533 | |
| 534 | while (1) |
| 535 | { |
| 536 | status = WaitForMultipleObjectscxx . . $ WaitForMultipleObjects(b9c7375e997c2ab5).(nCount, hEvents, FALSEcxx . . $ `winpr/include/winpr/wtypes.h:122:9`!, INFINITEcxx . . $ `winpr/include/winpr/synch.h:212:9`!); |
| 537 | |
| 538 | if (status == WAIT_FAILEDcxx . . $ `winpr/include/winpr/synch.h:222:9`!) |
| 539 | { |
| 540 | error = GetLastErrorcxx . . $ GetLastError(db52760e79bf9054).(); |
| 541 | WLog_ERRcxx . . $ `winpr/include/winpr/wlog.h:347:9`!(TAGcxx . . $ `channels/smartcard/client/smartcard_main.h:38:9`!, "WaitForMultipleObjects failed with error %" PRIu32cxx . . $ `<external>/15933738808807975373/inttypes.h:109:10`! "!", error); |
| 542 | break; |
| 543 | } |
| 544 | |
| 545 | if (status == WAIT_OBJECT_0cxx . . $ `winpr/include/winpr/synch.h:214:9`!) |
| 546 | { |
| 547 | if (!MessageQueue_Peekcxx . . $ MessageQueue_Peek(86df90ae267cd1ca).(smartcard->IrpQueuecxx . . $ $anonymous_type_4711dac392aa0bc9_0#IrpQueue., &message, TRUEcxx . . $ `winpr/include/winpr/wtypes.h:126:9`!)) |
| 548 | { |
| 549 | WLog_ERRcxx . . $ `winpr/include/winpr/wlog.h:347:9`!(TAGcxx . . $ `channels/smartcard/client/smartcard_main.h:38:9`!, "MessageQueue_Peek failed!"); |
| 550 | error = ERROR_INTERNAL_ERRORcxx . . $ `winpr/include/winpr/error.h:985:9`!; |
| 551 | break; |
| 552 | } |
| 553 | |
| 554 | if (message.idcxx . . $ s_wMessage#id. == WMQ_QUITcxx . . $ `winpr/include/winpr/collections.h:845:9`!) |
| 555 | break; |
| 556 | |
| 557 | irp = (IRPcxx . . $ IRP#*)message.wParamcxx . . $ s_wMessage#wParam.; |
| 558 | |
| 559 | if (irp) |
| 560 | { |
| 561 | BOOLcxx . . $ BOOL# handled = FALSEcxx . . $ `winpr/include/winpr/wtypes.h:122:9`!; |
| 562 | if ((error = smartcard_process_irpcxx . . $ smartcard_process_irp(7a9f2d5612c5c231).(smartcard, irp, &handled))) |
| 563 | { |
| 564 | WLog_ERRcxx . . $ `winpr/include/winpr/wlog.h:347:9`!(TAGcxx . . $ `channels/smartcard/client/smartcard_main.h:38:9`!, "smartcard_process_irp failed with error %" PRIu32cxx . . $ `<external>/15933738808807975373/inttypes.h:109:10`! "!", error); |
| 565 | goto out; |
| 566 | } |
| 567 | if (!handled) |
| 568 | { |
| 569 | WINPR_ASSERTcxx . . $ `winpr/include/winpr/assert-api.h:76:9`!(irp->Discard); |
| 570 | irp->Discardcxx . . $ S_IRP#Discard.(irp); |
| 571 | } |
| 572 | } |
| 573 | } |
| 574 | } |
| 575 | |
| 576 | out: |
| 577 | |
| 578 | if (error && smartcard->rdpcontextcxx . . $ $anonymous_type_4711dac392aa0bc9_0#rdpcontext.) |
| 579 | setChannelErrorcxx . . $ setChannelError(5de635fef11cc662).(smartcard->rdpcontextcxx . . $ $anonymous_type_4711dac392aa0bc9_0#rdpcontext., error, "smartcard_thread_func reported an error"); |
| 580 | |
| 581 | ExitThreadcxx . . $ ExitThread(cb2f890c2fdad230).(error); |
| 582 | return error; |
| 583 | } |
| 584 | |
| 585 | /** |
| 586 | * Function description |
| 587 | * |
| 588 | * @return 0 on success, otherwise a Win32 error code |
| 589 | */ |
| 590 | static UINTcxx . . $ UINT# smartcard_irp_requestcxx . . $ smartcard_irp_request(949c9602d43ec5f7).(DEVICEcxx . . $ DEVICE#* device, IRPcxx . . $ IRP#* irp) |
| 591 | { |
| 592 | SMARTCARD_DEVICEcxx . . $ SMARTCARD_DEVICE#* smartcard = CAST_FROM_DEVICEcxx . . $ `channels/smartcard/client/smartcard_main.c:40:9`!(device); |
| 593 | |
| 594 | if (!smartcard) |
| 595 | { |
| 596 | irp->Discardcxx . . $ S_IRP#Discard.(irp); |
| 597 | return ERROR_INVALID_PARAMETERcxx . . $ `winpr/include/winpr/error.h:252:9`!; |
| 598 | } |
| 599 | |
| 600 | if (!MessageQueue_Postcxx . . $ MessageQueue_Post(d228958df36e3ed0).(smartcard->IrpQueuecxx . . $ $anonymous_type_4711dac392aa0bc9_0#IrpQueue., nullptrcxx . . $ `winpr/include/winpr/platform.h:88:9`!, 0, (void*)irp, nullptrcxx . . $ `winpr/include/winpr/platform.h:88:9`!)) |
| 601 | { |
| 602 | WLog_ERRcxx . . $ `winpr/include/winpr/wlog.h:347:9`!(TAGcxx . . $ `channels/smartcard/client/smartcard_main.h:38:9`!, "MessageQueue_Post failed!"); |
| 603 | irp->Discardcxx . . $ S_IRP#Discard.(irp); |
| 604 | return ERROR_INTERNAL_ERRORcxx . . $ `winpr/include/winpr/error.h:985:9`!; |
| 605 | } |
| 606 | |
| 607 | return CHANNEL_RC_OKcxx . . $ `winpr/include/winpr/wtsapi.h:159:9`!; |
| 608 | } |
| 609 | |
| 610 | static void smartcard_free_irpcxx . . $ smartcard_free_irp(5d22bdacc48458e8).(void* obj) |
| 611 | { |
| 612 | wMessagecxx . . $ wMessage#* msg = obj; |
| 613 | if (!msg) |
| 614 | return; |
| 615 | if (msg->idcxx . . $ s_wMessage#id. != 0) |
| 616 | return; |
| 617 | |
| 618 | IRPcxx . . $ IRP#* irp = (IRPcxx . . $ IRP#*)msg->wParamcxx . . $ s_wMessage#wParam.; |
| 619 | if (!irp) |
| 620 | return; |
| 621 | WINPR_ASSERTcxx . . $ `winpr/include/winpr/assert-api.h:76:9`!(irp->Discard); |
| 622 | irp->Discardcxx . . $ S_IRP#Discard.(irp); |
| 623 | } |
| 624 | |
| 625 | /* smartcard is always built-in */ |
| 626 | #define DeviceServiceEntrycxx . . $ `channels/smartcard/client/smartcard_main.c:626:9`! smartcard_DeviceServiceEntry |
| 627 | |
| 628 | /** |
| 629 | * Function description |
| 630 | * |
| 631 | * @return 0 on success, otherwise a Win32 error code |
| 632 | */ |
| 633 | FREERDP_ENTRY_POINTcxx . . $ `include/freerdp/api.h:30:9`!(UINT VCAPITYPEcxx . . $ `winpr/include/winpr/wtsapi.h:120:9`! DeviceServiceEntrycxx . . $ `channels/smartcard/client/smartcard_main.c:626:9`!(PDEVICE_SERVICE_ENTRY_POINTS pEntryPoints)) |
| 634 | { |
| 635 | BOOLcxx . . $ BOOL# registered = FALSEcxx . . $ `winpr/include/winpr/wtypes.h:122:9`!; |
| 636 | UINTcxx . . $ UINT# error = CHANNEL_RC_NO_MEMORYcxx . . $ `winpr/include/winpr/wtsapi.h:171:9`!; |
| 637 | |
| 638 | SMARTCARD_DEVICEcxx . . $ SMARTCARD_DEVICE#* smartcard = (SMARTCARD_DEVICEcxx . . $ SMARTCARD_DEVICE#*)calloccxx . . $ calloc(63a7bf2941bfcd7a).(1, sizeof(SMARTCARD_DEVICEcxx . . $ SMARTCARD_DEVICE#)); |
| 639 | WLog_VRBcxx . . $ `winpr/include/winpr/wlog.h:339:9`!(TAGcxx . . $ `channels/smartcard/client/smartcard_main.h:38:9`!, "smartcard device create: %p", (const void*)smartcard); |
| 640 | if (!smartcard) |
| 641 | { |
| 642 | WLog_ERRcxx . . $ `winpr/include/winpr/wlog.h:347:9`!(TAGcxx . . $ `channels/smartcard/client/smartcard_main.h:38:9`!, "calloc failed!"); |
| 643 | return CHANNEL_RC_NO_MEMORYcxx . . $ `winpr/include/winpr/wtsapi.h:171:9`!; |
| 644 | } |
| 645 | |
| 646 | smartcard->devicecxx . . $ $anonymous_type_4711dac392aa0bc9_0#device..typecxx . . $ S_DEVICE#type. = RDPDR_DTYP_SMARTCARDcxx . . $ RDPDR_DTYP_SMARTCARD.; |
| 647 | smartcard->devicecxx . . $ $anonymous_type_4711dac392aa0bc9_0#device..namecxx . . $ S_DEVICE#name. = "SCARD"; |
| 648 | smartcard->devicecxx . . $ $anonymous_type_4711dac392aa0bc9_0#device..IRPRequestcxx . . $ S_DEVICE#IRPRequest. = smartcard_irp_requestcxx . . $ smartcard_irp_request(949c9602d43ec5f7).; |
| 649 | smartcard->devicecxx . . $ $anonymous_type_4711dac392aa0bc9_0#device..Initcxx . . $ S_DEVICE#Init. = smartcard_initcxx . . $ smartcard_init(deb90cd3bde539e2).; |
| 650 | smartcard->devicecxx . . $ $anonymous_type_4711dac392aa0bc9_0#device..Freecxx . . $ S_DEVICE#Free. = smartcard_freecxx . . $ smartcard_free(deb90cd3bde539e2).; |
| 651 | smartcard->rdpcontextcxx . . $ $anonymous_type_4711dac392aa0bc9_0#rdpcontext. = pEntryPoints->rdpcontextcxx . . $ $anonymous_type_80e6cdcfdafc0ed2_0#rdpcontext.; |
| 652 | smartcard->IrpQueuecxx . . $ $anonymous_type_4711dac392aa0bc9_0#IrpQueue. = MessageQueue_Newcxx . . $ MessageQueue_New(16a3a0bf8651d5f6).(nullptrcxx . . $ `winpr/include/winpr/platform.h:88:9`!); |
| 653 | |
| 654 | if (!smartcard->IrpQueuecxx . . $ $anonymous_type_4711dac392aa0bc9_0#IrpQueue.) |
| 655 | { |
| 656 | WLog_ERRcxx . . $ `winpr/include/winpr/wlog.h:347:9`!(TAGcxx . . $ `channels/smartcard/client/smartcard_main.h:38:9`!, "MessageQueue_New failed!"); |
| 657 | goto fail; |
| 658 | } |
| 659 | |
| 660 | wObjectcxx . . $ wObject#* obj = MessageQueue_Objectcxx . . $ MessageQueue_Object(cd23635037a4f9b3).(smartcard->IrpQueuecxx . . $ $anonymous_type_4711dac392aa0bc9_0#IrpQueue.); |
| 661 | WINPR_ASSERTcxx . . $ `winpr/include/winpr/assert-api.h:76:9`!(obj); |
| 662 | obj->fnObjectFreecxx . . $ $anonymous_type_ae1bcafa0ded638f_0#fnObjectFree. = smartcard_free_irpcxx . . $ smartcard_free_irp(5d22bdacc48458e8).; |
| 663 | |
| 664 | smartcard->rgOutstandingMessagescxx . . $ $anonymous_type_4711dac392aa0bc9_0#rgOutstandingMessages. = ListDictionary_Newcxx . . $ ListDictionary_New(63016af20d8a484f).(TRUEcxx . . $ `winpr/include/winpr/wtypes.h:126:9`!); |
| 665 | |
| 666 | if (!smartcard->rgOutstandingMessagescxx . . $ $anonymous_type_4711dac392aa0bc9_0#rgOutstandingMessages.) |
| 667 | { |
| 668 | WLog_ERRcxx . . $ `winpr/include/winpr/wlog.h:347:9`!(TAGcxx . . $ `channels/smartcard/client/smartcard_main.h:38:9`!, "ListDictionary_New failed!"); |
| 669 | goto fail; |
| 670 | } |
| 671 | |
| 672 | smartcard->callctxcxx . . $ $anonymous_type_4711dac392aa0bc9_0#callctx. = smartcard_call_context_new_with_contextcxx . . $ smartcard_call_context_new_with_context(79b58e11c9c3cab6).(smartcard->rdpcontextcxx . . $ $anonymous_type_4711dac392aa0bc9_0#rdpcontext.); |
| 673 | if (!smartcard->callctxcxx . . $ $anonymous_type_4711dac392aa0bc9_0#callctx.) |
| 674 | goto fail; |
| 675 | |
| 676 | if (!smarcard_call_set_callbackscxx . . $ smarcard_call_set_callbacks(f577fd7df5986f90).(smartcard->callctxcxx . . $ $anonymous_type_4711dac392aa0bc9_0#callctx., smartcard, smartcard_context_newcxx . . $ smartcard_context_new(417ab160f6baadc6)., |
| 677 | smartcard_context_freecxx . . $ smartcard_context_free(5d22bdacc48458e8).)) |
| 678 | goto fail; |
| 679 | |
| 680 | error = pEntryPoints->RegisterDevicecxx . . $ $anonymous_type_80e6cdcfdafc0ed2_0#RegisterDevice.(pEntryPoints->devmancxx . . $ $anonymous_type_80e6cdcfdafc0ed2_0#devman., &smartcard->devicecxx . . $ $anonymous_type_4711dac392aa0bc9_0#device.); |
| 681 | if (error) |
| 682 | { |
| 683 | WLog_ERRcxx . . $ `winpr/include/winpr/wlog.h:347:9`!(TAGcxx . . $ `channels/smartcard/client/smartcard_main.h:38:9`!, "RegisterDevice failed!"); |
| 684 | goto fail; |
| 685 | } |
| 686 | |
| 687 | registered = TRUEcxx . . $ `winpr/include/winpr/wtypes.h:126:9`!; |
| 688 | smartcard->threadcxx . . $ $anonymous_type_4711dac392aa0bc9_0#thread. = |
| 689 | CreateThreadcxx . . $ CreateThread(b708535bf8f563fd).(nullptrcxx . . $ `winpr/include/winpr/platform.h:88:9`!, 0, smartcard_thread_funccxx . . $ smartcard_thread_func(6769d0e399bf81e3)., smartcard, CREATE_SUSPENDEDcxx . . $ `winpr/include/winpr/thread.h:301:9`!, nullptrcxx . . $ `winpr/include/winpr/platform.h:88:9`!); |
| 690 | |
| 691 | if (!smartcard->threadcxx . . $ $anonymous_type_4711dac392aa0bc9_0#thread.) |
| 692 | { |
| 693 | WLog_ERRcxx . . $ `winpr/include/winpr/wlog.h:347:9`!(TAGcxx . . $ `channels/smartcard/client/smartcard_main.h:38:9`!, "CreateThread failed!"); |
| 694 | error = ERROR_INTERNAL_ERRORcxx . . $ `winpr/include/winpr/error.h:985:9`!; |
| 695 | goto fail; |
| 696 | } |
| 697 | |
| 698 | ResumeThreadcxx . . $ ResumeThread(6769d0e399bf81e3).(smartcard->threadcxx . . $ $anonymous_type_4711dac392aa0bc9_0#thread.); |
| 699 | |
| 700 | if (pEntryPoints->devicecxx . . $ $anonymous_type_80e6cdcfdafc0ed2_0#device.->Namecxx . . $ $anonymous_type_ead674a03c2ca7a6_14#Name.) |
| 701 | { |
| 702 | if (!smartcard_call_context_addcxx . . $ smartcard_call_context_add(2af360f946cc5f4a).(smartcard->callctxcxx . . $ $anonymous_type_4711dac392aa0bc9_0#callctx., pEntryPoints->devicecxx . . $ $anonymous_type_80e6cdcfdafc0ed2_0#device.->Namecxx . . $ $anonymous_type_ead674a03c2ca7a6_14#Name.)) |
| 703 | goto fail; |
| 704 | } |
| 705 | |
| 706 | return CHANNEL_RC_OKcxx . . $ `winpr/include/winpr/wtsapi.h:159:9`!; |
| 707 | fail: |
| 708 | if (!registered) |
| 709 | smartcard_free_cxx . . $ smartcard_free_(cb14c3e65898bc6a).(smartcard); |
| 710 | return error; |
| 711 | } |