diff --git a/include/libssh/callbacks.h b/include/libssh/callbacks.h index 0bcadc80..8804370b 100644 --- a/include/libssh/callbacks.h +++ b/include/libssh/callbacks.h @@ -94,6 +94,19 @@ typedef void (*ssh_status_callback) (ssh_session session, float status, typedef void (*ssh_global_request_callback) (ssh_session session, ssh_message message, void *userdata); +/** + * @brief Handles an SSH new channel open X11 request. This happens when the server + * sends back an X11 connection attempt. This is a client-side API + * @param session current session handler + * @param userdata Userdata to be passed to the callback function. + * @returns a valid ssh_channel handle if the request is to be allowed + * @returns NULL if the request should not be allowed + * @warning The channel pointer returned by this callback must be closed by the application. + */ +typedef ssh_channel (*ssh_channel_open_request_x11_callback) (ssh_session session, + const char * originator_address, int originator_port, void *userdata); + + /** * The structure to replace libssh functions with appropriate callbacks. */ @@ -121,6 +134,10 @@ struct ssh_callbacks_struct { * This function will be called each time a global request is received. */ ssh_global_request_callback global_request_function; + /** This function will be called when an incoming X11 request is received. + */ + ssh_channel_open_request_x11_callback channel_open_request_x11_function; + }; typedef struct ssh_callbacks_struct *ssh_callbacks; @@ -185,7 +202,6 @@ typedef int (*ssh_service_request_callback) (ssh_session session, const char *se */ typedef ssh_channel (*ssh_channel_open_request_session_callback) (ssh_session session, void *userdata); - /** * This structure can be used to implement a libssh server, with appropriate callbacks. */ diff --git a/src/messages.c b/src/messages.c index 3701effb..bda622ff 100644 --- a/src/messages.c +++ b/src/messages.c @@ -130,6 +130,19 @@ static int ssh_execute_server_callbacks(ssh_session session, ssh_message msg){ ssh_message_reply_default(msg); } return SSH_OK; + } else if (msg->channel_request_open.type == SSH_CHANNEL_X11){ + if(ssh_callbacks_exists(session->common.callbacks, channel_open_request_x11_function)){ + channel = session->common.callbacks->channel_open_request_x11_function (session, + msg->channel_request_open.originator, msg->channel_request_open.originator_port, + session->common.callbacks->userdata); + if(channel != NULL) { + rc = ssh_message_channel_request_open_reply_accept_channel(msg, channel); + return SSH_OK; + } else { + ssh_message_reply_default(msg); + } + return SSH_OK; + } } } break;