From 6a40f9e627c00742007f5f9eb5bd5c4d654a74db Mon Sep 17 00:00:00 2001 From: Randall Winkhart Date: Thu, 8 May 2025 16:03:36 +0000 Subject: [PATCH] Close listener when daemon is killed due to failed RPC auth --- daemon/2serverUNIXGeneric.go | 6 +++--- daemon/2serverWindows.go | 5 +++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/daemon/2serverUNIXGeneric.go b/daemon/2serverUNIXGeneric.go index 079a06d..81d4096 100644 --- a/daemon/2serverUNIXGeneric.go +++ b/daemon/2serverUNIXGeneric.go @@ -61,7 +61,7 @@ func Start(passphrase string) { continue } // use a goroutine to check the client's identity - go handleConn(conn) + go handleConn(conn, sigChan) } } @@ -71,7 +71,7 @@ func Start(passphrase string) { // The passphrase is only returned if the client's executable hash matches the daemon's hash // and if the request is coming from the same user. // This ensures that only the binary the daemon is embedded in can retrieve the passphrase. -func handleConn(conn net.Conn) { +func handleConn(conn net.Conn, sigChan chan os.Signal) { ucred := peercred.Get(conn) // check if the RPC call is coming from an identical binary and from the same user @@ -84,6 +84,6 @@ func handleConn(conn net.Conn) { // log the client's path, and kill the daemon conn.Close() log.Printf("Request received from invalid client: PID(%d), UID(%s), Path(%s)", ucred.PID, ucred.UID, callingBinPath) // TODO log to file - os.Exit(2) + sigChan <- syscall.SIGTERM } } diff --git a/daemon/2serverWindows.go b/daemon/2serverWindows.go index 65edf51..d0c96ca 100644 --- a/daemon/2serverWindows.go +++ b/daemon/2serverWindows.go @@ -83,13 +83,13 @@ func Start(passphrase string) { timer.Reset(3 * time.Minute) // use a goroutine to check the client's identity - go handleConn(conn) + go handleConn(conn, sigChan) } } // handleConn verifies the identity of the client. // It gets the PID of the client process and verifies it's running the same binary -func handleConn(conn net.Conn) { +func handleConn(conn net.Conn, sigChan chan os.Signal) { ucred := peercred.Get(conn) // get server SID (UID) @@ -107,6 +107,7 @@ func handleConn(conn net.Conn) { // log the client's path, and kill the daemon conn.Close() log.Printf("Request received from invalid client: PID(%d), UID(%s), Path(%s)", ucred.PID, ucred.UID, callingBinPath) // TODO log to file + sigChan <- syscall.SIGTERM os.Exit(2) } }