From e68fe8193856e556071756811d22dfa09294a750 Mon Sep 17 00:00:00 2001 From: Nick Couchman Date: Fri, 23 Feb 2018 05:34:44 -0500 Subject: [PATCH] GUACAMOLE-445: Pass printer name from settings to RDP session. --- src/protocols/rdp/guac_rdpdr/rdpdr_messages.c | 1 - src/protocols/rdp/guac_rdpdr/rdpdr_messages.h | 6 ------ src/protocols/rdp/guac_rdpdr/rdpdr_printer.c | 19 ++++++++++++++----- src/protocols/rdp/guac_rdpdr/rdpdr_printer.h | 2 +- src/protocols/rdp/guac_rdpdr/rdpdr_service.c | 2 +- src/protocols/rdp/rdp_settings.c | 1 + 6 files changed, 17 insertions(+), 14 deletions(-) diff --git a/src/protocols/rdp/guac_rdpdr/rdpdr_messages.c b/src/protocols/rdp/guac_rdpdr/rdpdr_messages.c index fc9cd0f8..7bc9f3b2 100644 --- a/src/protocols/rdp/guac_rdpdr/rdpdr_messages.c +++ b/src/protocols/rdp/guac_rdpdr/rdpdr_messages.c @@ -273,4 +273,3 @@ void guac_rdpdr_process_prn_cache_data(guac_rdpdrPlugin* rdpdr, wStream* input_s void guac_rdpdr_process_prn_using_xps(guac_rdpdrPlugin* rdpdr, wStream* input_stream) { guac_client_log(rdpdr->client, GUAC_LOG_INFO, "Printer unexpectedly switched to XPS mode"); } - diff --git a/src/protocols/rdp/guac_rdpdr/rdpdr_messages.h b/src/protocols/rdp/guac_rdpdr/rdpdr_messages.h index 24a25938..8f276524 100644 --- a/src/protocols/rdp/guac_rdpdr/rdpdr_messages.h +++ b/src/protocols/rdp/guac_rdpdr/rdpdr_messages.h @@ -76,12 +76,6 @@ #define GUAC_PRINTER_DRIVER "M\0S\0 \0P\0u\0b\0l\0i\0s\0h\0e\0r\0 \0I\0m\0a\0g\0e\0s\0e\0t\0t\0e\0r\0\0\0" #define GUAC_PRINTER_DRIVER_LENGTH 50 -/** - * Name of the printer itself. - */ -#define GUAC_PRINTER_NAME "G\0u\0a\0c\0a\0m\0o\0l\0e\0\0\0" -#define GUAC_PRINTER_NAME_LENGTH 20 - /** * Name of the filesystem. */ diff --git a/src/protocols/rdp/guac_rdpdr/rdpdr_printer.c b/src/protocols/rdp/guac_rdpdr/rdpdr_printer.c index 40ac36f2..055288a5 100644 --- a/src/protocols/rdp/guac_rdpdr/rdpdr_printer.c +++ b/src/protocols/rdp/guac_rdpdr/rdpdr_printer.c @@ -25,12 +25,14 @@ #include "rdp.h" #include "rdp_print_job.h" #include "rdp_status.h" +#include "unicode.h" #include #include #include #include #include +#include #include #ifdef ENABLE_WINPR @@ -141,18 +143,25 @@ static void guac_rdpdr_device_printer_announce_handler(guac_rdpdr_device* device Stream_Write(output_stream, "PRN1\0\0\0\0", 8); /* DOS name */ /* Printer data */ - Stream_Write_UINT32(output_stream, 24 + GUAC_PRINTER_DRIVER_LENGTH + GUAC_PRINTER_NAME_LENGTH); + int settings_length = guac_utf8_strlen(device->device_name); + int printer_name_length = (settings_length + 1) * 2; + char printer_name[printer_name_length]; + guac_rdp_utf8_to_utf16((const unsigned char*)device->device_name, + settings_length, printer_name, printer_name_length); + printer_name[printer_name_length - 2] = '\0'; + printer_name[printer_name_length - 1] = '\0'; + Stream_Write_UINT32(output_stream, 24 + GUAC_PRINTER_DRIVER_LENGTH + printer_name_length); Stream_Write_UINT32(output_stream, RDPDR_PRINTER_ANNOUNCE_FLAG_DEFAULTPRINTER | RDPDR_PRINTER_ANNOUNCE_FLAG_NETWORKPRINTER); Stream_Write_UINT32(output_stream, 0); /* reserved - must be 0 */ Stream_Write_UINT32(output_stream, 0); /* PnPName length (PnPName is ultimately ignored) */ Stream_Write_UINT32(output_stream, GUAC_PRINTER_DRIVER_LENGTH); /* DriverName length */ - Stream_Write_UINT32(output_stream, GUAC_PRINTER_NAME_LENGTH); /* PrinterName length */ + Stream_Write_UINT32(output_stream, printer_name_length); /* PrinterName length */ Stream_Write_UINT32(output_stream, 0); /* CachedFields length */ Stream_Write(output_stream, GUAC_PRINTER_DRIVER, GUAC_PRINTER_DRIVER_LENGTH); - Stream_Write(output_stream, GUAC_PRINTER_NAME, GUAC_PRINTER_NAME_LENGTH); + Stream_Write(output_stream, printer_name, printer_name_length); } @@ -190,7 +199,7 @@ static void guac_rdpdr_device_printer_free_handler(guac_rdpdr_device* device) { /* Do nothing */ } -void guac_rdpdr_register_printer(guac_rdpdrPlugin* rdpdr) { +void guac_rdpdr_register_printer(guac_rdpdrPlugin* rdpdr, char* printer_name) { int id = rdpdr->devices_registered++; @@ -200,7 +209,7 @@ void guac_rdpdr_register_printer(guac_rdpdrPlugin* rdpdr) { /* Init device */ device->rdpdr = rdpdr; device->device_id = id; - device->device_name = "Guacamole Printer"; + device->device_name = printer_name; /* Set handlers */ device->announce_handler = guac_rdpdr_device_printer_announce_handler; diff --git a/src/protocols/rdp/guac_rdpdr/rdpdr_printer.h b/src/protocols/rdp/guac_rdpdr/rdpdr_printer.h index 6f203d6b..3d48dad9 100644 --- a/src/protocols/rdp/guac_rdpdr/rdpdr_printer.h +++ b/src/protocols/rdp/guac_rdpdr/rdpdr_printer.h @@ -35,7 +35,7 @@ * Registers a new printer device within the RDPDR plugin. This must be done * before RDPDR connection finishes. */ -void guac_rdpdr_register_printer(guac_rdpdrPlugin* rdpdr); +void guac_rdpdr_register_printer(guac_rdpdrPlugin* rdpdr, char* printer_name); #endif diff --git a/src/protocols/rdp/guac_rdpdr/rdpdr_service.c b/src/protocols/rdp/guac_rdpdr/rdpdr_service.c index 233b117c..611d21a5 100644 --- a/src/protocols/rdp/guac_rdpdr/rdpdr_service.c +++ b/src/protocols/rdp/guac_rdpdr/rdpdr_service.c @@ -96,7 +96,7 @@ void guac_rdpdr_process_connect(rdpSvcPlugin* plugin) { /* Register printer if enabled */ if (rdp_client->settings->printing_enabled) - guac_rdpdr_register_printer(rdpdr); + guac_rdpdr_register_printer(rdpdr, rdp_client->settings->printer_name); /* Register drive if enabled */ if (rdp_client->settings->drive_enabled) diff --git a/src/protocols/rdp/rdp_settings.c b/src/protocols/rdp/rdp_settings.c index 0ce3e846..18525429 100644 --- a/src/protocols/rdp/rdp_settings.c +++ b/src/protocols/rdp/rdp_settings.c @@ -990,6 +990,7 @@ void guac_rdp_settings_free(guac_rdp_settings* settings) { free(settings->remote_app_args); free(settings->remote_app_dir); free(settings->username); + free(settings->printer_name); /* Free channel name array */ if (settings->svc_names != NULL) {