diff options
author | Axel Eppe <aeppe@google.com> | 2018-04-06 13:41:39 +0100 |
---|---|---|
committer | Andreas Schneider <asn@cryptomilk.org> | 2018-04-10 11:16:23 +0200 |
commit | fb2fefb3c65996abac7defcdc0ea758060ea3111 (patch) | |
tree | 83267b031841644d37e69ac51c0b532bddb68107 | |
parent | 6026fc80369ba588a10d6d1abe1767e379a5b97b (diff) | |
download | libssh-fb2fefb3c65996abac7defcdc0ea758060ea3111.tar.gz libssh-fb2fefb3c65996abac7defcdc0ea758060ea3111.tar.xz libssh-fb2fefb3c65996abac7defcdc0ea758060ea3111.zip |
channels: add ssh_channel_request_send_break to support RFC 4335
Signed-off-by: Axel Eppe <aeppe@google.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
-rw-r--r-- | include/libssh/libssh.h | 1 | ||||
-rw-r--r-- | src/channels.c | 49 |
2 files changed, 50 insertions, 0 deletions
diff --git a/include/libssh/libssh.h b/include/libssh/libssh.h index b00a428a..0f509aea 100644 --- a/include/libssh/libssh.h +++ b/include/libssh/libssh.h @@ -418,6 +418,7 @@ LIBSSH_API int ssh_channel_request_pty_size(ssh_channel channel, const char *ter int cols, int rows); LIBSSH_API int ssh_channel_request_shell(ssh_channel channel); LIBSSH_API int ssh_channel_request_send_signal(ssh_channel channel, const char *signum); +LIBSSH_API int ssh_channel_request_send_break(ssh_channel channel, uint32_t length); LIBSSH_API int ssh_channel_request_sftp(ssh_channel channel); LIBSSH_API int ssh_channel_request_subsystem(ssh_channel channel, const char *subsystem); LIBSSH_API int ssh_channel_request_x11(ssh_channel channel, int single_connection, const char *protocol, diff --git a/src/channels.c b/src/channels.c index 6e65dc62..d43cc82a 100644 --- a/src/channels.c +++ b/src/channels.c @@ -2529,6 +2529,55 @@ error: /** + * @brief Send a break signal to the server (as described in RFC 4335). + * + * Sends a break signal to the remote process. + * Note, that remote system may not support breaks. + * In such a case this request will be silently ignored. + * Only SSH-v2 is supported. + * + * @param[in] channel The channel to send the break to. + * + * @param[in] length The break-length in milliseconds to send. + * + * @return SSH_OK on success, SSH_ERROR if an error occurred + * (including attempts to send signal via SSH-v1 session). + */ +int ssh_channel_request_send_break(ssh_channel channel, uint32_t length) { + ssh_buffer buffer = NULL; + int rc = SSH_ERROR; + + if (channel == NULL) { + return SSH_ERROR; + } + +#ifdef WITH_SSH1 + if (channel->version == 1) { + return SSH_ERROR; + } +#endif + + buffer = ssh_buffer_new(); + if (buffer == NULL) { + ssh_set_error_oom(channel->session); + goto error; + } + + rc = ssh_buffer_pack(buffer, "d", length); + if (rc != SSH_OK) { + ssh_set_error_oom(channel->session); + goto error; + } + + rc = channel_request(channel, "break", buffer, 0); + +error: + ssh_buffer_free(buffer); + return rc; +} + + +/** * @brief Read data from a channel into a buffer. * * @param[in] channel The channel to read from. |