File tree Expand file tree Collapse file tree 2 files changed +12
-3
lines changed Expand file tree Collapse file tree 2 files changed +12
-3
lines changed Original file line number Diff line number Diff line change @@ -39,6 +39,7 @@ type Server struct {
3939 Version string // server version to be sent before the initial handshake
4040 Banner string // server banner
4141
42+ BannerHandler BannerHandler // server banner handler, overrides Banner
4243 KeyboardInteractiveHandler KeyboardInteractiveHandler // keyboard-interactive authentication handler
4344 PasswordHandler PasswordHandler // password authentication handler
4445 PublicKeyHandler PublicKeyHandler // public key authentication handler
@@ -134,10 +135,16 @@ func (srv *Server) config(ctx Context) *gossh.ServerConfig {
134135 config .ServerVersion = "SSH-2.0-" + srv .Version
135136 }
136137 if srv .Banner != "" {
137- config .BannerCallback = func (conn gossh.ConnMetadata ) string {
138+ config .BannerCallback = func (_ gossh.ConnMetadata ) string {
138139 return srv .Banner
139140 }
140141 }
142+ if srv .BannerHandler != nil {
143+ config .BannerCallback = func (conn gossh.ConnMetadata ) string {
144+ applyConnMetadata (ctx , conn )
145+ return srv .BannerHandler (ctx )
146+ }
147+ }
141148 if srv .PasswordHandler != nil {
142149 config .PasswordCallback = func (conn gossh.ConnMetadata , password []byte ) (* gossh.Permissions , error ) {
143150 applyConnMetadata (ctx , conn )
Original file line number Diff line number Diff line change @@ -35,6 +35,9 @@ type Option func(*Server) error
3535// Handler is a callback for handling established SSH sessions.
3636type Handler func (Session )
3737
38+ // BannerHandler is a callback for displaying the server banner.
39+ type BannerHandler func (ctx Context ) string
40+
3841// PublicKeyHandler is a callback for performing public key authentication.
3942type PublicKeyHandler func (ctx Context , key PublicKey ) bool
4043
@@ -115,8 +118,7 @@ func Handle(handler Handler) {
115118
116119// KeysEqual is constant time compare of the keys to avoid timing attacks.
117120func KeysEqual (ak , bk PublicKey ) bool {
118-
119- //avoid panic if one of the keys is nil, return false instead
121+ // avoid panic if one of the keys is nil, return false instead
120122 if ak == nil || bk == nil {
121123 return false
122124 }
You can’t perform that action at this time.
0 commit comments