Merge pull request #201 from ejohnstown/shutdown-fix

Echoserver Maintenance
pull/202/head
JacobBarthelmeh 2019-10-10 15:54:31 -06:00 committed by GitHub
commit 74e42d582b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 66 additions and 23 deletions

View File

@ -325,6 +325,16 @@ static int sftp_worker(thread_ctx_t* threadCtx) {
if (error == WS_WANT_READ || error == WS_WANT_WRITE)
ret = WS_WANT_READ;
if (ret == WS_FATAL_ERROR && error == 0) {
WOLFSSH_CHANNEL* channel =
wolfSSH_ChannelNext(threadCtx->ssh, NULL);
if (channel && wolfSSH_ChannelGetEof(channel)) {
ret = 0;
error = 0;
break;
}
}
} while (ret != WS_FATAL_ERROR);
return ret;
@ -372,7 +382,7 @@ wolfSSL_Mutex doneLock;
static THREAD_RETURN WOLFSSH_THREAD server_worker(void* vArgs)
{
int ret = 0;
int ret = 0, error = 0;
thread_ctx_t* threadCtx = (thread_ctx_t*)vArgs;
if (!threadCtx->nonBlock)
@ -399,19 +409,31 @@ static THREAD_RETURN WOLFSSH_THREAD server_worker(void* vArgs)
break;
}
if (ret == WS_FATAL_ERROR && wolfSSH_get_error(threadCtx->ssh) ==
WS_VERSION_E) {
ret = 0; /* don't break out of loop with version miss match */
printf("Unsupported version error\n");
}
else if (ret == WS_FATAL_ERROR && wolfSSH_get_error(threadCtx->ssh) ==
WS_USER_AUTH_E) {
ret = 0; /* don't break out of loop with user auth error */
printf("User Authentication error\n");
if (ret == WS_FATAL_ERROR) {
const char* errorStr;
error = wolfSSH_get_error(threadCtx->ssh);
errorStr = wolfSSH_ErrorToName(error);
if (error == WS_VERSION_E) {
ret = 0; /* don't break out of loop with version miss match */
printf("%s\n", errorStr);
}
else if (error == WS_USER_AUTH_E) {
ret = 0; /* don't break out of loop with user auth error */
printf("%s\n", errorStr);
}
else if (error == WS_SOCKET_ERROR_E) {
ret = 0;
printf("%s\n", errorStr);
}
}
if (wolfSSH_shutdown(threadCtx->ssh) != WS_SUCCESS) {
fprintf(stderr, "Error with SSH shutdown.\n");
if (error != WS_SOCKET_ERROR_E && error != WS_FATAL_ERROR)
{
if (wolfSSH_shutdown(threadCtx->ssh) != WS_SUCCESS) {
fprintf(stderr, "Error with SSH shutdown.\n");
}
}
WCLOSESOCKET(threadCtx->fd);
@ -419,7 +441,7 @@ static THREAD_RETURN WOLFSSH_THREAD server_worker(void* vArgs)
if (ret != 0) {
fprintf(stderr, "Error [%d] \"%s\" with handling connection.\n", ret,
wolfSSH_ErrorToName(ret));
wolfSSH_ErrorToName(error));
#ifndef WOLFSSH_NO_EXIT
wc_LockMutex(&doneLock);
quit = 1;

View File

@ -1574,6 +1574,21 @@ WOLFSSH_CHANNEL* wolfSSH_ChannelNext(WOLFSSH* ssh, WOLFSSH_CHANNEL* channel)
}
int wolfSSH_ChannelGetEof(WOLFSSH_CHANNEL* channel)
{
int eof = 1;
WLOG(WS_LOG_DEBUG, "Entering wolfSSH_ChannelGetEof()");
if (channel)
eof = (int)channel->receivedEof;
WLOG(WS_LOG_DEBUG, "Leaving wolfSSH_ChannelGetEof(), %s",
eof ? "true" : "false");
return eof;
}
/* Protocols that have loops over wolfSSH_stream_send without doing any reads
* will run into the issue of not checking for a peer window adjustment packet.
* This function allows for checking for a peer window adjustment packet without

View File

@ -553,6 +553,7 @@ static int SFTP_GetHeader(WOLFSSH* ssh, word32* reqId, byte* type)
int ret;
word32 len;
byte buf[WOLFSSH_SFTP_HEADER];
WLOG(WS_LOG_SFTP, "Entering SFTP_GetHeader()");
if (type == NULL || reqId == NULL || ssh == NULL) {
WLOG(WS_LOG_SFTP, "NULL argument error");
@ -573,6 +574,8 @@ static int SFTP_GetHeader(WOLFSSH* ssh, word32* reqId, byte* type)
*type = buf[LENGTH_SZ];
ato32(buf + UINT32_SZ + MSG_ID_SZ, reqId);
WLOG(WS_LOG_SFTP, "Leaving SFTP_GetHeader(), %d",
len - UINT32_SZ - MSG_ID_SZ);
return len - UINT32_SZ - MSG_ID_SZ;
}
@ -1007,6 +1010,8 @@ int wolfSSH_SFTP_read(WOLFSSH* ssh)
int maxSz, ret = WS_SUCCESS;
WS_SFTP_RECV_STATE* state = NULL;
WLOG(WS_LOG_DEBUG, "Entering wolfSSH_SFTP_read()");
if (ssh == NULL)
return WS_BAD_ARGUMENT;
@ -2099,7 +2104,7 @@ static int wolfSSH_SFTPNAME_readdir(WOLFSSH* ssh, WDIR* dir, WS_SFTPNAME* out,
word32 nameLen = (word32)WSTRLEN(dirName);
if (nameLen > MAX_PATH - 3) {
WLOG(WS_LOG_DEBUG, "Path name is too long.");
WLOG(WS_LOG_SFTP, "Path name is too long.");
return WS_FATAL_ERROR;
}
WSTRNCPY(name, dirName, MAX_PATH);
@ -4993,7 +4998,7 @@ static int wolfSSH_SFTP_GetHandle(WOLFSSH* ssh, byte* handle, word32* handleSz)
return ret;
default:
WLOG(WS_LOG_DEBUG, "Bad SFTP GetHandle state, program error");
WLOG(WS_LOG_SFTP, "Bad SFTP GetHandle state, program error");
return WS_INPUT_CASE_E;
}
}
@ -5323,7 +5328,7 @@ static int SFTP_STAT(WOLFSSH* ssh, char* dir, WS_SFTP_FILEATRB* atr, byte type)
return WS_SUCCESS;
default:
WLOG(WS_LOG_DEBUG, "Bad SFTP LSTAT state, program error");
WLOG(WS_LOG_SFTP, "Bad SFTP LSTAT state, program error");
return WS_INPUT_CASE_E;
}
}
@ -5615,7 +5620,7 @@ int wolfSSH_SFTP_Open(WOLFSSH* ssh, char* dir, word32 reason,
return ret;
default:
WLOG(WS_LOG_DEBUG, "Bad SFTP Open state, program error");
WLOG(WS_LOG_SFTP, "Bad SFTP Open state, program error");
return WS_INPUT_CASE_E;
}
}
@ -5824,7 +5829,7 @@ int wolfSSH_SFTP_SendWritePacket(WOLFSSH* ssh, byte* handle, word32 handleSz,
return ret;
default:
WLOG(WS_LOG_DEBUG, "Bad SFTP Send Write Packet state, "
WLOG(WS_LOG_SFTP, "Bad SFTP Send Write Packet state, "
"program error");
ssh->error = WS_INPUT_CASE_E;
return WS_FATAL_ERROR;
@ -6056,7 +6061,7 @@ int wolfSSH_SFTP_SendReadPacket(WOLFSSH* ssh, byte* handle, word32 handleSz,
return ret;
default:
WLOG(WS_LOG_DEBUG, "Bad SFTP Send Read Packet state, "
WLOG(WS_LOG_SFTP, "Bad SFTP Send Read Packet state, "
"program error");
ssh->error = WS_INPUT_CASE_E;
return WS_FATAL_ERROR;
@ -6368,7 +6373,7 @@ int wolfSSH_SFTP_Close(WOLFSSH* ssh, byte* handle, word32 handleSz)
return ret;
default:
WLOG(WS_LOG_DEBUG, "Bad SFTP Close state, program error");
WLOG(WS_LOG_SFTP, "Bad SFTP Close state, program error");
return WS_INPUT_CASE_E;
}
}
@ -6634,7 +6639,7 @@ int wolfSSH_SFTP_Rename(WOLFSSH* ssh, const char* old, const char* nw)
return ret;
default:
WLOG(WS_LOG_DEBUG, "Bad SFTP Rename state, program error");
WLOG(WS_LOG_SFTP, "Bad SFTP Rename state, program error");
ssh->error = WS_INPUT_CASE_E;
return WS_FATAL_ERROR;
}
@ -7193,7 +7198,7 @@ int wolfSSH_SFTP_Get(WOLFSSH* ssh, char* from,
return ret;
default:
WLOG(WS_LOG_DEBUG, "Bad SFTP Get state, program error");
WLOG(WS_LOG_SFTP, "Bad SFTP Get state, program error");
return WS_INPUT_CASE_E;
}
}
@ -7392,7 +7397,7 @@ int wolfSSH_SFTP_Put(WOLFSSH* ssh, char* from, char* to, byte resume,
return ret;
default:
WLOG(WS_LOG_DEBUG, "Bad SFTP Put state, program error");
WLOG(WS_LOG_SFTP, "Bad SFTP Put state, program error");
return WS_INPUT_CASE_E;
}
}

View File

@ -92,6 +92,7 @@ WOLFSSH_API int wolfSSH_ChannelGetFwdFd(const WOLFSSH_CHANNEL*);
WOLFSSH_API int wolfSSH_ChannelRead(WOLFSSH_CHANNEL*, byte*, word32);
WOLFSSH_API int wolfSSH_ChannelSend(WOLFSSH_CHANNEL*, const byte*, word32);
WOLFSSH_API int wolfSSH_ChannelExit(WOLFSSH_CHANNEL*);
WOLFSSH_API int wolfSSH_ChannelGetEof(WOLFSSH_CHANNEL*);
WOLFSSH_API int wolfSSH_get_error(const WOLFSSH*);