From 2691532061161b0d33940b008182c9c0e874455f Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Mon, 25 Nov 2019 09:39:21 +0100 Subject: [PATCH 1/3] Fixed const correctness of encomsp functions. --- channels/encomsp/client/encomsp_main.c | 161 ++++++++++++++++--------- channels/encomsp/client/encomsp_main.h | 14 --- client/Sample/tf_channels.c | 5 +- client/Wayland/wlf_channels.c | 5 +- client/X11/xf_client.c | 24 +++- include/freerdp/client/encomsp.h | 31 ++--- 6 files changed, 147 insertions(+), 93 deletions(-) diff --git a/channels/encomsp/client/encomsp_main.c b/channels/encomsp/client/encomsp_main.c index 2d22eeb59..c6440617e 100644 --- a/channels/encomsp/client/encomsp_main.c +++ b/channels/encomsp/client/encomsp_main.c @@ -31,6 +31,21 @@ #include "encomsp_main.h" +struct encomsp_plugin +{ + CHANNEL_DEF channelDef; + CHANNEL_ENTRY_POINTS_FREERDP_EX channelEntryPoints; + + EncomspClientContext* context; + + HANDLE thread; + wStream* data_in; + void* InitHandle; + DWORD OpenHandle; + wMessageQueue* queue; + rdpContext* rdpcontext; +}; + /** * Function description * @@ -54,7 +69,7 @@ static UINT encomsp_read_header(wStream* s, ENCOMSP_ORDER_HEADER* header) * * @return 0 on success, otherwise a Win32 error code */ -static UINT encomsp_write_header(wStream* s, ENCOMSP_ORDER_HEADER* header) +static UINT encomsp_write_header(wStream* s, const ENCOMSP_ORDER_HEADER* header) { Stream_Write_UINT16(s, header->Type); /* Type (2 bytes) */ Stream_Write_UINT16(s, header->Length); /* Length (2 bytes) */ @@ -138,9 +153,9 @@ static UINT encomsp_virtual_channel_write(encomspPlugin* encomsp, wStream* s) * @return 0 on success, otherwise a Win32 error code */ static UINT encomsp_recv_filter_updated_pdu(encomspPlugin* encomsp, wStream* s, - ENCOMSP_ORDER_HEADER* header) + const ENCOMSP_ORDER_HEADER* header) { - int beg, end; + size_t beg, end, pos; EncomspClientContext* context; ENCOMSP_FILTER_UPDATED_PDU pdu; UINT error = CHANNEL_RC_OK; @@ -149,7 +164,10 @@ static UINT encomsp_recv_filter_updated_pdu(encomspPlugin* encomsp, wStream* s, if (!context) return ERROR_INVALID_HANDLE; - beg = ((int)Stream_GetPosition(s)) - ENCOMSP_ORDER_HEADER_SIZE; + pos = Stream_GetPosition(s); + if (pos < ENCOMSP_ORDER_HEADER_SIZE) + return ERROR_INVALID_DATA; + beg = pos - ENCOMSP_ORDER_HEADER_SIZE; CopyMemory(&pdu, header, sizeof(ENCOMSP_ORDER_HEADER)); if (Stream_GetRemainingLength(s) < 1) @@ -159,7 +177,7 @@ static UINT encomsp_recv_filter_updated_pdu(encomspPlugin* encomsp, wStream* s, } Stream_Read_UINT8(s, pdu.Flags); /* Flags (1 byte) */ - end = (int)Stream_GetPosition(s); + end = Stream_GetPosition(s); if ((beg + header->Length) < end) { @@ -192,9 +210,9 @@ static UINT encomsp_recv_filter_updated_pdu(encomspPlugin* encomsp, wStream* s, * @return 0 on success, otherwise a Win32 error code */ static UINT encomsp_recv_application_created_pdu(encomspPlugin* encomsp, wStream* s, - ENCOMSP_ORDER_HEADER* header) + const ENCOMSP_ORDER_HEADER* header) { - int beg, end; + size_t beg, end, pos; EncomspClientContext* context; ENCOMSP_APPLICATION_CREATED_PDU pdu; UINT error; @@ -203,15 +221,18 @@ static UINT encomsp_recv_application_created_pdu(encomspPlugin* encomsp, wStream if (!context) return ERROR_INVALID_HANDLE; - beg = ((int)Stream_GetPosition(s)) - ENCOMSP_ORDER_HEADER_SIZE; - CopyMemory(&pdu, header, sizeof(ENCOMSP_ORDER_HEADER)); - if (Stream_GetRemainingLength(s) < 6) { WLog_ERR(TAG, "Not enough data!"); return ERROR_INVALID_DATA; } + pos = Stream_GetPosition(s); + if (pos < ENCOMSP_ORDER_HEADER_SIZE) + return ERROR_INVALID_DATA; + beg = pos - ENCOMSP_ORDER_HEADER_SIZE; + CopyMemory(&pdu, header, sizeof(ENCOMSP_ORDER_HEADER)); + Stream_Read_UINT16(s, pdu.Flags); /* Flags (2 bytes) */ Stream_Read_UINT32(s, pdu.AppId); /* AppId (4 bytes) */ @@ -221,7 +242,7 @@ static UINT encomsp_recv_application_created_pdu(encomspPlugin* encomsp, wStream return error; } - end = (int)Stream_GetPosition(s); + end = Stream_GetPosition(s); if ((beg + header->Length) < end) { @@ -254,9 +275,9 @@ static UINT encomsp_recv_application_created_pdu(encomspPlugin* encomsp, wStream * @return 0 on success, otherwise a Win32 error code */ static UINT encomsp_recv_application_removed_pdu(encomspPlugin* encomsp, wStream* s, - ENCOMSP_ORDER_HEADER* header) + const ENCOMSP_ORDER_HEADER* header) { - int beg, end; + size_t beg, end, pos; EncomspClientContext* context; ENCOMSP_APPLICATION_REMOVED_PDU pdu; UINT error = CHANNEL_RC_OK; @@ -265,7 +286,10 @@ static UINT encomsp_recv_application_removed_pdu(encomspPlugin* encomsp, wStream if (!context) return ERROR_INVALID_HANDLE; - beg = ((int)Stream_GetPosition(s)) - ENCOMSP_ORDER_HEADER_SIZE; + pos = Stream_GetPosition(s); + if (pos < ENCOMSP_ORDER_HEADER_SIZE) + return ERROR_INVALID_DATA; + beg = pos - ENCOMSP_ORDER_HEADER_SIZE; CopyMemory(&pdu, header, sizeof(ENCOMSP_ORDER_HEADER)); if (Stream_GetRemainingLength(s) < 4) @@ -275,7 +299,7 @@ static UINT encomsp_recv_application_removed_pdu(encomspPlugin* encomsp, wStream } Stream_Read_UINT32(s, pdu.AppId); /* AppId (4 bytes) */ - end = (int)Stream_GetPosition(s); + end = Stream_GetPosition(s); if ((beg + header->Length) < end) { @@ -308,9 +332,9 @@ static UINT encomsp_recv_application_removed_pdu(encomspPlugin* encomsp, wStream * @return 0 on success, otherwise a Win32 error code */ static UINT encomsp_recv_window_created_pdu(encomspPlugin* encomsp, wStream* s, - ENCOMSP_ORDER_HEADER* header) + const ENCOMSP_ORDER_HEADER* header) { - int beg, end; + size_t beg, end, pos; EncomspClientContext* context; ENCOMSP_WINDOW_CREATED_PDU pdu; UINT error; @@ -319,7 +343,10 @@ static UINT encomsp_recv_window_created_pdu(encomspPlugin* encomsp, wStream* s, if (!context) return ERROR_INVALID_HANDLE; - beg = ((int)Stream_GetPosition(s)) - ENCOMSP_ORDER_HEADER_SIZE; + pos = Stream_GetPosition(s); + if (pos < ENCOMSP_ORDER_HEADER_SIZE) + return ERROR_INVALID_DATA; + beg = pos - ENCOMSP_ORDER_HEADER_SIZE; CopyMemory(&pdu, header, sizeof(ENCOMSP_ORDER_HEADER)); if (Stream_GetRemainingLength(s) < 10) @@ -338,7 +365,7 @@ static UINT encomsp_recv_window_created_pdu(encomspPlugin* encomsp, wStream* s, return error; } - end = (int)Stream_GetPosition(s); + end = Stream_GetPosition(s); if ((beg + header->Length) < end) { @@ -371,9 +398,9 @@ static UINT encomsp_recv_window_created_pdu(encomspPlugin* encomsp, wStream* s, * @return 0 on success, otherwise a Win32 error code */ static UINT encomsp_recv_window_removed_pdu(encomspPlugin* encomsp, wStream* s, - ENCOMSP_ORDER_HEADER* header) + const ENCOMSP_ORDER_HEADER* header) { - int beg, end; + size_t beg, end, pos; EncomspClientContext* context; ENCOMSP_WINDOW_REMOVED_PDU pdu; UINT error = CHANNEL_RC_OK; @@ -382,7 +409,10 @@ static UINT encomsp_recv_window_removed_pdu(encomspPlugin* encomsp, wStream* s, if (!context) return ERROR_INVALID_HANDLE; - beg = ((int)Stream_GetPosition(s)) - ENCOMSP_ORDER_HEADER_SIZE; + pos = Stream_GetPosition(s); + if (pos < ENCOMSP_ORDER_HEADER_SIZE) + return ERROR_INVALID_DATA; + beg = pos - ENCOMSP_ORDER_HEADER_SIZE; CopyMemory(&pdu, header, sizeof(ENCOMSP_ORDER_HEADER)); if (Stream_GetRemainingLength(s) < 4) @@ -392,7 +422,7 @@ static UINT encomsp_recv_window_removed_pdu(encomspPlugin* encomsp, wStream* s, } Stream_Read_UINT32(s, pdu.WndId); /* WndId (4 bytes) */ - end = (int)Stream_GetPosition(s); + end = Stream_GetPosition(s); if ((beg + header->Length) < end) { @@ -425,9 +455,9 @@ static UINT encomsp_recv_window_removed_pdu(encomspPlugin* encomsp, wStream* s, * @return 0 on success, otherwise a Win32 error code */ static UINT encomsp_recv_show_window_pdu(encomspPlugin* encomsp, wStream* s, - ENCOMSP_ORDER_HEADER* header) + const ENCOMSP_ORDER_HEADER* header) { - int beg, end; + size_t beg, end, pos; EncomspClientContext* context; ENCOMSP_SHOW_WINDOW_PDU pdu; UINT error = CHANNEL_RC_OK; @@ -436,7 +466,10 @@ static UINT encomsp_recv_show_window_pdu(encomspPlugin* encomsp, wStream* s, if (!context) return ERROR_INVALID_HANDLE; - beg = ((int)Stream_GetPosition(s)) - ENCOMSP_ORDER_HEADER_SIZE; + pos = Stream_GetPosition(s); + if (pos < ENCOMSP_ORDER_HEADER_SIZE) + return ERROR_INVALID_DATA; + beg = pos - ENCOMSP_ORDER_HEADER_SIZE; CopyMemory(&pdu, header, sizeof(ENCOMSP_ORDER_HEADER)); if (Stream_GetRemainingLength(s) < 4) @@ -446,7 +479,7 @@ static UINT encomsp_recv_show_window_pdu(encomspPlugin* encomsp, wStream* s, } Stream_Read_UINT32(s, pdu.WndId); /* WndId (4 bytes) */ - end = (int)Stream_GetPosition(s); + end = Stream_GetPosition(s); if ((beg + header->Length) < end) { @@ -479,9 +512,9 @@ static UINT encomsp_recv_show_window_pdu(encomspPlugin* encomsp, wStream* s, * @return 0 on success, otherwise a Win32 error code */ static UINT encomsp_recv_participant_created_pdu(encomspPlugin* encomsp, wStream* s, - ENCOMSP_ORDER_HEADER* header) + const ENCOMSP_ORDER_HEADER* header) { - int beg, end; + size_t beg, end, pos; EncomspClientContext* context; ENCOMSP_PARTICIPANT_CREATED_PDU pdu; UINT error; @@ -490,7 +523,10 @@ static UINT encomsp_recv_participant_created_pdu(encomspPlugin* encomsp, wStream if (!context) return ERROR_INVALID_HANDLE; - beg = ((int)Stream_GetPosition(s)) - ENCOMSP_ORDER_HEADER_SIZE; + pos = Stream_GetPosition(s); + if (pos < ENCOMSP_ORDER_HEADER_SIZE) + return ERROR_INVALID_DATA; + beg = pos - ENCOMSP_ORDER_HEADER_SIZE; CopyMemory(&pdu, header, sizeof(ENCOMSP_ORDER_HEADER)); if (Stream_GetRemainingLength(s) < 10) @@ -509,7 +545,7 @@ static UINT encomsp_recv_participant_created_pdu(encomspPlugin* encomsp, wStream return error; } - end = (int)Stream_GetPosition(s); + end = Stream_GetPosition(s); if ((beg + header->Length) < end) { @@ -542,9 +578,9 @@ static UINT encomsp_recv_participant_created_pdu(encomspPlugin* encomsp, wStream * @return 0 on success, otherwise a Win32 error code */ static UINT encomsp_recv_participant_removed_pdu(encomspPlugin* encomsp, wStream* s, - ENCOMSP_ORDER_HEADER* header) + const ENCOMSP_ORDER_HEADER* header) { - int beg, end; + size_t beg, end; EncomspClientContext* context; ENCOMSP_PARTICIPANT_REMOVED_PDU pdu; UINT error = CHANNEL_RC_OK; @@ -553,19 +589,19 @@ static UINT encomsp_recv_participant_removed_pdu(encomspPlugin* encomsp, wStream if (!context) return ERROR_INVALID_HANDLE; - beg = ((int)Stream_GetPosition(s)) - ENCOMSP_ORDER_HEADER_SIZE; - CopyMemory(&pdu, header, sizeof(ENCOMSP_ORDER_HEADER)); - if (Stream_GetRemainingLength(s) < 12) { WLog_ERR(TAG, "Not enough data!"); return ERROR_INVALID_DATA; } + beg = (Stream_GetPosition(s)) - ENCOMSP_ORDER_HEADER_SIZE; + CopyMemory(&pdu, header, sizeof(ENCOMSP_ORDER_HEADER)); + Stream_Read_UINT32(s, pdu.ParticipantId); /* ParticipantId (4 bytes) */ Stream_Read_UINT32(s, pdu.DiscType); /* DiscType (4 bytes) */ Stream_Read_UINT32(s, pdu.DiscCode); /* DiscCode (4 bytes) */ - end = (int)Stream_GetPosition(s); + end = Stream_GetPosition(s); if ((beg + header->Length) < end) { @@ -598,9 +634,9 @@ static UINT encomsp_recv_participant_removed_pdu(encomspPlugin* encomsp, wStream * @return 0 on success, otherwise a Win32 error code */ static UINT encomsp_recv_change_participant_control_level_pdu(encomspPlugin* encomsp, wStream* s, - ENCOMSP_ORDER_HEADER* header) + const ENCOMSP_ORDER_HEADER* header) { - int beg, end; + size_t beg, end, pos; EncomspClientContext* context; ENCOMSP_CHANGE_PARTICIPANT_CONTROL_LEVEL_PDU pdu; UINT error = CHANNEL_RC_OK; @@ -609,7 +645,10 @@ static UINT encomsp_recv_change_participant_control_level_pdu(encomspPlugin* enc if (!context) return ERROR_INVALID_HANDLE; - beg = ((int)Stream_GetPosition(s)) - ENCOMSP_ORDER_HEADER_SIZE; + pos = Stream_GetPosition(s); + if (pos < ENCOMSP_ORDER_HEADER_SIZE) + return ERROR_INVALID_DATA; + beg = pos - ENCOMSP_ORDER_HEADER_SIZE; CopyMemory(&pdu, header, sizeof(ENCOMSP_ORDER_HEADER)); if (Stream_GetRemainingLength(s) < 6) @@ -620,7 +659,7 @@ static UINT encomsp_recv_change_participant_control_level_pdu(encomspPlugin* enc Stream_Read_UINT16(s, pdu.Flags); /* Flags (2 bytes) */ Stream_Read_UINT32(s, pdu.ParticipantId); /* ParticipantId (4 bytes) */ - end = (int)Stream_GetPosition(s); + end = Stream_GetPosition(s); if ((beg + header->Length) < end) { @@ -653,16 +692,17 @@ static UINT encomsp_recv_change_participant_control_level_pdu(encomspPlugin* enc * * @return 0 on success, otherwise a Win32 error code */ -static UINT -encomsp_send_change_participant_control_level_pdu(EncomspClientContext* context, - ENCOMSP_CHANGE_PARTICIPANT_CONTROL_LEVEL_PDU* pdu) +static UINT encomsp_send_change_participant_control_level_pdu( + EncomspClientContext* context, const ENCOMSP_CHANGE_PARTICIPANT_CONTROL_LEVEL_PDU* pdu) { wStream* s; encomspPlugin* encomsp; UINT error; + ENCOMSP_ORDER_HEADER header; + encomsp = (encomspPlugin*)context->handle; - pdu->Type = ODTYPE_PARTICIPANT_CTRL_CHANGED; - pdu->Length = ENCOMSP_ORDER_HEADER_SIZE + 6; + header.Type = ODTYPE_PARTICIPANT_CTRL_CHANGED; + header.Length = ENCOMSP_ORDER_HEADER_SIZE + 6; s = Stream_New(NULL, pdu->Length); if (!s) @@ -671,7 +711,7 @@ encomsp_send_change_participant_control_level_pdu(EncomspClientContext* context, return CHANNEL_RC_NO_MEMORY; } - if ((error = encomsp_write_header(s, (ENCOMSP_ORDER_HEADER*)pdu))) + if ((error = encomsp_write_header(s, &header))) { WLog_ERR(TAG, "encomsp_write_header failed with error %" PRIu32 "!", error); return error; @@ -689,9 +729,9 @@ encomsp_send_change_participant_control_level_pdu(EncomspClientContext* context, * @return 0 on success, otherwise a Win32 error code */ static UINT encomsp_recv_graphics_stream_paused_pdu(encomspPlugin* encomsp, wStream* s, - ENCOMSP_ORDER_HEADER* header) + const ENCOMSP_ORDER_HEADER* header) { - int beg, end; + size_t beg, end, pos; EncomspClientContext* context; ENCOMSP_GRAPHICS_STREAM_PAUSED_PDU pdu; UINT error = CHANNEL_RC_OK; @@ -700,9 +740,12 @@ static UINT encomsp_recv_graphics_stream_paused_pdu(encomspPlugin* encomsp, wStr if (!context) return ERROR_INVALID_HANDLE; - beg = ((int)Stream_GetPosition(s)) - ENCOMSP_ORDER_HEADER_SIZE; + pos = Stream_GetPosition(s); + if (pos < ENCOMSP_ORDER_HEADER_SIZE) + return ERROR_INVALID_DATA; + beg = pos - ENCOMSP_ORDER_HEADER_SIZE; CopyMemory(&pdu, header, sizeof(ENCOMSP_ORDER_HEADER)); - end = (int)Stream_GetPosition(s); + end = Stream_GetPosition(s); if ((beg + header->Length) < end) { @@ -735,9 +778,9 @@ static UINT encomsp_recv_graphics_stream_paused_pdu(encomspPlugin* encomsp, wStr * @return 0 on success, otherwise a Win32 error code */ static UINT encomsp_recv_graphics_stream_resumed_pdu(encomspPlugin* encomsp, wStream* s, - ENCOMSP_ORDER_HEADER* header) + const ENCOMSP_ORDER_HEADER* header) { - int beg, end; + size_t beg, end, pos; EncomspClientContext* context; ENCOMSP_GRAPHICS_STREAM_RESUMED_PDU pdu; UINT error = CHANNEL_RC_OK; @@ -746,9 +789,12 @@ static UINT encomsp_recv_graphics_stream_resumed_pdu(encomspPlugin* encomsp, wSt if (!context) return ERROR_INVALID_HANDLE; - beg = ((int)Stream_GetPosition(s)) - ENCOMSP_ORDER_HEADER_SIZE; + pos = Stream_GetPosition(s); + if (pos < ENCOMSP_ORDER_HEADER_SIZE) + return ERROR_INVALID_DATA; + beg = pos - ENCOMSP_ORDER_HEADER_SIZE; CopyMemory(&pdu, header, sizeof(ENCOMSP_ORDER_HEADER)); - end = (int)Stream_GetPosition(s); + end = Stream_GetPosition(s); if ((beg + header->Length) < end) { @@ -922,7 +968,6 @@ static UINT encomsp_process_receive(encomspPlugin* encomsp, wStream* s) default: WLog_ERR(TAG, "header.Type %" PRIu16 " not found", header.Type); return ERROR_INVALID_DATA; - break; } } @@ -938,7 +983,7 @@ static void encomsp_process_connect(encomspPlugin* encomsp) * * @return 0 on success, otherwise a Win32 error code */ -static UINT encomsp_virtual_channel_event_data_received(encomspPlugin* encomsp, void* pData, +static UINT encomsp_virtual_channel_event_data_received(encomspPlugin* encomsp, const void* pData, UINT32 dataLength, UINT32 totalLength, UINT32 dataFlags) { @@ -963,7 +1008,7 @@ static UINT encomsp_virtual_channel_event_data_received(encomspPlugin* encomsp, data_in = encomsp->data_in; - if (!Stream_EnsureRemainingCapacity(data_in, (int)dataLength)) + if (!Stream_EnsureRemainingCapacity(data_in, dataLength)) { WLog_ERR(TAG, "Stream_EnsureRemainingCapacity failed!"); return ERROR_INTERNAL_ERROR; diff --git a/channels/encomsp/client/encomsp_main.h b/channels/encomsp/client/encomsp_main.h index 7b23ed1bb..ad43ceae1 100644 --- a/channels/encomsp/client/encomsp_main.h +++ b/channels/encomsp/client/encomsp_main.h @@ -37,20 +37,6 @@ #define TAG CHANNELS_TAG("encomsp.client") -struct encomsp_plugin -{ - CHANNEL_DEF channelDef; - CHANNEL_ENTRY_POINTS_FREERDP_EX channelEntryPoints; - - EncomspClientContext* context; - - HANDLE thread; - wStream* data_in; - void* InitHandle; - DWORD OpenHandle; - wMessageQueue* queue; - rdpContext* rdpcontext; -}; typedef struct encomsp_plugin encomspPlugin; #endif /* FREERDP_CHANNEL_ENCOMSP_CLIENT_MAIN_H */ diff --git a/client/Sample/tf_channels.c b/client/Sample/tf_channels.c index 51e55afeb..e26f29f35 100644 --- a/client/Sample/tf_channels.c +++ b/client/Sample/tf_channels.c @@ -39,8 +39,9 @@ * * @return 0 on success, otherwise a Win32 error code */ -static UINT tf_encomsp_participant_created(EncomspClientContext* context, - ENCOMSP_PARTICIPANT_CREATED_PDU* participantCreated) +static UINT +tf_encomsp_participant_created(EncomspClientContext* context, + const ENCOMSP_PARTICIPANT_CREATED_PDU* participantCreated) { WINPR_UNUSED(context); WINPR_UNUSED(participantCreated); diff --git a/client/Wayland/wlf_channels.c b/client/Wayland/wlf_channels.c index 743dd54af..269fab017 100644 --- a/client/Wayland/wlf_channels.c +++ b/client/Wayland/wlf_channels.c @@ -33,8 +33,9 @@ * * @return 0 on success, otherwise a Win32 error code */ -static UINT wlf_encomsp_participant_created(EncomspClientContext* context, - ENCOMSP_PARTICIPANT_CREATED_PDU* participantCreated) +static UINT +wlf_encomsp_participant_created(EncomspClientContext* context, + const ENCOMSP_PARTICIPANT_CREATED_PDU* participantCreated) { return CHANNEL_RC_OK; } diff --git a/client/X11/xf_client.c b/client/X11/xf_client.c index 04f43b34f..388d8e591 100644 --- a/client/X11/xf_client.c +++ b/client/X11/xf_client.c @@ -756,9 +756,29 @@ BOOL xf_toggle_control(xfContext* xfc) * * @return 0 on success, otherwise a Win32 error code */ -static UINT xf_encomsp_participant_created(EncomspClientContext* context, - ENCOMSP_PARTICIPANT_CREATED_PDU* participantCreated) +static UINT +xf_encomsp_participant_created(EncomspClientContext* context, + const ENCOMSP_PARTICIPANT_CREATED_PDU* participantCreated) { + xfContext* xfc; + rdpSettings* settings; + BOOL request; + + if (!context || !context->custom || !participantCreated) + return ERROR_INVALID_PARAMETER; + + xfc = context->custom; + settings = xfc->context.settings; + + if (!settings) + return ERROR_INVALID_PARAMETER; + +#if 0 // TODO + request = freerdp_settings_get_bool(settings, FreeRDP_RequestControl); + if (request && (participantCreated->Flags & ENCOMSP_MAY_VIEW) && !(participantCreated->Flags & ENCOMSP_MAY_INTERACT)) + xf_toggle_control(xfc); +#endif + return CHANNEL_RC_OK; } diff --git a/include/freerdp/client/encomsp.h b/include/freerdp/client/encomsp.h index f69ef474c..e00578cdb 100644 --- a/include/freerdp/client/encomsp.h +++ b/include/freerdp/client/encomsp.h @@ -31,28 +31,29 @@ typedef struct _encomsp_client_context EncomspClientContext; typedef UINT (*pcEncomspFilterUpdated)(EncomspClientContext* context, - ENCOMSP_FILTER_UPDATED_PDU* filterUpdated); -typedef UINT (*pcEncomspApplicationCreated)(EncomspClientContext* context, - ENCOMSP_APPLICATION_CREATED_PDU* applicationCreated); -typedef UINT (*pcEncomspApplicationRemoved)(EncomspClientContext* context, - ENCOMSP_APPLICATION_REMOVED_PDU* applicationRemoved); + const ENCOMSP_FILTER_UPDATED_PDU* filterUpdated); +typedef UINT (*pcEncomspApplicationCreated)( + EncomspClientContext* context, const ENCOMSP_APPLICATION_CREATED_PDU* applicationCreated); +typedef UINT (*pcEncomspApplicationRemoved)( + EncomspClientContext* context, const ENCOMSP_APPLICATION_REMOVED_PDU* applicationRemoved); typedef UINT (*pcEncomspWindowCreated)(EncomspClientContext* context, - ENCOMSP_WINDOW_CREATED_PDU* windowCreated); + const ENCOMSP_WINDOW_CREATED_PDU* windowCreated); typedef UINT (*pcEncomspWindowRemoved)(EncomspClientContext* context, - ENCOMSP_WINDOW_REMOVED_PDU* windowRemoved); + const ENCOMSP_WINDOW_REMOVED_PDU* windowRemoved); typedef UINT (*pcEncomspShowWindow)(EncomspClientContext* context, - ENCOMSP_SHOW_WINDOW_PDU* showWindow); -typedef UINT (*pcEncomspParticipantCreated)(EncomspClientContext* context, - ENCOMSP_PARTICIPANT_CREATED_PDU* participantCreated); -typedef UINT (*pcEncomspParticipantRemoved)(EncomspClientContext* context, - ENCOMSP_PARTICIPANT_REMOVED_PDU* participantRemoved); + const ENCOMSP_SHOW_WINDOW_PDU* showWindow); +typedef UINT (*pcEncomspParticipantCreated)( + EncomspClientContext* context, const ENCOMSP_PARTICIPANT_CREATED_PDU* participantCreated); +typedef UINT (*pcEncomspParticipantRemoved)( + EncomspClientContext* context, const ENCOMSP_PARTICIPANT_REMOVED_PDU* participantRemoved); typedef UINT (*pcEncomspChangeParticipantControlLevel)( EncomspClientContext* context, - ENCOMSP_CHANGE_PARTICIPANT_CONTROL_LEVEL_PDU* changeParticipantControlLevel); + const ENCOMSP_CHANGE_PARTICIPANT_CONTROL_LEVEL_PDU* changeParticipantControlLevel); typedef UINT (*pcEncomspGraphicsStreamPaused)( - EncomspClientContext* context, ENCOMSP_GRAPHICS_STREAM_PAUSED_PDU* graphicsStreamPaused); + EncomspClientContext* context, const ENCOMSP_GRAPHICS_STREAM_PAUSED_PDU* graphicsStreamPaused); typedef UINT (*pcEncomspGraphicsStreamResumed)( - EncomspClientContext* context, ENCOMSP_GRAPHICS_STREAM_RESUMED_PDU* graphicsStreamResumed); + EncomspClientContext* context, + const ENCOMSP_GRAPHICS_STREAM_RESUMED_PDU* graphicsStreamResumed); struct _encomsp_client_context { From c5e261e066e3f5a9bdd90b9219563bad69ed9d2d Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Mon, 25 Nov 2019 09:54:56 +0100 Subject: [PATCH 2/3] Added new command line swith for automatich assistance control. --- client/Wayland/wlf_channels.c | 38 +++++++++++++++++++ client/X11/xf_client.c | 9 ++--- client/common/cmdline.c | 6 +++ client/common/cmdline.h | 2 + include/freerdp/settings.h | 20 +++++----- libfreerdp/common/settings_getters.c | 7 ++++ .../core/test/settings_property_lists.h | 1 + 7 files changed, 69 insertions(+), 14 deletions(-) diff --git a/client/Wayland/wlf_channels.c b/client/Wayland/wlf_channels.c index 269fab017..ff84fc2ff 100644 --- a/client/Wayland/wlf_channels.c +++ b/client/Wayland/wlf_channels.c @@ -28,6 +28,23 @@ #include "wlf_disp.h" #include "wlfreerdp.h" +BOOL encomsp_toggle_control(EncomspClientContext* encomsp, BOOL control) +{ + ENCOMSP_CHANGE_PARTICIPANT_CONTROL_LEVEL_PDU pdu; + + if (!encomsp) + return FALSE; + + pdu.ParticipantId = 0; + pdu.Flags = ENCOMSP_REQUEST_VIEW; + + if (control) + pdu.Flags |= ENCOMSP_REQUEST_INTERACT; + + encomsp->ChangeParticipantControlLevel(encomsp, &pdu); + return TRUE; +} + /** * Function description * @@ -37,6 +54,27 @@ static UINT wlf_encomsp_participant_created(EncomspClientContext* context, const ENCOMSP_PARTICIPANT_CREATED_PDU* participantCreated) { + wlfContext* wlf; + rdpSettings* settings; + BOOL request; + + if (!context || !context->custom || !participantCreated) + return ERROR_INVALID_PARAMETER; + + wlf = (wlfContext*)context->custom; + settings = wlf->context.settings; + + if (!settings) + return ERROR_INVALID_PARAMETER; + + request = freerdp_settings_get_bool(settings, FreeRDP_RemoteAssistanceRequestControl); + if (request && (participantCreated->Flags & ENCOMSP_MAY_VIEW) && + !(participantCreated->Flags & ENCOMSP_MAY_INTERACT)) + { + if (!encomsp_toggle_control(context, TRUE)) + return ERROR_INTERNAL_ERROR; + } + return CHANNEL_RC_OK; } diff --git a/client/X11/xf_client.c b/client/X11/xf_client.c index 388d8e591..69943c393 100644 --- a/client/X11/xf_client.c +++ b/client/X11/xf_client.c @@ -773,11 +773,10 @@ xf_encomsp_participant_created(EncomspClientContext* context, if (!settings) return ERROR_INVALID_PARAMETER; -#if 0 // TODO - request = freerdp_settings_get_bool(settings, FreeRDP_RequestControl); - if (request && (participantCreated->Flags & ENCOMSP_MAY_VIEW) && !(participantCreated->Flags & ENCOMSP_MAY_INTERACT)) - xf_toggle_control(xfc); -#endif + request = freerdp_settings_get_bool(settings, FreeRDP_RemoteAssistanceRequestControl); + if (request && (participantCreated->Flags & ENCOMSP_MAY_VIEW) && + !(participantCreated->Flags & ENCOMSP_MAY_INTERACT)) + xf_toggle_control(xfc); return CHANNEL_RC_OK; } diff --git a/client/common/cmdline.c b/client/common/cmdline.c index bdb3f4ba5..f7c5c4dca 100644 --- a/client/common/cmdline.c +++ b/client/common/cmdline.c @@ -2893,6 +2893,12 @@ int freerdp_client_settings_parse_command_line_arguments(rdpSettings* settings, else settings->MaxTimeInCheckLoop = (UINT32)val; } + CommandLineSwitchCase(arg, "auto-request-control") + { + if (!freerdp_settings_set_bool(settings, FreeRDP_RemoteAssistanceRequestControl, + enable)) + return COMMAND_LINE_ERROR; + } CommandLineSwitchCase(arg, "async-input") { settings->AsyncInput = enable; diff --git a/client/common/cmdline.h b/client/common/cmdline.h index e47a26449..0a201e4f1 100644 --- a/client/common/cmdline.h +++ b/client/common/cmdline.h @@ -46,6 +46,8 @@ static const COMMAND_LINE_ARGUMENT_A args[] = { "Remote application workspace path" }, { "assistance", COMMAND_LINE_VALUE_REQUIRED, "", NULL, NULL, -1, NULL, "Remote assistance password" }, + { "auto-request-control", COMMAND_LINE_VALUE_FLAG, "", NULL, NULL, -1, NULL, + "Automatically request remote assistance input control" }, { "async-channels", COMMAND_LINE_VALUE_BOOL, NULL, BoolValueFalse, NULL, -1, NULL, "Asynchronous channels (experimental)" }, { "async-input", COMMAND_LINE_VALUE_BOOL, NULL, BoolValueFalse, NULL, -1, NULL, diff --git a/include/freerdp/settings.h b/include/freerdp/settings.h index 3cad588a4..2dccdab9f 100644 --- a/include/freerdp/settings.h +++ b/include/freerdp/settings.h @@ -633,6 +633,7 @@ typedef struct _RDPDR_PARALLEL RDPDR_PARALLEL; #define FreeRDP_EncomspVirtualChannel (1029) #define FreeRDP_RemdeskVirtualChannel (1030) #define FreeRDP_LyncRdpMode (1031) +#define FreeRDP_RemoteAssistanceRequestControl (1032) #define FreeRDP_TlsSecurity (1088) #define FreeRDP_NlaSecurity (1089) #define FreeRDP_RdpSecurity (1090) @@ -1063,15 +1064,16 @@ struct rdp_settings UINT64 padding1024[1024 - 969]; /* 969 */ /* Remote Assistance */ - ALIGN64 BOOL RemoteAssistanceMode; /* 1024 */ - ALIGN64 char* RemoteAssistanceSessionId; /* 1025 */ - ALIGN64 char* RemoteAssistancePassStub; /* 1026 */ - ALIGN64 char* RemoteAssistancePassword; /* 1027 */ - ALIGN64 char* RemoteAssistanceRCTicket; /* 1028 */ - ALIGN64 BOOL EncomspVirtualChannel; /* 1029 */ - ALIGN64 BOOL RemdeskVirtualChannel; /* 1030 */ - ALIGN64 BOOL LyncRdpMode; /* 1031 */ - UINT64 padding1088[1088 - 1032]; /* 1032 */ + ALIGN64 BOOL RemoteAssistanceMode; /* 1024 */ + ALIGN64 char* RemoteAssistanceSessionId; /* 1025 */ + ALIGN64 char* RemoteAssistancePassStub; /* 1026 */ + ALIGN64 char* RemoteAssistancePassword; /* 1027 */ + ALIGN64 char* RemoteAssistanceRCTicket; /* 1028 */ + ALIGN64 BOOL EncomspVirtualChannel; /* 1029 */ + ALIGN64 BOOL RemdeskVirtualChannel; /* 1030 */ + ALIGN64 BOOL LyncRdpMode; /* 1031 */ + ALIGN64 BOOL RemoteAssistanceRequestControl; /* 1032 */ + UINT64 padding1088[1088 - 1033]; /* 1033 */ /** * X.224 Connection Request/Confirm diff --git a/libfreerdp/common/settings_getters.c b/libfreerdp/common/settings_getters.c index 86bacd00b..c9a2ff021 100644 --- a/libfreerdp/common/settings_getters.c +++ b/libfreerdp/common/settings_getters.c @@ -165,6 +165,9 @@ BOOL freerdp_settings_get_bool(const rdpSettings* settings, size_t id) case FreeRDP_LyncRdpMode: return settings->LyncRdpMode; + case FreeRDP_RemoteAssistanceRequestControl: + return settings->RemoteAssistanceRequestControl; + case FreeRDP_TlsSecurity: return settings->TlsSecurity; @@ -715,6 +718,10 @@ BOOL freerdp_settings_set_bool(rdpSettings* settings, size_t id, BOOL val) settings->LyncRdpMode = val; break; + case FreeRDP_RemoteAssistanceRequestControl: + settings->RemoteAssistanceRequestControl = val; + break; + case FreeRDP_TlsSecurity: settings->TlsSecurity = val; break; diff --git a/libfreerdp/core/test/settings_property_lists.h b/libfreerdp/core/test/settings_property_lists.h index 8e608c970..0b8ac3795 100644 --- a/libfreerdp/core/test/settings_property_lists.h +++ b/libfreerdp/core/test/settings_property_lists.h @@ -54,6 +54,7 @@ static const size_t bool_list_indices[] = { FreeRDP_EncomspVirtualChannel, FreeRDP_RemdeskVirtualChannel, FreeRDP_LyncRdpMode, + FreeRDP_RemoteAssistanceRequestControl, FreeRDP_TlsSecurity, FreeRDP_NlaSecurity, FreeRDP_RdpSecurity, From fd968cdf84bd9026b2b508e0b843b2dc954fd99f Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Mon, 25 Nov 2019 10:32:05 +0100 Subject: [PATCH 3/3] Fixed dead store warning. --- channels/printer/client/cups/printer_cups.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/channels/printer/client/cups/printer_cups.c b/channels/printer/client/cups/printer_cups.c index b78632e9c..3d94d6b8e 100644 --- a/channels/printer/client/cups/printer_cups.c +++ b/channels/printer/client/cups/printer_cups.c @@ -326,9 +326,8 @@ static rdpPrinter** printer_cups_enum_printers(rdpPrinterDriver* driver) { if (dest->instance == NULL) { - rdpPrinter* current = printers[num_printers]; - current = printer_cups_new_printer((rdpCupsPrinterDriver*)driver, dest->name, NULL, - dest->is_default); + rdpPrinter* current = printer_cups_new_printer((rdpCupsPrinterDriver*)driver, + dest->name, NULL, dest->is_default); if (!current) { printer_cups_release_enum_printers(printers);