Skip to content

Commit ce0c30c

Browse files
bradfitzMaisem Ali
authored andcommitted
ssh: add WithBannerError
Co-Authored-By: Maisem Ali <[email protected]> Signed-off-by: Brad Fitzpatrick <[email protected]>
1 parent 3b3b0fc commit ce0c30c

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

ssh/server.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,19 @@ func isAcceptableAlgo(algo string) bool {
310310
return false
311311
}
312312

313+
// WithBannerError is an error wrapper type that can be returned from an authentication
314+
// function to additionally write out a banner error message.
315+
type WithBannerError struct {
316+
Err error
317+
Message string
318+
}
319+
320+
func (e WithBannerError) Unwrap() error {
321+
return e.Err
322+
}
323+
324+
func (e WithBannerError) Error() string { return e.Err.Error() }
325+
313326
func checkSourceAddress(addr net.Addr, sourceAddrs string) error {
314327
if addr == nil {
315328
return errors.New("ssh: no address known for client, but source-address match required")
@@ -668,6 +681,13 @@ userAuthLoop:
668681
break userAuthLoop
669682
}
670683

684+
var w WithBannerError
685+
if errors.As(authErr, &w) && w.Message != "" {
686+
bannerMsg := &userAuthBannerMsg{Message: w.Message}
687+
if err := s.transport.writePacket(Marshal(bannerMsg)); err != nil {
688+
return nil, err
689+
}
690+
}
671691
if errors.Is(authErr, ErrDenied) {
672692
var failureMsg userAuthFailureMsg
673693
if config.ImplictAuthMethod != "" {

0 commit comments

Comments
 (0)