|
|
@@ -34,12 +34,12 @@ type ServerConfig struct {
|
|
|
// PasswordCallback, if non-nil, is called when a user attempts to
|
|
|
// authenticate using a password. It may be called concurrently from
|
|
|
// several goroutines.
|
|
|
- PasswordCallback func(user, password string) bool
|
|
|
+ PasswordCallback func(conn *ServerConn, user, password string) bool
|
|
|
|
|
|
// PublicKeyCallback, if non-nil, is called when a client attempts public
|
|
|
// key authentication. It must return true iff the given public key is
|
|
|
// valid for the given user.
|
|
|
- PublicKeyCallback func(user, algo string, pubkey []byte) bool
|
|
|
+ PublicKeyCallback func(conn *ServerConn, user, algo string, pubkey []byte) bool
|
|
|
|
|
|
// Cryptographic-related configuration.
|
|
|
Crypto CryptoConfig
|
|
|
@@ -150,6 +150,11 @@ type ServerConn struct {
|
|
|
// before attempting to authenticate with it, we end up with duplicate
|
|
|
// queries for public key validity.
|
|
|
cachedPubKeys []cachedPubKey
|
|
|
+
|
|
|
+ // User holds the successfully authenticated user name.
|
|
|
+ // It is empty if no authentication is used. It is populated before
|
|
|
+ // any authentication callback is called and not assigned to after that.
|
|
|
+ User string
|
|
|
}
|
|
|
|
|
|
// Server returns a new SSH server connection
|
|
|
@@ -369,7 +374,7 @@ func (s *ServerConn) testPubKey(user, algo string, pubKey []byte) bool {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- result := s.config.PublicKeyCallback(user, algo, pubKey)
|
|
|
+ result := s.config.PublicKeyCallback(s, user, algo, pubKey)
|
|
|
if len(s.cachedPubKeys) < maxCachedPubKeys {
|
|
|
c := cachedPubKey{
|
|
|
user: user,
|
|
|
@@ -421,7 +426,8 @@ userAuthLoop:
|
|
|
return ParseError{msgUserAuthRequest}
|
|
|
}
|
|
|
|
|
|
- if s.config.PasswordCallback(userAuthReq.User, string(password)) {
|
|
|
+ s.User = userAuthReq.User
|
|
|
+ if s.config.PasswordCallback(s, userAuthReq.User, string(password)) {
|
|
|
break userAuthLoop
|
|
|
}
|
|
|
case "publickey":
|
|
|
@@ -489,6 +495,7 @@ userAuthLoop:
|
|
|
default:
|
|
|
return errors.New("ssh: isAcceptableAlgo incorrect")
|
|
|
}
|
|
|
+ s.User = userAuthReq.User
|
|
|
if s.testPubKey(userAuthReq.User, algo, pubKey) {
|
|
|
break userAuthLoop
|
|
|
}
|