Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added admin features #64

Merged
merged 11 commits into from
Dec 26, 2019
Prev Previous commit
Next Next commit
Fixed channel cleanup
  • Loading branch information
antoniomika committed Dec 24, 2019
commit 28b9614a16f793b56df9507cd3b8387df6951a4d
19 changes: 0 additions & 19 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,25 +332,6 @@ func main() {
func (s *SSHConnection) CleanUp(state *State) {
close(s.Close)
s.SSHConn.Close()
s.Listeners.Range(func(key, val interface{}) bool {
_, ok := key.(*net.UnixAddr)

if ok {
actualUnixListener, ok := val.(*net.UnixListener)

if ok {
actualUnixListener.Close()
} else {
actualUnixConn := val.(*net.UnixConn)
actualUnixConn.Close()
}
} else {
actualTCPListener := val.(*net.TCPListener)
actualTCPListener.Close()
}

return true
})
state.SSHConnections.Delete(s.SSHConn.RemoteAddr())
log.Println("Closed SSH connection for:", s.SSHConn.RemoteAddr(), "user:", s.SSHConn.User())
}
14 changes: 8 additions & 6 deletions requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,18 @@ func handleRemoteForward(newRequest *ssh.Request, sshConn *SSHConnection, state
state.Listeners.Store(chanListener.Addr(), chanListener)
sshConn.Listeners.Store(chanListener.Addr(), chanListener)

defer func() {
cleanupChanListener := func() {
chanListener.Close()
state.Listeners.Delete(chanListener.Addr())
sshConn.Listeners.Delete(chanListener.Addr())
os.Remove(tmpfile.Name())
}

defer cleanupChanListener()

go func() {
<-sshConn.Close
cleanupChanListener()
}()

connType := "tcp"
Expand Down Expand Up @@ -177,11 +184,6 @@ func handleRemoteForward(newRequest *ssh.Request, sshConn *SSHConnection, state

sendMessage(sshConn, requestMessages, false)

go func() {
<-sshConn.Close
chanListener.Close()
}()

for {
cl, err := chanListener.Accept()
if err != nil {
Expand Down