From 5a68f932d6cc048c3ec9df8c48e64cb4e7a36202 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Tue, 14 Feb 2017 00:02:17 -0800 Subject: [PATCH] GUACAMOLE-200: Maintain print jobs at top level. Do not rely on proper free of RDPDR plugin. --- src/protocols/rdp/client.c | 8 +++++ src/protocols/rdp/guac_rdpdr/rdpdr_printer.c | 31 ++++++++++---------- src/protocols/rdp/rdp.h | 6 ++++ 3 files changed, 29 insertions(+), 16 deletions(-) diff --git a/src/protocols/rdp/client.c b/src/protocols/rdp/client.c index 2a9a6905..203bdb08 100644 --- a/src/protocols/rdp/client.c +++ b/src/protocols/rdp/client.c @@ -23,6 +23,8 @@ #include "client.h" #include "rdp.h" #include "rdp_disp.h" +#include "rdp_fs.h" +#include "rdp_print_job.h" #include "user.h" #ifdef ENABLE_COMMON_SSH @@ -105,6 +107,12 @@ int guac_rdp_client_free_handler(guac_client* client) { if (rdp_client->filesystem != NULL) guac_rdp_fs_free(rdp_client->filesystem); + /* Clean up print job, if active */ + if (rdp_client->active_job != NULL) { + guac_rdp_print_job_kill(rdp_client->active_job); + guac_rdp_print_job_free(rdp_client->active_job); + } + #ifdef ENABLE_COMMON_SSH /* Free SFTP filesystem, if loaded */ if (rdp_client->sftp_filesystem) diff --git a/src/protocols/rdp/guac_rdpdr/rdpdr_printer.c b/src/protocols/rdp/guac_rdpdr/rdpdr_printer.c index 812eaf0b..3733b013 100644 --- a/src/protocols/rdp/guac_rdpdr/rdpdr_printer.c +++ b/src/protocols/rdp/guac_rdpdr/rdpdr_printer.c @@ -22,6 +22,7 @@ #include "rdpdr_messages.h" #include "rdpdr_printer.h" #include "rdpdr_service.h" +#include "rdp.h" #include "rdp_print_job.h" #include "rdp_status.h" @@ -48,11 +49,14 @@ void guac_rdpdr_process_print_job_create(guac_rdpdr_device* device, wStream* input_stream, int completion_id) { + guac_client* client = device->rdpdr->client; + guac_rdp_client* rdp_client = (guac_rdp_client*) client->data; + /* Log creation of print job */ - guac_client_log(device->rdpdr->client, GUAC_LOG_INFO, "Print job created"); + guac_client_log(client, GUAC_LOG_INFO, "Print job created"); /* Create print job */ - device->data = guac_client_for_owner(device->rdpdr->client, + rdp_client->active_job = guac_client_for_owner(client, guac_rdp_print_job_alloc, NULL); /* Respond with success */ @@ -67,7 +71,9 @@ void guac_rdpdr_process_print_job_create(guac_rdpdr_device* device, void guac_rdpdr_process_print_job_write(guac_rdpdr_device* device, wStream* input_stream, int completion_id) { - guac_rdp_print_job* job = (guac_rdp_print_job*) device->data; + guac_client* client = device->rdpdr->client; + guac_rdp_client* rdp_client = (guac_rdp_client*) client->data; + guac_rdp_print_job* job = (guac_rdp_print_job*) rdp_client->active_job; unsigned char* buffer; int length; @@ -104,8 +110,11 @@ void guac_rdpdr_process_print_job_write(guac_rdpdr_device* device, void guac_rdpdr_process_print_job_close(guac_rdpdr_device* device, wStream* input_stream, int completion_id) { + guac_client* client = device->rdpdr->client; + guac_rdp_client* rdp_client = (guac_rdp_client*) client->data; + guac_rdp_print_job* job = (guac_rdp_print_job*) rdp_client->active_job; + /* End print job */ - guac_rdp_print_job* job = (guac_rdp_print_job*) device->data; if (job != NULL) { guac_rdp_print_job_free(job); device->data = NULL; @@ -118,7 +127,7 @@ void guac_rdpdr_process_print_job_close(guac_rdpdr_device* device, svc_plugin_send((rdpSvcPlugin*) device->rdpdr, output_stream); /* Log end of print job */ - guac_client_log(device->rdpdr->client, GUAC_LOG_INFO, "Print job closed"); + guac_client_log(client, GUAC_LOG_INFO, "Print job closed"); } @@ -178,14 +187,7 @@ static void guac_rdpdr_device_printer_iorequest_handler(guac_rdpdr_device* devic } static void guac_rdpdr_device_printer_free_handler(guac_rdpdr_device* device) { - - /* Terminate and free print job if open */ - guac_rdp_print_job* job = (guac_rdp_print_job*) device->data; - if (job != NULL) { - guac_rdp_print_job_kill(job); - guac_rdp_print_job_free(job); - } - + /* Do nothing */ } void guac_rdpdr_register_printer(guac_rdpdrPlugin* rdpdr) { @@ -205,8 +207,5 @@ void guac_rdpdr_register_printer(guac_rdpdrPlugin* rdpdr) { device->iorequest_handler = guac_rdpdr_device_printer_iorequest_handler; device->free_handler = guac_rdpdr_device_printer_free_handler; - /* No active print job yet */ - device->data = NULL; - } diff --git a/src/protocols/rdp/rdp.h b/src/protocols/rdp/rdp.h index af26408f..e3e33119 100644 --- a/src/protocols/rdp/rdp.h +++ b/src/protocols/rdp/rdp.h @@ -30,6 +30,7 @@ #include "keyboard.h" #include "rdp_disp.h" #include "rdp_fs.h" +#include "rdp_print_job.h" #include "rdp_settings.h" #include @@ -120,6 +121,11 @@ typedef struct guac_rdp_client { */ guac_rdp_fs* filesystem; + /** + * The currently-active print job, or NULL if no print job is active. + */ + guac_rdp_print_job* active_job; + #ifdef ENABLE_COMMON_SSH /** * The user and credentials used to authenticate for SFTP.