From 1e6fea7fa79b28ba262241f1d6f7820dc3daa494 Mon Sep 17 00:00:00 2001 From: Bernhard Miklautz Date: Mon, 11 Dec 2017 14:00:09 +0100 Subject: [PATCH] fix channel/smartcard: simplify channel variables Path was not really used and name was duplicated. Use the device->Name directly. --- channels/smartcard/client/smartcard_main.c | 22 +--------------- channels/smartcard/client/smartcard_main.h | 3 --- channels/smartcard/client/smartcard_pack.c | 2 +- client/common/cmdline.c | 42 ++++++++++-------------------- include/freerdp/settings.h | 1 - libfreerdp/common/settings.c | 9 +------ 6 files changed, 17 insertions(+), 62 deletions(-) diff --git a/channels/smartcard/client/smartcard_main.c b/channels/smartcard/client/smartcard_main.c index f21f0f2..9fe2c36 100644 --- a/channels/smartcard/client/smartcard_main.c +++ b/channels/smartcard/client/smartcard_main.c @@ -677,17 +677,12 @@ static UINT smartcard_irp_request(DEVICE* device, IRP* irp) */ UINT DeviceServiceEntry(PDEVICE_SERVICE_ENTRY_POINTS pEntryPoints) { - char* name; - char* path; size_t length; - int ck; RDPDR_SMARTCARD* device; SMARTCARD_DEVICE* smartcard; LONG status; UINT error = CHANNEL_RC_NO_MEMORY; device = (RDPDR_SMARTCARD*) pEntryPoints->device; - name = device->Name; - path = device->Path; smartcard = (SMARTCARD_DEVICE*) calloc(1, sizeof(SMARTCARD_DEVICE)); if (!smartcard) @@ -712,23 +707,8 @@ UINT DeviceServiceEntry(PDEVICE_SERVICE_ENTRY_POINTS pEntryPoints) } Stream_Write(smartcard->device.data, "SCARD", 6); - smartcard->name = NULL; - smartcard->path = NULL; - if (path) - { - smartcard->path = path; - smartcard->name = name; - } - else if (name) - { - if (1 == sscanf(name, "%d", &ck)) - smartcard->path = name; - else - smartcard->name = name; - } - - status = SCardAddReaderName(&smartcard->thread, (LPSTR) name); + status = SCardAddReaderName(&smartcard->thread, (LPSTR) device->Name); if (status != SCARD_S_SUCCESS) { diff --git a/channels/smartcard/client/smartcard_main.h b/channels/smartcard/client/smartcard_main.h index 10cdb50..8451234 100644 --- a/channels/smartcard/client/smartcard_main.h +++ b/channels/smartcard/client/smartcard_main.h @@ -110,9 +110,6 @@ struct _SMARTCARD_DEVICE { DEVICE device; - char* name; - char* path; - HANDLE thread; HANDLE StartedEvent; wMessageQueue* IrpQueue; diff --git a/channels/smartcard/client/smartcard_pack.c b/channels/smartcard/client/smartcard_pack.c index 1f89d54..373064e 100644 --- a/channels/smartcard/client/smartcard_pack.c +++ b/channels/smartcard/client/smartcard_pack.c @@ -850,7 +850,7 @@ void smartcard_trace_list_readers_return(SMARTCARD_DEVICE* smartcard, ListReader CopyMemory(mszA, ret->msz, ret->cBytes); } - for (index = 0; index < length - 2; index++) + for (index = 0; index < length - 1; index++) { if (mszA[index] == '\0') mszA[index] = ','; diff --git a/client/common/cmdline.c b/client/common/cmdline.c index 6db75b9..17c3c16 100644 --- a/client/common/cmdline.c +++ b/client/common/cmdline.c @@ -476,43 +476,29 @@ BOOL freerdp_client_add_device_channel(rdpSettings* settings, int count, settings->RedirectSmartCards = TRUE; settings->DeviceRedirection = TRUE; - if (count > 1) - { - smartcard = (RDPDR_SMARTCARD*) calloc(1, sizeof(RDPDR_SMARTCARD)); - - if (!smartcard) - return FALSE; - - smartcard->Type = RDPDR_DTYP_SMARTCARD; + smartcard = (RDPDR_SMARTCARD*) calloc(1, sizeof(RDPDR_SMARTCARD)); - if (count > 1) - { - if (!(smartcard->Name = _strdup(params[1]))) - { - free(smartcard); - return FALSE; - } - } + if (!smartcard) + return FALSE; - if (count > 2) - { - if (!(smartcard->Path = _strdup(params[2]))) - { - free(smartcard->Name); - free(smartcard); - return FALSE; - } - } + smartcard->Type = RDPDR_DTYP_SMARTCARD; - if (!freerdp_device_collection_add(settings, (RDPDR_DEVICE*) smartcard)) + if (count > 1 && strlen(params[1])) + { + if (!(smartcard->Name = _strdup(params[1]))) { - free(smartcard->Path); - free(smartcard->Name); free(smartcard); return FALSE; } } + if (!freerdp_device_collection_add(settings, (RDPDR_DEVICE*) smartcard)) + { + free(smartcard->Name); + free(smartcard); + return FALSE; + } + return TRUE; } else if (strcmp(params[0], "serial") == 0) diff --git a/include/freerdp/settings.h b/include/freerdp/settings.h index 2e1f796..3bbf536 100644 --- a/include/freerdp/settings.h +++ b/include/freerdp/settings.h @@ -446,7 +446,6 @@ struct _RDPDR_SMARTCARD UINT32 Id; UINT32 Type; char* Name; - char* Path; }; typedef struct _RDPDR_SMARTCARD RDPDR_SMARTCARD; diff --git a/libfreerdp/common/settings.c b/libfreerdp/common/settings.c index 76d2439..fd4b008 100644 --- a/libfreerdp/common/settings.c +++ b/libfreerdp/common/settings.c @@ -307,13 +307,6 @@ out_print_name_error: goto out_smartc_name_error; } - if (smartcard->Path) - { - _smartcard->Path = _strdup(smartcard->Path); - if (!_smartcard->Path) - goto out_smartc_path_error; - } - return (RDPDR_DEVICE*) _smartcard; out_smartc_path_error: @@ -428,7 +421,7 @@ void freerdp_device_collection_free(rdpSettings* settings) } else if (settings->DeviceArray[index]->Type == RDPDR_DTYP_SMARTCARD) { - free(((RDPDR_SMARTCARD*) device)->Path); + } else if (settings->DeviceArray[index]->Type == RDPDR_DTYP_SERIAL) { -- 2.7.4