2008-12-02 22:09:34 +00:00
|
|
|
module Msf
|
|
|
|
module RPC
|
|
|
|
class Base
|
|
|
|
|
2010-07-20 20:36:09 +00:00
|
|
|
def initialize(framework,tokens,users)
|
2008-12-02 22:09:34 +00:00
|
|
|
@framework = framework
|
|
|
|
@tokens = tokens
|
|
|
|
@users = users
|
|
|
|
end
|
|
|
|
|
2011-05-15 23:51:53 +00:00
|
|
|
private
|
|
|
|
|
2011-05-14 18:38:44 +00:00
|
|
|
def authenticate(token)
|
2008-12-02 22:09:34 +00:00
|
|
|
stale = []
|
2011-05-14 18:38:44 +00:00
|
|
|
|
|
|
|
# Force the encoding to ASCII-8BIT
|
|
|
|
token = token.unpack("C*").pack("C*")
|
|
|
|
|
2008-12-02 22:09:34 +00:00
|
|
|
@tokens.each_key do |t|
|
2010-03-15 20:16:37 +00:00
|
|
|
user,ctime,mtime,perm = @tokens[t]
|
|
|
|
if ! perm and mtime + 300 < Time.now.to_i
|
2008-12-02 22:09:34 +00:00
|
|
|
stale << t
|
|
|
|
end
|
|
|
|
end
|
2010-03-15 20:16:37 +00:00
|
|
|
|
2008-12-02 22:09:34 +00:00
|
|
|
stale.each { |t| @tokens.delete(t) }
|
2010-03-15 20:16:37 +00:00
|
|
|
|
2011-05-14 18:38:44 +00:00
|
|
|
if not @tokens[token]
|
2008-12-02 22:09:34 +00:00
|
|
|
raise ::XMLRPC::FaultException.new(401, "authentication error")
|
|
|
|
end
|
2010-03-15 20:16:37 +00:00
|
|
|
|
2008-12-02 22:09:34 +00:00
|
|
|
@tokens[token][2] = Time.now.to_i
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2010-03-15 20:16:37 +00:00
|
|
|
|