Skip to content

Commit

Permalink
Add DefaultServerConfigCallback option for create custom default (#95)
Browse files Browse the repository at this point in the history
ServerConfigs
  • Loading branch information
binwiederhier authored and progrium committed Feb 21, 2019
1 parent bed87f3 commit 4b72c66
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
10 changes: 8 additions & 2 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ type Server struct {
PtyCallback PtyCallback // callback for allowing PTY sessions, allows all if nil
ConnCallback ConnCallback // optional callback for wrapping net.Conn before handling
LocalPortForwardingCallback LocalPortForwardingCallback // callback for allowing local port forwarding, denies all if nil
ReversePortForwardingCallback ReversePortForwardingCallback //callback for allowing reverse port forwarding, denies all if nil
ReversePortForwardingCallback ReversePortForwardingCallback // callback for allowing reverse port forwarding, denies all if nil
DefaultServerConfigCallback DefaultServerConfigCallback // callback for configuring detailed SSH options

IdleTimeout time.Duration // connection timeout when no activity, none if empty
MaxTimeout time.Duration // absolute connection timeout, none if empty
Expand Down Expand Up @@ -77,7 +78,12 @@ func (srv *Server) ensureHandlers() {
}

func (srv *Server) config(ctx Context) *gossh.ServerConfig {
config := &gossh.ServerConfig{}
var config *gossh.ServerConfig
if srv.DefaultServerConfigCallback == nil {
config = &gossh.ServerConfig{}
} else {
config = srv.DefaultServerConfigCallback(ctx)
}
for _, signer := range srv.HostSigners {
config.AddHostKey(signer)
}
Expand Down
3 changes: 3 additions & 0 deletions ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ type LocalPortForwardingCallback func(ctx Context, destinationHost string, desti
// ReversePortForwardingCallback is a hook for allowing reverse port forwarding
type ReversePortForwardingCallback func(ctx Context, bindHost string, bindPort uint32) bool

// DefaultServerConfigCallback is a hook for creating custom default server configs
type DefaultServerConfigCallback func(ctx Context) *gossh.ServerConfig

// Window represents the size of a PTY window.
type Window struct {
Width int
Expand Down

0 comments on commit 4b72c66

Please sign in to comment.