Skip to content

Add DefaultServerConfigCallback option for create custom default ServerConfigs #95

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

Merged
merged 1 commit into from
Feb 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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