channels/smartcard: cleanup context/handle management

This commit is contained in:
Marc-André Moreau 2014-04-11 14:01:42 -04:00
parent 8cac6519e1
commit f99c8ed8d0
3 changed files with 430 additions and 187 deletions

View File

@ -187,8 +187,7 @@ static UINT32 smartcard_EstablishContext(SMARTCARD_DEVICE* smartcard, IRP* irp)
status = ret.ReturnCode = SCardEstablishContext(call.dwScope, NULL, NULL, &hContext); status = ret.ReturnCode = SCardEstablishContext(call.dwScope, NULL, NULL, &hContext);
ret.Context.pbContext = (UINT64) hContext; smartcard_scard_context_native_to_redir(smartcard, &ret.Context, hContext);
ret.Context.cbContext = sizeof(ULONG_PTR);
smartcard_trace_establish_context_return(smartcard, &ret); smartcard_trace_establish_context_return(smartcard, &ret);
@ -209,17 +208,12 @@ static UINT32 smartcard_ReleaseContext(SMARTCARD_DEVICE* smartcard, IRP* irp)
status = smartcard_unpack_context_call(smartcard, irp->input, &call); status = smartcard_unpack_context_call(smartcard, irp->input, &call);
WLog_Print(smartcard->log, WLOG_DEBUG, "ReleaseContext_Call {"); smartcard_trace_context_call(smartcard, &call, "ReleaseContext");
WLog_Print(smartcard->log, WLOG_DEBUG, "hContext: 0x%08X (%d)",
call.Context.pbContext, call.Context.cbContext);
WLog_Print(smartcard->log, WLOG_DEBUG, "}");
if (status) if (status)
return status; return status;
hContext = (ULONG_PTR) call.Context.pbContext; hContext = smartcard_scard_context_native_from_redir(smartcard, &call.Context);
status = ret.ReturnCode = SCardReleaseContext(hContext); status = ret.ReturnCode = SCardReleaseContext(hContext);
@ -235,17 +229,12 @@ static UINT32 smartcard_IsValidContext(SMARTCARD_DEVICE* smartcard, IRP* irp)
status = smartcard_unpack_context_call(smartcard, irp->input, &call); status = smartcard_unpack_context_call(smartcard, irp->input, &call);
WLog_Print(smartcard->log, WLOG_DEBUG, "IsValidContext_Call {"); smartcard_trace_context_call(smartcard, &call, "IsValidContext");
WLog_Print(smartcard->log, WLOG_DEBUG, "hContext: 0x%08X (%d)",
call.Context.pbContext, call.Context.cbContext);
WLog_Print(smartcard->log, WLOG_DEBUG, "}");
if (status) if (status)
return status; return status;
hContext = (ULONG_PTR) call.Context.pbContext; hContext = smartcard_scard_context_native_from_redir(smartcard, &call.Context);
status = ret.ReturnCode = SCardIsValidContext(hContext); status = ret.ReturnCode = SCardIsValidContext(hContext);
@ -263,12 +252,12 @@ static UINT32 smartcard_ListReadersA(SMARTCARD_DEVICE* smartcard, IRP* irp)
status = smartcard_unpack_list_readers_call(smartcard, irp->input, &call); status = smartcard_unpack_list_readers_call(smartcard, irp->input, &call);
smartcard_trace_list_readers_call(smartcard, &call); smartcard_trace_list_readers_call(smartcard, &call, FALSE);
if (status) if (status)
return status; return status;
hContext = (ULONG_PTR) call.Context.pbContext; hContext = smartcard_scard_context_native_from_redir(smartcard, &call.Context);
cchReaders = SCARD_AUTOALLOCATE; cchReaders = SCARD_AUTOALLOCATE;
@ -280,7 +269,7 @@ static UINT32 smartcard_ListReadersA(SMARTCARD_DEVICE* smartcard, IRP* irp)
if (status) if (status)
return status; return status;
smartcard_trace_list_readers_return(smartcard, &ret); smartcard_trace_list_readers_return(smartcard, &ret, FALSE);
status = smartcard_pack_list_readers_return(smartcard, irp->output, &ret); status = smartcard_pack_list_readers_return(smartcard, irp->output, &ret);
@ -307,12 +296,12 @@ static UINT32 smartcard_ListReadersW(SMARTCARD_DEVICE* smartcard, IRP* irp)
status = smartcard_unpack_list_readers_call(smartcard, irp->input, &call); status = smartcard_unpack_list_readers_call(smartcard, irp->input, &call);
smartcard_trace_list_readers_call(smartcard, &call); smartcard_trace_list_readers_call(smartcard, &call, TRUE);
if (status) if (status)
return status; return status;
hContext = (ULONG_PTR) call.Context.pbContext; hContext = smartcard_scard_context_native_from_redir(smartcard, &call.Context);
cchReaders = SCARD_AUTOALLOCATE; cchReaders = SCARD_AUTOALLOCATE;
@ -324,7 +313,7 @@ static UINT32 smartcard_ListReadersW(SMARTCARD_DEVICE* smartcard, IRP* irp)
if (status) if (status)
return status; return status;
smartcard_trace_list_readers_return(smartcard, &ret); smartcard_trace_list_readers_return(smartcard, &ret, TRUE);
status = smartcard_pack_list_readers_return(smartcard, irp->output, &ret); status = smartcard_pack_list_readers_return(smartcard, irp->output, &ret);
@ -356,7 +345,7 @@ static UINT32 smartcard_GetStatusChangeA(SMARTCARD_DEVICE* smartcard, IRP* irp)
if (status) if (status)
return status; return status;
hContext = (ULONG_PTR) call.Context.pbContext; hContext = smartcard_scard_context_native_from_redir(smartcard, &call.Context);
status = ret.ReturnCode = SCardGetStatusChangeA(hContext, call.dwTimeOut, call.rgReaderStates, call.cReaders); status = ret.ReturnCode = SCardGetStatusChangeA(hContext, call.dwTimeOut, call.rgReaderStates, call.cReaders);
@ -414,7 +403,7 @@ static UINT32 smartcard_GetStatusChangeW(SMARTCARD_DEVICE* smartcard, IRP* irp)
if (status) if (status)
return status; return status;
hContext = (ULONG_PTR) call.Context.pbContext; hContext = smartcard_scard_context_native_from_redir(smartcard, &call.Context);
status = ret.ReturnCode = SCardGetStatusChangeW(hContext, call.dwTimeOut, call.rgReaderStates, call.cReaders); status = ret.ReturnCode = SCardGetStatusChangeW(hContext, call.dwTimeOut, call.rgReaderStates, call.cReaders);
@ -465,17 +454,12 @@ static UINT32 smartcard_Cancel(SMARTCARD_DEVICE* smartcard, IRP* irp)
status = smartcard_unpack_context_call(smartcard, irp->input, &call); status = smartcard_unpack_context_call(smartcard, irp->input, &call);
WLog_Print(smartcard->log, WLOG_DEBUG, "Cancel_Call {"); smartcard_trace_context_call(smartcard, &call, "Cancel");
WLog_Print(smartcard->log, WLOG_DEBUG, "hContext: 0x%08X (%d)",
call.Context.pbContext, call.Context.cbContext);
WLog_Print(smartcard->log, WLOG_DEBUG, "}");
if (status) if (status)
return status; return status;
hContext = (ULONG_PTR) call.Context.pbContext; hContext = smartcard_scard_context_native_from_redir(smartcard, &call.Context);
status = ret.ReturnCode = SCardCancel(hContext); status = ret.ReturnCode = SCardCancel(hContext);
@ -499,7 +483,7 @@ UINT32 smartcard_ConnectA(SMARTCARD_DEVICE* smartcard, IRP* irp)
if (status) if (status)
return status; return status;
hContext = (ULONG_PTR) call.Common.Context.pbContext; hContext = smartcard_scard_context_native_from_redir(smartcard, &call.Common.Context);
if ((call.Common.dwPreferredProtocols == SCARD_PROTOCOL_UNDEFINED) && if ((call.Common.dwPreferredProtocols == SCARD_PROTOCOL_UNDEFINED) &&
(call.Common.dwShareMode != SCARD_SHARE_DIRECT)) (call.Common.dwShareMode != SCARD_SHARE_DIRECT))
@ -513,11 +497,8 @@ UINT32 smartcard_ConnectA(SMARTCARD_DEVICE* smartcard, IRP* irp)
if (status) if (status)
return status; return status;
ret.hCard.Context.pbContext = (UINT64) hContext; smartcard_scard_context_native_to_redir(smartcard, &ret.hCard.Context, hContext);
ret.hCard.Context.cbContext = sizeof(ULONG_PTR); smartcard_scard_handle_native_to_redir(smartcard, &ret.hCard, hCard);
ret.hCard.pbHandle = (UINT64) hCard;
ret.hCard.cbHandle = sizeof(ULONG_PTR);
smartcard_trace_connect_return(smartcard, &ret); smartcard_trace_connect_return(smartcard, &ret);
@ -549,7 +530,7 @@ UINT32 smartcard_ConnectW(SMARTCARD_DEVICE* smartcard, IRP* irp)
if (status) if (status)
return status; return status;
hContext = (ULONG_PTR) call.Common.Context.pbContext; hContext = smartcard_scard_context_native_from_redir(smartcard, &call.Common.Context);
if ((call.Common.dwPreferredProtocols == SCARD_PROTOCOL_UNDEFINED) && if ((call.Common.dwPreferredProtocols == SCARD_PROTOCOL_UNDEFINED) &&
(call.Common.dwShareMode != SCARD_SHARE_DIRECT)) (call.Common.dwShareMode != SCARD_SHARE_DIRECT))
@ -563,11 +544,8 @@ UINT32 smartcard_ConnectW(SMARTCARD_DEVICE* smartcard, IRP* irp)
if (status) if (status)
return status; return status;
ret.hCard.Context.pbContext = (UINT64) hContext; smartcard_scard_context_native_to_redir(smartcard, &ret.hCard.Context, hContext);
ret.hCard.Context.cbContext = sizeof(ULONG_PTR); smartcard_scard_handle_native_to_redir(smartcard, &ret.hCard, hCard);
ret.hCard.pbHandle = (UINT64) hCard;
ret.hCard.cbHandle = sizeof(ULONG_PTR);
smartcard_trace_connect_return(smartcard, &ret); smartcard_trace_connect_return(smartcard, &ret);
@ -595,8 +573,8 @@ static UINT32 smartcard_Reconnect(SMARTCARD_DEVICE* smartcard, IRP* irp)
if (status) if (status)
return status; return status;
hCard = (ULONG_PTR) call.hCard.pbHandle; hCard = smartcard_scard_handle_native_from_redir(smartcard, &call.hCard);
hContext = (ULONG_PTR) call.hCard.Context.pbContext; hContext = smartcard_scard_context_native_from_redir(smartcard, &call.hCard.Context);
status = ret.ReturnCode = SCardReconnect(hCard, call.dwShareMode, status = ret.ReturnCode = SCardReconnect(hCard, call.dwShareMode,
call.dwPreferredProtocols, call.dwInitialization, &ret.dwActiveProtocol); call.dwPreferredProtocols, call.dwInitialization, &ret.dwActiveProtocol);
@ -622,20 +600,13 @@ static UINT32 smartcard_Disconnect(SMARTCARD_DEVICE* smartcard, IRP* irp)
status = smartcard_unpack_hcard_and_disposition_call(smartcard, irp->input, &call); status = smartcard_unpack_hcard_and_disposition_call(smartcard, irp->input, &call);
WLog_Print(smartcard->log, WLOG_DEBUG, "Cancel_Call {"); smartcard_trace_hcard_and_disposition_call(smartcard, &call, "Disconnect");
WLog_Print(smartcard->log, WLOG_DEBUG, "hContext: 0x%08X (%d) hCard: 0x%08X (%d)",
call.hCard.Context.pbContext, call.hCard.Context.cbContext, call.hCard.pbHandle, call.hCard.pbHandle);
WLog_Print(smartcard->log, WLOG_DEBUG, "dwDisposition: 0x%08X", call.dwDisposition);
WLog_Print(smartcard->log, WLOG_DEBUG, "}");
if (status) if (status)
return status; return status;
hCard = (ULONG_PTR) call.hCard.pbHandle; hCard = smartcard_scard_handle_native_from_redir(smartcard, &call.hCard);
hContext = (ULONG_PTR) call.hCard.Context.pbContext; hContext = smartcard_scard_context_native_from_redir(smartcard, &call.hCard.Context);
status = ret.ReturnCode = SCardDisconnect(hCard, (DWORD) call.dwDisposition); status = ret.ReturnCode = SCardDisconnect(hCard, (DWORD) call.dwDisposition);
@ -655,20 +626,13 @@ static UINT32 smartcard_BeginTransaction(SMARTCARD_DEVICE* smartcard, IRP* irp)
status = smartcard_unpack_hcard_and_disposition_call(smartcard, irp->input, &call); status = smartcard_unpack_hcard_and_disposition_call(smartcard, irp->input, &call);
WLog_Print(smartcard->log, WLOG_DEBUG, "BeginTransaction_Call {"); smartcard_trace_hcard_and_disposition_call(smartcard, &call, "BeginTransaction");
WLog_Print(smartcard->log, WLOG_DEBUG, "hContext: 0x%08X (%d) hCard: 0x%08X (%d)",
call.hCard.Context.pbContext, call.hCard.Context.cbContext, call.hCard.pbHandle, call.hCard.pbHandle);
WLog_Print(smartcard->log, WLOG_DEBUG, "dwDisposition: 0x%08X", call.dwDisposition);
WLog_Print(smartcard->log, WLOG_DEBUG, "}");
if (status) if (status)
return status; return status;
hCard = (ULONG_PTR) call.hCard.pbHandle; hCard = smartcard_scard_handle_native_from_redir(smartcard, &call.hCard);
hContext = (ULONG_PTR) call.hCard.Context.pbContext; hContext = smartcard_scard_context_native_from_redir(smartcard, &call.hCard.Context);
status = ret.ReturnCode = SCardBeginTransaction(hCard); status = ret.ReturnCode = SCardBeginTransaction(hCard);
@ -688,20 +652,13 @@ static UINT32 smartcard_EndTransaction(SMARTCARD_DEVICE* smartcard, IRP* irp)
status = smartcard_unpack_hcard_and_disposition_call(smartcard, irp->input, &call); status = smartcard_unpack_hcard_and_disposition_call(smartcard, irp->input, &call);
WLog_Print(smartcard->log, WLOG_DEBUG, "EndTransaction_Call {"); smartcard_trace_hcard_and_disposition_call(smartcard, &call, "EndTransaction");
WLog_Print(smartcard->log, WLOG_DEBUG, "hContext: 0x%08X (%d) hCard: 0x%08X (%d)",
call.hCard.Context.pbContext, call.hCard.Context.cbContext, call.hCard.pbHandle, call.hCard.pbHandle);
WLog_Print(smartcard->log, WLOG_DEBUG, "dwDisposition: 0x%08X", call.dwDisposition);
WLog_Print(smartcard->log, WLOG_DEBUG, "}");
if (status) if (status)
return status; return status;
hCard = (ULONG_PTR) call.hCard.pbHandle; hCard = smartcard_scard_handle_native_from_redir(smartcard, &call.hCard);
hContext = (ULONG_PTR) call.hCard.Context.pbContext; hContext = smartcard_scard_context_native_from_redir(smartcard, &call.hCard.Context);
status = ret.ReturnCode = SCardEndTransaction(hCard, call.dwDisposition); status = ret.ReturnCode = SCardEndTransaction(hCard, call.dwDisposition);
@ -724,8 +681,8 @@ static UINT32 smartcard_State(SMARTCARD_DEVICE* smartcard, IRP* irp)
if (status) if (status)
return status; return status;
hCard = (ULONG_PTR) call.hCard.pbHandle; hCard = smartcard_scard_handle_native_from_redir(smartcard, &call.hCard);
hContext = (ULONG_PTR) call.hCard.Context.pbContext; hContext = smartcard_scard_context_native_from_redir(smartcard, &call.hCard.Context);
ret.cbAtrLen = SCARD_ATR_LENGTH; ret.cbAtrLen = SCARD_ATR_LENGTH;
@ -757,11 +714,13 @@ static DWORD smartcard_StatusA(SMARTCARD_DEVICE* smartcard, IRP* irp)
status = smartcard_unpack_status_call(smartcard, irp->input, &call); status = smartcard_unpack_status_call(smartcard, irp->input, &call);
smartcard_trace_status_call(smartcard, &call, FALSE);
if (status) if (status)
return status; return status;
hCard = (ULONG_PTR) call.hCard.pbHandle; hCard = smartcard_scard_handle_native_from_redir(smartcard, &call.hCard);
hContext = (ULONG_PTR) call.hCard.Context.pbContext; hContext = smartcard_scard_context_native_from_redir(smartcard, &call.hCard.Context);
if (call.cbAtrLen > 32) if (call.cbAtrLen > 32)
call.cbAtrLen = 32; call.cbAtrLen = 32;
@ -774,15 +733,11 @@ static DWORD smartcard_StatusA(SMARTCARD_DEVICE* smartcard, IRP* irp)
status = ret.ReturnCode = SCardStatusA(hCard, (LPSTR) &mszReaderNames, &cchReaderLen, status = ret.ReturnCode = SCardStatusA(hCard, (LPSTR) &mszReaderNames, &cchReaderLen,
&ret.dwState, &ret.dwProtocol, (BYTE*) &ret.pbAtr, &ret.cbAtrLen); &ret.dwState, &ret.dwProtocol, (BYTE*) &ret.pbAtr, &ret.cbAtrLen);
if (ret.ReturnCode)
{
Stream_Zero(irp->output, 256);
return ret.ReturnCode;
}
ret.mszReaderNames = (BYTE*) mszReaderNames; ret.mszReaderNames = (BYTE*) mszReaderNames;
ret.cBytes = cchReaderLen * 2; ret.cBytes = cchReaderLen * 2;
smartcard_trace_status_return(smartcard, &ret, FALSE);
status = smartcard_pack_status_return(smartcard, irp->output, &ret); status = smartcard_pack_status_return(smartcard, irp->output, &ret);
if (status) if (status)
@ -806,11 +761,13 @@ static DWORD smartcard_StatusW(SMARTCARD_DEVICE* smartcard, IRP* irp)
status = smartcard_unpack_status_call(smartcard, irp->input, &call); status = smartcard_unpack_status_call(smartcard, irp->input, &call);
smartcard_trace_status_call(smartcard, &call, TRUE);
if (status) if (status)
return status; return status;
hCard = (ULONG_PTR) call.hCard.pbHandle; hCard = smartcard_scard_handle_native_from_redir(smartcard, &call.hCard);
hContext = (ULONG_PTR) call.hCard.Context.pbContext; hContext = smartcard_scard_context_native_from_redir(smartcard, &call.hCard.Context);
if (call.cbAtrLen > 32) if (call.cbAtrLen > 32)
call.cbAtrLen = 32; call.cbAtrLen = 32;
@ -823,15 +780,11 @@ static DWORD smartcard_StatusW(SMARTCARD_DEVICE* smartcard, IRP* irp)
status = ret.ReturnCode = SCardStatusW(hCard, (LPWSTR) &mszReaderNames, &cchReaderLen, status = ret.ReturnCode = SCardStatusW(hCard, (LPWSTR) &mszReaderNames, &cchReaderLen,
&ret.dwState, &ret.dwProtocol, (BYTE*) &ret.pbAtr, &ret.cbAtrLen); &ret.dwState, &ret.dwProtocol, (BYTE*) &ret.pbAtr, &ret.cbAtrLen);
if (ret.ReturnCode)
{
Stream_Zero(irp->output, 256);
return ret.ReturnCode;
}
ret.mszReaderNames = (BYTE*) mszReaderNames; ret.mszReaderNames = (BYTE*) mszReaderNames;
ret.cBytes = cchReaderLen * 2; ret.cBytes = cchReaderLen * 2;
smartcard_trace_status_return(smartcard, &ret, TRUE);
status = smartcard_pack_status_return(smartcard, irp->output, &ret); status = smartcard_pack_status_return(smartcard, irp->output, &ret);
if (status) if (status)
@ -856,8 +809,8 @@ static UINT32 smartcard_Transmit(SMARTCARD_DEVICE* smartcard, IRP* irp)
if (status) if (status)
return status; return status;
hCard = (ULONG_PTR) call.hCard.pbHandle; hCard = smartcard_scard_handle_native_from_redir(smartcard, &call.hCard);
hContext = (ULONG_PTR) call.hCard.Context.pbContext; hContext = smartcard_scard_context_native_from_redir(smartcard, &call.hCard.Context);
ret.cbRecvLength = 0; ret.cbRecvLength = 0;
ret.pbRecvBuffer = NULL; ret.pbRecvBuffer = NULL;
@ -910,8 +863,8 @@ static UINT32 smartcard_Control(SMARTCARD_DEVICE* smartcard, IRP* irp)
if (status) if (status)
return status; return status;
hCard = (ULONG_PTR) call.hCard.pbHandle; hCard = smartcard_scard_handle_native_from_redir(smartcard, &call.hCard);
hContext = (ULONG_PTR) call.hCard.Context.pbContext; hContext = smartcard_scard_context_native_from_redir(smartcard, &call.hCard.Context);
if (DEVICE_TYPE_FROM_CTL_CODE(call.dwControlCode) == FILE_DEVICE_SMARTCARD) if (DEVICE_TYPE_FROM_CTL_CODE(call.dwControlCode) == FILE_DEVICE_SMARTCARD)
{ {
@ -953,11 +906,13 @@ static UINT32 smartcard_GetAttrib(SMARTCARD_DEVICE* smartcard, IRP* irp)
status = smartcard_unpack_get_attrib_call(smartcard, irp->input, &call); status = smartcard_unpack_get_attrib_call(smartcard, irp->input, &call);
smartcard_trace_get_attrib_call(smartcard, &call);
if (status) if (status)
return status; return status;
hCard = (ULONG_PTR) call.hCard.pbHandle; hCard = smartcard_scard_handle_native_from_redir(smartcard, &call.hCard);
hContext = (ULONG_PTR) call.hCard.Context.pbContext; hContext = smartcard_scard_context_native_from_redir(smartcard, &call.hCard.Context);
ret.pbAttr = NULL; ret.pbAttr = NULL;
@ -973,6 +928,8 @@ static UINT32 smartcard_GetAttrib(SMARTCARD_DEVICE* smartcard, IRP* irp)
ret.cbAttrLen = cbAttrLen; ret.cbAttrLen = cbAttrLen;
smartcard_trace_get_attrib_return(smartcard, &ret, call.dwAttrId);
if (ret.ReturnCode) if (ret.ReturnCode)
{ {
WLog_Print(smartcard->log, WLOG_WARN, WLog_Print(smartcard->log, WLOG_WARN,

View File

@ -128,23 +128,6 @@ UINT32 smartcard_pack_private_type_header(SMARTCARD_DEVICE* smartcard, wStream*
return 0; return 0;
} }
UINT32 smartcard_unpack_read_offset_align(SMARTCARD_DEVICE* smartcard, wStream* s, UINT32 alignment)
{
UINT32 pad;
UINT32 offset;
offset = Stream_GetPosition(s);
pad = offset;
offset = (offset + alignment - 1) & ~(alignment - 1);
pad = offset - pad;
if (pad)
Stream_Seek(s, pad);
return pad;
}
UINT32 smartcard_unpack_read_size_align(SMARTCARD_DEVICE* smartcard, wStream* s, UINT32 size, UINT32 alignment) UINT32 smartcard_unpack_read_size_align(SMARTCARD_DEVICE* smartcard, wStream* s, UINT32 size, UINT32 alignment)
{ {
UINT32 pad; UINT32 pad;
@ -159,23 +142,6 @@ UINT32 smartcard_unpack_read_size_align(SMARTCARD_DEVICE* smartcard, wStream* s,
return pad; return pad;
} }
UINT32 smartcard_pack_write_offset_align(SMARTCARD_DEVICE* smartcard, wStream* s, UINT32 alignment)
{
UINT32 pad;
UINT32 offset;
offset = Stream_GetPosition(s);
pad = offset;
offset = (offset + alignment - 1) & ~(alignment - 1);
pad = offset - pad;
if (pad)
Stream_Zero(s, pad);
return pad;
}
UINT32 smartcard_pack_write_size_align(SMARTCARD_DEVICE* smartcard, wStream* s, UINT32 size, UINT32 alignment) UINT32 smartcard_pack_write_size_align(SMARTCARD_DEVICE* smartcard, wStream* s, UINT32 size, UINT32 alignment)
{ {
UINT32 pad; UINT32 pad;
@ -190,8 +156,69 @@ UINT32 smartcard_pack_write_size_align(SMARTCARD_DEVICE* smartcard, wStream* s,
return pad; return pad;
} }
SCARDCONTEXT smartcard_scard_context_native_from_redir(SMARTCARD_DEVICE* smartcard, REDIR_SCARDCONTEXT* context)
{
SCARDCONTEXT hContext = 0;
if (context->cbContext != sizeof(ULONG_PTR))
{
WLog_Print(smartcard->log, WLOG_WARN,
"REDIR_SCARDCONTEXT does not match native size: Actual: %d, Expected: %d",
context->cbContext, sizeof(ULONG_PTR));
}
if (context->cbContext > 4)
hContext = (ULONG_PTR) context->pbContext.QuadPart;
else
hContext = (ULONG_PTR) context->pbContext.LowPart;
return hContext;
}
void smartcard_scard_context_native_to_redir(SMARTCARD_DEVICE* smartcard, REDIR_SCARDCONTEXT* context, SCARDCONTEXT hContext)
{
context->cbContext = sizeof(ULONG_PTR);
if (context->cbContext > 4)
context->pbContext.QuadPart = (UINT64) hContext;
else
context->pbContext.LowPart = (UINT32) hContext;
}
SCARDHANDLE smartcard_scard_handle_native_from_redir(SMARTCARD_DEVICE* smartcard, REDIR_SCARDHANDLE* handle)
{
SCARDHANDLE hCard = 0;
if (handle->cbHandle != sizeof(ULONG_PTR))
{
WLog_Print(smartcard->log, WLOG_WARN,
"REDIR_SCARDHANDLE does not match native size: Actual: %d, Expected: %d",
handle->cbHandle, sizeof(ULONG_PTR));
}
if (handle->cbHandle > 4)
hCard = (ULONG_PTR) handle->pbHandle.QuadPart;
else
hCard = (ULONG_PTR) handle->pbHandle.LowPart;
return hCard;
}
void smartcard_scard_handle_native_to_redir(SMARTCARD_DEVICE* smartcard, REDIR_SCARDHANDLE* context, SCARDHANDLE hCard)
{
context->cbHandle = sizeof(ULONG_PTR);
if (context->cbHandle > 4)
context->pbHandle.QuadPart = (UINT64) hCard;
else
context->pbHandle.LowPart = (UINT32) hCard;
}
UINT32 smartcard_unpack_redir_scard_context(SMARTCARD_DEVICE* smartcard, wStream* s, REDIR_SCARDCONTEXT* context) UINT32 smartcard_unpack_redir_scard_context(SMARTCARD_DEVICE* smartcard, wStream* s, REDIR_SCARDCONTEXT* context)
{ {
context->cbContext = 0;
context->pbContext.QuadPart = 0;
if (Stream_GetRemainingLength(s) < 4) if (Stream_GetRemainingLength(s) < 4)
{ {
WLog_Print(smartcard->log, WLOG_WARN, "REDIR_SCARDCONTEXT is too short: %d", WLog_Print(smartcard->log, WLOG_WARN, "REDIR_SCARDCONTEXT is too short: %d",
@ -234,8 +261,6 @@ UINT32 smartcard_pack_redir_scard_context(SMARTCARD_DEVICE* smartcard, wStream*
UINT32 smartcard_unpack_redir_scard_context_ref(SMARTCARD_DEVICE* smartcard, wStream* s, REDIR_SCARDCONTEXT* context) UINT32 smartcard_unpack_redir_scard_context_ref(SMARTCARD_DEVICE* smartcard, wStream* s, REDIR_SCARDCONTEXT* context)
{ {
UINT32 length;
if (Stream_GetRemainingLength(s) < 4) if (Stream_GetRemainingLength(s) < 4)
{ {
WLog_Print(smartcard->log, WLOG_WARN, "REDIR_SCARDCONTEXT is too short: Actual: %d, Expected: %d\n", WLog_Print(smartcard->log, WLOG_WARN, "REDIR_SCARDCONTEXT is too short: Actual: %d, Expected: %d\n",
@ -243,25 +268,25 @@ UINT32 smartcard_unpack_redir_scard_context_ref(SMARTCARD_DEVICE* smartcard, wSt
return STATUS_BUFFER_TOO_SMALL; return STATUS_BUFFER_TOO_SMALL;
} }
Stream_Read_UINT32(s, length); /* Length (4 bytes) */ Stream_Read_UINT32(s, context->cbContext); /* Length (4 bytes) */
if ((length != 4) && (length != 8)) if ((context->cbContext != 4) && (context->cbContext != 8))
{ {
WLog_Print(smartcard->log, WLOG_WARN, "REDIR_SCARDCONTEXT length is not 4 or 8: %d\n", length); WLog_Print(smartcard->log, WLOG_WARN, "REDIR_SCARDCONTEXT length is not 4 or 8: %d\n", context->cbContext);
return STATUS_INVALID_PARAMETER; return STATUS_INVALID_PARAMETER;
} }
if ((Stream_GetRemainingLength(s) < length) || (!length)) if ((Stream_GetRemainingLength(s) < context->cbContext) || (!context->cbContext))
{ {
WLog_Print(smartcard->log, WLOG_WARN, "REDIR_SCARDCONTEXT is too short: Actual: %d, Expected: %d\n", WLog_Print(smartcard->log, WLOG_WARN, "REDIR_SCARDCONTEXT is too short: Actual: %d, Expected: %d\n",
(int) Stream_GetRemainingLength(s), length); (int) Stream_GetRemainingLength(s), context->cbContext);
return STATUS_BUFFER_TOO_SMALL; return STATUS_BUFFER_TOO_SMALL;
} }
if (length > 4) if (context->cbContext > 4)
Stream_Read_UINT64(s, context->pbContext); Stream_Read_UINT64(s, context->pbContext.QuadPart);
else else
Stream_Read_UINT32(s, context->pbContext); Stream_Read_UINT32(s, context->pbContext.LowPart);
return SCARD_S_SUCCESS; return SCARD_S_SUCCESS;
} }
@ -273,9 +298,9 @@ UINT32 smartcard_pack_redir_scard_context_ref(SMARTCARD_DEVICE* smartcard, wStre
Stream_Write_UINT32(s, context->cbContext); /* Length (4 bytes) */ Stream_Write_UINT32(s, context->cbContext); /* Length (4 bytes) */
if (context->cbContext > 4) if (context->cbContext > 4)
Stream_Write_UINT64(s, context->pbContext); Stream_Write_UINT64(s, context->pbContext.QuadPart);
else if (context->cbContext > 0) else if (context->cbContext > 0)
Stream_Write_UINT32(s, context->pbContext); Stream_Write_UINT32(s, context->pbContext.LowPart);
} }
return SCARD_S_SUCCESS; return SCARD_S_SUCCESS;
@ -285,6 +310,10 @@ UINT32 smartcard_unpack_redir_scard_handle(SMARTCARD_DEVICE* smartcard, wStream*
{ {
UINT32 status; UINT32 status;
UINT32 length; UINT32 length;
UINT32 pbHandleNdrPtr;
handle->cbHandle = 0;
handle->pbHandle.QuadPart = 0;
status = smartcard_unpack_redir_scard_context(smartcard, s, &(handle->Context)); status = smartcard_unpack_redir_scard_context(smartcard, s, &(handle->Context));
@ -307,7 +336,7 @@ UINT32 smartcard_unpack_redir_scard_handle(SMARTCARD_DEVICE* smartcard, wStream*
return STATUS_BUFFER_TOO_SMALL; return STATUS_BUFFER_TOO_SMALL;
} }
Stream_Seek_UINT32(s); /* NdrPtr (4 bytes) */ Stream_Read_UINT32(s, pbHandleNdrPtr); /* NdrPtr (4 bytes) */
return 0; return 0;
} }
@ -332,7 +361,6 @@ 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 smartcard_unpack_redir_scard_handle_ref(SMARTCARD_DEVICE* smartcard, wStream* s, REDIR_SCARDHANDLE* handle)
{ {
UINT32 length;
UINT32 status; UINT32 status;
status = smartcard_unpack_redir_scard_context_ref(smartcard, s, &(handle->Context)); status = smartcard_unpack_redir_scard_context_ref(smartcard, s, &(handle->Context));
@ -347,25 +375,25 @@ UINT32 smartcard_unpack_redir_scard_handle_ref(SMARTCARD_DEVICE* smartcard, wStr
return STATUS_BUFFER_TOO_SMALL; return STATUS_BUFFER_TOO_SMALL;
} }
Stream_Read_UINT32(s, length); /* Length (4 bytes) */ Stream_Read_UINT32(s, handle->cbHandle); /* Length (4 bytes) */
if ((length != 4) && (length != 8)) if ((handle->cbHandle != 4) && (handle->cbHandle != 8))
{ {
WLog_Print(smartcard->log, WLOG_WARN, "REDIR_SCARDHANDLE length is not 4 or 8: %d\n", length); WLog_Print(smartcard->log, WLOG_WARN, "REDIR_SCARDHANDLE length is not 4 or 8: %d\n", handle->cbHandle);
return STATUS_INVALID_PARAMETER; return STATUS_INVALID_PARAMETER;
} }
if ((Stream_GetRemainingLength(s) < length) || (!length)) if ((Stream_GetRemainingLength(s) < handle->cbHandle) || (!handle->cbHandle))
{ {
WLog_Print(smartcard->log, WLOG_WARN, "REDIR_SCARDHANDLE is too short: Actual: %d, Expected: %d\n", WLog_Print(smartcard->log, WLOG_WARN, "REDIR_SCARDHANDLE is too short: Actual: %d, Expected: %d\n",
(int) Stream_GetRemainingLength(s), length); (int) Stream_GetRemainingLength(s), handle->cbHandle);
return STATUS_BUFFER_TOO_SMALL; return STATUS_BUFFER_TOO_SMALL;
} }
if (length > 4) if (handle->cbHandle > 4)
Stream_Read_UINT64(s, handle->pbHandle); Stream_Read_UINT64(s, handle->pbHandle.QuadPart);
else else
Stream_Read_UINT32(s, handle->pbHandle); Stream_Read_UINT32(s, handle->pbHandle.LowPart);
return 0; return 0;
} }
@ -384,9 +412,9 @@ UINT32 smartcard_pack_redir_scard_handle_ref(SMARTCARD_DEVICE* smartcard, wStrea
Stream_Write_UINT32(s, handle->cbHandle); /* Length (4 bytes) */ Stream_Write_UINT32(s, handle->cbHandle); /* Length (4 bytes) */
if (handle->cbHandle > 4) if (handle->cbHandle > 4)
Stream_Write_UINT64(s, handle->pbHandle); Stream_Write_UINT64(s, handle->pbHandle.HighPart);
else else
Stream_Write_UINT32(s, handle->pbHandle); Stream_Write_UINT32(s, handle->pbHandle.LowPart);
} }
return 0; return 0;
@ -440,12 +468,20 @@ void smartcard_trace_establish_context_return(SMARTCARD_DEVICE* smartcard, Estab
if (!WLog_IsLevelActive(smartcard->log, WLOG_DEBUG)) if (!WLog_IsLevelActive(smartcard->log, WLOG_DEBUG))
return; return;
WLog_Print(smartcard->log, WLOG_DEBUG, "EstablishContext_Call {"); WLog_Print(smartcard->log, WLOG_DEBUG, "EstablishContext_Return {");
WLog_Print(smartcard->log, WLOG_DEBUG, "ReturnCode: 0x%08X", ret->ReturnCode); WLog_Print(smartcard->log, WLOG_DEBUG, "ReturnCode: 0x%08X", ret->ReturnCode);
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);
}
else
{
WLog_Print(smartcard->log, WLOG_DEBUG, "hContext: 0x%08X (%d)", WLog_Print(smartcard->log, WLOG_DEBUG, "hContext: 0x%08X (%d)",
ret->Context.pbContext, ret->Context.cbContext); ret->Context.pbContext.LowPart, ret->Context.cbContext);
}
WLog_Print(smartcard->log, WLOG_DEBUG, "}"); WLog_Print(smartcard->log, WLOG_DEBUG, "}");
} }
@ -467,6 +503,24 @@ UINT32 smartcard_unpack_context_call(SMARTCARD_DEVICE* smartcard, wStream* s, Co
return SCARD_S_SUCCESS; return SCARD_S_SUCCESS;
} }
void smartcard_trace_context_call(SMARTCARD_DEVICE* smartcard, Context_Call* call, const char* name)
{
WLog_Print(smartcard->log, WLOG_DEBUG, "%s_Call {", name);
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);
}
else
{
WLog_Print(smartcard->log, WLOG_DEBUG, "hContext: 0x%08X (%d)",
call->Context.pbContext.LowPart, call->Context.cbContext);
}
WLog_Print(smartcard->log, WLOG_DEBUG, "}");
}
UINT32 smartcard_unpack_list_readers_call(SMARTCARD_DEVICE* smartcard, wStream* s, ListReaders_Call* call) UINT32 smartcard_unpack_list_readers_call(SMARTCARD_DEVICE* smartcard, wStream* s, ListReaders_Call* call)
{ {
UINT32 status; UINT32 status;
@ -540,23 +594,28 @@ UINT32 smartcard_unpack_list_readers_call(SMARTCARD_DEVICE* smartcard, wStream*
return SCARD_S_SUCCESS; return SCARD_S_SUCCESS;
} }
void smartcard_trace_list_readers_call(SMARTCARD_DEVICE* smartcard, ListReaders_Call* call) void smartcard_trace_list_readers_call(SMARTCARD_DEVICE* smartcard, ListReaders_Call* call, BOOL unicode)
{ {
BOOL unicode;
char* mszGroupsA = NULL; char* mszGroupsA = NULL;
if (!WLog_IsLevelActive(smartcard->log, WLOG_DEBUG)) if (!WLog_IsLevelActive(smartcard->log, WLOG_DEBUG))
return; return;
unicode = ((call->cBytes > 2) && !call->mszGroups[1]) ? TRUE : FALSE;
if (unicode) if (unicode)
ConvertFromUnicode(CP_UTF8, 0, (WCHAR*) call->mszGroups, call->cBytes / 2, &mszGroupsA, 0, NULL, NULL); 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_Call {");
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);
}
else
{
WLog_Print(smartcard->log, WLOG_DEBUG, "hContext: 0x%08X (%d)", WLog_Print(smartcard->log, WLOG_DEBUG, "hContext: 0x%08X (%d)",
call->Context.pbContext, call->Context.cbContext); call->Context.pbContext.LowPart, call->Context.cbContext);
}
WLog_Print(smartcard->log, WLOG_DEBUG, WLog_Print(smartcard->log, WLOG_DEBUG,
"cBytes: %d mszGroups: %s fmszReadersIsNULL: %d cchReaders: 0x%08X", "cBytes: %d mszGroups: %s fmszReadersIsNULL: %d cchReaders: 0x%08X",
@ -592,18 +651,15 @@ UINT32 smartcard_pack_list_readers_return(SMARTCARD_DEVICE* smartcard, wStream*
return SCARD_S_SUCCESS; return SCARD_S_SUCCESS;
} }
void smartcard_trace_list_readers_return(SMARTCARD_DEVICE* smartcard, ListReaders_Return* ret) void smartcard_trace_list_readers_return(SMARTCARD_DEVICE* smartcard, ListReaders_Return* ret, BOOL unicode)
{ {
int index; int index;
int length; int length;
BOOL unicode;
char* mszA = NULL; char* mszA = NULL;
if (!WLog_IsLevelActive(smartcard->log, WLOG_DEBUG)) if (!WLog_IsLevelActive(smartcard->log, WLOG_DEBUG))
return; return;
unicode = ((ret->cBytes > 2) && !ret->msz[1]) ? TRUE : FALSE;
if (unicode) if (unicode)
{ {
length = ret->cBytes / 2; length = ret->cBytes / 2;
@ -699,8 +755,17 @@ void smartcard_trace_connect_a_call(SMARTCARD_DEVICE* smartcard, ConnectA_Call*
WLog_Print(smartcard->log, WLOG_DEBUG, "ConnectA_Call {"); WLog_Print(smartcard->log, WLOG_DEBUG, "ConnectA_Call {");
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);
}
else
{
WLog_Print(smartcard->log, WLOG_DEBUG, "hContext: 0x%08X (%d)", WLog_Print(smartcard->log, WLOG_DEBUG, "hContext: 0x%08X (%d)",
call->Common.Context.pbContext, call->Common.Context.cbContext); call->Common.Context.pbContext.LowPart, call->Common.Context.cbContext);
}
WLog_Print(smartcard->log, WLOG_DEBUG, "szReader: %s dwShareMode: 0x%08X dwPreferredProtocols: 0x%08X", WLog_Print(smartcard->log, WLOG_DEBUG, "szReader: %s dwShareMode: 0x%08X dwPreferredProtocols: 0x%08X",
call->szReader, call->Common.dwShareMode, call->Common.dwPreferredProtocols); call->szReader, call->Common.dwShareMode, call->Common.dwPreferredProtocols);
@ -756,8 +821,17 @@ void smartcard_trace_connect_w_call(SMARTCARD_DEVICE* smartcard, ConnectW_Call*
WLog_Print(smartcard->log, WLOG_DEBUG, "ConnectA_Call {"); WLog_Print(smartcard->log, WLOG_DEBUG, "ConnectA_Call {");
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);
}
else
{
WLog_Print(smartcard->log, WLOG_DEBUG, "hContext: 0x%08X (%d)", WLog_Print(smartcard->log, WLOG_DEBUG, "hContext: 0x%08X (%d)",
call->Common.Context.pbContext, call->Common.Context.cbContext); call->Common.Context.pbContext.LowPart, call->Common.Context.cbContext);
}
WLog_Print(smartcard->log, WLOG_DEBUG, "szReader: %s dwShareMode: 0x%08X dwPreferredProtocols: %d", WLog_Print(smartcard->log, WLOG_DEBUG, "szReader: %s dwShareMode: 0x%08X dwPreferredProtocols: %d",
szReaderA, call->Common.dwShareMode, call->Common.dwPreferredProtocols); szReaderA, call->Common.dwShareMode, call->Common.dwPreferredProtocols);
@ -793,8 +867,28 @@ void smartcard_trace_connect_return(SMARTCARD_DEVICE* smartcard, Connect_Return*
WLog_Print(smartcard->log, WLOG_DEBUG, "Connect_Return {"); WLog_Print(smartcard->log, WLOG_DEBUG, "Connect_Return {");
WLog_Print(smartcard->log, WLOG_DEBUG, "hContext: 0x%08X (%d) hCard: 0x%08X (%d)", if (ret->hCard.Context.cbContext > 4)
ret->hCard.Context.pbContext, ret->hCard.Context.cbContext, ret->hCard.pbHandle, ret->hCard.cbHandle); {
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);
}
else
{
WLog_Print(smartcard->log, WLOG_DEBUG, "hContext: 0x%08X (%d)",
ret->hCard.Context.pbContext.LowPart, ret->hCard.Context.cbContext);
}
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);
}
else
{
WLog_Print(smartcard->log, WLOG_DEBUG, "hCard: 0x%08X (%d)",
ret->hCard.pbHandle.LowPart, ret->hCard.cbHandle);
}
WLog_Print(smartcard->log, WLOG_DEBUG, "dwActiveProtocol: 0x%08X", WLog_Print(smartcard->log, WLOG_DEBUG, "dwActiveProtocol: 0x%08X",
ret->dwActiveProtocol); ret->dwActiveProtocol);
@ -863,6 +957,38 @@ UINT32 smartcard_unpack_hcard_and_disposition_call(SMARTCARD_DEVICE* smartcard,
return SCARD_S_SUCCESS; return SCARD_S_SUCCESS;
} }
void smartcard_trace_hcard_and_disposition_call(SMARTCARD_DEVICE* smartcard, HCardAndDisposition_Call* call, const char* name)
{
WLog_Print(smartcard->log, WLOG_DEBUG, "%s_Call {", name);
if (call->hCard.Context.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);
}
else
{
WLog_Print(smartcard->log, WLOG_DEBUG, "hContext: 0x%08X (%d)",
call->hCard.Context.pbContext.LowPart, call->hCard.Context.cbContext);
}
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);
}
else
{
WLog_Print(smartcard->log, WLOG_DEBUG, "hCard: 0x%08X (%d)",
call->hCard.pbHandle.LowPart, call->hCard.pbHandle);
}
WLog_Print(smartcard->log, WLOG_DEBUG, "dwDisposition: 0x%08X", call->dwDisposition);
WLog_Print(smartcard->log, WLOG_DEBUG, "}");
}
UINT32 smartcard_unpack_get_status_change_a_call(SMARTCARD_DEVICE* smartcard, wStream* s, GetStatusChangeA_Call* call) UINT32 smartcard_unpack_get_status_change_a_call(SMARTCARD_DEVICE* smartcard, wStream* s, GetStatusChangeA_Call* call)
{ {
UINT32 index; UINT32 index;
@ -990,8 +1116,16 @@ void smartcard_trace_get_status_change_a_call(SMARTCARD_DEVICE* smartcard, GetSt
WLog_Print(smartcard->log, WLOG_DEBUG, "GetStatusChangeA_Call {"); WLog_Print(smartcard->log, WLOG_DEBUG, "GetStatusChangeA_Call {");
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);
}
else
{
WLog_Print(smartcard->log, WLOG_DEBUG, "hContext: 0x%08X (%d)", WLog_Print(smartcard->log, WLOG_DEBUG, "hContext: 0x%08X (%d)",
call->Context.pbContext, call->Context.cbContext); call->Context.pbContext.LowPart, call->Context.cbContext);
}
WLog_Print(smartcard->log, WLOG_DEBUG, "dwTimeOut: 0x%08X cReaders: %d", WLog_Print(smartcard->log, WLOG_DEBUG, "dwTimeOut: 0x%08X cReaders: %d",
call->dwTimeOut, call->cReaders); call->dwTimeOut, call->cReaders);
@ -1128,8 +1262,16 @@ void smartcard_trace_get_status_change_w_call(SMARTCARD_DEVICE* smartcard, GetSt
WLog_Print(smartcard->log, WLOG_DEBUG, "GetStatusChangeW_Call {"); WLog_Print(smartcard->log, WLOG_DEBUG, "GetStatusChangeW_Call {");
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);
}
else
{
WLog_Print(smartcard->log, WLOG_DEBUG, "hContext: 0x%08X (%d)", WLog_Print(smartcard->log, WLOG_DEBUG, "hContext: 0x%08X (%d)",
call->Context.pbContext, call->Context.cbContext); call->Context.pbContext.LowPart, call->Context.cbContext);
}
WLog_Print(smartcard->log, WLOG_DEBUG, "dwTimeOut: 0x%08X cReaders: %d", WLog_Print(smartcard->log, WLOG_DEBUG, "dwTimeOut: 0x%08X cReaders: %d",
call->dwTimeOut, call->cReaders); call->dwTimeOut, call->cReaders);
@ -1269,6 +1411,42 @@ UINT32 smartcard_unpack_status_call(SMARTCARD_DEVICE* smartcard, wStream* s, Sta
return SCARD_S_SUCCESS; return SCARD_S_SUCCESS;
} }
void smartcard_trace_status_call(SMARTCARD_DEVICE* smartcard, Status_Call* call, BOOL unicode)
{
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)
{
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);
}
else
{
WLog_Print(smartcard->log, WLOG_DEBUG, "hContext: 0x%08X (%d)",
call->hCard.Context.pbContext.LowPart, call->hCard.Context.cbContext);
}
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);
}
else
{
WLog_Print(smartcard->log, WLOG_DEBUG, "hCard: 0x%08X (%d)",
call->hCard.pbHandle.LowPart, call->hCard.pbHandle);
}
WLog_Print(smartcard->log, WLOG_DEBUG, "fmszReaderNamesIsNULL: %d cchReaderLen: %d cbAtrLen: %d",
call->fmszReaderNamesIsNULL, call->cchReaderLen, call->cbAtrLen);
WLog_Print(smartcard->log, WLOG_DEBUG, "}");
}
UINT32 smartcard_pack_status_return(SMARTCARD_DEVICE* smartcard, wStream* s, Status_Return* ret) UINT32 smartcard_pack_status_return(SMARTCARD_DEVICE* smartcard, wStream* s, Status_Return* ret)
{ {
Stream_Write_UINT32(s, ret->cBytes); /* cBytes (4 bytes) */ Stream_Write_UINT32(s, ret->cBytes); /* cBytes (4 bytes) */
@ -1290,6 +1468,47 @@ UINT32 smartcard_pack_status_return(SMARTCARD_DEVICE* smartcard, wStream* s, Sta
return SCARD_S_SUCCESS; return SCARD_S_SUCCESS;
} }
void smartcard_trace_status_return(SMARTCARD_DEVICE* smartcard, Status_Return* ret, BOOL unicode)
{
UINT32 index;
UINT32 length;
char* mszReaderNamesA = NULL;
if (unicode)
{
length = ret->cBytes / 2;
ConvertFromUnicode(CP_UTF8, 0, (WCHAR*) ret->mszReaderNames, length, &mszReaderNamesA, 0, NULL, NULL);
}
else
{
length = ret->cBytes;
mszReaderNamesA = (char*) malloc(length);
CopyMemory(mszReaderNamesA, ret->mszReaderNames, ret->cBytes);
}
for (index = 0; index < length - 2; index++)
{
if (mszReaderNamesA[index] == '\0')
mszReaderNamesA[index] = ',';
}
if (!WLog_IsLevelActive(smartcard->log, WLOG_DEBUG))
return;
WLog_Print(smartcard->log, WLOG_DEBUG, "Status%s_Return {", unicode ? "W" : "A");
WLog_Print(smartcard->log, WLOG_DEBUG, "ReturnCode: 0x%08X", ret->ReturnCode);
WLog_Print(smartcard->log, WLOG_DEBUG, "cBytes: %d dwState: 0x%08X dwProtocol: 0x%08X cbAtrLen: %d",
ret->cBytes, ret->dwState, ret->dwProtocol, ret->cbAtrLen);
WLog_Print(smartcard->log, WLOG_DEBUG, "mszReaderNames: %s", mszReaderNamesA);
WLog_Print(smartcard->log, WLOG_DEBUG, "}");
free(mszReaderNamesA);
}
UINT32 smartcard_unpack_get_attrib_call(SMARTCARD_DEVICE* smartcard, wStream* s, GetAttrib_Call* call) UINT32 smartcard_unpack_get_attrib_call(SMARTCARD_DEVICE* smartcard, wStream* s, GetAttrib_Call* call)
{ {
UINT32 status; UINT32 status;
@ -1318,6 +1537,42 @@ UINT32 smartcard_unpack_get_attrib_call(SMARTCARD_DEVICE* smartcard, wStream* s,
return SCARD_S_SUCCESS; return SCARD_S_SUCCESS;
} }
void smartcard_trace_get_attrib_call(SMARTCARD_DEVICE* smartcard, GetAttrib_Call* call)
{
if (!WLog_IsLevelActive(smartcard->log, WLOG_DEBUG))
return;
WLog_Print(smartcard->log, WLOG_DEBUG, "GetAttrib_Call {");
if (call->hCard.Context.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);
}
else
{
WLog_Print(smartcard->log, WLOG_DEBUG, "hContext: 0x%08X (%d)",
call->hCard.Context.pbContext.LowPart, call->hCard.Context.cbContext);
}
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);
}
else
{
WLog_Print(smartcard->log, WLOG_DEBUG, "hCard: 0x%08X (%d)",
call->hCard.pbHandle.LowPart, call->hCard.pbHandle);
}
WLog_Print(smartcard->log, WLOG_DEBUG, "dwAttrId: %s (0x%08X) fpbAttrIsNULL: %d cbAttrLen: 0x%08X",
SCardGetAttributeString(call->dwAttrId), call->dwAttrId, call->fpbAttrIsNULL, call->cbAttrLen);
WLog_Print(smartcard->log, WLOG_DEBUG, "}");
}
UINT32 smartcard_pack_get_attrib_return(SMARTCARD_DEVICE* smartcard, wStream* s, GetAttrib_Return* ret) UINT32 smartcard_pack_get_attrib_return(SMARTCARD_DEVICE* smartcard, wStream* s, GetAttrib_Return* ret)
{ {
Stream_Write_UINT32(s, ret->cbAttrLen); /* cbAttrLen (4 bytes) */ Stream_Write_UINT32(s, ret->cbAttrLen); /* cbAttrLen (4 bytes) */
@ -1334,6 +1589,26 @@ UINT32 smartcard_pack_get_attrib_return(SMARTCARD_DEVICE* smartcard, wStream* s,
return SCARD_S_SUCCESS; return SCARD_S_SUCCESS;
} }
void smartcard_trace_get_attrib_return(SMARTCARD_DEVICE* smartcard, GetAttrib_Return* ret, DWORD dwAttrId)
{
if (!WLog_IsLevelActive(smartcard->log, WLOG_DEBUG))
return;
WLog_Print(smartcard->log, WLOG_DEBUG, "GetAttrib_Return {");
WLog_Print(smartcard->log, WLOG_DEBUG, "ReturnCode: 0x%08X", ret->ReturnCode);
WLog_Print(smartcard->log, WLOG_DEBUG, "dwAttrId: %s (0x%08X) cbAttrLen: 0x%08X",
SCardGetAttributeString(dwAttrId), dwAttrId, ret->cbAttrLen);
if (dwAttrId == SCARD_ATTR_VENDOR_NAME)
{
WLog_Print(smartcard->log, WLOG_DEBUG, "pbAttr: %.*s", ret->cbAttrLen, (char*) ret->pbAttr);
}
WLog_Print(smartcard->log, WLOG_DEBUG, "}");
}
UINT32 smartcard_unpack_control_call(SMARTCARD_DEVICE* smartcard, wStream* s, Control_Call* call) UINT32 smartcard_unpack_control_call(SMARTCARD_DEVICE* smartcard, wStream* s, Control_Call* call)
{ {
UINT32 status; UINT32 status;

View File

@ -32,14 +32,14 @@
typedef struct _REDIR_SCARDCONTEXT typedef struct _REDIR_SCARDCONTEXT
{ {
/* [range] */ DWORD cbContext; /* [range] */ DWORD cbContext;
/* [size_is][unique] */ UINT64 pbContext; /* [size_is][unique] */ ULARGE_INTEGER pbContext;
} REDIR_SCARDCONTEXT; } REDIR_SCARDCONTEXT;
typedef struct _REDIR_SCARDHANDLE typedef struct _REDIR_SCARDHANDLE
{ {
REDIR_SCARDCONTEXT Context; REDIR_SCARDCONTEXT Context;
/* [range] */ DWORD cbHandle; /* [range] */ DWORD cbHandle;
/* [size_is] */ UINT64 pbHandle; /* [size_is] */ ULARGE_INTEGER pbHandle;
} REDIR_SCARDHANDLE; } REDIR_SCARDHANDLE;
typedef struct _Long_Return typedef struct _Long_Return
@ -420,12 +420,15 @@ typedef struct _WriteCacheW_Call
#define SMARTCARD_COMMON_TYPE_HEADER_LENGTH 8 #define SMARTCARD_COMMON_TYPE_HEADER_LENGTH 8
#define SMARTCARD_PRIVATE_TYPE_HEADER_LENGTH 8 #define SMARTCARD_PRIVATE_TYPE_HEADER_LENGTH 8
UINT32 smartcard_unpack_read_offset_align(SMARTCARD_DEVICE* smartcard, wStream* s, UINT32 alignment);
UINT32 smartcard_pack_write_offset_align(SMARTCARD_DEVICE* smartcard, wStream* s, UINT32 alignment);
UINT32 smartcard_pack_write_size_align(SMARTCARD_DEVICE* smartcard, wStream* s, UINT32 size, UINT32 alignment); UINT32 smartcard_pack_write_size_align(SMARTCARD_DEVICE* smartcard, wStream* s, UINT32 size, UINT32 alignment);
UINT32 smartcard_unpack_read_size_align(SMARTCARD_DEVICE* smartcard, wStream* s, UINT32 size, UINT32 alignment); UINT32 smartcard_unpack_read_size_align(SMARTCARD_DEVICE* smartcard, wStream* s, UINT32 size, UINT32 alignment);
SCARDCONTEXT smartcard_scard_context_native_from_redir(SMARTCARD_DEVICE* smartcard, REDIR_SCARDCONTEXT* context);
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);
UINT32 smartcard_unpack_common_type_header(SMARTCARD_DEVICE* smartcard, wStream* s); UINT32 smartcard_unpack_common_type_header(SMARTCARD_DEVICE* smartcard, wStream* s);
UINT32 smartcard_pack_common_type_header(SMARTCARD_DEVICE* smartcard, wStream* s); UINT32 smartcard_pack_common_type_header(SMARTCARD_DEVICE* smartcard, wStream* s);
@ -451,12 +454,13 @@ UINT32 smartcard_pack_establish_context_return(SMARTCARD_DEVICE* smartcard, wStr
void smartcard_trace_establish_context_return(SMARTCARD_DEVICE* smartcard, EstablishContext_Return* ret); void smartcard_trace_establish_context_return(SMARTCARD_DEVICE* smartcard, EstablishContext_Return* ret);
UINT32 smartcard_unpack_context_call(SMARTCARD_DEVICE* smartcard, wStream* s, Context_Call* call); UINT32 smartcard_unpack_context_call(SMARTCARD_DEVICE* smartcard, wStream* s, Context_Call* call);
void smartcard_trace_context_call(SMARTCARD_DEVICE* smartcard, Context_Call* call, const char* name);
UINT32 smartcard_unpack_list_readers_call(SMARTCARD_DEVICE* smartcard, wStream* s, ListReaders_Call* call); UINT32 smartcard_unpack_list_readers_call(SMARTCARD_DEVICE* smartcard, wStream* s, ListReaders_Call* call);
void smartcard_trace_list_readers_call(SMARTCARD_DEVICE* smartcard, ListReaders_Call* call); void smartcard_trace_list_readers_call(SMARTCARD_DEVICE* smartcard, ListReaders_Call* call, BOOL unicode);
UINT32 smartcard_pack_list_readers_return(SMARTCARD_DEVICE* smartcard, wStream* s, ListReaders_Return* ret); UINT32 smartcard_pack_list_readers_return(SMARTCARD_DEVICE* smartcard, wStream* s, ListReaders_Return* ret);
void smartcard_trace_list_readers_return(SMARTCARD_DEVICE* smartcard, ListReaders_Return* ret); void smartcard_trace_list_readers_return(SMARTCARD_DEVICE* smartcard, ListReaders_Return* ret, BOOL unicode);
UINT32 smartcard_unpack_connect_a_call(SMARTCARD_DEVICE* smartcard, wStream* s, ConnectA_Call* call); UINT32 smartcard_unpack_connect_a_call(SMARTCARD_DEVICE* smartcard, wStream* s, ConnectA_Call* call);
void smartcard_trace_connect_a_call(SMARTCARD_DEVICE* smartcard, ConnectA_Call* call); void smartcard_trace_connect_a_call(SMARTCARD_DEVICE* smartcard, ConnectA_Call* call);
@ -471,6 +475,7 @@ UINT32 smartcard_unpack_reconnect_call(SMARTCARD_DEVICE* smartcard, wStream* s,
UINT32 smartcard_pack_reconnect_return(SMARTCARD_DEVICE* smartcard, wStream* s, Reconnect_Return* ret); UINT32 smartcard_pack_reconnect_return(SMARTCARD_DEVICE* smartcard, wStream* s, Reconnect_Return* ret);
UINT32 smartcard_unpack_hcard_and_disposition_call(SMARTCARD_DEVICE* smartcard, wStream* s, HCardAndDisposition_Call* call); UINT32 smartcard_unpack_hcard_and_disposition_call(SMARTCARD_DEVICE* smartcard, wStream* s, HCardAndDisposition_Call* call);
void smartcard_trace_hcard_and_disposition_call(SMARTCARD_DEVICE* smartcard, HCardAndDisposition_Call* call, const char* name);
UINT32 smartcard_unpack_get_status_change_a_call(SMARTCARD_DEVICE* smartcard, wStream* s, GetStatusChangeA_Call* call); UINT32 smartcard_unpack_get_status_change_a_call(SMARTCARD_DEVICE* smartcard, wStream* s, GetStatusChangeA_Call* call);
void smartcard_trace_get_status_change_a_call(SMARTCARD_DEVICE* smartcard, GetStatusChangeA_Call* call); void smartcard_trace_get_status_change_a_call(SMARTCARD_DEVICE* smartcard, GetStatusChangeA_Call* call);
@ -485,10 +490,16 @@ UINT32 smartcard_unpack_state_call(SMARTCARD_DEVICE* smartcard, wStream* s, Stat
UINT32 smartcard_pack_state_return(SMARTCARD_DEVICE* smartcard, wStream* s, State_Return* ret); UINT32 smartcard_pack_state_return(SMARTCARD_DEVICE* smartcard, wStream* s, State_Return* ret);
UINT32 smartcard_unpack_status_call(SMARTCARD_DEVICE* smartcard, wStream* s, Status_Call* call); UINT32 smartcard_unpack_status_call(SMARTCARD_DEVICE* smartcard, wStream* s, Status_Call* call);
void smartcard_trace_status_call(SMARTCARD_DEVICE* smartcard, Status_Call* call, BOOL unicode);
UINT32 smartcard_pack_status_return(SMARTCARD_DEVICE* smartcard, wStream* s, Status_Return* ret); UINT32 smartcard_pack_status_return(SMARTCARD_DEVICE* smartcard, wStream* s, Status_Return* ret);
void smartcard_trace_status_return(SMARTCARD_DEVICE* smartcard, Status_Return* ret, BOOL unicode);
UINT32 smartcard_unpack_get_attrib_call(SMARTCARD_DEVICE* smartcard, wStream* s, GetAttrib_Call* call); UINT32 smartcard_unpack_get_attrib_call(SMARTCARD_DEVICE* smartcard, wStream* s, GetAttrib_Call* call);
void smartcard_trace_get_attrib_call(SMARTCARD_DEVICE* smartcard, GetAttrib_Call* call);
UINT32 smartcard_pack_get_attrib_return(SMARTCARD_DEVICE* smartcard, wStream* s, GetAttrib_Return* ret); UINT32 smartcard_pack_get_attrib_return(SMARTCARD_DEVICE* smartcard, wStream* s, GetAttrib_Return* ret);
void smartcard_trace_get_attrib_return(SMARTCARD_DEVICE* smartcard, GetAttrib_Return* ret, DWORD dwAttrId);
UINT32 smartcard_unpack_control_call(SMARTCARD_DEVICE* smartcard, wStream* s, Control_Call* call); UINT32 smartcard_unpack_control_call(SMARTCARD_DEVICE* smartcard, wStream* s, Control_Call* call);
UINT32 smartcard_pack_control_return(SMARTCARD_DEVICE* smartcard, wStream* s, Control_Return* ret); UINT32 smartcard_pack_control_return(SMARTCARD_DEVICE* smartcard, wStream* s, Control_Return* ret);