diff options
-rw-r--r-- | include/libssh/libssh.h | 1 | ||||
-rw-r--r-- | libssh/channels.c | 51 |
2 files changed, 52 insertions, 0 deletions
diff --git a/include/libssh/libssh.h b/include/libssh/libssh.h index f18e4066..8ae0faf3 100644 --- a/include/libssh/libssh.h +++ b/include/libssh/libssh.h @@ -332,6 +332,7 @@ LIBSSH_API int channel_request_shell(ssh_channel channel); LIBSSH_API int channel_request_subsystem(ssh_channel channel, const char *system); LIBSSH_API int channel_request_env(ssh_channel channel, const char *name, const char *value); LIBSSH_API int channel_request_exec(ssh_channel channel, const char *cmd); +LIBSSH_API int channel_request_send_signal(ssh_channel channel, const char *signal); LIBSSH_API int channel_request_sftp(ssh_channel channel); LIBSSH_API int channel_request_x11(ssh_channel channel, int single_connection, const char *protocol, const char *cookie, int screen_number); diff --git a/libssh/channels.c b/libssh/channels.c index 6e70285c..ed405892 100644 --- a/libssh/channels.c +++ b/libssh/channels.c @@ -1654,6 +1654,57 @@ error: return rc; } + +/** + * @brief Send a signal to remote process (as described in RFC 4254, section 6.9). + * + * Sends a signal 'signal' to the remote process. + * Note, that remote system may not support signals concept. + * In such a case this request will be silently ignored. + * Only SSH-v2 is supported (I'm not sure about SSH-v1). + * + * @param channel The channel to send signal. + * + * @param signal The signal to send (without SIG prefix) + * (e.g. "TERM" or "KILL"). + * + * @return SSH_SUCCESS on success, SSH_ERROR on error (including attempt to send signal via SSH-v1 session). + * + */ +int channel_request_send_signal(ssh_channel channel, const char *signal) { + ssh_buffer buffer = NULL; + ssh_string encoded_signal = NULL; + int rc = SSH_ERROR; + +#ifdef WITH_SSH1 + if (channel->version == 1) { + return SSH_ERROR; // TODO: Add support for SSH-v1 if possible. + } +#endif + + buffer = buffer_new(); + if (buffer == NULL) { + goto error; + } + + encoded_signal = string_from_char(signal); + if (encoded_signal == NULL) { + goto error; + } + + if (buffer_add_ssh_string(buffer, encoded_signal) < 0) { + goto error; + } + + rc = channel_request(channel, "signal", buffer, 0); +error: + buffer_free(buffer); + string_free(encoded_signal); + return rc; +} + + + /* TODO : fix the delayed close thing */ /* TODO : fix the blocking behaviours */ |