aboutsummaryrefslogtreecommitdiff
path: root/src/channels.c
AgeCommit message (Collapse)AuthorFilesLines
2024-03-06Issue #157: Use the current TTY's settings by default.Daniel Evers1-3/+12
When opening a PTY on the server, try to use the current TTY's settings (i.e. based on STDIN). If that fails or STDIN isn't a TTY, use default modes that avoid any character translation. Don't rely on stdin to be a TTY (breaks CI). Instead, open a PTY and temporarily use that as "fake" stdin. Signed-off-by: Daniel Evers (daniel.evers@utimaco.com) Reviewed-by: Jakub Jelen <jjelen@redhat.com>
2024-03-06Fix #157: Allow to set terminal modes for PTYsDaniel Evers1-5/+17
Added the new function `ssh_channel_request_pty_size_modes` which allows to pass additional encoded SSH terminal modes (see opcodes in RFC 4245). Signed-off-by: Daniel Evers (daniel.evers@utimaco.com) Reviewed-by: Jakub Jelen <jjelen@redhat.com>
2024-01-02Document that ssh_channel_read_nonblocking() will trigger callbacksJamesWrigley1-1/+1
Signed-off-by: James Wrigley <james@puiterwijk.org> Reviewed-by: Jakub Jelen <jjelen@redhat.com> Reviewed-by: Norbert Pocs <norbertpocs0@gmail.com>
2024-01-02Document that ssh_channel_read_nonblocking() may return SSH_EOFJamesWrigley1-4/+2
The current documentation incorrectly states that it will return 0 on EOF, but the function calls ssh_channel_poll() internally, which will return SSH_EOF, which will then be returned by ssh_channel_read_nonblocking(). Signed-off-by: James Wrigley <james@puiterwijk.org> Reviewed-by: Jakub Jelen <jjelen@redhat.com> Reviewed-by: Norbert Pocs <norbertpocs0@gmail.com>
2023-09-08Allow sending data payloads of remote_maxpacket length.Tom Deseyn1-8/+5
Signed-off-by: Tom Deseyn <tom.deseyn@gmail.com> Reviewed-by: Jakub Jelen <jjelen@redhat.com>
2023-09-01channel: use a larger window size to increase receive throughput.Tom Deseyn1-53/+55
The window size controls how much data the peer can send before we send back a message to to increase the window. This changes the default window from 1.28MB to 2MiB. 2MiB matches the OpenSSH default session size. The code is also refactored to grow the windows on code paths where data is consumed, and move the condition that checks if the growing the window is needed into the grow method. Signed-off-by: Tom Deseyn <tom.deseyn@gmail.com> Reviewed-by: Jakub Jelen <jjelen@redhat.com> Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2023-08-07channels: Do not be so picky about the extended data typeJakub Jelen1-3/+2
assume stderr by default and log only warning in case the data type is non-standard. Signed-off-by: Jakub Jelen <jjelen@redhat.com> Reviewed-by: Sahana Prasad <sahana@redhat.com> Reviewed-by: Norbert Pocs <npocs@redhat.com>
2023-08-07channels: Fix reading stderr from channelsJakub Jelen1-1/+2
broken in 4b8db203b00a5b80191d95e4a6eb6a3159a918b0 Signed-off-by: Jakub Jelen <jjelen@redhat.com> Reviewed-by: Sahana Prasad <sahana@redhat.com> Reviewed-by: Norbert Pocs <npocs@redhat.com>
2023-06-28channels: Avoid out-of-bounds writesJakub Jelen1-3/+9
CID 1470005 Thanks coverity Signed-off-by: Jakub Jelen <jjelen@redhat.com> Reviewed-by: Norbert Pocs <npocs@redhat.com>
2023-06-22channels: Refactor channel_rcv_data, check for errors and report more useful ↵Jakub Jelen1-10/+21
errors CID 1513157 Thanks coverity Signed-off-by: Jakub Jelen <jjelen@redhat.com> Reviewed-by: Sahana Prasad <sahana@redhat.com>
2023-06-20channels: Reformat channel_rcv_change_windowJakub Jelen1-88/+92
Signed-off-by: Jakub Jelen <jjelen@redhat.com> Reviewed-by: Sahana Prasad <sahana@redhat.com>
2023-04-14Emit channel_write_wontblock when remote window becomes non-zero.Tom Deseyn1-1/+17
Signed-off-by: Tom Deseyn <tom.deseyn@gmail.com> Reviewed-by: Jakub Jelen <jjelen@redhat.com>
2023-02-01documentation: Fix Missing param doxygen warningsNorbert Pocs1-1/+1
Signed-off-by: Norbert Pocs <npocs@redhat.com> Reviewed-by: Jakub Jelen <jjelen@redhat.com>
2023-01-02Add callbacks for channel open response, and channel request response.Tom Deseyn1-0/+28
Signed-off-by: Tom Deseyn <tom.deseyn@gmail.com> Reviewed-by: Jakub Jelen <jjelen@redhat.com> Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2022-10-12Fix various spelling issues reported by codespellJakub Jelen1-2/+4
Signed-off-by: Jakub Jelen <jjelen@redhat.com> Reviewed-by: Anderson Toshiyuki Sasaki <ansasaki@redhat.com>
2022-10-12remove the unnecessary cast of SSH_LOGXiang Xiao1-3/+3
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com> Reviewed-by: Jakub Jelen <jjelen@redhat.com>
2022-10-12change the format specifier of uint32_t from PRId32 to PRIu32Xiang Xiao1-18/+18
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com> Reviewed-by: Jakub Jelen <jjelen@redhat.com>
2022-10-12fix printf format warningXiang Xiao1-24/+24
uint32_t should be formated by PRI?32 Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com> Reviewed-by: Jakub Jelen <jjelen@redhat.com> Change-Id: I811cfd764010f9e8bb599b370155ac065ee1905c
2022-10-07SSH_LOG_DEBUG: Recategorize loglevelsNorbert Pocs1-13/+13
Loglevel INFO is the default openssh configuration setting which does not print redundant information. On a system using openssh with loglevels set by the terms of openssh will cause unwanted log lines in the output. recategorized based on - SSH_LOG_DEBUG are informational debug logs (no error) Signed-off-by: Norbert Pocs <npocs@redhat.com> Reviewed-by: Jakub Jelen <jjelen@redhat.com> Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2022-10-07SSH_LOG_TRACE: Recategorize loglevelsNorbert Pocs1-1/+1
Do not print out logs when no fatal error happens. This approach is similiar to openssh, when Error/Fatal does not print recoverable error logs. recategorized based on - SSH_LOG_TRACE are debug logs when error happens Signed-off-by: Norbert Pocs <npocs@redhat.com> Reviewed-by: Jakub Jelen <jjelen@redhat.com> Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2022-06-15Fix type mismatch warningsNorbert Pocs1-12/+14
Signed-off-by: Norbert Pocs <npocs@redhat.com> Reviewed-by: Andreas Schneider <asn@cryptomilk.org> Reviewed-by: Jakub Jelen <jjelen@redhat.com>
2022-06-09Remove bogus semicolonsJakub Jelen1-1/+1
Signed-off-by: Jakub Jelen <jjelen@redhat.com> Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2022-06-09Deprecate duplicate/ unused functionsSahana Prasad1-9/+5
and fix obvious naming mistakes, mostly in documentation Signed-off-by: Sahana Prasad <sahana@redhat.com> Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2022-06-09Reformat most of the function headersJakub Jelen1-82/+133
Signed-off-by: Jakub Jelen <jjelen@redhat.com> Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2022-06-09Remove remaining mentions of SSH-v1 protocolJakub Jelen1-12/+1
also remove anything mentioning limitation to SSHv2 as it is the only protocol supported these days. Signed-off-by: Jakub Jelen <jjelen@redhat.com> Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2022-06-09Improve documentation by mentioning the free functionsJakub Jelen1-0/+3
Related: https://gitlab.com/libssh/libssh-mirror/-/issues/3 Signed-off-by: Jakub Jelen <jjelen@redhat.com> Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2022-06-07channels: Add originator to ssh_channel_acceptTomas Holmqvist1-5/+35
Added API function ssh_channel_open_forward_port that is the same as ssh_channel_accept_forward with the addition to determine the originator address and port Signed-off-by: Tomas Holmqvist <tomhol@gmail.com> Reviewed-by: Jakub Jelen <jjelen@redhat.com>
2022-05-02Fix multiple spelling and grammar mistakesJunda Ai1-9/+9
Signed-off-by: Junda Ai <aijunda29@gmail.com> Reviewed-by: Jakub Jelen <jjelen@redhat.com>
2021-11-02channels: Avoid memory leakJakub Jelen1-0/+1
Thanks oss-fuzz: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=40116 Signed-off-by: Jakub Jelen <jjelen@redhat.com> Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2021-09-15channels: Fix segfaults when the channel data is freedArtyom V. Poptsov1-5/+10
Calling some channel procedures on a freed channel is always resulting in segmentation fault errors. The reason is that when a channel is freed with 'ssh_channel_do_free' procedure, its 'session' field is set to NULL; then when a channel procedure tries to access any field of 'channel->session' structure it is effectively dereferencing a NULL pointer. The change fixes that behavior by adding a check which ensures that a channel state is not SSH_CHANNEL_FLAG_FREED_LOCAL before accessing its parent session. Also the test suite is updated to check for the fixed errors, and the Doxygen documentation updated accordingly. There was a bug introduced in b0fb7d15: 'ssh_channel_poll', 'ssh_channel_poll_timeout' and 'ssh_channel_get_exit_status' would compare the channel state to the 'SSH_CHANNEL_FLAG_FREED_LOCAL' constant to check if the channel is alive. But the procedures must check the channel flags for the presence of 'SSH_CHANNEL_FLAG_FREED_LOCAL' bits instead. This change fixes the bug. Signed-off-by: Artyom V. Poptsov <poptsov.artyom@gmail.com> Reviewed-by: Jakub Jelen <jjelen@redhat.com>
2021-07-07[#48/T22] Added missing server reply on auth-agent-req when a reply was ↵Jeremy Cross1-8/+29
requested by the client. PuTTY for Windows chokes without this reply if "Allow agent forwarding" is enabled. Reply will be successful if channel_auth_agent_req_function callback is defined. Based on an unmerged patch by Jon Simons. Signed-off-by: Jeremy Cross <jcross@beyondtrust.com> Reviewed-by: Jakub Jelen <jjelen@redhat.com>
2021-05-27channels: Read into buffer directly in channel_read_bufferXiang Xiao1-11/+20
to avoid allocate 8KB buffer from stack Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com> Reviewed-by: Jakub Jelen <jjelen@redhat.com> Change-Id: Ifc198705cb8ecec6f0a609f84965382dc151693b
2021-05-27Fix error: dereferencing pointer to incomplete type ‘struct timeval’Xiang Xiao1-0/+3
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com> Reviewed-by: Jakub Jelen <jjelen@redhat.com> Change-Id: I99d2016595966d805c9e27b5c2f2a0a5b4ad8611
2021-05-12Revert "Fix error: dereferencing pointer to incomplete type ‘struct ↵Jakub Jelen1-3/+0
timeval’" because of inconsistent author and sign-off This reverts commit 8ea7fc6129fd41884788d0fc1f1759f3ec8c2cab. Signed-off-by: Jakub Jelen <jjelen@redhat.com> Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2021-05-10Fix error: dereferencing pointer to incomplete type ‘struct timeval’Xiang Xiao1-0/+3
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com> Reviewed-by: Jakub Jelen <jjelen@redhat.com> Reviewed-by: Sahana Prasad <sahana@redhat.com> Change-Id: I99d2016595966d805c9e27b5c2f2a0a5b4ad8611
2021-01-11channel_rcv_close: indentationTom Deseyn1-30/+30
Signed-off-by: Tom Deseyn <tom.deseyn@gmail.com> Reviewed-by: Anderson Toshiyuki Sasaki <ansasaki@redhat.com>
2021-01-11channesl: Fix delayed closeTom Deseyn1-13/+28
If the SSH2_MSG_CHANNEL_CLOSE was previously received, change the channel state to SSH_STATE_CHANNEL_CLOSED in ssh_channel_read_timeout() after reading all data available. Fixes T31 Signed-off-by: Tom Deseyn <tom.deseyn@gmail.com> Reviewed-by: Anderson Toshiyuki Sasaki <ansasaki@redhat.com>
2020-12-11Always check return value of ssh_list_new()Dirkjan Bussink1-0/+7
Another item identified during code review was cases where the return value of ssh_list_new() was not properly checked and handled. This updates all cases that were missing this to handle failure to allocate a new list. Signed-off-by: Dirkjan Bussink <d.bussink@gmail.com> Reviewed-by: Jakub Jelen <jjelen@redhat.com> Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2020-06-23channel: Do not return error if the server closed the channelAnderson Toshiyuki Sasaki1-3/+4
If the server properly closed the channel, the client should not return error if it finds the channel closed. Fixes T231 Signed-off-by: Anderson Toshiyuki Sasaki <ansasaki@redhat.com> Reviewed-by: Jakub Jelen <jjelen@redhat.com>
2020-04-20channels: Avoid returning SSH_AGAIN from ssh_channel_poll_timeout()Jakub Jelen1-0/+6
This addresses a regression introduced in 3bad0607, partially fixed in 022409e9, but the function was still able to return SSH_AGAIN, which was not expected by callers. Based on discussion in [1] and [2] [1] https://gitlab.com/libssh/libssh-mirror/-/merge_requests/101 [2] https://www.libssh.org/archive/libssh/2020-03/0000029.html Signed-off-by: Jakub Jelen <jjelen@redhat.com> Reviewed-by: Anderson Toshiyuki Sasaki <ansasaki@redhat.com>
2020-04-20channels: reformatJakub Jelen1-2/+2
Signed-off-by: Jakub Jelen <jjelen@redhat.com> Reviewed-by: Anderson Toshiyuki Sasaki <ansasaki@redhat.com>
2020-02-12channels: Replace PRIdS with ANSI C99 %zuAndreas Schneider1-2/+2
Signed-off-by: Andreas Schneider <asn@cryptomilk.org> Reviewed-by: Jakub Jelen <jjelen@redhat.com>
2020-01-23channels: Fix ssh_channel_poll_timeout() not returing available bytesAndreas Schneider1-0/+5
Fixes T211 Signed-off-by: Andreas Schneider <asn@cryptomilk.org> Reviewed-by: Jakub Jelen <jjelen@redhat.com> Reviewed-by: Anderson Toshiyuki Sasaki <ansasaki@redhat.com>
2019-12-09channels: Use SSH_BUFFER_FREE()Andreas Schneider1-19/+19
Fixes T183 Signed-off-by: Andreas Schneider <asn@cryptomilk.org> Reviewed-by: Jakub Jelen <jjelen@redhat.com>
2019-12-09channels: Use SSH_STRING_FREE()Andreas Schneider1-4/+4
Fixes T183 Signed-off-by: Andreas Schneider <asn@cryptomilk.org> Reviewed-by: Jakub Jelen <jjelen@redhat.com>
2019-12-09channels: Return size_t for count_ptrs()Andreas Schneider1-2/+3
Fixes T188 Signed-off-by: Andreas Schneider <asn@cryptomilk.org> Reviewed-by: Jakub Jelen <jjelen@redhat.com>
2019-12-09channels: Fix integer and bool argument of channel_default_bufferize()Andreas Schneider1-4/+8
Fixes T188 Signed-off-by: Andreas Schneider <asn@cryptomilk.org> Reviewed-by: Jakub Jelen <jjelen@redhat.com>
2019-12-09channels: Fix type of arguments of grow_window()Andreas Schneider1-1/+4
Fixes T188 Signed-off-by: Andreas Schneider <asn@cryptomilk.org> Reviewed-by: Jakub Jelen <jjelen@redhat.com>
2019-12-09channels: Fix type of arguments of channel_open()Andreas Schneider1-2/+2
Fixes T188 Signed-off-by: Andreas Schneider <asn@cryptomilk.org> Reviewed-by: Jakub Jelen <jjelen@redhat.com>
2019-12-09channels: Use ssize_t for to_readAndreas Schneider1-4/+4
Fixes T188 Signed-off-by: Andreas Schneider <asn@cryptomilk.org> Reviewed-by: Jakub Jelen <jjelen@redhat.com>