Skip to content

Commit

Permalink
Refactoring Channels
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ejohnstown committed Nov 4, 2024
1 parent a52ff73 commit 1fb0328
Showing 1 changed file with 25 additions and 13 deletions.
38 changes: 25 additions & 13 deletions apps/wolfsshd/wolfsshd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}

Expand All @@ -640,7 +641,6 @@ static int SCP_Subsystem(WOLFSSHD_CONNECTION* conn, WOLFSSH* ssh,
conn->ip);
}

(void)conn;
#ifdef _WIN32
/* stop impersonating the user */
RevertToSelf();
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 1fb0328

Please sign in to comment.