Skip to content

Commit

Permalink
ssh: add WithBannerError
Browse files Browse the repository at this point in the history
Co-Authored-By: Maisem Ali <maisem@tailscale.com>
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
  • Loading branch information
2 people authored and iQQBot committed Jul 27, 2023
1 parent 9bba4fc commit 023be46
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 @@ -301,6 +301,19 @@ func (s *connection) serverHandshake(config *ServerConfig) (*Permissions, error)
return perms, err
}

// 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 @@ -678,6 +691,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 023be46

Please sign in to comment.