Skip to content

Commit

Permalink
touch up after rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
JacobBarthelmeh committed Jul 17, 2024
1 parent 4b79f8f commit 920919d
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 21 deletions.
53 changes: 32 additions & 21 deletions apps/wolfsshd/wolfsshd.c
Original file line number Diff line number Diff line change
Expand Up @@ -1166,7 +1166,10 @@ static int SHELL_Subsystem(WOLFSSHD_CONNECTION* conn, WOLFSSH* ssh,
byte shellBuffer[EXAMPLE_BUFFER_SZ];
byte channelBuffer[EXAMPLE_BUFFER_SZ];
char* forcedCmd;
int windowFull = 0;
int windowFull = 0; /* Contains size of bytes from shellBuffer that did
* not get passed on to wolfSSH yet. This happens
* with window full errors or when rekeying. */
int wantWrite = 0;
int peerConnected = 1;
int stdoutEmpty = 0;

Expand Down Expand Up @@ -1416,7 +1419,7 @@ static int SHELL_Subsystem(WOLFSSHD_CONNECTION* conn, WOLFSSH* ssh,
maxFd = sshFd;

FD_ZERO(&writeFds);
if (windowFull) {
if (windowFull || wantWrite) {
FD_SET(sshFd, &writeFds);
}

Expand Down Expand Up @@ -1445,10 +1448,10 @@ static int SHELL_Subsystem(WOLFSSHD_CONNECTION* conn, WOLFSSH* ssh,
pending = 1; /* found some pending SSH data */
}

if (windowFull || pending || FD_ISSET(sshFd, &readFds)) {
if (wantWrite || windowFull || pending || FD_ISSET(sshFd, &readFds)) {
word32 lastChannel = 0;

windowFull = 0;
wantWrite = 0;
/* The following tries to read from the first channel inside
the stream. If the pending data in the socket is for
another channel, this will return an error with id
Expand All @@ -1459,24 +1462,31 @@ static int SHELL_Subsystem(WOLFSSHD_CONNECTION* conn, WOLFSSH* ssh,
if (cnt_r < 0) {
rc = wolfSSH_get_error(ssh);
if (rc == WS_CHAN_RXD) {
if (lastChannel == shellChannelId) {
cnt_r = wolfSSH_ChannelIdRead(ssh, shellChannelId,
if (!windowFull) { /* don't rewrite channeldBuffer if full
* of windowFull left overs */
if (lastChannel == shellChannelId) {
cnt_r = wolfSSH_ChannelIdRead(ssh, shellChannelId,
channelBuffer,
sizeof channelBuffer);
if (cnt_r <= 0)
break;
cnt_w = (int)write(childFd,
channelBuffer, cnt_r);
if (cnt_w <= 0)
break;
if (cnt_r <= 0)
break;
cnt_w = (int)write(childFd,
channelBuffer, cnt_r);
if (cnt_w <= 0)
break;
}
}
}
else if (rc == WS_CHANNEL_CLOSED) {
peerConnected = 0;
continue;
}
else if (rc == WS_WANT_WRITE) {
windowFull = 1;
wantWrite = 1;
continue;
}
else if (rc == WS_REKEYING) {
wantWrite = 1;
continue;
}
else if (rc != WS_WANT_READ) {
Expand All @@ -1489,10 +1499,11 @@ static int SHELL_Subsystem(WOLFSSHD_CONNECTION* conn, WOLFSSH* ssh,
if (windowFull) {
cnt_w = wolfSSH_ChannelIdSend(ssh, shellChannelId,
shellBuffer, windowFull);
if (cnt_w == WS_WINDOW_FULL) {
if (cnt_w == WS_WINDOW_FULL || cnt_w == WS_REKEYING) {
continue;
}
else if (cnt_w == WS_WANT_WRITE) {
wantWrite = 1;
continue;
}
else {
Expand All @@ -1519,12 +1530,12 @@ static int SHELL_Subsystem(WOLFSSHD_CONNECTION* conn, WOLFSSH* ssh,
if (cnt_r > 0) {
cnt_w = wolfSSH_extended_data_send(ssh, shellBuffer,
cnt_r);
if (cnt_w == WS_WINDOW_FULL) {
if (cnt_w == WS_WINDOW_FULL || cnt_w == WS_REKEYING) {
windowFull = cnt_r; /* save amount to be sent */
continue;
}
else if (cnt_w == WS_WANT_WRITE) {
windowFull = 1;
wantWrite = 1;
continue;
}
else if (cnt_w < 0)
Expand All @@ -1551,12 +1562,12 @@ static int SHELL_Subsystem(WOLFSSHD_CONNECTION* conn, WOLFSSH* ssh,
if (cnt_r > 0) {
cnt_w = wolfSSH_ChannelIdSend(ssh, shellChannelId,
shellBuffer, cnt_r);
if (cnt_w == WS_WINDOW_FULL) {
if (cnt_w == WS_WINDOW_FULL || cnt_w == WS_REKEYING) {
windowFull = cnt_r; /* save amount to be sent */
continue;
}
else if (cnt_w == WS_WANT_WRITE) {
windowFull = 1;
wantWrite = 1;
continue;
}
else if (cnt_w < 0) {
Expand All @@ -1581,12 +1592,12 @@ static int SHELL_Subsystem(WOLFSSHD_CONNECTION* conn, WOLFSSH* ssh,
if (cnt_r > 0) {
cnt_w = wolfSSH_ChannelIdSend(ssh, shellChannelId,
shellBuffer, cnt_r);
if (cnt_w == WS_WINDOW_FULL) {
windowFull = 1;
if (cnt_w == WS_WINDOW_FULL || cnt_w == WS_REKEYING) {
windowFull = cnt_r;
continue;
}
else if (cnt_w == WS_WANT_WRITE) {
windowFull = 1;
wantWrite = 1;
continue;
}
else if (cnt_w < 0) {
Expand Down
2 changes: 2 additions & 0 deletions examples/client/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -468,8 +468,10 @@ int ClientUserAuth(byte authType,
* passed in a public key file, use public key auth */
if (pubKeyLoaded == 1) {
if (authType == WOLFSSH_USERAUTH_PASSWORD) {
#ifdef WOLFSSH_DEBUG
printf("rejecting password type with %s in favor of pub key\n",
(char*)authData->username);
#endif
return WOLFSSH_USERAUTH_FAILURE;
}
}
Expand Down

0 comments on commit 920919d

Please sign in to comment.