Merge pull request #603 from JacobBarthelmeh/sshd

pull/606/head
John Safranek 2023-10-17 09:04:15 -07:00 committed by GitHub
commit 74cf1d4014
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 15 deletions

View File

@ -762,7 +762,7 @@ static int CheckPasswordWIN(const char* usr, const byte* pw, word32 pwSz, WOLFSS
usrWSz = WSTRLEN(usr) * sizeof(WCHAR); usrWSz = WSTRLEN(usr) * sizeof(WCHAR);
usrW = (WCHAR*)WMALLOC(usrWSz + 1, authCtx->heap, DYNTYPE_SSHD); usrW = (WCHAR*)WMALLOC((usrWSz * sizeof(WCHAR)) + sizeof(WCHAR), authCtx->heap, DYNTYPE_SSHD);
if (usrW == NULL) { if (usrW == NULL) {
wolfSSH_Log(WS_LOG_ERROR, "[SSHD] Ran out of memory"); wolfSSH_Log(WS_LOG_ERROR, "[SSHD] Ran out of memory");
ret = WSSHD_AUTH_FAILURE; ret = WSSHD_AUTH_FAILURE;

View File

@ -1671,6 +1671,7 @@ static void* HandleConnection(void* arg)
WCLOSESOCKET(conn->fd); WCLOSESOCKET(conn->fd);
} }
wolfSSH_Log(WS_LOG_INFO, "[SSHD] Return from closing connection = %d", ret); wolfSSH_Log(WS_LOG_INFO, "[SSHD] Return from closing connection = %d", ret);
WFREE(conn, NULL, DYNTYPE_SSHD);
#ifdef _WIN32 #ifdef _WIN32
return 0; return 0;
@ -1966,7 +1967,11 @@ static int StartSSHD(int argc, char** argv)
break; break;
#else #else
ShowUsage(); ShowUsage();
#ifndef _WIN32
return WS_FATAL_ERROR; return WS_FATAL_ERROR;
#else
return;
#endif
#endif #endif
case 't': case 't':
@ -2144,27 +2149,33 @@ static int StartSSHD(int argc, char** argv)
#endif #endif
/* wait for incoming connections and fork them off */ /* wait for incoming connections and fork them off */
while (ret == WS_SUCCESS && quit == 0) { while (ret == WS_SUCCESS && quit == 0) {
WOLFSSHD_CONNECTION conn; WOLFSSHD_CONNECTION* conn;
#ifdef WOLFSSL_NUCLEUS #ifdef WOLFSSL_NUCLEUS
struct addr_struct clientAddr; struct addr_struct clientAddr;
#else #else
SOCKADDR_IN_T clientAddr; SOCKADDR_IN_T clientAddr;
socklen_t clientAddrSz = sizeof(clientAddr); socklen_t clientAddrSz = sizeof(clientAddr);
#endif #endif
conn.auth = auth; conn = (WOLFSSHD_CONNECTION*)WMALLOC(sizeof(WOLFSSHD_CONNECTION), NULL, DYNTYPE_SSHD);
conn.listenFd = (int)listenFd; if (conn == NULL) {
conn.isThreaded = isDaemon; wolfSSH_Log(WS_LOG_ERROR, "[SSHD] Failed to malloc memory for connection");
break;
}
conn->auth = auth;
conn->listenFd = (int)listenFd;
conn->isThreaded = isDaemon;
/* wait for a connection */ /* wait for a connection */
if (PendingConnection(listenFd)) { if (PendingConnection(listenFd)) {
conn.ctx = ctx; conn->ctx = ctx;
#ifdef WOLFSSL_NUCLEUS #ifdef WOLFSSL_NUCLEUS
conn.fd = NU_Accept(listenFd, &clientAddr, 0); conn->fd = NU_Accept(listenFd, &clientAddr, 0);
#else #else
conn.fd = (int)accept(listenFd, (struct sockaddr*)&clientAddr, conn->fd = (int)accept(listenFd, (struct sockaddr*)&clientAddr,
&clientAddrSz); &clientAddrSz);
if (conn.fd >= 0) { if (conn->fd >= 0) {
inet_ntop(AF_INET, &clientAddr.sin_addr, conn.ip, inet_ntop(AF_INET, &clientAddr.sin_addr, conn->ip,
INET_ADDRSTRLEN); INET_ADDRSTRLEN);
} }
#endif #endif
@ -2172,7 +2183,7 @@ static int StartSSHD(int argc, char** argv)
{ {
#ifdef USE_WINDOWS_API #ifdef USE_WINDOWS_API
unsigned long blocking = 1; unsigned long blocking = 1;
if (ioctlsocket(conn.fd, FIONBIO, &blocking) if (ioctlsocket(conn->fd, FIONBIO, &blocking)
== SOCKET_ERROR) == SOCKET_ERROR)
err_sys("ioctlsocket failed"); err_sys("ioctlsocket failed");
#elif defined(WOLFSSL_MDK_ARM) || defined(WOLFSSL_KEIL_TCP_NET) \ #elif defined(WOLFSSL_MDK_ARM) || defined(WOLFSSL_KEIL_TCP_NET) \
@ -2180,15 +2191,15 @@ static int StartSSHD(int argc, char** argv)
defined(WOLFSSL_NUCLEUS) defined(WOLFSSL_NUCLEUS)
/* non blocking not supported, for now */ /* non blocking not supported, for now */
#else #else
int flags = fcntl(conn.fd, F_GETFL, 0); int flags = fcntl(conn->fd, F_GETFL, 0);
if (flags < 0) if (flags < 0)
err_sys("fcntl get failed"); err_sys("fcntl get failed");
flags = fcntl(conn.fd, F_SETFL, flags | O_NONBLOCK); flags = fcntl(conn->fd, F_SETFL, flags | O_NONBLOCK);
if (flags < 0) if (flags < 0)
err_sys("fcntl set failed"); err_sys("fcntl set failed");
#endif #endif
} }
ret = NewConnection(&conn); ret = NewConnection(conn);
} }
#ifdef _WIN32 #ifdef _WIN32
/* check if service has been shutdown */ /* check if service has been shutdown */
@ -2258,7 +2269,7 @@ int main(int argc, char** argv)
} }
} }
else { else {
StartSSHD(argc, (LPSTR*)argv); StartSSHD(argc, (LPTSTR*)argv);
} }
return 0; return 0;
#else #else