Adds an auth_info hash to the SSH connection object (populated by password and publickey auth) to record the details of a successful authentication. Useful for querying which password or publickey was actually used to authenticate.

git-svn-id: file:///home/svn/framework3/trunk@9059 4d416f70-5f16-0410-b530-b9f4589650da
unstable
Tod Beardsley 2010-04-13 16:47:21 +00:00
parent 52d17d73da
commit 5dc72cf63d
4 changed files with 20 additions and 2 deletions

View File

@ -20,6 +20,11 @@ module Net
case message.type
when USERAUTH_SUCCESS
debug { "password succeeded" }
if session.options[:record_auth_info]
session.auth_info[:method] = "password"
session.auth_info[:user] = username
session.auth_info[:password] = password
end
return true
when USERAUTH_FAILURE
debug { "password failed" }

View File

@ -67,6 +67,11 @@ module Net
case message.type
when USERAUTH_SUCCESS
debug { "publickey succeeded (#{identity.fingerprint})" }
if session.options[:record_auth_info]
session.auth_info[:method] = "publickey"
session.auth_info[:user] = username
session.auth_info[:pubkey_id] = identity.fingerprint
end
return true
when USERAUTH_FAILURE
debug { "publickey failed (#{identity.fingerprint})" }

View File

@ -31,6 +31,9 @@ module Net; module SSH; module Authentication
# a hash of options, given at construction time
attr_reader :options
# when a successful auth is made, note the auth info if session.options[:record_auth_info]
attr_accessor :auth_info
# Instantiates a new Authentication::Session object over the given
# transport layer abstraction.
def initialize(transport, options={})
@ -41,6 +44,7 @@ module Net; module SSH; module Authentication
@options = options
@allowed_auth_methods = @auth_methods
@auth_info = {}
end
# Attempts to authenticate the given user, in preparation for the next
@ -132,3 +136,4 @@ module Net; module SSH; module Authentication
end
end
end; end; end

View File

@ -46,6 +46,9 @@ module Net; module SSH; module Connection
# The list of callbacks for pending requests. See #send_global_request.
attr_reader :pending_requests #:nodoc:
# when a successful auth is made, note the auth info if session.options[:record_auth_info]
attr_accessor :auth_info
class NilChannel
def initialize(session)
@session = session