From 1fb0328c76a17be49a064c766dd62895ad4486cd Mon Sep 17 00:00:00 2001 From: John Safranek Date: Fri, 5 Apr 2024 11:38:37 -0700 Subject: [PATCH] Refactoring Channels 1. Round out the updates to SCP support in wolfSSHd. 2. Add a select around the SFTP application accept. 3. Removed no-op with the conn in the scp handler as it is used. --- apps/wolfsshd/wolfsshd.c | 38 +++++++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/apps/wolfsshd/wolfsshd.c b/apps/wolfsshd/wolfsshd.c index 39ac89394..3cbd8b7d2 100644 --- a/apps/wolfsshd/wolfsshd.c +++ b/apps/wolfsshd/wolfsshd.c @@ -614,23 +614,24 @@ static int SCP_Subsystem(WOLFSSHD_CONNECTION* conn, WOLFSSH* ssh, #endif if (ret == WS_SUCCESS) { - ret = wolfSSH_accept(ssh); + ret = wolfSSH_SCP_DoRequest(ssh); error = wolfSSH_get_error(ssh); - while (ret != WS_SUCCESS && ret != WS_SCP_COMPLETE + while (ret != WS_SUCCESS + && ret != WS_SCP_COMPLETE && (error == WS_WANT_READ || error == WS_WANT_WRITE)) { - select_ret = tcp_select(conn->fd, 1); - if (select_ret == WS_SELECT_RECV_READY || - select_ret == WS_SELECT_ERROR_READY || - error == WS_WANT_WRITE) - { - ret = wolfSSH_accept(ssh); + if (select_ret == WS_SELECT_RECV_READY + || select_ret == WS_SELECT_ERROR_READY + || error == WS_WANT_WRITE) { + ret = wolfSSH_SCP_DoRequest(ssh); error = wolfSSH_get_error(ssh); } - else if (select_ret == WS_SELECT_TIMEOUT) + else if (select_ret == WS_SELECT_TIMEOUT) { error = WS_WANT_READ; - else + } + else { error = WS_FATAL_ERROR; + } } } @@ -640,7 +641,6 @@ static int SCP_Subsystem(WOLFSSHD_CONNECTION* conn, WOLFSSH* ssh, conn->ip); } - (void)conn; #ifdef _WIN32 /* stop impersonating the user */ RevertToSelf(); @@ -2035,9 +2035,21 @@ static void* HandleConnection(void* arg) } else if (conn->doSftp) { #ifdef WOLFSSH_SFTP + int select_ret; do { - ret = wolfSSH_SFTP_accept(ssh); - /* XXX Need some select */ + select_ret = tcp_select(conn->fd, 1); + if (select_ret == WS_SELECT_RECV_READY + || select_ret == WS_SELECT_ERROR_READY + || error == WS_WANT_WRITE) { + ret = wolfSSH_SFTP_accept(ssh); + error = wolfSSH_get_error(ssh); + } + else if (select_ret == WS_SELECT_TIMEOUT) { + error = WS_WANT_READ; + } + else { + error = WS_FATAL_ERROR; + } } while (ret != WS_SFTP_COMPLETE && (error == WS_WANT_READ || error == WS_WANT_WRITE)); if (ret == WS_SFTP_COMPLETE) {