1
mirror of https://github.com/rapid7/metasploit-framework synced 2024-11-12 11:52:01 +01:00

differentiate between protocol errors and login failues

git-svn-id: file:///home/svn/framework3/trunk@9099 4d416f70-5f16-0410-b530-b9f4589650da
This commit is contained in:
James Lee 2010-04-16 22:29:33 +00:00
parent 2485dcb1b7
commit 8eff6b6438

View File

@ -35,6 +35,13 @@ class APIError < ::RuntimeError
end
end
class AuthenticationFailed < APIError
def initialize(req)
self.req = req
self.reason = "Login Failed"
end
end
module XMLUtils
def parse_xml(xml)
::REXML::Document.new(xml.to_s)
@ -346,12 +353,15 @@ class Connection
# Establish a new connection and Session ID
def login
r = execute(make_xml('LoginRequest', { 'sync-id' => 0, 'password' => @password, 'user-id' => @username }))
begin
r = execute(make_xml('LoginRequest', { 'sync-id' => 0, 'password' => @password, 'user-id' => @username }))
rescue APIError
raise AuthenticationFailed.new(r)
end
if(r.success)
@session_id = r.sid
return true
end
raise APIError.new(r, 'Login failed')
end
# Logout of the current connection