|
|
@ -31,7 +31,6 @@ var ( |
|
|
|
verbose = flag.Bool("verbose", false, "Enable verbose mode") |
|
|
|
verbose = flag.Bool("verbose", false, "Enable verbose mode") |
|
|
|
|
|
|
|
|
|
|
|
authmutex sync.Mutex |
|
|
|
authmutex sync.Mutex |
|
|
|
listenmutex sync.Mutex |
|
|
|
|
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
type sshClient struct { |
|
|
|
type sshClient struct { |
|
|
@ -41,6 +40,7 @@ type sshClient struct { |
|
|
|
AllowedLocalPorts []uint32 |
|
|
|
AllowedLocalPorts []uint32 |
|
|
|
AllowedRemotePorts []uint32 |
|
|
|
AllowedRemotePorts []uint32 |
|
|
|
Stopping bool |
|
|
|
Stopping bool |
|
|
|
|
|
|
|
ListenMutex sync.Mutex |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
type bindInfo struct { |
|
|
|
type bindInfo struct { |
|
|
@ -129,7 +129,7 @@ func main() { |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
client := sshClient{sshConn.Permissions.CriticalOptions["name"], sshConn, make(map[string]net.Listener), nil, nil, false} |
|
|
|
client := sshClient{sshConn.Permissions.CriticalOptions["name"], sshConn, make(map[string]net.Listener), nil, nil, false, sync.Mutex{}} |
|
|
|
allowedLocalPorts := sshConn.Permissions.CriticalOptions["localports"] |
|
|
|
allowedLocalPorts := sshConn.Permissions.CriticalOptions["localports"] |
|
|
|
allowedRemotePorts := sshConn.Permissions.CriticalOptions["remoteports"] |
|
|
|
allowedRemotePorts := sshConn.Permissions.CriticalOptions["remoteports"] |
|
|
|
|
|
|
|
|
|
|
@ -144,7 +144,7 @@ func main() { |
|
|
|
|
|
|
|
|
|
|
|
go func() { |
|
|
|
go func() { |
|
|
|
err := client.Conn.Wait() |
|
|
|
err := client.Conn.Wait() |
|
|
|
listenmutex.Lock() |
|
|
|
client.ListenMutex.Lock() |
|
|
|
client.Stopping = true |
|
|
|
client.Stopping = true |
|
|
|
|
|
|
|
|
|
|
|
if *verbose { |
|
|
|
if *verbose { |
|
|
@ -156,7 +156,7 @@ func main() { |
|
|
|
} |
|
|
|
} |
|
|
|
listener.Close() |
|
|
|
listener.Close() |
|
|
|
} |
|
|
|
} |
|
|
|
listenmutex.Unlock() |
|
|
|
client.ListenMutex.Unlock() |
|
|
|
}() |
|
|
|
}() |
|
|
|
|
|
|
|
|
|
|
|
go handleRequest(&client, reqs) |
|
|
|
go handleRequest(&client, reqs) |
|
|
@ -454,29 +454,29 @@ func handleRequest(client *sshClient, reqs <-chan *ssh.Request) { |
|
|
|
|
|
|
|
|
|
|
|
// RFC4254: 7.1 for forwarding
|
|
|
|
// RFC4254: 7.1 for forwarding
|
|
|
|
if req.Type == "tcpip-forward" { |
|
|
|
if req.Type == "tcpip-forward" { |
|
|
|
listenmutex.Lock() |
|
|
|
client.ListenMutex.Lock() |
|
|
|
/* If we are closing, do not set up a new listener */ |
|
|
|
/* If we are closing, do not set up a new listener */ |
|
|
|
if client.Stopping { |
|
|
|
if client.Stopping { |
|
|
|
listenmutex.Unlock() |
|
|
|
client.ListenMutex.Unlock() |
|
|
|
req.Reply(false, []byte{}) |
|
|
|
req.Reply(false, []byte{}) |
|
|
|
continue |
|
|
|
continue |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
listener, bindinfo, err := handleTcpIpForward(client, req) |
|
|
|
listener, bindinfo, err := handleTcpIpForward(client, req) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
listenmutex.Unlock() |
|
|
|
client.ListenMutex.Unlock() |
|
|
|
continue |
|
|
|
continue |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
client.Listeners[bindinfo.Bound] = listener |
|
|
|
client.Listeners[bindinfo.Bound] = listener |
|
|
|
listenmutex.Unlock() |
|
|
|
client.ListenMutex.Unlock() |
|
|
|
|
|
|
|
|
|
|
|
go handleListener(client, bindinfo, listener) |
|
|
|
go handleListener(client, bindinfo, listener) |
|
|
|
continue |
|
|
|
continue |
|
|
|
} else if req.Type == "cancel-tcpip-forward" { |
|
|
|
} else if req.Type == "cancel-tcpip-forward" { |
|
|
|
listenmutex.Lock() |
|
|
|
client.ListenMutex.Lock() |
|
|
|
handleTcpIPForwardCancel(client, req) |
|
|
|
handleTcpIPForwardCancel(client, req) |
|
|
|
listenmutex.Unlock() |
|
|
|
client.ListenMutex.Unlock() |
|
|
|
continue |
|
|
|
continue |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
// Discard everything else
|
|
|
|
// Discard everything else
|
|
|
|