From 92e2f4e42074693bdc540ec9d0ae7392c7771a65 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Mon, 18 Apr 2016 18:53:12 -0700 Subject: [PATCH 1/4] GUACAMOLE-33: Restore guac_common_cursor_remove_user() (reverts commit af7968e). --- src/common/guac_cursor.c | 9 +++++++++ src/common/guac_cursor.h | 15 +++++++++++++++ src/protocols/vnc/user.c | 9 +++++++++ src/protocols/vnc/user.h | 5 +++++ 4 files changed, 38 insertions(+) diff --git a/src/common/guac_cursor.c b/src/common/guac_cursor.c index e376ab03..4ed66b1d 100644 --- a/src/common/guac_cursor.c +++ b/src/common/guac_cursor.c @@ -367,3 +367,12 @@ void guac_common_cursor_set_blank(guac_common_cursor* cursor) { } +void guac_common_cursor_remove_user(guac_common_cursor* cursor, + guac_user* user) { + + /* Disassociate from given user */ + if (cursor->user == user) + cursor->user = NULL; + +} + diff --git a/src/common/guac_cursor.h b/src/common/guac_cursor.h index ae359b7f..9db7067d 100644 --- a/src/common/guac_cursor.h +++ b/src/common/guac_cursor.h @@ -249,4 +249,19 @@ void guac_common_cursor_set_ibar(guac_common_cursor* cursor); */ void guac_common_cursor_set_blank(guac_common_cursor* cursor); +/** + * Removes the given user, such that future synchronization will not occur. + * This is necessary when a user leaves the connection. If a user leaves the + * connection and this is not called, the corresponding guac_user and socket + * may cease to be valid, and future synchronization attempts will segfault. + * + * @param cursor + * The cursor to remove the user from. + * + * @param user + * The user to remove. + */ +void guac_common_cursor_remove_user(guac_common_cursor* cursor, + guac_user* user); + #endif diff --git a/src/protocols/vnc/user.c b/src/protocols/vnc/user.c index 0b89d7c9..53423a11 100644 --- a/src/protocols/vnc/user.c +++ b/src/protocols/vnc/user.c @@ -97,3 +97,12 @@ int guac_vnc_user_join_handler(guac_user* user, int argc, char** argv) { } +int guac_vnc_user_leave_handler(guac_user* user) { + + guac_vnc_client* vnc_client = (guac_vnc_client*) user->client->data; + + guac_common_cursor_remove_user(vnc_client->display->cursor, user); + + return 0; +} + diff --git a/src/protocols/vnc/user.h b/src/protocols/vnc/user.h index 125e4965..e74b2a05 100644 --- a/src/protocols/vnc/user.h +++ b/src/protocols/vnc/user.h @@ -29,5 +29,10 @@ */ guac_user_join_handler guac_vnc_user_join_handler; +/** + * Handler for leaving users. + */ +guac_user_leave_handler guac_vnc_user_leave_handler; + #endif From 46b29edc5f64d361a6d190b67425910423a7b3a9 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Mon, 18 Apr 2016 18:58:16 -0700 Subject: [PATCH 2/4] GUACAMOLE-33: Actually use VNC's leave handler. --- src/protocols/vnc/client.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/protocols/vnc/client.c b/src/protocols/vnc/client.c index 10391dd3..f3840bb7 100644 --- a/src/protocols/vnc/client.c +++ b/src/protocols/vnc/client.c @@ -52,6 +52,7 @@ int guac_client_init(guac_client* client) { /* Set handlers */ client->join_handler = guac_vnc_user_join_handler; + client->leave_handler = guac_vnc_user_leave_handler; client->free_handler = guac_vnc_client_free_handler; return 0; From 82fd6a279b110a7d1cab7a7f3c48c9dfcaecb7e3 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Mon, 18 Apr 2016 19:03:38 -0700 Subject: [PATCH 3/4] GUACAMOLE-33: Implement leave handlers for RDP, SSH, and telnet. --- src/protocols/rdp/user.c | 9 +++++++++ src/protocols/rdp/user.h | 5 +++++ src/protocols/ssh/user.c | 9 +++++++++ src/protocols/ssh/user.h | 9 +++++++-- src/protocols/telnet/user.c | 10 ++++++++++ src/protocols/telnet/user.h | 5 +++++ 6 files changed, 45 insertions(+), 2 deletions(-) diff --git a/src/protocols/rdp/user.c b/src/protocols/rdp/user.c index 6ded2eb8..af597dbd 100644 --- a/src/protocols/rdp/user.c +++ b/src/protocols/rdp/user.c @@ -122,3 +122,12 @@ int guac_rdp_user_file_handler(guac_user* user, guac_stream* stream, return 0; } +int guac_rdp_user_leave_handler(guac_user* user) { + + guac_rdp_client* rdp_client = (guac_rdp_client*) user->client->data; + + guac_common_cursor_remove_user(rdp_client->display->cursor, user); + + return 0; +} + diff --git a/src/protocols/rdp/user.h b/src/protocols/rdp/user.h index fe94d3e8..99b8c578 100644 --- a/src/protocols/rdp/user.h +++ b/src/protocols/rdp/user.h @@ -27,6 +27,11 @@ */ guac_user_join_handler guac_rdp_user_join_handler; +/** + * Handler for leaving users. + */ +guac_user_leave_handler guac_rdp_user_leave_handler; + /** * Handler for received simple file uploads. This handler will automatically * select between RDPDR and SFTP depending on which is available and which has diff --git a/src/protocols/ssh/user.c b/src/protocols/ssh/user.c index fc9913c9..4a224a0b 100644 --- a/src/protocols/ssh/user.c +++ b/src/protocols/ssh/user.c @@ -82,3 +82,12 @@ int guac_ssh_user_join_handler(guac_user* user, int argc, char** argv) { } +int guac_ssh_user_leave_handler(guac_user* user) { + + guac_ssh_client* ssh_client = (guac_ssh_client*) user->client->data; + + guac_common_cursor_remove_user(ssh_client->term->cursor, user); + + return 0; +} + diff --git a/src/protocols/ssh/user.h b/src/protocols/ssh/user.h index b9e99400..8287fed4 100644 --- a/src/protocols/ssh/user.h +++ b/src/protocols/ssh/user.h @@ -17,8 +17,8 @@ * under the License. */ -#ifndef GUAC_VNC_USER_H -#define GUAC_VNC_USER_H +#ifndef GUAC_SSH_USER_H +#define GUAC_SSH_USER_H #include "config.h" @@ -29,5 +29,10 @@ */ guac_user_join_handler guac_ssh_user_join_handler; +/** + * Handler for leaving users. + */ +guac_user_leave_handler guac_ssh_user_leave_handler; + #endif diff --git a/src/protocols/telnet/user.c b/src/protocols/telnet/user.c index 45855bde..427112b6 100644 --- a/src/protocols/telnet/user.c +++ b/src/protocols/telnet/user.c @@ -78,3 +78,13 @@ int guac_telnet_user_join_handler(guac_user* user, int argc, char** argv) { } +int guac_telnet_user_leave_handler(guac_user* user) { + + guac_telnet_client* telnet_client = + (guac_telnet_client*) user->client->data; + + guac_common_cursor_remove_user(telnet_client->term->cursor, user); + + return 0; +} + diff --git a/src/protocols/telnet/user.h b/src/protocols/telnet/user.h index 0968f679..910f0cb5 100644 --- a/src/protocols/telnet/user.h +++ b/src/protocols/telnet/user.h @@ -29,5 +29,10 @@ */ guac_user_join_handler guac_telnet_user_join_handler; +/** + * Handler for leaving users. + */ +guac_user_leave_handler guac_telnet_user_leave_handler; + #endif From 2b8e1555c68b3eab2b401e506849353d7a04e29e Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Mon, 18 Apr 2016 20:07:54 -0700 Subject: [PATCH 4/4] GUACAMOLE-33: Fix comment regarding user removal. --- src/common/guac_cursor.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/common/guac_cursor.h b/src/common/guac_cursor.h index 9db7067d..a6d9681e 100644 --- a/src/common/guac_cursor.h +++ b/src/common/guac_cursor.h @@ -252,8 +252,8 @@ void guac_common_cursor_set_blank(guac_common_cursor* cursor); /** * Removes the given user, such that future synchronization will not occur. * This is necessary when a user leaves the connection. If a user leaves the - * connection and this is not called, the corresponding guac_user and socket - * may cease to be valid, and future synchronization attempts will segfault. + * connection and this is not called, the mouse cursor state may not update + * correctly in response to mouse events. * * @param cursor * The cursor to remove the user from.