Skip to content

Commit

Permalink
ssh: add WithBannerError
Browse files Browse the repository at this point in the history
Co-Authored-By: Maisem Ali <[email protected]>
Signed-off-by: Brad Fitzpatrick <[email protected]>
  • Loading branch information
2 people authored and iQQBot committed Aug 21, 2022
1 parent 3b3b0fc commit ce0c30c
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions ssh/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,19 @@ func isAcceptableAlgo(algo string) bool {
return false
}

// WithBannerError is an error wrapper type that can be returned from an authentication
// function to additionally write out a banner error message.
type WithBannerError struct {
Err error
Message string
}

func (e WithBannerError) Unwrap() error {
return e.Err
}

func (e WithBannerError) Error() string { return e.Err.Error() }

func checkSourceAddress(addr net.Addr, sourceAddrs string) error {
if addr == nil {
return errors.New("ssh: no address known for client, but source-address match required")
Expand Down Expand Up @@ -668,6 +681,13 @@ userAuthLoop:
break userAuthLoop
}

var w WithBannerError
if errors.As(authErr, &w) && w.Message != "" {
bannerMsg := &userAuthBannerMsg{Message: w.Message}
if err := s.transport.writePacket(Marshal(bannerMsg)); err != nil {
return nil, err
}
}
if errors.Is(authErr, ErrDenied) {
var failureMsg userAuthFailureMsg
if config.ImplictAuthMethod != "" {
Expand Down

0 comments on commit ce0c30c

Please sign in to comment.