ssh: fix error variable naming convention, add docs
Follow up to CL 96336 Change-Id: I038f3901919c5136273e5df051bc6e958082f830 Reviewed-on: https://go-review.googlesource.com/96415 Reviewed-by: Han-Wen Nienhuys <hanwen@google.com> Run-TryBot: Han-Wen Nienhuys <hanwen@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
committed by
Han-Wen Nienhuys
parent
49796115aa
commit
beaf6a3570
@@ -614,8 +614,8 @@ func TestClientAuthErrorList(t *testing.T) {
|
|||||||
for i, e := range authErrs.Errors {
|
for i, e := range authErrs.Errors {
|
||||||
switch i {
|
switch i {
|
||||||
case 0:
|
case 0:
|
||||||
if e != NoAuthError {
|
if e != ErrNoAuth {
|
||||||
t.Fatalf("errors: got error %v, want NoAuthError", e)
|
t.Fatalf("errors: got error %v, want ErrNoAuth", e)
|
||||||
}
|
}
|
||||||
case 1:
|
case 1:
|
||||||
if e != publicKeyErr {
|
if e != publicKeyErr {
|
||||||
|
|||||||
+12
-7
@@ -166,6 +166,9 @@ type ServerConn struct {
|
|||||||
// unsuccessful, it closes the connection and returns an error. The
|
// unsuccessful, it closes the connection and returns an error. The
|
||||||
// Request and NewChannel channels must be serviced, or the connection
|
// Request and NewChannel channels must be serviced, or the connection
|
||||||
// will hang.
|
// will hang.
|
||||||
|
//
|
||||||
|
// The returned error may be of type *ServerAuthError for
|
||||||
|
// authentication errors.
|
||||||
func NewServerConn(c net.Conn, config *ServerConfig) (*ServerConn, <-chan NewChannel, <-chan *Request, error) {
|
func NewServerConn(c net.Conn, config *ServerConfig) (*ServerConn, <-chan NewChannel, <-chan *Request, error) {
|
||||||
fullConf := *config
|
fullConf := *config
|
||||||
fullConf.SetDefaults()
|
fullConf.SetDefaults()
|
||||||
@@ -292,12 +295,13 @@ func checkSourceAddress(addr net.Addr, sourceAddrs string) error {
|
|||||||
return fmt.Errorf("ssh: remote address %v is not allowed because of source-address restriction", addr)
|
return fmt.Errorf("ssh: remote address %v is not allowed because of source-address restriction", addr)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ServerAuthError implements the error interface. It appends any authentication
|
// ServerAuthError represents server authentication errors and is
|
||||||
// errors that may occur, and is returned if all of the authentication methods
|
// sometimes returned by NewServerConn. It appends any authentication
|
||||||
// provided by the user failed to authenticate.
|
// errors that may occur, and is returned if all of the authentication
|
||||||
|
// methods provided by the user failed to authenticate.
|
||||||
type ServerAuthError struct {
|
type ServerAuthError struct {
|
||||||
// Errors contains authentication errors returned by the authentication
|
// Errors contains authentication errors returned by the authentication
|
||||||
// callback methods. The first entry typically is NoAuthError.
|
// callback methods. The first entry is typically ErrNoAuth.
|
||||||
Errors []error
|
Errors []error
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -309,11 +313,12 @@ func (l ServerAuthError) Error() string {
|
|||||||
return "[" + strings.Join(errs, ", ") + "]"
|
return "[" + strings.Join(errs, ", ") + "]"
|
||||||
}
|
}
|
||||||
|
|
||||||
// NoAuthError is the unique error that is returned if no
|
// ErrNoAuth is the error value returned if no
|
||||||
// authentication method has been passed yet. This happens as a normal
|
// authentication method has been passed yet. This happens as a normal
|
||||||
// part of the authentication loop, since the client first tries
|
// part of the authentication loop, since the client first tries
|
||||||
// 'none' authentication to discover available methods.
|
// 'none' authentication to discover available methods.
|
||||||
var NoAuthError = errors.New("ssh: no auth passed yet")
|
// It is returned in ServerAuthError.Errors from NewServerConn.
|
||||||
|
var ErrNoAuth = errors.New("ssh: no auth passed yet")
|
||||||
|
|
||||||
func (s *connection) serverAuthenticate(config *ServerConfig) (*Permissions, error) {
|
func (s *connection) serverAuthenticate(config *ServerConfig) (*Permissions, error) {
|
||||||
sessionID := s.transport.getSessionID()
|
sessionID := s.transport.getSessionID()
|
||||||
@@ -369,7 +374,7 @@ userAuthLoop:
|
|||||||
}
|
}
|
||||||
|
|
||||||
perms = nil
|
perms = nil
|
||||||
authErr := NoAuthError
|
authErr := ErrNoAuth
|
||||||
|
|
||||||
switch userAuthReq.Method {
|
switch userAuthReq.Method {
|
||||||
case "none":
|
case "none":
|
||||||
|
|||||||
Reference in New Issue
Block a user