mirror of
https://github.com/morgan9e/FreeRDP
synced 2026-04-14 00:14:11 +09:00
[utils,smartcard] better logging and error checks
* Use wLog as argument where possible to reduce the number of WLog_Get calls * Do better failure checks to avoid reading invalid memory
This commit is contained in:
@@ -51,6 +51,17 @@ extern "C"
|
||||
FREERDP_API const char* rdpdr_cap_type_string(UINT16 capability);
|
||||
|
||||
FREERDP_API LONG scard_log_status_error(const char* tag, const char* what, LONG status);
|
||||
|
||||
/** @brief log a smartcard related issue with a wLog
|
||||
*
|
||||
* @param log The logger to use
|
||||
* @param what The module affected
|
||||
* @param status The status to log
|
||||
*
|
||||
* @return The \ref status logged
|
||||
* @since version 3.16.0
|
||||
*/
|
||||
FREERDP_API LONG scard_log_status_error_wlog(wLog* log, const char* what, LONG status);
|
||||
FREERDP_API const char* scard_get_ioctl_string(UINT32 ioControlCode, BOOL funcName);
|
||||
|
||||
FREERDP_API BOOL rdpdr_write_iocompletion_header(wStream* out, UINT32 DeviceId,
|
||||
|
||||
@@ -32,6 +32,7 @@ set(${MODULE_PREFIX}_SRCS
|
||||
gfx.c
|
||||
drdynvc.c
|
||||
smartcard_operations.c
|
||||
smartcard_pack.h
|
||||
smartcard_pack.c
|
||||
smartcard_call.c
|
||||
stopwatch.c
|
||||
|
||||
@@ -29,6 +29,12 @@
|
||||
#include <freerdp/log.h>
|
||||
|
||||
LONG scard_log_status_error(const char* tag, const char* what, LONG status)
|
||||
{
|
||||
wLog* log = WLog_Get(tag);
|
||||
return scard_log_status_error_wlog(log, what, status);
|
||||
}
|
||||
|
||||
LONG scard_log_status_error_wlog(wLog* log, const char* what, LONG status)
|
||||
{
|
||||
if (status != SCARD_S_SUCCESS)
|
||||
{
|
||||
@@ -44,7 +50,7 @@ LONG scard_log_status_error(const char* tag, const char* what, LONG status)
|
||||
default:
|
||||
break;
|
||||
}
|
||||
WLog_Print(WLog_Get(tag), level, "%s failed with error %s [%" PRId32 "]", what,
|
||||
WLog_Print(log, level, "%s failed with error %s [%" PRId32 "]", what,
|
||||
SCardGetErrorString(status), status);
|
||||
}
|
||||
return status;
|
||||
|
||||
@@ -41,8 +41,10 @@
|
||||
#include <freerdp/utils/smartcard_pack.h>
|
||||
#include <freerdp/utils/smartcard_call.h>
|
||||
|
||||
#include "smartcard_pack.h"
|
||||
|
||||
#include <freerdp/log.h>
|
||||
#define TAG FREERDP_TAG("utils.smartcard.call")
|
||||
#define SCARD_TAG FREERDP_TAG("utils.smartcard.call")
|
||||
|
||||
#if defined(WITH_SMARTCARD_EMULATE)
|
||||
#include <freerdp/emulate/scard/smartcard_emulate.h>
|
||||
@@ -75,6 +77,7 @@ struct s_scard_call_context
|
||||
|
||||
void* (*fn_new)(void*, SCARDCONTEXT);
|
||||
void (*fn_free)(void*);
|
||||
wLog* log;
|
||||
};
|
||||
|
||||
struct s_scard_context_element
|
||||
@@ -117,14 +120,14 @@ static LONG smartcard_EstablishContext_Call(scard_call_context* smartcard, wStre
|
||||
|
||||
if (!HashTable_Insert(smartcard->rgSCardContextList, key, (void*)pContext))
|
||||
{
|
||||
WLog_ERR(TAG, "ListDictionary_Add failed!");
|
||||
WLog_Print(smartcard->log, WLOG_ERROR, "ListDictionary_Add failed!");
|
||||
context_free(pContext);
|
||||
return STATUS_INTERNAL_ERROR;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return scard_log_status_error(TAG, "SCardEstablishContext", status);
|
||||
return scard_log_status_error_wlog(smartcard->log, "SCardEstablishContext", status);
|
||||
}
|
||||
|
||||
// NOLINTNEXTLINE(clang-analyzer-unix.Malloc): HashTable_Insert takes ownership of pContext
|
||||
@@ -133,7 +136,8 @@ static LONG smartcard_EstablishContext_Call(scard_call_context* smartcard, wStre
|
||||
status = smartcard_pack_establish_context_return(out, &ret);
|
||||
if (status != SCARD_S_SUCCESS)
|
||||
{
|
||||
return scard_log_status_error(TAG, "smartcard_pack_establish_context_return", status);
|
||||
return scard_log_status_error_wlog(smartcard->log,
|
||||
"smartcard_pack_establish_context_return", status);
|
||||
}
|
||||
|
||||
return ret.ReturnCode;
|
||||
@@ -155,10 +159,10 @@ static LONG smartcard_ReleaseContext_Call(scard_call_context* smartcard,
|
||||
HashTable_Remove(smartcard->rgSCardContextList, (void*)operation->hContext);
|
||||
else
|
||||
{
|
||||
return scard_log_status_error(TAG, "SCardReleaseContext", ret.ReturnCode);
|
||||
return scard_log_status_error_wlog(smartcard->log, "SCardReleaseContext", ret.ReturnCode);
|
||||
}
|
||||
|
||||
smartcard_trace_long_return(&ret, "ReleaseContext");
|
||||
smartcard_trace_long_return_int(smartcard->log, &ret, "ReleaseContext");
|
||||
return ret.ReturnCode;
|
||||
}
|
||||
|
||||
@@ -173,7 +177,7 @@ static LONG smartcard_IsValidContext_Call(scard_call_context* smartcard,
|
||||
WINPR_ASSERT(operation);
|
||||
|
||||
ret.ReturnCode = wrap(smartcard, SCardIsValidContext, operation->hContext);
|
||||
smartcard_trace_long_return(&ret, "IsValidContext");
|
||||
smartcard_trace_long_return_int(smartcard->log, &ret, "IsValidContext");
|
||||
return ret.ReturnCode;
|
||||
}
|
||||
|
||||
@@ -356,7 +360,7 @@ static LONG smartcard_ListReadersA_Call(scard_call_context* smartcard, wStream*
|
||||
|
||||
if (status != SCARD_S_SUCCESS)
|
||||
{
|
||||
(void)scard_log_status_error(TAG, "SCardListReadersA", status);
|
||||
(void)scard_log_status_error_wlog(smartcard->log, "SCardListReadersA", status);
|
||||
return smartcard_pack_list_readers_return(out, &ret, FALSE);
|
||||
}
|
||||
|
||||
@@ -369,7 +373,8 @@ static LONG smartcard_ListReadersA_Call(scard_call_context* smartcard, wStream*
|
||||
wrap(smartcard, SCardFreeMemory, operation->hContext, mszReaders);
|
||||
|
||||
if (status != SCARD_S_SUCCESS)
|
||||
return scard_log_status_error(TAG, "smartcard_pack_list_readers_return", status);
|
||||
return scard_log_status_error_wlog(smartcard->log, "smartcard_pack_list_readers_return",
|
||||
status);
|
||||
|
||||
return ret.ReturnCode;
|
||||
}
|
||||
@@ -412,7 +417,7 @@ static LONG smartcard_ListReadersW_Call(scard_call_context* smartcard, wStream*
|
||||
|
||||
if (status != SCARD_S_SUCCESS)
|
||||
{
|
||||
(void)scard_log_status_error(TAG, "SCardListReadersW", status);
|
||||
(void)scard_log_status_error_wlog(smartcard->log, "SCardListReadersW", status);
|
||||
return smartcard_pack_list_readers_return(out, &ret, TRUE);
|
||||
}
|
||||
|
||||
@@ -443,8 +448,8 @@ static LONG smartcard_IntroduceReaderGroupA_Call(scard_call_context* smartcard,
|
||||
|
||||
call = &operation->call.contextAndStringA;
|
||||
ret.ReturnCode = wrap(smartcard, SCardIntroduceReaderGroupA, operation->hContext, call->sz);
|
||||
scard_log_status_error(TAG, "SCardIntroduceReaderGroupA", ret.ReturnCode);
|
||||
smartcard_trace_long_return(&ret, "IntroduceReaderGroupA");
|
||||
scard_log_status_error_wlog(smartcard->log, "SCardIntroduceReaderGroupA", ret.ReturnCode);
|
||||
smartcard_trace_long_return_int(smartcard->log, &ret, "IntroduceReaderGroupA");
|
||||
return ret.ReturnCode;
|
||||
}
|
||||
|
||||
@@ -461,8 +466,8 @@ static LONG smartcard_IntroduceReaderGroupW_Call(scard_call_context* smartcard,
|
||||
|
||||
call = &operation->call.contextAndStringW;
|
||||
ret.ReturnCode = wrap(smartcard, SCardIntroduceReaderGroupW, operation->hContext, call->sz);
|
||||
scard_log_status_error(TAG, "SCardIntroduceReaderGroupW", ret.ReturnCode);
|
||||
smartcard_trace_long_return(&ret, "IntroduceReaderGroupW");
|
||||
scard_log_status_error_wlog(smartcard->log, "SCardIntroduceReaderGroupW", ret.ReturnCode);
|
||||
smartcard_trace_long_return_int(smartcard->log, &ret, "IntroduceReaderGroupW");
|
||||
return ret.ReturnCode;
|
||||
}
|
||||
|
||||
@@ -480,8 +485,8 @@ static LONG smartcard_IntroduceReaderA_Call(scard_call_context* smartcard,
|
||||
call = &operation->call.contextAndTwoStringA;
|
||||
ret.ReturnCode =
|
||||
wrap(smartcard, SCardIntroduceReaderA, operation->hContext, call->sz1, call->sz2);
|
||||
scard_log_status_error(TAG, "SCardIntroduceReaderA", ret.ReturnCode);
|
||||
smartcard_trace_long_return(&ret, "IntroduceReaderA");
|
||||
scard_log_status_error_wlog(smartcard->log, "SCardIntroduceReaderA", ret.ReturnCode);
|
||||
smartcard_trace_long_return_int(smartcard->log, &ret, "IntroduceReaderA");
|
||||
return ret.ReturnCode;
|
||||
}
|
||||
|
||||
@@ -499,8 +504,8 @@ static LONG smartcard_IntroduceReaderW_Call(scard_call_context* smartcard,
|
||||
call = &operation->call.contextAndTwoStringW;
|
||||
ret.ReturnCode =
|
||||
wrap(smartcard, SCardIntroduceReaderW, operation->hContext, call->sz1, call->sz2);
|
||||
scard_log_status_error(TAG, "SCardIntroduceReaderW", ret.ReturnCode);
|
||||
smartcard_trace_long_return(&ret, "IntroduceReaderW");
|
||||
scard_log_status_error_wlog(smartcard->log, "SCardIntroduceReaderW", ret.ReturnCode);
|
||||
smartcard_trace_long_return_int(smartcard->log, &ret, "IntroduceReaderW");
|
||||
return ret.ReturnCode;
|
||||
}
|
||||
|
||||
@@ -517,8 +522,8 @@ static LONG smartcard_ForgetReaderA_Call(scard_call_context* smartcard,
|
||||
|
||||
call = &operation->call.contextAndStringA;
|
||||
ret.ReturnCode = wrap(smartcard, SCardForgetReaderA, operation->hContext, call->sz);
|
||||
scard_log_status_error(TAG, "SCardForgetReaderA", ret.ReturnCode);
|
||||
smartcard_trace_long_return(&ret, "SCardForgetReaderA");
|
||||
scard_log_status_error_wlog(smartcard->log, "SCardForgetReaderA", ret.ReturnCode);
|
||||
smartcard_trace_long_return_int(smartcard->log, &ret, "SCardForgetReaderA");
|
||||
return ret.ReturnCode;
|
||||
}
|
||||
|
||||
@@ -535,8 +540,8 @@ static LONG smartcard_ForgetReaderW_Call(scard_call_context* smartcard,
|
||||
|
||||
call = &operation->call.contextAndStringW;
|
||||
ret.ReturnCode = wrap(smartcard, SCardForgetReaderW, operation->hContext, call->sz);
|
||||
scard_log_status_error(TAG, "SCardForgetReaderW", ret.ReturnCode);
|
||||
smartcard_trace_long_return(&ret, "SCardForgetReaderW");
|
||||
scard_log_status_error_wlog(smartcard->log, "SCardForgetReaderW", ret.ReturnCode);
|
||||
smartcard_trace_long_return_int(smartcard->log, &ret, "SCardForgetReaderW");
|
||||
return ret.ReturnCode;
|
||||
}
|
||||
|
||||
@@ -554,8 +559,8 @@ static LONG smartcard_AddReaderToGroupA_Call(scard_call_context* smartcard,
|
||||
call = &operation->call.contextAndTwoStringA;
|
||||
ret.ReturnCode =
|
||||
wrap(smartcard, SCardAddReaderToGroupA, operation->hContext, call->sz1, call->sz2);
|
||||
scard_log_status_error(TAG, "SCardAddReaderToGroupA", ret.ReturnCode);
|
||||
smartcard_trace_long_return(&ret, "SCardAddReaderToGroupA");
|
||||
scard_log_status_error_wlog(smartcard->log, "SCardAddReaderToGroupA", ret.ReturnCode);
|
||||
smartcard_trace_long_return_int(smartcard->log, &ret, "SCardAddReaderToGroupA");
|
||||
return ret.ReturnCode;
|
||||
}
|
||||
|
||||
@@ -573,8 +578,8 @@ static LONG smartcard_AddReaderToGroupW_Call(scard_call_context* smartcard,
|
||||
call = &operation->call.contextAndTwoStringW;
|
||||
ret.ReturnCode =
|
||||
wrap(smartcard, SCardAddReaderToGroupW, operation->hContext, call->sz1, call->sz2);
|
||||
scard_log_status_error(TAG, "SCardAddReaderToGroupW", ret.ReturnCode);
|
||||
smartcard_trace_long_return(&ret, "SCardAddReaderToGroupA");
|
||||
scard_log_status_error_wlog(smartcard->log, "SCardAddReaderToGroupW", ret.ReturnCode);
|
||||
smartcard_trace_long_return_int(smartcard->log, &ret, "SCardAddReaderToGroupA");
|
||||
return ret.ReturnCode;
|
||||
}
|
||||
|
||||
@@ -592,8 +597,8 @@ static LONG smartcard_RemoveReaderFromGroupA_Call(scard_call_context* smartcard,
|
||||
call = &operation->call.contextAndTwoStringA;
|
||||
ret.ReturnCode =
|
||||
wrap(smartcard, SCardRemoveReaderFromGroupA, operation->hContext, call->sz1, call->sz2);
|
||||
scard_log_status_error(TAG, "SCardRemoveReaderFromGroupA", ret.ReturnCode);
|
||||
smartcard_trace_long_return(&ret, "SCardRemoveReaderFromGroupA");
|
||||
scard_log_status_error_wlog(smartcard->log, "SCardRemoveReaderFromGroupA", ret.ReturnCode);
|
||||
smartcard_trace_long_return_int(smartcard->log, &ret, "SCardRemoveReaderFromGroupA");
|
||||
return ret.ReturnCode;
|
||||
}
|
||||
|
||||
@@ -611,8 +616,8 @@ static LONG smartcard_RemoveReaderFromGroupW_Call(scard_call_context* smartcard,
|
||||
call = &operation->call.contextAndTwoStringW;
|
||||
ret.ReturnCode =
|
||||
wrap(smartcard, SCardRemoveReaderFromGroupW, operation->hContext, call->sz1, call->sz2);
|
||||
scard_log_status_error(TAG, "SCardRemoveReaderFromGroupW", ret.ReturnCode);
|
||||
smartcard_trace_long_return(&ret, "SCardRemoveReaderFromGroupW");
|
||||
scard_log_status_error_wlog(smartcard->log, "SCardRemoveReaderFromGroupW", ret.ReturnCode);
|
||||
smartcard_trace_long_return_int(smartcard->log, &ret, "SCardRemoveReaderFromGroupW");
|
||||
return ret.ReturnCode;
|
||||
}
|
||||
|
||||
@@ -630,7 +635,7 @@ static LONG smartcard_LocateCardsA_Call(scard_call_context* smartcard, wStream*
|
||||
|
||||
ret.ReturnCode = wrap(smartcard, SCardLocateCardsA, operation->hContext, call->mszCards,
|
||||
call->rgReaderStates, call->cReaders);
|
||||
scard_log_status_error(TAG, "SCardLocateCardsA", ret.ReturnCode);
|
||||
scard_log_status_error_wlog(smartcard->log, "SCardLocateCardsA", ret.ReturnCode);
|
||||
ret.cReaders = call->cReaders;
|
||||
ret.rgReaderStates = NULL;
|
||||
|
||||
@@ -673,7 +678,7 @@ static LONG smartcard_LocateCardsW_Call(scard_call_context* smartcard, wStream*
|
||||
|
||||
ret.ReturnCode = wrap(smartcard, SCardLocateCardsW, operation->hContext, call->mszCards,
|
||||
call->rgReaderStates, call->cReaders);
|
||||
scard_log_status_error(TAG, "SCardLocateCardsW", ret.ReturnCode);
|
||||
scard_log_status_error_wlog(smartcard->log, "SCardLocateCardsW", ret.ReturnCode);
|
||||
ret.cReaders = call->cReaders;
|
||||
ret.rgReaderStates = NULL;
|
||||
|
||||
@@ -739,7 +744,7 @@ static LONG smartcard_ReadCacheA_Call(scard_call_context* smartcard, wStream* ou
|
||||
if ((ret.ReturnCode != SCARD_W_CACHE_ITEM_NOT_FOUND) &&
|
||||
(ret.ReturnCode != SCARD_W_CACHE_ITEM_STALE))
|
||||
{
|
||||
scard_log_status_error(TAG, "SCardReadCacheA", ret.ReturnCode);
|
||||
scard_log_status_error_wlog(smartcard->log, "SCardReadCacheA", ret.ReturnCode);
|
||||
}
|
||||
|
||||
status = smartcard_pack_read_cache_return(out, &ret);
|
||||
@@ -776,7 +781,7 @@ static LONG smartcard_ReadCacheW_Call(scard_call_context* smartcard, wStream* ou
|
||||
if ((ret.ReturnCode != SCARD_W_CACHE_ITEM_NOT_FOUND) &&
|
||||
(ret.ReturnCode != SCARD_W_CACHE_ITEM_STALE))
|
||||
{
|
||||
scard_log_status_error(TAG, "SCardReadCacheW", ret.ReturnCode);
|
||||
scard_log_status_error_wlog(smartcard->log, "SCardReadCacheW", ret.ReturnCode);
|
||||
}
|
||||
|
||||
status = smartcard_pack_read_cache_return(out, &ret);
|
||||
@@ -805,8 +810,8 @@ static LONG smartcard_WriteCacheA_Call(scard_call_context* smartcard,
|
||||
ret.ReturnCode = wrap(smartcard, SCardWriteCacheA, operation->hContext,
|
||||
call->Common.CardIdentifier, call->Common.FreshnessCounter,
|
||||
call->szLookupName, call->Common.pbData, call->Common.cbDataLen);
|
||||
scard_log_status_error(TAG, "SCardWriteCacheA", ret.ReturnCode);
|
||||
smartcard_trace_long_return(&ret, "SCardWriteCacheA");
|
||||
scard_log_status_error_wlog(smartcard->log, "SCardWriteCacheA", ret.ReturnCode);
|
||||
smartcard_trace_long_return_int(smartcard->log, &ret, "SCardWriteCacheA");
|
||||
return ret.ReturnCode;
|
||||
}
|
||||
|
||||
@@ -826,8 +831,8 @@ static LONG smartcard_WriteCacheW_Call(scard_call_context* smartcard,
|
||||
ret.ReturnCode = wrap(smartcard, SCardWriteCacheW, operation->hContext,
|
||||
call->Common.CardIdentifier, call->Common.FreshnessCounter,
|
||||
call->szLookupName, call->Common.pbData, call->Common.cbDataLen);
|
||||
scard_log_status_error(TAG, "SCardWriteCacheW", ret.ReturnCode);
|
||||
smartcard_trace_long_return(&ret, "SCardWriteCacheW");
|
||||
scard_log_status_error_wlog(smartcard->log, "SCardWriteCacheW", ret.ReturnCode);
|
||||
smartcard_trace_long_return_int(smartcard->log, &ret, "SCardWriteCacheW");
|
||||
return ret.ReturnCode;
|
||||
}
|
||||
|
||||
@@ -842,7 +847,7 @@ static LONG smartcard_GetTransmitCount_Call(scard_call_context* smartcard, wStre
|
||||
WINPR_ASSERT(operation);
|
||||
|
||||
ret.ReturnCode = wrap(smartcard, SCardGetTransmitCount, operation->hCard, &ret.cTransmitCount);
|
||||
scard_log_status_error(TAG, "SCardGetTransmitCount", ret.ReturnCode);
|
||||
scard_log_status_error_wlog(smartcard->log, "SCardGetTransmitCount", ret.ReturnCode);
|
||||
status = smartcard_pack_get_transmit_count_return(out, &ret);
|
||||
if (status != SCARD_S_SUCCESS)
|
||||
return status;
|
||||
@@ -857,8 +862,9 @@ static LONG smartcard_ReleaseStartedEvent_Call(scard_call_context* smartcard, wS
|
||||
WINPR_UNUSED(out);
|
||||
WINPR_UNUSED(operation);
|
||||
|
||||
WLog_WARN(TAG, "According to [MS-RDPESC] 3.1.4 Message Processing Events and Sequencing Rules "
|
||||
"this is not supported?!?");
|
||||
WLog_Print(smartcard->log, WLOG_WARN,
|
||||
"According to [MS-RDPESC] 3.1.4 Message Processing Events and Sequencing Rules "
|
||||
"this is not supported?!?");
|
||||
return SCARD_E_UNSUPPORTED_FEATURE;
|
||||
}
|
||||
|
||||
@@ -878,7 +884,7 @@ static LONG smartcard_GetReaderIcon_Call(scard_call_context* smartcard, wStream*
|
||||
ret.cbDataLen = SCARD_AUTOALLOCATE;
|
||||
ret.ReturnCode = wrap(smartcard, SCardGetReaderIconW, operation->hContext, call->szReaderName,
|
||||
(LPBYTE)&ret.pbData, &ret.cbDataLen);
|
||||
scard_log_status_error(TAG, "SCardGetReaderIconW", ret.ReturnCode);
|
||||
scard_log_status_error_wlog(smartcard->log, "SCardGetReaderIconW", ret.ReturnCode);
|
||||
if ((ret.ReturnCode == SCARD_S_SUCCESS) && (ret.cbDataLen == SCARD_AUTOALLOCATE))
|
||||
return SCARD_F_UNKNOWN_ERROR;
|
||||
|
||||
@@ -905,7 +911,7 @@ static LONG smartcard_GetDeviceTypeId_Call(scard_call_context* smartcard, wStrea
|
||||
|
||||
ret.ReturnCode = wrap(smartcard, SCardGetDeviceTypeIdW, operation->hContext, call->szReaderName,
|
||||
&ret.dwDeviceId);
|
||||
scard_log_status_error(TAG, "SCardGetDeviceTypeIdW", ret.ReturnCode);
|
||||
scard_log_status_error_wlog(smartcard->log, "SCardGetDeviceTypeIdW", ret.ReturnCode);
|
||||
|
||||
status = smartcard_pack_device_type_id_return(out, &ret);
|
||||
if (status != SCARD_S_SUCCESS)
|
||||
@@ -954,7 +960,7 @@ static LONG smartcard_GetStatusChangeA_Call(scard_call_context* smartcard, wStre
|
||||
if (dwTimeOut != INFINITE)
|
||||
x += dwTimeStep;
|
||||
}
|
||||
scard_log_status_error(TAG, "SCardGetStatusChangeA", ret.ReturnCode);
|
||||
scard_log_status_error_wlog(smartcard->log, "SCardGetStatusChangeA", ret.ReturnCode);
|
||||
|
||||
for (UINT32 index = 0; index < ret.cReaders; index++)
|
||||
{
|
||||
@@ -1017,7 +1023,7 @@ static LONG smartcard_GetStatusChangeW_Call(scard_call_context* smartcard, wStre
|
||||
if (dwTimeOut != INFINITE)
|
||||
x += dwTimeStep;
|
||||
}
|
||||
scard_log_status_error(TAG, "SCardGetStatusChangeW", ret.ReturnCode);
|
||||
scard_log_status_error_wlog(smartcard->log, "SCardGetStatusChangeW", ret.ReturnCode);
|
||||
|
||||
for (UINT32 index = 0; index < ret.cReaders; index++)
|
||||
{
|
||||
@@ -1049,8 +1055,8 @@ static LONG smartcard_Cancel_Call(scard_call_context* smartcard, WINPR_ATTR_UNUS
|
||||
WINPR_ASSERT(operation);
|
||||
|
||||
ret.ReturnCode = wrap(smartcard, SCardCancel, operation->hContext);
|
||||
scard_log_status_error(TAG, "SCardCancel", ret.ReturnCode);
|
||||
smartcard_trace_long_return(&ret, "Cancel");
|
||||
scard_log_status_error_wlog(smartcard->log, "SCardCancel", ret.ReturnCode);
|
||||
smartcard_trace_long_return_int(smartcard->log, &ret, "Cancel");
|
||||
return ret.ReturnCode;
|
||||
}
|
||||
|
||||
@@ -1141,7 +1147,7 @@ static LONG smartcard_Reconnect_Call(scard_call_context* smartcard, wStream* out
|
||||
ret.ReturnCode =
|
||||
wrap(smartcard, SCardReconnect, operation->hCard, call->dwShareMode,
|
||||
call->dwPreferredProtocols, call->dwInitialization, &ret.dwActiveProtocol);
|
||||
scard_log_status_error(TAG, "SCardReconnect", ret.ReturnCode);
|
||||
scard_log_status_error_wlog(smartcard->log, "SCardReconnect", ret.ReturnCode);
|
||||
status = smartcard_pack_reconnect_return(out, &ret);
|
||||
if (status != SCARD_S_SUCCESS)
|
||||
return status;
|
||||
@@ -1162,8 +1168,8 @@ static LONG smartcard_Disconnect_Call(scard_call_context* smartcard, WINPR_ATTR_
|
||||
call = &operation->call.hCardAndDisposition;
|
||||
|
||||
ret.ReturnCode = wrap(smartcard, SCardDisconnect, operation->hCard, call->dwDisposition);
|
||||
scard_log_status_error(TAG, "SCardDisconnect", ret.ReturnCode);
|
||||
smartcard_trace_long_return(&ret, "Disconnect");
|
||||
scard_log_status_error_wlog(smartcard->log, "SCardDisconnect", ret.ReturnCode);
|
||||
smartcard_trace_long_return_int(smartcard->log, &ret, "Disconnect");
|
||||
|
||||
return ret.ReturnCode;
|
||||
}
|
||||
@@ -1179,8 +1185,8 @@ static LONG smartcard_BeginTransaction_Call(scard_call_context* smartcard,
|
||||
WINPR_ASSERT(operation);
|
||||
|
||||
ret.ReturnCode = wrap(smartcard, SCardBeginTransaction, operation->hCard);
|
||||
scard_log_status_error(TAG, "SCardBeginTransaction", ret.ReturnCode);
|
||||
smartcard_trace_long_return(&ret, "BeginTransaction");
|
||||
scard_log_status_error_wlog(smartcard->log, "SCardBeginTransaction", ret.ReturnCode);
|
||||
smartcard_trace_long_return_int(smartcard->log, &ret, "BeginTransaction");
|
||||
return ret.ReturnCode;
|
||||
}
|
||||
|
||||
@@ -1198,8 +1204,8 @@ static LONG smartcard_EndTransaction_Call(scard_call_context* smartcard,
|
||||
call = &operation->call.hCardAndDisposition;
|
||||
|
||||
ret.ReturnCode = wrap(smartcard, SCardEndTransaction, operation->hCard, call->dwDisposition);
|
||||
scard_log_status_error(TAG, "SCardEndTransaction", ret.ReturnCode);
|
||||
smartcard_trace_long_return(&ret, "EndTransaction");
|
||||
scard_log_status_error_wlog(smartcard->log, "SCardEndTransaction", ret.ReturnCode);
|
||||
smartcard_trace_long_return_int(smartcard->log, &ret, "EndTransaction");
|
||||
return ret.ReturnCode;
|
||||
}
|
||||
|
||||
@@ -1217,7 +1223,7 @@ static LONG smartcard_State_Call(scard_call_context* smartcard, wStream* out,
|
||||
ret.ReturnCode = wrap(smartcard, SCardState, operation->hCard, &ret.dwState, &ret.dwProtocol,
|
||||
(BYTE*)&ret.rgAtr, &ret.cbAtrLen);
|
||||
|
||||
scard_log_status_error(TAG, "SCardState", ret.ReturnCode);
|
||||
scard_log_status_error_wlog(smartcard->log, "SCardState", ret.ReturnCode);
|
||||
status = smartcard_pack_state_return(out, &ret);
|
||||
if (status != SCARD_S_SUCCESS)
|
||||
return status;
|
||||
@@ -1254,7 +1260,7 @@ static LONG smartcard_StatusA_Call(scard_call_context* smartcard, wStream* out,
|
||||
call->fmszReaderNamesIsNULL ? NULL : (LPSTR)&mszReaderNames, &cchReaderLen,
|
||||
&ret.dwState, &ret.dwProtocol, cbAtrLen ? (BYTE*)&ret.pbAtr : NULL, &cbAtrLen);
|
||||
|
||||
scard_log_status_error(TAG, "SCardStatusA", status);
|
||||
scard_log_status_error_wlog(smartcard->log, "SCardStatusA", status);
|
||||
if ((ret.ReturnCode == SCARD_S_SUCCESS) && (cchReaderLen == SCARD_AUTOALLOCATE))
|
||||
return SCARD_F_UNKNOWN_ERROR;
|
||||
|
||||
@@ -1309,7 +1315,7 @@ static LONG smartcard_StatusW_Call(scard_call_context* smartcard, wStream* out,
|
||||
wrap(smartcard, SCardStatusW, operation->hCard,
|
||||
call->fmszReaderNamesIsNULL ? NULL : (LPWSTR)&mszReaderNames, &ret.cBytes,
|
||||
&ret.dwState, &ret.dwProtocol, (BYTE*)&ret.pbAtr, &cbAtrLen);
|
||||
scard_log_status_error(TAG, "SCardStatusW", status);
|
||||
scard_log_status_error_wlog(smartcard->log, "SCardStatusW", status);
|
||||
if ((ret.ReturnCode == SCARD_S_SUCCESS) && (ret.cBytes == SCARD_AUTOALLOCATE))
|
||||
return SCARD_F_UNKNOWN_ERROR;
|
||||
|
||||
@@ -1369,7 +1375,7 @@ static LONG smartcard_Transmit_Call(scard_call_context* smartcard, wStream* out,
|
||||
wrap(smartcard, SCardTransmit, operation->hCard, call->pioSendPci, call->pbSendBuffer,
|
||||
call->cbSendLength, ret.pioRecvPci, ret.pbRecvBuffer, &(ret.cbRecvLength));
|
||||
|
||||
scard_log_status_error(TAG, "SCardTransmit", ret.ReturnCode);
|
||||
scard_log_status_error_wlog(smartcard->log, "SCardTransmit", ret.ReturnCode);
|
||||
|
||||
status = smartcard_pack_transmit_return(out, &ret);
|
||||
free(ret.pbRecvBuffer);
|
||||
@@ -1400,7 +1406,7 @@ static LONG smartcard_Control_Call(scard_call_context* smartcard, wStream* out,
|
||||
ret.ReturnCode =
|
||||
wrap(smartcard, SCardControl, operation->hCard, call->dwControlCode, call->pvInBuffer,
|
||||
call->cbInBufferSize, ret.pvOutBuffer, call->cbOutBufferSize, &ret.cbOutBufferSize);
|
||||
scard_log_status_error(TAG, "SCardControl", ret.ReturnCode);
|
||||
scard_log_status_error_wlog(smartcard->log, "SCardControl", ret.ReturnCode);
|
||||
status = smartcard_pack_control_return(out, &ret);
|
||||
|
||||
free(ret.pvOutBuffer);
|
||||
@@ -1441,7 +1447,7 @@ static LONG smartcard_GetAttrib_Call(scard_call_context* smartcard, wStream* out
|
||||
|
||||
ret.ReturnCode =
|
||||
wrap(smartcard, SCardGetAttrib, operation->hCard, call->dwAttrId, pbAttr, &cbAttrLen);
|
||||
scard_log_status_error(TAG, "SCardGetAttrib", ret.ReturnCode);
|
||||
scard_log_status_error_wlog(smartcard->log, "SCardGetAttrib", ret.ReturnCode);
|
||||
if ((ret.ReturnCode == SCARD_S_SUCCESS) && (cbAttrLen == SCARD_AUTOALLOCATE))
|
||||
return SCARD_F_UNKNOWN_ERROR;
|
||||
|
||||
@@ -1470,8 +1476,8 @@ static LONG smartcard_SetAttrib_Call(scard_call_context* smartcard, WINPR_ATTR_U
|
||||
|
||||
ret.ReturnCode = wrap(smartcard, SCardSetAttrib, operation->hCard, call->dwAttrId, call->pbAttr,
|
||||
call->cbAttrLen);
|
||||
scard_log_status_error(TAG, "SCardSetAttrib", ret.ReturnCode);
|
||||
smartcard_trace_long_return(&ret, "SetAttrib");
|
||||
scard_log_status_error_wlog(smartcard->log, "SCardSetAttrib", ret.ReturnCode);
|
||||
smartcard_trace_long_return_int(smartcard->log, &ret, "SetAttrib");
|
||||
|
||||
return ret.ReturnCode;
|
||||
}
|
||||
@@ -1525,7 +1531,7 @@ static LONG smartcard_LocateCardsByATRA_Call(scard_call_context* smartcard, wStr
|
||||
status = ret.ReturnCode = wrap(smartcard, SCardGetStatusChangeA, operation->hContext,
|
||||
0x000001F4, states, call->cReaders);
|
||||
|
||||
scard_log_status_error(TAG, "SCardGetStatusChangeA", status);
|
||||
scard_log_status_error_wlog(smartcard->log, "SCardGetStatusChangeA", status);
|
||||
for (UINT32 i = 0; i < call->cAtrs; i++)
|
||||
{
|
||||
for (UINT32 j = 0; j < call->cReaders; j++)
|
||||
@@ -1822,9 +1828,10 @@ LONG smartcard_irp_device_control_call(scard_call_context* smartcard, wStream* o
|
||||
(result != SCARD_E_NO_READERS_AVAILABLE) && (result != SCARD_E_NO_SERVICE) &&
|
||||
(result != SCARD_W_CACHE_ITEM_NOT_FOUND) && (result != SCARD_W_CACHE_ITEM_STALE))
|
||||
{
|
||||
WLog_WARN(TAG, "IRP failure: %s (0x%08" PRIX32 "), status: %s (0x%08" PRIX32 ")",
|
||||
scard_get_ioctl_string(ioControlCode, TRUE), ioControlCode,
|
||||
SCardGetErrorString(result), result);
|
||||
WLog_Print(smartcard->log, WLOG_WARN,
|
||||
"IRP failure: %s (0x%08" PRIX32 "), status: %s (0x%08" PRIX32 ")",
|
||||
scard_get_ioctl_string(ioControlCode, TRUE), ioControlCode,
|
||||
SCardGetErrorString(result), result);
|
||||
}
|
||||
|
||||
*pIoStatus = STATUS_SUCCESS;
|
||||
@@ -1833,8 +1840,9 @@ LONG smartcard_irp_device_control_call(scard_call_context* smartcard, wStream* o
|
||||
{
|
||||
/* NTSTATUS error */
|
||||
*pIoStatus = result;
|
||||
WLog_WARN(TAG, "IRP failure: %s (0x%08" PRIX32 "), ntstatus: 0x%08" PRIX32 "",
|
||||
scard_get_ioctl_string(ioControlCode, TRUE), ioControlCode, result);
|
||||
WLog_Print(smartcard->log, WLOG_WARN,
|
||||
"IRP failure: %s (0x%08" PRIX32 "), ntstatus: 0x%08" PRIX32 "",
|
||||
scard_get_ioctl_string(ioControlCode, TRUE), ioControlCode, result);
|
||||
}
|
||||
|
||||
Stream_SealLength(out);
|
||||
@@ -1856,10 +1864,10 @@ LONG smartcard_irp_device_control_call(scard_call_context* smartcard, wStream* o
|
||||
*/
|
||||
if (outputBufferLength > operation->outputBufferLength)
|
||||
{
|
||||
WLog_WARN(TAG,
|
||||
"IRP warn: expected outputBufferLength %" PRIu32 ", but current limit %" PRIu32
|
||||
", respond with STATUS_BUFFER_TOO_SMALL",
|
||||
operation->outputBufferLength, outputBufferLength);
|
||||
WLog_Print(smartcard->log, WLOG_WARN,
|
||||
"IRP warn: expected outputBufferLength %" PRIu32 ", but current limit %" PRIu32
|
||||
", respond with STATUS_BUFFER_TOO_SMALL",
|
||||
operation->outputBufferLength, outputBufferLength);
|
||||
|
||||
*pIoStatus = STATUS_BUFFER_TOO_SMALL;
|
||||
result = *pIoStatus;
|
||||
@@ -1898,6 +1906,9 @@ scard_call_context* smartcard_call_context_new(const rdpSettings* settings)
|
||||
if (!ctx)
|
||||
goto fail;
|
||||
|
||||
ctx->log = WLog_Get(SCARD_TAG);
|
||||
WINPR_ASSERT(ctx->log);
|
||||
|
||||
ctx->stopEvent = CreateEventA(NULL, TRUE, FALSE, NULL);
|
||||
if (!ctx->stopEvent)
|
||||
goto fail;
|
||||
@@ -1917,7 +1928,7 @@ scard_call_context* smartcard_call_context_new(const rdpSettings* settings)
|
||||
if (!ctx->emulation)
|
||||
goto fail;
|
||||
#else
|
||||
WLog_ERR(TAG, "Smartcard emulation requested, but not supported!");
|
||||
WLog_Print(ctx->log, WLOG_ERROR, "Smartcard emulation requested, but not supported!");
|
||||
goto fail;
|
||||
#endif
|
||||
}
|
||||
@@ -1930,7 +1941,8 @@ scard_call_context* smartcard_call_context_new(const rdpSettings* settings)
|
||||
|
||||
if (!ctx->hWinSCardLibrary)
|
||||
{
|
||||
WLog_ERR(TAG, "Failed to load WinSCard library: '%s'", WinSCardModule);
|
||||
WLog_Print(ctx->log, WLOG_ERROR, "Failed to load WinSCard library: '%s'",
|
||||
WinSCardModule);
|
||||
goto fail;
|
||||
}
|
||||
|
||||
@@ -1945,7 +1957,7 @@ scard_call_context* smartcard_call_context_new(const rdpSettings* settings)
|
||||
|
||||
if (!ctx->pWinSCardApi)
|
||||
{
|
||||
WLog_ERR(TAG, "Failed to load WinSCard API!");
|
||||
WLog_Print(ctx->log, WLOG_ERROR, "Failed to load WinSCard API!");
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -221,26 +221,18 @@ static LONG smartcard_LocateCardsW_Decode(wStream* s, SMARTCARD_OPERATION* opera
|
||||
|
||||
static LONG smartcard_GetStatusChangeA_Decode(wStream* s, SMARTCARD_OPERATION* operation)
|
||||
{
|
||||
LONG status = 0;
|
||||
|
||||
WINPR_ASSERT(s);
|
||||
WINPR_ASSERT(operation);
|
||||
|
||||
status = smartcard_unpack_get_status_change_a_call(s, &operation->call.getStatusChangeA);
|
||||
|
||||
return status;
|
||||
return smartcard_unpack_get_status_change_a_call(s, &operation->call.getStatusChangeA);
|
||||
}
|
||||
|
||||
static LONG smartcard_GetStatusChangeW_Decode(wStream* s, SMARTCARD_OPERATION* operation)
|
||||
{
|
||||
LONG status = 0;
|
||||
|
||||
WINPR_ASSERT(s);
|
||||
WINPR_ASSERT(operation);
|
||||
|
||||
status = smartcard_unpack_get_status_change_w_call(s, &operation->call.getStatusChangeW);
|
||||
|
||||
return status;
|
||||
return smartcard_unpack_get_status_change_w_call(s, &operation->call.getStatusChangeW);
|
||||
}
|
||||
|
||||
static LONG smartcard_Cancel_Decode(wStream* s, SMARTCARD_OPERATION* operation)
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
28
libfreerdp/utils/smartcard_pack.h
Normal file
28
libfreerdp/utils/smartcard_pack.h
Normal file
@@ -0,0 +1,28 @@
|
||||
/**
|
||||
* FreeRDP: A Remote Desktop Protocol Implementation
|
||||
* Smart Card Structure Packing
|
||||
*
|
||||
* Copyright 2025 Armin Novak <armin.novak@thincast.com>
|
||||
* Copyright 2025 Thincast Technologies GmbH
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <winpr/wlog.h>
|
||||
#include <freerdp/api.h>
|
||||
#include <freerdp/channels/scard.h>
|
||||
|
||||
FREERDP_LOCAL void smartcard_trace_long_return_int(wLog* log, const Long_Return* ret,
|
||||
const char* name);
|
||||
Reference in New Issue
Block a user