Skip to content

Commit 781aa27

Browse files
touch up after rebase
1 parent 46832e4 commit 781aa27

2 files changed

Lines changed: 34 additions & 21 deletions

File tree

apps/wolfsshd/wolfsshd.c

Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1173,7 +1173,10 @@ static int SHELL_Subsystem(WOLFSSHD_CONNECTION* conn, WOLFSSH* ssh,
11731173
byte shellBuffer[EXAMPLE_BUFFER_SZ];
11741174
byte channelBuffer[EXAMPLE_BUFFER_SZ];
11751175
char* forcedCmd;
1176-
int windowFull = 0;
1176+
int windowFull = 0; /* Contains size of bytes from shellBuffer that did
1177+
* not get passed on to wolfSSH yet. This happens
1178+
* with window full errors or when rekeying. */
1179+
int wantWrite = 0;
11771180
int peerConnected = 1;
11781181
int stdoutEmpty = 0;
11791182

@@ -1423,7 +1426,7 @@ static int SHELL_Subsystem(WOLFSSHD_CONNECTION* conn, WOLFSSH* ssh,
14231426
maxFd = sshFd;
14241427

14251428
FD_ZERO(&writeFds);
1426-
if (windowFull) {
1429+
if (windowFull || wantWrite) {
14271430
FD_SET(sshFd, &writeFds);
14281431
}
14291432

@@ -1452,10 +1455,10 @@ static int SHELL_Subsystem(WOLFSSHD_CONNECTION* conn, WOLFSSH* ssh,
14521455
pending = 1; /* found some pending SSH data */
14531456
}
14541457

1455-
if (windowFull || pending || FD_ISSET(sshFd, &readFds)) {
1458+
if (wantWrite || windowFull || pending || FD_ISSET(sshFd, &readFds)) {
14561459
word32 lastChannel = 0;
14571460

1458-
windowFull = 0;
1461+
wantWrite = 0;
14591462
/* The following tries to read from the first channel inside
14601463
the stream. If the pending data in the socket is for
14611464
another channel, this will return an error with id
@@ -1466,24 +1469,31 @@ static int SHELL_Subsystem(WOLFSSHD_CONNECTION* conn, WOLFSSH* ssh,
14661469
if (cnt_r < 0) {
14671470
rc = wolfSSH_get_error(ssh);
14681471
if (rc == WS_CHAN_RXD) {
1469-
if (lastChannel == shellChannelId) {
1470-
cnt_r = wolfSSH_ChannelIdRead(ssh, shellChannelId,
1472+
if (!windowFull) { /* don't rewrite channeldBuffer if full
1473+
* of windowFull left overs */
1474+
if (lastChannel == shellChannelId) {
1475+
cnt_r = wolfSSH_ChannelIdRead(ssh, shellChannelId,
14711476
channelBuffer,
14721477
sizeof channelBuffer);
1473-
if (cnt_r <= 0)
1474-
break;
1475-
cnt_w = (int)write(childFd,
1476-
channelBuffer, cnt_r);
1477-
if (cnt_w <= 0)
1478-
break;
1478+
if (cnt_r <= 0)
1479+
break;
1480+
cnt_w = (int)write(childFd,
1481+
channelBuffer, cnt_r);
1482+
if (cnt_w <= 0)
1483+
break;
1484+
}
14791485
}
14801486
}
14811487
else if (rc == WS_CHANNEL_CLOSED) {
14821488
peerConnected = 0;
14831489
continue;
14841490
}
14851491
else if (rc == WS_WANT_WRITE) {
1486-
windowFull = 1;
1492+
wantWrite = 1;
1493+
continue;
1494+
}
1495+
else if (rc == WS_REKEYING) {
1496+
wantWrite = 1;
14871497
continue;
14881498
}
14891499
else if (rc != WS_WANT_READ) {
@@ -1496,10 +1506,11 @@ static int SHELL_Subsystem(WOLFSSHD_CONNECTION* conn, WOLFSSH* ssh,
14961506
if (windowFull) {
14971507
cnt_w = wolfSSH_ChannelIdSend(ssh, shellChannelId,
14981508
shellBuffer, windowFull);
1499-
if (cnt_w == WS_WINDOW_FULL) {
1509+
if (cnt_w == WS_WINDOW_FULL || cnt_w == WS_REKEYING) {
15001510
continue;
15011511
}
15021512
else if (cnt_w == WS_WANT_WRITE) {
1513+
wantWrite = 1;
15031514
continue;
15041515
}
15051516
else {
@@ -1526,12 +1537,12 @@ static int SHELL_Subsystem(WOLFSSHD_CONNECTION* conn, WOLFSSH* ssh,
15261537
if (cnt_r > 0) {
15271538
cnt_w = wolfSSH_extended_data_send(ssh, shellBuffer,
15281539
cnt_r);
1529-
if (cnt_w == WS_WINDOW_FULL) {
1540+
if (cnt_w == WS_WINDOW_FULL || cnt_w == WS_REKEYING) {
15301541
windowFull = cnt_r; /* save amount to be sent */
15311542
continue;
15321543
}
15331544
else if (cnt_w == WS_WANT_WRITE) {
1534-
windowFull = 1;
1545+
wantWrite = 1;
15351546
continue;
15361547
}
15371548
else if (cnt_w < 0)
@@ -1558,12 +1569,12 @@ static int SHELL_Subsystem(WOLFSSHD_CONNECTION* conn, WOLFSSH* ssh,
15581569
if (cnt_r > 0) {
15591570
cnt_w = wolfSSH_ChannelIdSend(ssh, shellChannelId,
15601571
shellBuffer, cnt_r);
1561-
if (cnt_w == WS_WINDOW_FULL) {
1572+
if (cnt_w == WS_WINDOW_FULL || cnt_w == WS_REKEYING) {
15621573
windowFull = cnt_r; /* save amount to be sent */
15631574
continue;
15641575
}
15651576
else if (cnt_w == WS_WANT_WRITE) {
1566-
windowFull = 1;
1577+
wantWrite = 1;
15671578
continue;
15681579
}
15691580
else if (cnt_w < 0) {
@@ -1588,12 +1599,12 @@ static int SHELL_Subsystem(WOLFSSHD_CONNECTION* conn, WOLFSSH* ssh,
15881599
if (cnt_r > 0) {
15891600
cnt_w = wolfSSH_ChannelIdSend(ssh, shellChannelId,
15901601
shellBuffer, cnt_r);
1591-
if (cnt_w == WS_WINDOW_FULL) {
1592-
windowFull = 1;
1602+
if (cnt_w == WS_WINDOW_FULL || cnt_w == WS_REKEYING) {
1603+
windowFull = cnt_r;
15931604
continue;
15941605
}
15951606
else if (cnt_w == WS_WANT_WRITE) {
1596-
windowFull = 1;
1607+
wantWrite = 1;
15971608
continue;
15981609
}
15991610
else if (cnt_w < 0) {

examples/client/common.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,8 +468,10 @@ int ClientUserAuth(byte authType,
468468
* passed in a public key file, use public key auth */
469469
if (pubKeyLoaded == 1) {
470470
if (authType == WOLFSSH_USERAUTH_PASSWORD) {
471+
#ifdef WOLFSSH_DEBUG
471472
printf("rejecting password type with %s in favor of pub key\n",
472473
(char*)authData->username);
474+
#endif
473475
return WOLFSSH_USERAUTH_FAILURE;
474476
}
475477
}

0 commit comments

Comments
 (0)