From 79453d1bb482b062a7bf556e869eb0b8ab123b14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Moreau?= Date: Fri, 11 Apr 2014 16:27:01 -0400 Subject: [PATCH] channels/smartcard: make handles completely opaque --- .../smartcard/client/smartcard_operations.c | 24 +- channels/smartcard/client/smartcard_pack.c | 364 +++++++++++------- channels/smartcard/client/smartcard_pack.h | 17 +- winpr/libwinpr/smartcard/smartcard_pcsc.c | 38 +- 4 files changed, 270 insertions(+), 173 deletions(-) diff --git a/channels/smartcard/client/smartcard_operations.c b/channels/smartcard/client/smartcard_operations.c index 88b23dda1..80a22eea6 100644 --- a/channels/smartcard/client/smartcard_operations.c +++ b/channels/smartcard/client/smartcard_operations.c @@ -497,7 +497,7 @@ UINT32 smartcard_ConnectA(SMARTCARD_DEVICE* smartcard, IRP* irp) if (status) return status; - smartcard_scard_context_native_to_redir(smartcard, &ret.hCard.Context, hContext); + smartcard_scard_context_native_to_redir(smartcard, &ret.hContext, hContext); smartcard_scard_handle_native_to_redir(smartcard, &ret.hCard, hCard); smartcard_trace_connect_return(smartcard, &ret); @@ -544,7 +544,7 @@ UINT32 smartcard_ConnectW(SMARTCARD_DEVICE* smartcard, IRP* irp) if (status) return status; - smartcard_scard_context_native_to_redir(smartcard, &ret.hCard.Context, hContext); + smartcard_scard_context_native_to_redir(smartcard, &ret.hContext, hContext); smartcard_scard_handle_native_to_redir(smartcard, &ret.hCard, hCard); smartcard_trace_connect_return(smartcard, &ret); @@ -573,8 +573,8 @@ static UINT32 smartcard_Reconnect(SMARTCARD_DEVICE* smartcard, IRP* irp) if (status) return status; + hContext = smartcard_scard_context_native_from_redir(smartcard, &call.hContext); hCard = smartcard_scard_handle_native_from_redir(smartcard, &call.hCard); - hContext = smartcard_scard_context_native_from_redir(smartcard, &call.hCard.Context); status = ret.ReturnCode = SCardReconnect(hCard, call.dwShareMode, call.dwPreferredProtocols, call.dwInitialization, &ret.dwActiveProtocol); @@ -605,8 +605,8 @@ static UINT32 smartcard_Disconnect(SMARTCARD_DEVICE* smartcard, IRP* irp) if (status) return status; + hContext = smartcard_scard_context_native_from_redir(smartcard, &call.hContext); hCard = smartcard_scard_handle_native_from_redir(smartcard, &call.hCard); - hContext = smartcard_scard_context_native_from_redir(smartcard, &call.hCard.Context); status = ret.ReturnCode = SCardDisconnect(hCard, (DWORD) call.dwDisposition); @@ -631,8 +631,8 @@ static UINT32 smartcard_BeginTransaction(SMARTCARD_DEVICE* smartcard, IRP* irp) if (status) return status; + hContext = smartcard_scard_context_native_from_redir(smartcard, &call.hContext); hCard = smartcard_scard_handle_native_from_redir(smartcard, &call.hCard); - hContext = smartcard_scard_context_native_from_redir(smartcard, &call.hCard.Context); status = ret.ReturnCode = SCardBeginTransaction(hCard); @@ -657,8 +657,8 @@ static UINT32 smartcard_EndTransaction(SMARTCARD_DEVICE* smartcard, IRP* irp) if (status) return status; + hContext = smartcard_scard_context_native_from_redir(smartcard, &call.hContext); hCard = smartcard_scard_handle_native_from_redir(smartcard, &call.hCard); - hContext = smartcard_scard_context_native_from_redir(smartcard, &call.hCard.Context); status = ret.ReturnCode = SCardEndTransaction(hCard, call.dwDisposition); @@ -681,8 +681,8 @@ static UINT32 smartcard_State(SMARTCARD_DEVICE* smartcard, IRP* irp) if (status) return status; + hContext = smartcard_scard_context_native_from_redir(smartcard, &call.hContext); hCard = smartcard_scard_handle_native_from_redir(smartcard, &call.hCard); - hContext = smartcard_scard_context_native_from_redir(smartcard, &call.hCard.Context); ret.cbAtrLen = SCARD_ATR_LENGTH; @@ -719,8 +719,8 @@ static DWORD smartcard_StatusA(SMARTCARD_DEVICE* smartcard, IRP* irp) if (status) return status; + hContext = smartcard_scard_context_native_from_redir(smartcard, &call.hContext); hCard = smartcard_scard_handle_native_from_redir(smartcard, &call.hCard); - hContext = smartcard_scard_context_native_from_redir(smartcard, &call.hCard.Context); if (call.cbAtrLen > 32) call.cbAtrLen = 32; @@ -766,8 +766,8 @@ static DWORD smartcard_StatusW(SMARTCARD_DEVICE* smartcard, IRP* irp) if (status) return status; + hContext = smartcard_scard_context_native_from_redir(smartcard, &call.hContext); hCard = smartcard_scard_handle_native_from_redir(smartcard, &call.hCard); - hContext = smartcard_scard_context_native_from_redir(smartcard, &call.hCard.Context); if (call.cbAtrLen > 32) call.cbAtrLen = 32; @@ -809,8 +809,8 @@ static UINT32 smartcard_Transmit(SMARTCARD_DEVICE* smartcard, IRP* irp) if (status) return status; + hContext = smartcard_scard_context_native_from_redir(smartcard, &call.hContext); hCard = smartcard_scard_handle_native_from_redir(smartcard, &call.hCard); - hContext = smartcard_scard_context_native_from_redir(smartcard, &call.hCard.Context); ret.cbRecvLength = 0; ret.pbRecvBuffer = NULL; @@ -863,8 +863,8 @@ static UINT32 smartcard_Control(SMARTCARD_DEVICE* smartcard, IRP* irp) if (status) return status; + hContext = smartcard_scard_context_native_from_redir(smartcard, &call.hContext); hCard = smartcard_scard_handle_native_from_redir(smartcard, &call.hCard); - hContext = smartcard_scard_context_native_from_redir(smartcard, &call.hCard.Context); if (DEVICE_TYPE_FROM_CTL_CODE(call.dwControlCode) == FILE_DEVICE_SMARTCARD) { @@ -911,8 +911,8 @@ static UINT32 smartcard_GetAttrib(SMARTCARD_DEVICE* smartcard, IRP* irp) if (status) return status; + hContext = smartcard_scard_context_native_from_redir(smartcard, &call.hContext); hCard = smartcard_scard_handle_native_from_redir(smartcard, &call.hCard); - hContext = smartcard_scard_context_native_from_redir(smartcard, &call.hCard.Context); ret.pbAttr = NULL; diff --git a/channels/smartcard/client/smartcard_pack.c b/channels/smartcard/client/smartcard_pack.c index fccbd8394..6a860e752 100644 --- a/channels/smartcard/client/smartcard_pack.c +++ b/channels/smartcard/client/smartcard_pack.c @@ -165,24 +165,20 @@ SCARDCONTEXT smartcard_scard_context_native_from_redir(SMARTCARD_DEVICE* smartca WLog_Print(smartcard->log, WLOG_WARN, "REDIR_SCARDCONTEXT does not match native size: Actual: %d, Expected: %d", context->cbContext, sizeof(ULONG_PTR)); + return 0; } - if (context->cbContext > 4) - hContext = (ULONG_PTR) context->pbContext.QuadPart; - else - hContext = (ULONG_PTR) context->pbContext.LowPart; + if (context->cbContext) + CopyMemory(&hContext, &(context->pbContext), context->cbContext); return hContext; } void smartcard_scard_context_native_to_redir(SMARTCARD_DEVICE* smartcard, REDIR_SCARDCONTEXT* context, SCARDCONTEXT hContext) { + ZeroMemory(context, sizeof(REDIR_SCARDCONTEXT)); context->cbContext = sizeof(ULONG_PTR); - - if (context->cbContext > 4) - context->pbContext.QuadPart = (UINT64) hContext; - else - context->pbContext.LowPart = (UINT32) hContext; + CopyMemory(&(context->pbContext), &hContext, context->cbContext); } SCARDHANDLE smartcard_scard_handle_native_from_redir(SMARTCARD_DEVICE* smartcard, REDIR_SCARDHANDLE* handle) @@ -194,32 +190,27 @@ SCARDHANDLE smartcard_scard_handle_native_from_redir(SMARTCARD_DEVICE* smartcard WLog_Print(smartcard->log, WLOG_WARN, "REDIR_SCARDHANDLE does not match native size: Actual: %d, Expected: %d", handle->cbHandle, sizeof(ULONG_PTR)); + return 0; } - if (handle->cbHandle > 4) - hCard = (ULONG_PTR) handle->pbHandle.QuadPart; - else - hCard = (ULONG_PTR) handle->pbHandle.LowPart; + if (handle->cbHandle) + CopyMemory(&hCard, &(handle->pbHandle), handle->cbHandle); return hCard; } -void smartcard_scard_handle_native_to_redir(SMARTCARD_DEVICE* smartcard, REDIR_SCARDHANDLE* context, SCARDHANDLE hCard) +void smartcard_scard_handle_native_to_redir(SMARTCARD_DEVICE* smartcard, REDIR_SCARDHANDLE* handle, SCARDHANDLE hCard) { - context->cbHandle = sizeof(ULONG_PTR); - - if (context->cbHandle > 4) - context->pbHandle.QuadPart = (UINT64) hCard; - else - context->pbHandle.LowPart = (UINT32) hCard; + ZeroMemory(handle, sizeof(REDIR_SCARDHANDLE)); + handle->cbHandle = sizeof(ULONG_PTR); + CopyMemory(&(handle->pbHandle), &hCard, handle->cbHandle); } UINT32 smartcard_unpack_redir_scard_context(SMARTCARD_DEVICE* smartcard, wStream* s, REDIR_SCARDCONTEXT* context) { UINT32 pbContextNdrPtr; - context->cbContext = 0; - context->pbContext.QuadPart = 0; + ZeroMemory(context, sizeof(REDIR_SCARDCONTEXT)); if (Stream_GetRemainingLength(s) < 4) { @@ -295,23 +286,18 @@ UINT32 smartcard_unpack_redir_scard_context_ref(SMARTCARD_DEVICE* smartcard, wSt } if (context->cbContext > 4) - Stream_Read_UINT64(s, context->pbContext.QuadPart); - else - Stream_Read_UINT32(s, context->pbContext.LowPart); + Stream_Read(s, &context->pbContext, context->cbContext); return SCARD_S_SUCCESS; } UINT32 smartcard_pack_redir_scard_context_ref(SMARTCARD_DEVICE* smartcard, wStream* s, REDIR_SCARDCONTEXT* context) { + Stream_Write_UINT32(s, context->cbContext); /* Length (4 bytes) */ + if (context->cbContext) { - Stream_Write_UINT32(s, context->cbContext); /* Length (4 bytes) */ - - if (context->cbContext > 4) - Stream_Write_UINT64(s, context->pbContext.QuadPart); - else if (context->cbContext > 0) - Stream_Write_UINT32(s, context->pbContext.LowPart); + Stream_Write(s, &context->pbContext, context->cbContext); } return SCARD_S_SUCCESS; @@ -319,17 +305,9 @@ UINT32 smartcard_pack_redir_scard_context_ref(SMARTCARD_DEVICE* smartcard, wStre UINT32 smartcard_unpack_redir_scard_handle(SMARTCARD_DEVICE* smartcard, wStream* s, REDIR_SCARDHANDLE* handle) { - UINT32 status; - UINT32 length; UINT32 pbHandleNdrPtr; - handle->cbHandle = 0; - handle->pbHandle.QuadPart = 0; - - status = smartcard_unpack_redir_scard_context(smartcard, s, &(handle->Context)); - - if (status) - return status; + ZeroMemory(handle, sizeof(REDIR_SCARDHANDLE)); if (Stream_GetRemainingLength(s) < 4) { @@ -349,19 +327,13 @@ UINT32 smartcard_unpack_redir_scard_handle(SMARTCARD_DEVICE* smartcard, wStream* Stream_Read_UINT32(s, pbHandleNdrPtr); /* NdrPtr (4 bytes) */ - return 0; + return SCARD_S_SUCCESS; } UINT32 smartcard_pack_redir_scard_handle(SMARTCARD_DEVICE* smartcard, wStream* s, REDIR_SCARDHANDLE* handle) { - UINT32 status; UINT32 pbHandleNdrPtr; - status = smartcard_pack_redir_scard_context(smartcard, s, &(handle->Context)); - - if (status) - return status; - pbHandleNdrPtr = (handle->cbHandle) ? 0x00020002 : 0; Stream_Write_UINT32(s, handle->cbHandle); /* cbHandle (4 bytes) */ @@ -372,14 +344,8 @@ UINT32 smartcard_pack_redir_scard_handle(SMARTCARD_DEVICE* smartcard, wStream* s UINT32 smartcard_unpack_redir_scard_handle_ref(SMARTCARD_DEVICE* smartcard, wStream* s, REDIR_SCARDHANDLE* handle) { - UINT32 status; UINT32 length; - status = smartcard_unpack_redir_scard_context_ref(smartcard, s, &(handle->Context)); - - if (status) - return status; - if (Stream_GetRemainingLength(s) < 4) { WLog_Print(smartcard->log, WLOG_WARN, "REDIR_SCARDHANDLE is too short: Actual: %d, Expected: %d\n", @@ -409,34 +375,20 @@ UINT32 smartcard_unpack_redir_scard_handle_ref(SMARTCARD_DEVICE* smartcard, wStr return STATUS_BUFFER_TOO_SMALL; } - if (handle->cbHandle > 4) - Stream_Read_UINT64(s, handle->pbHandle.QuadPart); - else - Stream_Read_UINT32(s, handle->pbHandle.LowPart); + if (handle->cbHandle) + Stream_Read(s, &(handle->pbHandle), handle->cbHandle); - return 0; + return SCARD_S_SUCCESS; } UINT32 smartcard_pack_redir_scard_handle_ref(SMARTCARD_DEVICE* smartcard, wStream* s, REDIR_SCARDHANDLE* handle) { - UINT32 status; - - status = smartcard_pack_redir_scard_context_ref(smartcard, s, &(handle->Context)); - - if (status) - return status; + Stream_Write_UINT32(s, handle->cbHandle); /* Length (4 bytes) */ if (handle->cbHandle) - { - Stream_Write_UINT32(s, handle->cbHandle); /* Length (4 bytes) */ + Stream_Write(s, &(handle->pbHandle), handle->cbHandle); - if (handle->cbHandle > 4) - Stream_Write_UINT64(s, handle->pbHandle.HighPart); - else - Stream_Write_UINT32(s, handle->pbHandle.LowPart); - } - - return 0; + return SCARD_S_SUCCESS; } UINT32 smartcard_unpack_establish_context_call(SMARTCARD_DEVICE* smartcard, wStream* s, EstablishContext_Call* call) @@ -484,6 +436,8 @@ UINT32 smartcard_pack_establish_context_return(SMARTCARD_DEVICE* smartcard, wStr void smartcard_trace_establish_context_return(SMARTCARD_DEVICE* smartcard, EstablishContext_Return* ret) { + BYTE* pb; + if (!WLog_IsLevelActive(smartcard->log, WLOG_DEBUG)) return; @@ -491,15 +445,17 @@ void smartcard_trace_establish_context_return(SMARTCARD_DEVICE* smartcard, Estab WLog_Print(smartcard->log, WLOG_DEBUG, "ReturnCode: 0x%08X", ret->ReturnCode); + pb = (BYTE*) &(ret->Context.pbContext); + if (ret->Context.cbContext > 4) { - WLog_Print(smartcard->log, WLOG_DEBUG, "hContext: 0x%08X%08X (%d)", - ret->Context.pbContext.HighPart, ret->Context.pbContext.LowPart, ret->Context.cbContext); + WLog_Print(smartcard->log, WLOG_DEBUG, "hContext: 0x%02X%02X%02X%02X%02X%02X%02X%02X (%d)", + pb[0], pb[1], pb[2], pb[3], pb[4], pb[5], pb[6], pb[7], ret->Context.cbContext); } else { - WLog_Print(smartcard->log, WLOG_DEBUG, "hContext: 0x%08X (%d)", - ret->Context.pbContext.LowPart, ret->Context.cbContext); + WLog_Print(smartcard->log, WLOG_DEBUG, "hContext: 0x%02X%02X%02X%02X (%d)", + pb[0], pb[1], pb[2], pb[3], ret->Context.cbContext); } WLog_Print(smartcard->log, WLOG_DEBUG, "}"); @@ -524,17 +480,21 @@ UINT32 smartcard_unpack_context_call(SMARTCARD_DEVICE* smartcard, wStream* s, Co void smartcard_trace_context_call(SMARTCARD_DEVICE* smartcard, Context_Call* call, const char* name) { + BYTE* pb; + WLog_Print(smartcard->log, WLOG_DEBUG, "%s_Call {", name); + pb = (BYTE*) &(call->Context.pbContext); + if (call->Context.cbContext > 4) { - WLog_Print(smartcard->log, WLOG_DEBUG, "hContext: 0x%08X%08X (%d)", - call->Context.pbContext.HighPart, call->Context.pbContext.LowPart, call->Context.cbContext); + WLog_Print(smartcard->log, WLOG_DEBUG, "hContext: 0x%02X%02X%02X%02X%02X%02X%02X%02X (%d)", + pb[0], pb[1], pb[2], pb[3], pb[4], pb[5], pb[6], pb[7], call->Context.cbContext); } else { - WLog_Print(smartcard->log, WLOG_DEBUG, "hContext: 0x%08X (%d)", - call->Context.pbContext.LowPart, call->Context.cbContext); + WLog_Print(smartcard->log, WLOG_DEBUG, "hContext: 0x%02X%02X%02X%02X (%d)", + pb[0], pb[1], pb[2], pb[3], call->Context.cbContext); } WLog_Print(smartcard->log, WLOG_DEBUG, "}"); @@ -615,6 +575,7 @@ UINT32 smartcard_unpack_list_readers_call(SMARTCARD_DEVICE* smartcard, wStream* void smartcard_trace_list_readers_call(SMARTCARD_DEVICE* smartcard, ListReaders_Call* call, BOOL unicode) { + BYTE* pb; char* mszGroupsA = NULL; if (!WLog_IsLevelActive(smartcard->log, WLOG_DEBUG)) @@ -623,17 +584,19 @@ void smartcard_trace_list_readers_call(SMARTCARD_DEVICE* smartcard, ListReaders_ if (unicode) ConvertFromUnicode(CP_UTF8, 0, (WCHAR*) call->mszGroups, call->cBytes / 2, &mszGroupsA, 0, NULL, NULL); - WLog_Print(smartcard->log, WLOG_DEBUG, "ListReaders_Call {"); + WLog_Print(smartcard->log, WLOG_DEBUG, "ListReaders%S_Call {", unicode ? "W" : "A"); + + pb = (BYTE*) &(call->Context.pbContext); if (call->Context.cbContext > 4) { - WLog_Print(smartcard->log, WLOG_DEBUG, "hContext: 0x%08X%08X (%d)", - call->Context.pbContext.HighPart, call->Context.pbContext.LowPart, call->Context.cbContext); + WLog_Print(smartcard->log, WLOG_DEBUG, "hContext: 0x%02X%02X%02X%02X%02X%02X%02X%02X (%d)", + pb[0], pb[1], pb[2], pb[3], pb[4], pb[5], pb[6], pb[7], call->Context.cbContext); } else { - WLog_Print(smartcard->log, WLOG_DEBUG, "hContext: 0x%08X (%d)", - call->Context.pbContext.LowPart, call->Context.cbContext); + WLog_Print(smartcard->log, WLOG_DEBUG, "hContext: 0x%02X%02X%02X%02X (%d)", + pb[0], pb[1], pb[2], pb[3], call->Context.cbContext); } WLog_Print(smartcard->log, WLOG_DEBUG, @@ -697,7 +660,7 @@ void smartcard_trace_list_readers_return(SMARTCARD_DEVICE* smartcard, ListReader mszA[index] = ','; } - WLog_Print(smartcard->log, WLOG_DEBUG, "ListReaders_Return {"); + WLog_Print(smartcard->log, WLOG_DEBUG, "ListReaders%s_Return {", unicode ? "W" : "A"); WLog_Print(smartcard->log, WLOG_DEBUG, "ReturnCode: 0x%08X cBytes: %d msz: %s", @@ -769,21 +732,24 @@ UINT32 smartcard_unpack_connect_a_call(SMARTCARD_DEVICE* smartcard, wStream* s, void smartcard_trace_connect_a_call(SMARTCARD_DEVICE* smartcard, ConnectA_Call* call) { + BYTE* pb; + if (!WLog_IsLevelActive(smartcard->log, WLOG_DEBUG)) return; WLog_Print(smartcard->log, WLOG_DEBUG, "ConnectA_Call {"); + pb = (BYTE*) &(call->Common.Context); + if (call->Common.Context.cbContext > 4) { - WLog_Print(smartcard->log, WLOG_DEBUG, "hContext: 0x%08X%08X (%d)", - call->Common.Context.pbContext.HighPart, call->Common.Context.pbContext.LowPart, - call->Common.Context.cbContext); + WLog_Print(smartcard->log, WLOG_DEBUG, "hContext: 0x%02X%02X%02X%02X%02X%02X%02X%02X (%d)", + pb[0], pb[1], pb[2], pb[3], pb[4], pb[5], pb[6], pb[7], call->Common.Context.cbContext); } else { - WLog_Print(smartcard->log, WLOG_DEBUG, "hContext: 0x%08X (%d)", - call->Common.Context.pbContext.LowPart, call->Common.Context.cbContext); + WLog_Print(smartcard->log, WLOG_DEBUG, "hContext: 0x%02X%02X%02X%02X (%d)", + pb[0], pb[1], pb[2], pb[3], call->Common.Context.cbContext); } WLog_Print(smartcard->log, WLOG_DEBUG, "szReader: %s dwShareMode: 0x%08X dwPreferredProtocols: 0x%08X", @@ -831,6 +797,7 @@ UINT32 smartcard_unpack_connect_w_call(SMARTCARD_DEVICE* smartcard, wStream* s, void smartcard_trace_connect_w_call(SMARTCARD_DEVICE* smartcard, ConnectW_Call* call) { + BYTE* pb; char* szReaderA = NULL; if (!WLog_IsLevelActive(smartcard->log, WLOG_DEBUG)) @@ -840,16 +807,17 @@ void smartcard_trace_connect_w_call(SMARTCARD_DEVICE* smartcard, ConnectW_Call* WLog_Print(smartcard->log, WLOG_DEBUG, "ConnectA_Call {"); + pb = (BYTE*) &(call->Common.Context); + if (call->Common.Context.cbContext > 4) { - WLog_Print(smartcard->log, WLOG_DEBUG, "hContext: 0x%08X%08X (%d)", - call->Common.Context.pbContext.HighPart, call->Common.Context.pbContext.LowPart, - call->Common.Context.cbContext); + WLog_Print(smartcard->log, WLOG_DEBUG, "hContext: 0x%02X%02X%02X%02X%02X%02X%02X%02X (%d)", + pb[0], pb[1], pb[2], pb[3], pb[4], pb[5], pb[6], pb[7], call->Common.Context.cbContext); } else { - WLog_Print(smartcard->log, WLOG_DEBUG, "hContext: 0x%08X (%d)", - call->Common.Context.pbContext.LowPart, call->Common.Context.cbContext); + WLog_Print(smartcard->log, WLOG_DEBUG, "hContext: 0x%02X%02X%02X%02X (%d)", + pb[0], pb[1], pb[2], pb[3], call->Common.Context.cbContext); } WLog_Print(smartcard->log, WLOG_DEBUG, "szReader: %s dwShareMode: 0x%08X dwPreferredProtocols: %d", @@ -864,6 +832,11 @@ UINT32 smartcard_pack_connect_return(SMARTCARD_DEVICE* smartcard, wStream* s, Co { UINT32 status; + status = smartcard_pack_redir_scard_context(smartcard, s, &(ret->hContext)); + + if (status) + return status; + status = smartcard_pack_redir_scard_handle(smartcard, s, &(ret->hCard)); if (status) @@ -871,6 +844,11 @@ UINT32 smartcard_pack_connect_return(SMARTCARD_DEVICE* smartcard, wStream* s, Co Stream_Write_UINT32(s, ret->dwActiveProtocol); /* dwActiveProtocol (4 bytes) */ + status = smartcard_pack_redir_scard_context_ref(smartcard, s, &(ret->hContext)); + + if (status) + return status; + status = smartcard_pack_redir_scard_handle_ref(smartcard, s, &(ret->hCard)); if (status) @@ -881,32 +859,37 @@ UINT32 smartcard_pack_connect_return(SMARTCARD_DEVICE* smartcard, wStream* s, Co void smartcard_trace_connect_return(SMARTCARD_DEVICE* smartcard, Connect_Return* ret) { + BYTE* pb; + if (!WLog_IsLevelActive(smartcard->log, WLOG_DEBUG)) return; WLog_Print(smartcard->log, WLOG_DEBUG, "Connect_Return {"); - if (ret->hCard.Context.cbContext > 4) + pb = (BYTE*) &(ret->hContext.pbContext); + + if (ret->hContext.cbContext > 4) { - WLog_Print(smartcard->log, WLOG_DEBUG, "hContext: 0x%08X%08X (%d)", - ret->hCard.Context.pbContext.HighPart, ret->hCard.Context.pbContext.LowPart, - ret->hCard.Context.cbContext); + WLog_Print(smartcard->log, WLOG_DEBUG, "hContext: 0x%02X%02X%02X%02X%02X%02X%02X%02X (%d)", + pb[0], pb[1], pb[2], pb[3], pb[4], pb[5], pb[6], pb[7], ret->hContext.cbContext); } else { - WLog_Print(smartcard->log, WLOG_DEBUG, "hContext: 0x%08X (%d)", - ret->hCard.Context.pbContext.LowPart, ret->hCard.Context.cbContext); + WLog_Print(smartcard->log, WLOG_DEBUG, "hContext: 0x%02X%02X%02X%02X (%d)", + pb[0], pb[1], pb[2], pb[3], ret->hContext.cbContext); } + pb = (BYTE*) &(ret->hCard.pbHandle); + if (ret->hCard.cbHandle > 4) { - WLog_Print(smartcard->log, WLOG_DEBUG, "hCard: 0x%08X%08X (%d)", - ret->hCard.pbHandle.HighPart, ret->hCard.pbHandle.LowPart, ret->hCard.cbHandle); + WLog_Print(smartcard->log, WLOG_DEBUG, "hCard: 0x%02X%02X%02X%02X%02X%02X%02X%02X (%d)", + pb[0], pb[1], pb[2], pb[3], pb[4], pb[5], pb[6], pb[7], ret->hCard.cbHandle); } else { - WLog_Print(smartcard->log, WLOG_DEBUG, "hCard: 0x%08X (%d)", - ret->hCard.pbHandle.LowPart, ret->hCard.cbHandle); + WLog_Print(smartcard->log, WLOG_DEBUG, "hCard: 0x%02X%02X%02X%02X (%d)", + pb[0], pb[1], pb[2], pb[3], ret->hCard.cbHandle); } WLog_Print(smartcard->log, WLOG_DEBUG, "dwActiveProtocol: 0x%08X", @@ -919,6 +902,11 @@ UINT32 smartcard_unpack_reconnect_call(SMARTCARD_DEVICE* smartcard, wStream* s, { UINT32 status; + status = smartcard_unpack_redir_scard_context(smartcard, s, &(call->hContext)); + + if (status) + return status; + status = smartcard_unpack_redir_scard_handle(smartcard, s, &(call->hCard)); if (status) @@ -935,6 +923,11 @@ UINT32 smartcard_unpack_reconnect_call(SMARTCARD_DEVICE* smartcard, wStream* s, Stream_Read_UINT32(s, call->dwPreferredProtocols); /* dwPreferredProtocols (4 bytes) */ Stream_Read_UINT32(s, call->dwInitialization); /* dwInitialization (4 bytes) */ + status = smartcard_unpack_redir_scard_context_ref(smartcard, s, &(call->hContext)); + + if (status) + return status; + status = smartcard_unpack_redir_scard_handle_ref(smartcard, s, &(call->hCard)); if (status) @@ -954,6 +947,11 @@ UINT32 smartcard_unpack_hcard_and_disposition_call(SMARTCARD_DEVICE* smartcard, { UINT32 status; + status = smartcard_unpack_redir_scard_context(smartcard, s, &(call->hContext)); + + if (status) + return status; + status = smartcard_unpack_redir_scard_handle(smartcard, s, &(call->hCard)); if (status) @@ -968,6 +966,11 @@ UINT32 smartcard_unpack_hcard_and_disposition_call(SMARTCARD_DEVICE* smartcard, Stream_Read_UINT32(s, call->dwDisposition); /* dwDisposition (4 bytes) */ + status = smartcard_unpack_redir_scard_context_ref(smartcard, s, &(call->hContext)); + + if (status) + return status; + status = smartcard_unpack_redir_scard_handle_ref(smartcard, s, &(call->hCard)); if (status) @@ -978,29 +981,34 @@ UINT32 smartcard_unpack_hcard_and_disposition_call(SMARTCARD_DEVICE* smartcard, void smartcard_trace_hcard_and_disposition_call(SMARTCARD_DEVICE* smartcard, HCardAndDisposition_Call* call, const char* name) { + BYTE* pb; + WLog_Print(smartcard->log, WLOG_DEBUG, "%s_Call {", name); - if (call->hCard.Context.cbContext > 4) + pb = (BYTE*) &(call->hContext.pbContext); + + if (call->hContext.cbContext > 4) { - WLog_Print(smartcard->log, WLOG_DEBUG, "hContext: 0x%08X%08X (%d)", - call->hCard.Context.pbContext.HighPart, call->hCard.Context.pbContext.LowPart, - call->hCard.Context.cbContext); + WLog_Print(smartcard->log, WLOG_DEBUG, "hContext: 0x%02X%02X%02X%02X%02X%02X%02X%02X (%d)", + pb[0], pb[1], pb[2], pb[3], pb[4], pb[5], pb[6], pb[7], call->hContext.cbContext); } else { - WLog_Print(smartcard->log, WLOG_DEBUG, "hContext: 0x%08X (%d)", - call->hCard.Context.pbContext.LowPart, call->hCard.Context.cbContext); + WLog_Print(smartcard->log, WLOG_DEBUG, "hContext: 0x%02X%02X%02X%02X (%d)", + pb[0], pb[1], pb[2], pb[3], call->hContext.cbContext); } + pb = (BYTE*) &(call->hCard.pbHandle); + if (call->hCard.cbHandle > 4) { - WLog_Print(smartcard->log, WLOG_DEBUG, "hCard: 0x%08X%08X (%d)", - call->hCard.pbHandle.HighPart, call->hCard.pbHandle.LowPart, call->hCard.pbHandle); + WLog_Print(smartcard->log, WLOG_DEBUG, "hCard: 0x%02X%02X%02X%02X%02X%02X%02X%02X (%d)", + pb[0], pb[1], pb[2], pb[3], pb[4], pb[5], pb[6], pb[7], call->hCard.cbHandle); } else { - WLog_Print(smartcard->log, WLOG_DEBUG, "hCard: 0x%08X (%d)", - call->hCard.pbHandle.LowPart, call->hCard.pbHandle); + WLog_Print(smartcard->log, WLOG_DEBUG, "hCard: 0x%02X%02X%02X%02X (%d)", + pb[0], pb[1], pb[2], pb[3], call->hCard.cbHandle); } WLog_Print(smartcard->log, WLOG_DEBUG, "dwDisposition: 0x%08X", call->dwDisposition); @@ -1127,6 +1135,7 @@ UINT32 smartcard_unpack_get_status_change_a_call(SMARTCARD_DEVICE* smartcard, wS void smartcard_trace_get_status_change_a_call(SMARTCARD_DEVICE* smartcard, GetStatusChangeA_Call* call) { + BYTE* pb; UINT32 index; LPSCARD_READERSTATEA readerState; @@ -1135,15 +1144,17 @@ void smartcard_trace_get_status_change_a_call(SMARTCARD_DEVICE* smartcard, GetSt WLog_Print(smartcard->log, WLOG_DEBUG, "GetStatusChangeA_Call {"); + pb = (BYTE*) &(call->Context.pbContext); + if (call->Context.cbContext > 4) { - WLog_Print(smartcard->log, WLOG_DEBUG, "hContext: 0x%08X%08X (%d)", - call->Context.pbContext.HighPart, call->Context.pbContext.LowPart, call->Context.cbContext); + WLog_Print(smartcard->log, WLOG_DEBUG, "hContext: 0x%02X%02X%02X%02X%02X%02X%02X%02X (%d)", + pb[0], pb[1], pb[2], pb[3], pb[4], pb[5], pb[6], pb[7], call->Context.cbContext); } else { - WLog_Print(smartcard->log, WLOG_DEBUG, "hContext: 0x%08X (%d)", - call->Context.pbContext.LowPart, call->Context.cbContext); + WLog_Print(smartcard->log, WLOG_DEBUG, "hContext: 0x%02X%02X%02X%02X (%d)", + pb[0], pb[1], pb[2], pb[3], call->Context.cbContext); } WLog_Print(smartcard->log, WLOG_DEBUG, "dwTimeOut: 0x%08X cReaders: %d", @@ -1273,6 +1284,7 @@ UINT32 smartcard_unpack_get_status_change_w_call(SMARTCARD_DEVICE* smartcard, wS void smartcard_trace_get_status_change_w_call(SMARTCARD_DEVICE* smartcard, GetStatusChangeW_Call* call) { + BYTE* pb; UINT32 index; LPSCARD_READERSTATEW readerState; @@ -1281,15 +1293,17 @@ void smartcard_trace_get_status_change_w_call(SMARTCARD_DEVICE* smartcard, GetSt WLog_Print(smartcard->log, WLOG_DEBUG, "GetStatusChangeW_Call {"); + pb = (BYTE*) &(call->Context.pbContext); + if (call->Context.cbContext > 4) { - WLog_Print(smartcard->log, WLOG_DEBUG, "hContext: 0x%08X%08X (%d)", - call->Context.pbContext.HighPart, call->Context.pbContext.LowPart, call->Context.cbContext); + WLog_Print(smartcard->log, WLOG_DEBUG, "hContext: 0x%02X%02X%02X%02X%02X%02X%02X%02X (%d)", + pb[0], pb[1], pb[2], pb[3], pb[4], pb[5], pb[6], pb[7], call->Context.cbContext); } else { - WLog_Print(smartcard->log, WLOG_DEBUG, "hContext: 0x%08X (%d)", - call->Context.pbContext.LowPart, call->Context.cbContext); + WLog_Print(smartcard->log, WLOG_DEBUG, "hContext: 0x%02X%02X%02X%02X (%d)", + pb[0], pb[1], pb[2], pb[3], call->Context.cbContext); } WLog_Print(smartcard->log, WLOG_DEBUG, "dwTimeOut: 0x%08X cReaders: %d", @@ -1365,6 +1379,11 @@ UINT32 smartcard_unpack_state_call(SMARTCARD_DEVICE* smartcard, wStream* s, Stat { UINT32 status; + status = smartcard_unpack_redir_scard_context(smartcard, s, &(call->hContext)); + + if (status) + return status; + status = smartcard_unpack_redir_scard_handle(smartcard, s, &(call->hCard)); if (status) @@ -1380,6 +1399,11 @@ UINT32 smartcard_unpack_state_call(SMARTCARD_DEVICE* smartcard, wStream* s, Stat Stream_Read_UINT32(s, call->fpbAtrIsNULL); /* fpbAtrIsNULL (4 bytes) */ Stream_Read_UINT32(s, call->cbAtrLen); /* cbAtrLen (4 bytes) */ + status = smartcard_unpack_redir_scard_context_ref(smartcard, s, &(call->hContext)); + + if (status) + return status; + status = smartcard_unpack_redir_scard_handle_ref(smartcard, s, &(call->hCard)); if (status) @@ -1406,6 +1430,11 @@ UINT32 smartcard_unpack_status_call(SMARTCARD_DEVICE* smartcard, wStream* s, Sta { UINT32 status; + status = smartcard_unpack_redir_scard_context(smartcard, s, &(call->hContext)); + + if (status) + return status; + status = smartcard_unpack_redir_scard_handle(smartcard, s, &(call->hCard)); if (status) @@ -1422,6 +1451,11 @@ UINT32 smartcard_unpack_status_call(SMARTCARD_DEVICE* smartcard, wStream* s, Sta Stream_Read_UINT32(s, call->cchReaderLen); /* cchReaderLen (4 bytes) */ Stream_Read_UINT32(s, call->cbAtrLen); /* cbAtrLen (4 bytes) */ + status = smartcard_unpack_redir_scard_context_ref(smartcard, s, &(call->hContext)); + + if (status) + return status; + status = smartcard_unpack_redir_scard_handle_ref(smartcard, s, &(call->hCard)); if (status) @@ -1432,32 +1466,37 @@ UINT32 smartcard_unpack_status_call(SMARTCARD_DEVICE* smartcard, wStream* s, Sta void smartcard_trace_status_call(SMARTCARD_DEVICE* smartcard, Status_Call* call, BOOL unicode) { + BYTE* pb; + if (!WLog_IsLevelActive(smartcard->log, WLOG_DEBUG)) return; WLog_Print(smartcard->log, WLOG_DEBUG, "Status%s_Call {", unicode ? "W" : "A"); - if (call->hCard.Context.cbContext > 4) + pb = (BYTE*) &(call->hContext.pbContext); + + if (call->hContext.cbContext > 4) { - WLog_Print(smartcard->log, WLOG_DEBUG, "hContext: 0x%08X%08X (%d)", - call->hCard.Context.pbContext.HighPart, call->hCard.Context.pbContext.LowPart, - call->hCard.Context.cbContext); + WLog_Print(smartcard->log, WLOG_DEBUG, "hContext: 0x%02X%02X%02X%02X%02X%02X%02X%02X (%d)", + pb[0], pb[1], pb[2], pb[3], pb[4], pb[5], pb[6], pb[7], call->hContext.cbContext); } else { - WLog_Print(smartcard->log, WLOG_DEBUG, "hContext: 0x%08X (%d)", - call->hCard.Context.pbContext.LowPart, call->hCard.Context.cbContext); + WLog_Print(smartcard->log, WLOG_DEBUG, "hContext: 0x%02X%02X%02X%02X (%d)", + pb[0], pb[1], pb[2], pb[3], call->hContext.cbContext); } + pb = (BYTE*) &(call->hCard.pbHandle); + if (call->hCard.cbHandle > 4) { - WLog_Print(smartcard->log, WLOG_DEBUG, "hCard: 0x%08X%08X (%d)", - call->hCard.pbHandle.HighPart, call->hCard.pbHandle.LowPart, call->hCard.pbHandle); + WLog_Print(smartcard->log, WLOG_DEBUG, "hCard: 0x%02X%02X%02X%02X%02X%02X%02X%02X (%d)", + pb[0], pb[1], pb[2], pb[3], pb[4], pb[5], pb[6], pb[7], call->hCard.cbHandle); } else { - WLog_Print(smartcard->log, WLOG_DEBUG, "hCard: 0x%08X (%d)", - call->hCard.pbHandle.LowPart, call->hCard.pbHandle); + WLog_Print(smartcard->log, WLOG_DEBUG, "hCard: 0x%02X%02X%02X%02X (%d)", + pb[0], pb[1], pb[2], pb[3], call->hCard.cbHandle); } WLog_Print(smartcard->log, WLOG_DEBUG, "fmszReaderNamesIsNULL: %d cchReaderLen: %d cbAtrLen: %d", @@ -1532,6 +1571,11 @@ UINT32 smartcard_unpack_get_attrib_call(SMARTCARD_DEVICE* smartcard, wStream* s, { UINT32 status; + status = smartcard_unpack_redir_scard_context(smartcard, s, &(call->hContext)); + + if (status) + return status; + status = smartcard_unpack_redir_scard_handle(smartcard, s, &(call->hCard)); if (status) @@ -1548,6 +1592,11 @@ UINT32 smartcard_unpack_get_attrib_call(SMARTCARD_DEVICE* smartcard, wStream* s, Stream_Read_UINT32(s, call->fpbAttrIsNULL); /* fpbAttrIsNULL (4 bytes) */ Stream_Read_UINT32(s, call->cbAttrLen); /* cbAttrLen (4 bytes) */ + status = smartcard_unpack_redir_scard_context_ref(smartcard, s, &(call->hContext)); + + if (status) + return status; + status = smartcard_unpack_redir_scard_handle_ref(smartcard, s, &(call->hCard)); if (status) @@ -1558,32 +1607,37 @@ UINT32 smartcard_unpack_get_attrib_call(SMARTCARD_DEVICE* smartcard, wStream* s, void smartcard_trace_get_attrib_call(SMARTCARD_DEVICE* smartcard, GetAttrib_Call* call) { + BYTE* pb; + if (!WLog_IsLevelActive(smartcard->log, WLOG_DEBUG)) return; WLog_Print(smartcard->log, WLOG_DEBUG, "GetAttrib_Call {"); - if (call->hCard.Context.cbContext > 4) + pb = (BYTE*) &(call->hContext.pbContext); + + if (call->hContext.cbContext > 4) { - WLog_Print(smartcard->log, WLOG_DEBUG, "hContext: 0x%08X%08X (%d)", - call->hCard.Context.pbContext.HighPart, call->hCard.Context.pbContext.LowPart, - call->hCard.Context.cbContext); + WLog_Print(smartcard->log, WLOG_DEBUG, "hContext: 0x%02X%02X%02X%02X%02X%02X%02X%02X (%d)", + pb[0], pb[1], pb[2], pb[3], pb[4], pb[5], pb[6], pb[7], call->hContext.cbContext); } else { - WLog_Print(smartcard->log, WLOG_DEBUG, "hContext: 0x%08X (%d)", - call->hCard.Context.pbContext.LowPart, call->hCard.Context.cbContext); + WLog_Print(smartcard->log, WLOG_DEBUG, "hContext: 0x%02X%02X%02X%02X (%d)", + pb[0], pb[1], pb[2], pb[3], call->hContext.cbContext); } + pb = (BYTE*) &(call->hCard.pbHandle); + if (call->hCard.cbHandle > 4) { - WLog_Print(smartcard->log, WLOG_DEBUG, "hCard: 0x%08X%08X (%d)", - call->hCard.pbHandle.HighPart, call->hCard.pbHandle.LowPart, call->hCard.pbHandle); + WLog_Print(smartcard->log, WLOG_DEBUG, "hCard: 0x%02X%02X%02X%02X%02X%02X%02X%02X (%d)", + pb[0], pb[1], pb[2], pb[3], pb[4], pb[5], pb[6], pb[7], call->hCard.cbHandle); } else { - WLog_Print(smartcard->log, WLOG_DEBUG, "hCard: 0x%08X (%d)", - call->hCard.pbHandle.LowPart, call->hCard.pbHandle); + WLog_Print(smartcard->log, WLOG_DEBUG, "hCard: 0x%02X%02X%02X%02X (%d)", + pb[0], pb[1], pb[2], pb[3], call->hCard.cbHandle); } WLog_Print(smartcard->log, WLOG_DEBUG, "dwAttrId: %s (0x%08X) fpbAttrIsNULL: %d cbAttrLen: 0x%08X", @@ -1635,6 +1689,11 @@ UINT32 smartcard_unpack_control_call(SMARTCARD_DEVICE* smartcard, wStream* s, Co call->pvInBuffer = NULL; + status = smartcard_unpack_redir_scard_context(smartcard, s, &(call->hContext)); + + if (status) + return status; + status = smartcard_unpack_redir_scard_handle(smartcard, s, &(call->hCard)); if (status) @@ -1653,6 +1712,11 @@ UINT32 smartcard_unpack_control_call(SMARTCARD_DEVICE* smartcard, wStream* s, Co Stream_Read_UINT32(s, call->fpvOutBufferIsNULL); /* fpvOutBufferIsNULL (4 bytes) */ Stream_Read_UINT32(s, call->cbOutBufferSize); /* cbOutBufferSize (4 bytes) */ + status = smartcard_unpack_redir_scard_context_ref(smartcard, s, &(call->hContext)); + + if (status) + return status; + status = smartcard_unpack_redir_scard_handle_ref(smartcard, s, &(call->hCard)); if (status) @@ -1715,6 +1779,11 @@ UINT32 smartcard_unpack_transmit_call(SMARTCARD_DEVICE* smartcard, wStream* s, T call->pioRecvPci = NULL; call->pbSendBuffer = NULL; + status = smartcard_unpack_redir_scard_context(smartcard, s, &(call->hContext)); + + if (status) + return status; + status = smartcard_unpack_redir_scard_handle(smartcard, s, &(call->hCard)); if (status) @@ -1750,6 +1819,11 @@ UINT32 smartcard_unpack_transmit_call(SMARTCARD_DEVICE* smartcard, wStream* s, T return STATUS_INVALID_PARAMETER; } + status = smartcard_unpack_redir_scard_context_ref(smartcard, s, &(call->hContext)); + + if (status) + return status; + status = smartcard_unpack_redir_scard_handle_ref(smartcard, s, &(call->hCard)); if (status) diff --git a/channels/smartcard/client/smartcard_pack.h b/channels/smartcard/client/smartcard_pack.h index 72561d578..6a1300d70 100644 --- a/channels/smartcard/client/smartcard_pack.h +++ b/channels/smartcard/client/smartcard_pack.h @@ -32,14 +32,13 @@ typedef struct _REDIR_SCARDCONTEXT { /* [range] */ DWORD cbContext; - /* [size_is][unique] */ ULARGE_INTEGER pbContext; + /* [size_is][unique] */ BYTE pbContext[8]; } REDIR_SCARDCONTEXT; typedef struct _REDIR_SCARDHANDLE { - REDIR_SCARDCONTEXT Context; /* [range] */ DWORD cbHandle; - /* [size_is] */ ULARGE_INTEGER pbHandle; + /* [size_is] */ BYTE pbHandle[8]; } REDIR_SCARDHANDLE; typedef struct _Long_Return @@ -232,12 +231,14 @@ typedef struct _ConnectW_Call typedef struct _Connect_Return { LONG ReturnCode; + REDIR_SCARDCONTEXT hContext; REDIR_SCARDHANDLE hCard; DWORD dwActiveProtocol; } Connect_Return; typedef struct _Reconnect_Call { + REDIR_SCARDCONTEXT hContext; REDIR_SCARDHANDLE hCard; DWORD dwShareMode; DWORD dwPreferredProtocols; @@ -252,12 +253,14 @@ typedef struct Reconnect_Return typedef struct _HCardAndDisposition_Call { + REDIR_SCARDCONTEXT hContext; REDIR_SCARDHANDLE hCard; DWORD dwDisposition; } HCardAndDisposition_Call; typedef struct _State_Call { + REDIR_SCARDCONTEXT hContext; REDIR_SCARDHANDLE hCard; LONG fpbAtrIsNULL; DWORD cbAtrLen; @@ -274,6 +277,7 @@ typedef struct _State_Return typedef struct _Status_Call { + REDIR_SCARDCONTEXT hContext; REDIR_SCARDHANDLE hCard; LONG fmszReaderNamesIsNULL; DWORD cchReaderLen; @@ -300,6 +304,7 @@ typedef struct _SCardIO_Request typedef struct _Transmit_Call { + REDIR_SCARDCONTEXT hContext; REDIR_SCARDHANDLE hCard; LPSCARD_IO_REQUEST pioSendPci; /* [range] */ DWORD cbSendLength; @@ -319,6 +324,7 @@ typedef struct _Transmit_Return typedef struct _GetTransmitCount_Call { + REDIR_SCARDCONTEXT hContext; REDIR_SCARDHANDLE hCard; } GetTransmitCount_Call; @@ -330,6 +336,7 @@ typedef struct _GetTransmitCount_Return typedef struct _Control_Call { + REDIR_SCARDCONTEXT hContext; REDIR_SCARDHANDLE hCard; DWORD dwControlCode; /* [range] */ DWORD cbInBufferSize; @@ -347,6 +354,7 @@ typedef struct _Control_Return typedef struct _GetAttrib_Call { + REDIR_SCARDCONTEXT hContext; REDIR_SCARDHANDLE hCard; DWORD dwAttrId; LONG fpbAttrIsNULL; @@ -362,6 +370,7 @@ typedef struct _GetAttrib_Return typedef struct _SetAttrib_Call { + REDIR_SCARDCONTEXT hContext; REDIR_SCARDHANDLE hCard; DWORD dwAttrId; /* [range] */ DWORD cbAttrLen; @@ -427,7 +436,7 @@ SCARDCONTEXT smartcard_scard_context_native_from_redir(SMARTCARD_DEVICE* smartca void smartcard_scard_context_native_to_redir(SMARTCARD_DEVICE* smartcard, REDIR_SCARDCONTEXT* context, SCARDCONTEXT hContext); SCARDHANDLE smartcard_scard_handle_native_from_redir(SMARTCARD_DEVICE* smartcard, REDIR_SCARDHANDLE* handle); -void smartcard_scard_handle_native_to_redir(SMARTCARD_DEVICE* smartcard, REDIR_SCARDHANDLE* context, SCARDHANDLE hCard); +void smartcard_scard_handle_native_to_redir(SMARTCARD_DEVICE* smartcard, REDIR_SCARDHANDLE* handle, SCARDHANDLE hCard); UINT32 smartcard_unpack_common_type_header(SMARTCARD_DEVICE* smartcard, wStream* s); UINT32 smartcard_pack_common_type_header(SMARTCARD_DEVICE* smartcard, wStream* s); diff --git a/winpr/libwinpr/smartcard/smartcard_pcsc.c b/winpr/libwinpr/smartcard/smartcard_pcsc.c index 8938add49..f30623dfb 100644 --- a/winpr/libwinpr/smartcard/smartcard_pcsc.c +++ b/winpr/libwinpr/smartcard/smartcard_pcsc.c @@ -1223,24 +1223,38 @@ WINSCARDAPI LONG WINAPI PCSC_SCardGetAttrib_Internal(SCARDHANDLE hCard, DWORD dw WINSCARDAPI LONG WINAPI PCSC_SCardGetAttrib(SCARDHANDLE hCard, DWORD dwAttrId, LPBYTE pbAttr, LPDWORD pcbAttrLen) { + DWORD cbAttrLen; + SCARDCONTEXT hContext; + BOOL attrAutoAlloc = FALSE; LONG status = SCARD_S_SUCCESS; + LPBYTE* pPbAttr = (LPBYTE*) pbAttr; + + cbAttrLen = *pcbAttrLen; + + if (*pcbAttrLen == SCARD_AUTOALLOCATE) + attrAutoAlloc = TRUE; + + hContext = PCSC_GetCardContextFromHandle(hCard); status = PCSC_SCardGetAttrib_Internal(hCard, dwAttrId, pbAttr, pcbAttrLen); - if (status == SCARD_E_UNSUPPORTED_FEATURE) + if (status == SCARD_S_SUCCESS) { - DWORD cbAttrLen; - SCARDCONTEXT hContext; - BOOL attrAutoAlloc = FALSE; - LPBYTE* pPbAttr = (LPBYTE*) pbAttr; - - cbAttrLen = *pcbAttrLen; - - if (*pcbAttrLen == SCARD_AUTOALLOCATE) - attrAutoAlloc = TRUE; - - hContext = PCSC_GetCardContextFromHandle(hCard); + if (dwAttrId == SCARD_ATTR_VENDOR_NAME) + { + /** + * pcsc-lite adds a null terminator to the vendor name, + * while WinSCard doesn't. Strip the null terminator. + */ + if (attrAutoAlloc) + *pcbAttrLen = strlen((char*) *pPbAttr); + else + *pcbAttrLen = strlen((char*) pbAttr); + } + } + else if (status == SCARD_E_UNSUPPORTED_FEATURE) + { if (dwAttrId == SCARD_ATTR_DEVICE_FRIENDLY_NAME_A) { WCHAR* pbAttrW = NULL;