From 4f70cc13e2aa28657e40f91dfcf03dd9c82a41e9 Mon Sep 17 00:00:00 2001 From: "Preston A. Elder" Date: Tue, 28 Jul 2009 10:21:40 -0700 Subject: Fleshed out server interface - Enables channel_request_open types of DIRECT_TCPIP, FORWARDED_TCPIP and X11 (ie. implemented the handling of those channel_request_open types). - Adds functions to retrieve the extra information relating to channel_request_open messages and channel_request messages. - Adds a channel_write_stderr method (obviously for writing to the STDERR channel from server side) - well, technically just converted the exiting channel_write to take an extra argument and created two wrapper functions. - Actually does the invoking of message_handle() from channel_recv_request. - Implemented the handling of the window-change and env channel_requests. - Implemented a few functions in server.h that were declared but not defined (eg. ssh_message_channel_request_channel). Signed-off-by: Preston A. Elder Signed-off-by: Andreas Schneider --- libssh/channels.c | 58 +++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 43 insertions(+), 15 deletions(-) (limited to 'libssh/channels.c') diff --git a/libssh/channels.c b/libssh/channels.c index cf8bbf6..f40ebc9 100644 --- a/libssh/channels.c +++ b/libssh/channels.c @@ -472,6 +472,7 @@ static void channel_rcv_request(SSH_SESSION *session) { ssh_string request_s; char *request; uint32_t status; + uint32_t startpos = session->in_buffer->pos; enter_function(); @@ -542,8 +543,13 @@ static void channel_rcv_request(SSH_SESSION *session) { leave_function(); return; } + /* TODO call message_handle since it handles channel requests as messages */ /* *but* reset buffer before !! */ + + session->in_buffer->pos = startpos; + message_handle(session, SSH2_MSG_CHANNEL_REQUEST); + ssh_log(session, SSH_LOG_PACKET, "Unknown request %s", request); SAFE_FREE(request); @@ -852,20 +858,7 @@ error: return rc; } -/** - * @brief Blocking write on channel. - * - * @param channel The channel to write to. - * - * @param data A pointer to the data to write. - * - * @param len The length of the buffer to write to. - * - * @return The number of bytes written, SSH_ERROR on error. - * - * @see channel_read() - */ -int channel_write(ssh_channel channel, const void *data, uint32_t len) { +int channel_write_common(ssh_channel channel, const void *data, uint32_t len, int is_stderr) { SSH_SESSION *session = channel->session; int origlen = len; int effectivelen; @@ -916,7 +909,8 @@ int channel_write(ssh_channel channel, const void *data, uint32_t len) { effectivelen = len; } - if (buffer_add_u8(session->out_buffer, SSH2_MSG_CHANNEL_DATA) < 0 || + if (buffer_add_u8(session->out_buffer, is_stderr ? + SSH2_MSG_CHANNEL_EXTENDED_DATA : SSH2_MSG_CHANNEL_DATA) < 0 || buffer_add_u32(session->out_buffer, htonl(channel->remote_channel)) < 0 || buffer_add_u32(session->out_buffer, htonl(effectivelen)) < 0 || @@ -946,6 +940,40 @@ error: return SSH_ERROR; } +/** + * @brief Blocking write on channel. + * + * @param channel The channel to write to. + * + * @param data A pointer to the data to write. + * + * @param len The length of the buffer to write to. + * + * @return The number of bytes written, SSH_ERROR on error. + * + * @see channel_read() + */ +int channel_write(ssh_channel channel, const void *data, uint32_t len) { + return channel_write_common(channel, data, len, 0); +} + +/** + * @brief Blocking write on channel for stderr. + * + * @param channel The channel to write to. + * + * @param data A pointer to the data to write. + * + * @param len The length of the buffer to write to. + * + * @return The number of bytes written, SSH_ERROR on error. + * + * @see channel_read() + */ +int channel_write_stderr(ssh_channel channel, const void *data, uint32_t len) { + return channel_write_common(channel, data, len, 1); +} + /** * @brief Check if the channel is open or not. * -- cgit