From 95431c3de1b78bc7bf9027c82382a04e898cd212 Mon Sep 17 00:00:00 2001 From: John Safranek Date: Thu, 8 Sep 2022 10:05:58 -0700 Subject: [PATCH] Child Listener 1. Stash a copy of wolfsshd's listenFd in the connection record. 2. After the fork, the child now closes the listenFd. 3. After the fork, the parent now closes the fd. --- apps/wolfsshd/wolfsshd.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/apps/wolfsshd/wolfsshd.c b/apps/wolfsshd/wolfsshd.c index 3bd61784..ef4420a5 100644 --- a/apps/wolfsshd/wolfsshd.c +++ b/apps/wolfsshd/wolfsshd.c @@ -102,6 +102,7 @@ typedef struct WOLFSSHD_CONNECTION { WOLFSSH_CTX* ctx; WOLFSSHD_AUTH* auth; int fd; + int listenFd; char ip[INET_ADDRSTRLEN]; } WOLFSSHD_CONNECTION; @@ -812,12 +813,14 @@ static int NewConnection(WOLFSSHD_CONNECTION* conn) if (ret == WS_SUCCESS) { if (pd == 0) { /* child process */ + WCLOSESOCKET(conn->listenFd); signal(SIGINT, SIG_DFL); (void)HandleConnection((void*)conn); exit(0); } else { wolfSSH_Log(WS_LOG_INFO, "[SSHD] Spawned new process %d\n", pd); + WCLOSESOCKET(conn->fd); } } @@ -1049,6 +1052,7 @@ int main(int argc, char** argv) socklen_t clientAddrSz = sizeof(clientAddr); #endif conn.auth = auth; + conn.listenFd = listenFd; /* wait for a connection */ if (PendingConnection(listenFd)) {