From dccf40c2bc8bcf0c91be4686618a8db975067678 Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Fri, 26 Feb 2016 14:50:27 +0100 Subject: [PATCH 1/2] Fixed duplicate loading of smartcard and printers. --- client/common/cmdline.c | 33 ++++++++++++++++++++------------- include/freerdp/settings.h | 2 ++ libfreerdp/common/settings.c | 17 +++++++++++++++++ 3 files changed, 39 insertions(+), 13 deletions(-) diff --git a/client/common/cmdline.c b/client/common/cmdline.c index 510ef716e..76a5b8dee 100644 --- a/client/common/cmdline.c +++ b/client/common/cmdline.c @@ -4,6 +4,7 @@ * * Copyright 2012 Marc-Andre Moreau * Copyright 2014 Norbert Federa + * Copyright 2016 Armin Novak * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -1311,7 +1312,7 @@ int freerdp_detect_posix_style_command_line_syntax(int argc, char** argv, } static BOOL freerdp_client_detect_command_line(int argc, char** argv, - DWORD* flags, BOOL ignoreUnknown) + DWORD* flags, BOOL ignoreUnknown) { int old_cli_status; int old_cli_count; @@ -2508,28 +2509,34 @@ BOOL freerdp_client_load_addins(rdpChannels* channels, rdpSettings* settings) { RDPDR_SMARTCARD* smartcard; - smartcard = (RDPDR_SMARTCARD*) calloc(1, sizeof(RDPDR_SMARTCARD)); + if (!freerdp_device_collection_find_type(settings, RDPDR_DTYP_SMARTCARD)) + { + smartcard = (RDPDR_SMARTCARD*) calloc(1, sizeof(RDPDR_SMARTCARD)); - if (!smartcard) - return FALSE; + if (!smartcard) + return FALSE; - smartcard->Type = RDPDR_DTYP_SMARTCARD; - if (!freerdp_device_collection_add(settings, (RDPDR_DEVICE*) smartcard)) - return FALSE; + smartcard->Type = RDPDR_DTYP_SMARTCARD; + if (!freerdp_device_collection_add(settings, (RDPDR_DEVICE*) smartcard)) + return FALSE; + } } if (settings->RedirectPrinters) { RDPDR_PRINTER* printer; - printer = (RDPDR_PRINTER*) calloc(1, sizeof(RDPDR_PRINTER)); + if (!freerdp_device_collection_find_type(settings, RDPDR_DTYP_PRINT)) + { + printer = (RDPDR_PRINTER*) calloc(1, sizeof(RDPDR_PRINTER)); - if (!printer) - return FALSE; + if (!printer) + return FALSE; - printer->Type = RDPDR_DTYP_PRINT; - if (!freerdp_device_collection_add(settings, (RDPDR_DEVICE*) printer)) - return FALSE; + printer->Type = RDPDR_DTYP_PRINT; + if (!freerdp_device_collection_add(settings, (RDPDR_DEVICE*) printer)) + return FALSE; + } } if (settings->RedirectClipboard) diff --git a/include/freerdp/settings.h b/include/freerdp/settings.h index a53054fab..210e7112c 100644 --- a/include/freerdp/settings.h +++ b/include/freerdp/settings.h @@ -4,6 +4,7 @@ * * Copyright 2009-2011 Jay Sorg * Copyright 2010-2012 Marc-Andre Moreau + * Copyright 2016 Armin Novak * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -1435,6 +1436,7 @@ FREERDP_API int freerdp_addin_replace_argument_value(ADDIN_ARGV* args, char* pre FREERDP_API BOOL freerdp_device_collection_add(rdpSettings* settings, RDPDR_DEVICE* device); FREERDP_API RDPDR_DEVICE* freerdp_device_collection_find(rdpSettings* settings, const char* name); +FREERDP_API RDPDR_DEVICE* freerdp_device_collection_find_type(rdpSettings* settings, UINT32 type); FREERDP_API RDPDR_DEVICE* freerdp_device_clone(RDPDR_DEVICE* device); FREERDP_API void freerdp_device_collection_free(rdpSettings* settings); diff --git a/libfreerdp/common/settings.c b/libfreerdp/common/settings.c index 859357a2a..bded9d0ec 100644 --- a/libfreerdp/common/settings.c +++ b/libfreerdp/common/settings.c @@ -3,6 +3,7 @@ * Settings Management * * Copyright 2012 Marc-Andre Moreau + * Copyright 2016 Armin Novak * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -208,6 +209,22 @@ RDPDR_DEVICE* freerdp_device_collection_find(rdpSettings* settings, const char* return NULL; } +RDPDR_DEVICE* freerdp_device_collection_find_type(rdpSettings* settings, UINT32 type) +{ + UINT32 index; + RDPDR_DEVICE* device; + + for (index = 0; index < settings->DeviceCount; index++) + { + device = (RDPDR_DEVICE*) settings->DeviceArray[index]; + + if (device->Type == type) + return device; + } + + return NULL; +} + RDPDR_DEVICE* freerdp_device_clone(RDPDR_DEVICE* device) { if (device->Type == RDPDR_DTYP_FILESYSTEM) From b7187d04a51a2a55b1a9bd33ef245889acc25548 Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Fri, 26 Feb 2016 15:21:19 +0100 Subject: [PATCH 2/2] Printer driver from command line now used. --- channels/printer/client/printer_cups.c | 26 ++++++++++++++++++------ channels/printer/client/printer_main.c | 6 ++---- channels/printer/client/printer_main.h | 3 ++- channels/printer/client/printer_win.c | 28 ++++++++++++++++++++------ 4 files changed, 46 insertions(+), 17 deletions(-) diff --git a/channels/printer/client/printer_cups.c b/channels/printer/client/printer_cups.c index d498ff6f6..9586f027f 100644 --- a/channels/printer/client/printer_cups.c +++ b/channels/printer/client/printer_cups.c @@ -5,6 +5,7 @@ * Copyright 2010-2011 Vic Lee * Copyright 2015 Thincast Technologies GmbH * Copyright 2015 DI (FH) Martin Haimberger + * Copyright 2016 Armin Novak * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -229,10 +230,12 @@ static void printer_cups_free_printer(rdpPrinter* printer) cups_printer->printjob->printjob.Close((rdpPrintJob*) cups_printer->printjob); free(printer->name); + free(printer->driver); free(printer); } -static rdpPrinter* printer_cups_new_printer(rdpCupsPrinterDriver* cups_driver, const char* name, BOOL is_default) +static rdpPrinter* printer_cups_new_printer(rdpCupsPrinterDriver* cups_driver, + const char* name, const char* driverName, BOOL is_default) { rdpCupsPrinter* cups_printer; @@ -247,8 +250,17 @@ static rdpPrinter* printer_cups_new_printer(rdpCupsPrinterDriver* cups_driver, c free(cups_printer); return NULL; } - /* This is a generic PostScript printer driver developed by MS, so it should be good in most cases */ - cups_printer->printer.driver = "MS Publisher Imagesetter"; + + if (driverName) + cups_printer->printer.driver = _strdup(driverName); + else + cups_printer->printer.driver = _strdup("MS Publisher Imagesetter"); + if (!cups_printer->printer.driver) + { + free(cups_printer->printer.name); + free(cups_printer); + return NULL; + } cups_printer->printer.is_default = is_default; cups_printer->printer.CreatePrintJob = printer_cups_create_printjob; @@ -279,7 +291,7 @@ static rdpPrinter** printer_cups_enum_printers(rdpPrinterDriver* driver) if (dest->instance == NULL) { printers[num_printers++] = printer_cups_new_printer((rdpCupsPrinterDriver*) driver, - dest->name, dest->is_default); + dest->name, NULL, dest->is_default); } } cupsFreeDests(num_dests, dests); @@ -287,11 +299,13 @@ static rdpPrinter** printer_cups_enum_printers(rdpPrinterDriver* driver) return printers; } -static rdpPrinter* printer_cups_get_printer(rdpPrinterDriver* driver, const char* name) +static rdpPrinter* printer_cups_get_printer(rdpPrinterDriver* driver, + const char* name, const char* driverName) { rdpCupsPrinterDriver* cups_driver = (rdpCupsPrinterDriver*) driver; - return printer_cups_new_printer(cups_driver, name, cups_driver->id_sequence == 1 ? TRUE : FALSE); + return printer_cups_new_printer(cups_driver, name, driverName, + cups_driver->id_sequence == 1 ? TRUE : FALSE); } static rdpCupsPrinterDriver* cups_driver = NULL; diff --git a/channels/printer/client/printer_main.c b/channels/printer/client/printer_main.c index fce501a18..74f6d436a 100644 --- a/channels/printer/client/printer_main.c +++ b/channels/printer/client/printer_main.c @@ -5,6 +5,7 @@ * Copyright 2010-2011 Vic Lee * Copyright 2015 Thincast Technologies GmbH * Copyright 2015 DI (FH) Martin Haimberger + * Copyright 2016 Armin Novak * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -489,7 +490,7 @@ UINT DeviceServiceEntry(PDEVICE_SERVICE_ENTRY_POINTS pEntryPoints) if (name && name[0]) { - printer = driver->GetPrinter(driver, name); + printer = driver->GetPrinter(driver, name, driver_name); if (!printer) { @@ -497,9 +498,6 @@ UINT DeviceServiceEntry(PDEVICE_SERVICE_ENTRY_POINTS pEntryPoints) return CHANNEL_RC_INITIALIZATION_ERROR; } - if (driver_name && driver_name[0]) - printer->driver = driver_name; - if ((error = printer_register(pEntryPoints, printer))) { WLog_ERR(TAG, "printer_register failed with error %lu!", error); diff --git a/channels/printer/client/printer_main.h b/channels/printer/client/printer_main.h index 3faa3ae7c..3d9b75a9d 100644 --- a/channels/printer/client/printer_main.h +++ b/channels/printer/client/printer_main.h @@ -5,6 +5,7 @@ * Copyright 2010-2011 Vic Lee * Copyright 2015 Thincast Technologies GmbH * Copyright 2015 DI (FH) Martin Haimberger + * Copyright 2016 Armin Novak * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -29,7 +30,7 @@ typedef struct rdp_printer rdpPrinter; typedef struct rdp_print_job rdpPrintJob; typedef rdpPrinter** (*pcEnumPrinters) (rdpPrinterDriver* driver); -typedef rdpPrinter* (*pcGetPrinter) (rdpPrinterDriver* driver, const char* name); +typedef rdpPrinter* (*pcGetPrinter) (rdpPrinterDriver* driver, const char* name, const char* driverName); struct rdp_printer_driver { diff --git a/channels/printer/client/printer_win.c b/channels/printer/client/printer_win.c index f30beebab..dc3664252 100644 --- a/channels/printer/client/printer_win.c +++ b/channels/printer/client/printer_win.c @@ -5,6 +5,7 @@ * Copyright 2012 Gerald Richter * Copyright 2015 Thincast Technologies GmbH * Copyright 2015 DI (FH) Martin Haimberger + * Copyright 2016 Armin Novak * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -175,10 +176,12 @@ static void printer_win_free_printer(rdpPrinter* printer) win_printer->printjob->printjob.Close((rdpPrintJob*) win_printer->printjob); free(printer->name); + free(printer->driver); free(printer); } -static rdpPrinter* printer_win_new_printer(rdpWinPrinterDriver* win_driver, const char* name, const wchar_t* drivername, BOOL is_default) +static rdpPrinter* printer_win_new_printer(rdpWinPrinterDriver* win_driver, + const char* name, const WCHAR* drivername, BOOL is_default) { rdpWinPrinter* win_printer; wchar_t wname[256]; @@ -216,7 +219,10 @@ static rdpPrinter* printer_win_new_printer(rdpWinPrinterDriver* win_driver, cons } GetPrinter(win_printer->hPrinter, 2, (LPBYTE) prninfo, needed, &needed); - win_printer->printer.driver = malloc(1000); + if (drivername) + win_printer->printer.driver = _wcsdup(drivername); + else + win_printer->printer.driver = _wcsdup(prninfo->pDriverName); if (!win_printer->printer.driver) { GlobalFree(prninfo); @@ -224,7 +230,6 @@ static rdpPrinter* printer_win_new_printer(rdpWinPrinterDriver* win_driver, cons free(win_printer); return NULL; } - wcstombs_s(&charsConverted, win_printer->printer.driver, 1000, prninfo->pDriverName, _TRUNCATE); return (rdpPrinter*)win_printer; } @@ -274,13 +279,24 @@ static rdpPrinter** printer_win_enum_printers(rdpPrinterDriver* driver) return printers; } -static rdpPrinter* printer_win_get_printer(rdpPrinterDriver* driver, const char* name) +static rdpPrinter* printer_win_get_printer(rdpPrinterDriver* driver, + const char* name, const char* driverName) { + WCHAR* driverNameW = NULL; rdpWinPrinterDriver* win_driver = (rdpWinPrinterDriver*)driver; rdpPrinter *myPrinter = NULL; - myPrinter = printer_win_new_printer(win_driver, name, L"", win_driver->id_sequence == 1 ? TRUE : FALSE); - + if (driverName) + { + ConvertToUnicode(CP_UTF8, 0, driverName, -1, &driverNameW, 0); + if (!driverNameW) + return NULL; + } + + myPrinter = printer_win_new_printer(win_driver, name, driverNameW, + win_driver->id_sequence == 1 ? TRUE : FALSE); + free(driverNameW); + return myPrinter; }