Skip to content

Commit 4b72c66

Browse files
binwiederhierprogrium
authored andcommitted
Add DefaultServerConfigCallback option for create custom default (#95)
ServerConfigs
1 parent bed87f3 commit 4b72c66

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

Diff for: server.go

+8-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ type Server struct {
3030
PtyCallback PtyCallback // callback for allowing PTY sessions, allows all if nil
3131
ConnCallback ConnCallback // optional callback for wrapping net.Conn before handling
3232
LocalPortForwardingCallback LocalPortForwardingCallback // callback for allowing local port forwarding, denies all if nil
33-
ReversePortForwardingCallback ReversePortForwardingCallback //callback for allowing reverse port forwarding, denies all if nil
33+
ReversePortForwardingCallback ReversePortForwardingCallback // callback for allowing reverse port forwarding, denies all if nil
34+
DefaultServerConfigCallback DefaultServerConfigCallback // callback for configuring detailed SSH options
3435

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

7980
func (srv *Server) config(ctx Context) *gossh.ServerConfig {
80-
config := &gossh.ServerConfig{}
81+
var config *gossh.ServerConfig
82+
if srv.DefaultServerConfigCallback == nil {
83+
config = &gossh.ServerConfig{}
84+
} else {
85+
config = srv.DefaultServerConfigCallback(ctx)
86+
}
8187
for _, signer := range srv.HostSigners {
8288
config.AddHostKey(signer)
8389
}

Diff for: ssh.go

+3
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ type LocalPortForwardingCallback func(ctx Context, destinationHost string, desti
5757
// ReversePortForwardingCallback is a hook for allowing reverse port forwarding
5858
type ReversePortForwardingCallback func(ctx Context, bindHost string, bindPort uint32) bool
5959

60+
// DefaultServerConfigCallback is a hook for creating custom default server configs
61+
type DefaultServerConfigCallback func(ctx Context) *gossh.ServerConfig
62+
6063
// Window represents the size of a PTY window.
6164
type Window struct {
6265
Width int

0 commit comments

Comments
 (0)