2012-06-29 05:18:28 +00:00
|
|
|
# -*- coding: binary -*-
|
2005-06-04 18:55:20 +00:00
|
|
|
|
|
|
|
module Rex
|
|
|
|
|
|
|
|
###
|
|
|
|
#
|
|
|
|
# Base mixin for all exceptions that can be thrown from inside Rex.
|
|
|
|
#
|
|
|
|
###
|
|
|
|
module Exception
|
|
|
|
end
|
|
|
|
|
2005-11-02 23:03:02 +00:00
|
|
|
###
|
2009-11-04 16:36:06 +00:00
|
|
|
#
|
2005-11-02 23:03:02 +00:00
|
|
|
# This exception is raised when a timeout occurs.
|
|
|
|
#
|
|
|
|
###
|
2005-06-04 18:55:20 +00:00
|
|
|
class TimeoutError < Interrupt
|
2013-08-30 21:28:33 +00:00
|
|
|
include Exception
|
2005-06-04 19:45:47 +00:00
|
|
|
|
2013-08-30 21:28:33 +00:00
|
|
|
def to_s
|
|
|
|
"Operation timed out."
|
|
|
|
end
|
2005-06-04 18:55:20 +00:00
|
|
|
end
|
|
|
|
|
2005-11-02 23:03:02 +00:00
|
|
|
###
|
|
|
|
#
|
|
|
|
# This exception is raised when a method is called or a feature is used that
|
|
|
|
# is not implemented.
|
|
|
|
#
|
|
|
|
###
|
2005-06-04 18:55:20 +00:00
|
|
|
class NotImplementedError < ::NotImplementedError
|
2013-08-30 21:28:33 +00:00
|
|
|
include Exception
|
2005-06-04 19:45:47 +00:00
|
|
|
|
2013-08-30 21:28:33 +00:00
|
|
|
def to_s
|
|
|
|
"The requested method is not implemented."
|
|
|
|
end
|
2005-06-04 18:55:20 +00:00
|
|
|
end
|
|
|
|
|
2005-11-02 23:03:02 +00:00
|
|
|
###
|
|
|
|
#
|
|
|
|
# This exception is raised when a generalized runtime error occurs.
|
|
|
|
#
|
|
|
|
###
|
2005-06-04 20:40:00 +00:00
|
|
|
class RuntimeError < ::RuntimeError
|
2013-08-30 21:28:33 +00:00
|
|
|
include Exception
|
2005-06-04 20:40:33 +00:00
|
|
|
end
|
2005-06-04 20:40:00 +00:00
|
|
|
|
2005-11-02 23:03:02 +00:00
|
|
|
###
|
|
|
|
#
|
|
|
|
# This exception is raised when an invalid argument is supplied to a method.
|
|
|
|
#
|
|
|
|
###
|
2005-06-04 18:55:20 +00:00
|
|
|
class ArgumentError < ::ArgumentError
|
2013-08-30 21:28:33 +00:00
|
|
|
include Exception
|
|
|
|
|
|
|
|
def initialize(message = nil)
|
|
|
|
@message = message
|
|
|
|
end
|
|
|
|
|
|
|
|
def to_s
|
|
|
|
str = 'An invalid argument was specified.'
|
|
|
|
if @message
|
|
|
|
str << " #{@message}"
|
|
|
|
end
|
|
|
|
str
|
|
|
|
end
|
2005-06-04 19:45:47 +00:00
|
|
|
end
|
|
|
|
|
2005-11-02 23:03:02 +00:00
|
|
|
###
|
|
|
|
#
|
|
|
|
# This exception is raised when an argument that was supplied to a method
|
|
|
|
# could not be parsed correctly.
|
|
|
|
#
|
|
|
|
###
|
2005-07-10 07:27:50 +00:00
|
|
|
class ArgumentParseError < ::ArgumentError
|
2013-08-30 21:28:33 +00:00
|
|
|
include Exception
|
2005-07-10 07:27:50 +00:00
|
|
|
|
2013-08-30 21:28:33 +00:00
|
|
|
def to_s
|
|
|
|
"The argument could not be parsed correctly."
|
|
|
|
end
|
2005-07-10 07:27:50 +00:00
|
|
|
end
|
|
|
|
|
2005-11-02 23:03:02 +00:00
|
|
|
###
|
|
|
|
#
|
|
|
|
# This exception is raised when an argument is ambiguous.
|
|
|
|
#
|
|
|
|
###
|
2005-07-14 20:05:41 +00:00
|
|
|
class AmbiguousArgumentError < ::RuntimeError
|
2013-08-30 21:28:33 +00:00
|
|
|
include Exception
|
2005-07-14 20:05:41 +00:00
|
|
|
|
2013-08-30 21:28:33 +00:00
|
|
|
def initialize(name = nil)
|
|
|
|
@name = name
|
|
|
|
end
|
2005-07-14 20:05:41 +00:00
|
|
|
|
2013-08-30 21:28:33 +00:00
|
|
|
def to_s
|
|
|
|
"The name #{@name} is ambiguous."
|
|
|
|
end
|
2005-07-14 20:05:41 +00:00
|
|
|
end
|
|
|
|
|
2005-11-02 23:03:02 +00:00
|
|
|
###
|
2005-09-29 20:18:24 +00:00
|
|
|
#
|
|
|
|
# This error is thrown when a stream is detected as being closed.
|
|
|
|
#
|
2005-11-02 23:03:02 +00:00
|
|
|
###
|
2005-09-29 20:18:24 +00:00
|
|
|
class StreamClosedError < ::IOError
|
2013-08-30 21:28:33 +00:00
|
|
|
include Exception
|
2005-09-29 20:18:24 +00:00
|
|
|
|
2013-08-30 21:28:33 +00:00
|
|
|
def initialize(stream)
|
|
|
|
@stream = stream
|
|
|
|
end
|
2005-09-29 20:18:24 +00:00
|
|
|
|
2013-08-30 21:28:33 +00:00
|
|
|
def stream
|
|
|
|
@stream
|
|
|
|
end
|
2005-09-29 20:18:24 +00:00
|
|
|
|
2013-08-30 21:28:33 +00:00
|
|
|
def to_s
|
|
|
|
"Stream #{@stream} is closed."
|
|
|
|
end
|
2005-09-29 20:18:24 +00:00
|
|
|
end
|
|
|
|
|
2005-06-04 19:45:47 +00:00
|
|
|
##
|
|
|
|
#
|
|
|
|
# Socket exceptions
|
|
|
|
#
|
|
|
|
##
|
|
|
|
|
2005-11-02 23:03:02 +00:00
|
|
|
###
|
|
|
|
#
|
|
|
|
# This exception is raised when a general socket error occurs.
|
|
|
|
#
|
|
|
|
###
|
2005-06-04 19:45:47 +00:00
|
|
|
module SocketError
|
2013-08-30 21:28:33 +00:00
|
|
|
include Exception
|
2005-06-04 19:45:47 +00:00
|
|
|
|
2013-08-30 21:28:33 +00:00
|
|
|
def to_s
|
|
|
|
"A socket error occurred."
|
|
|
|
end
|
2005-06-04 19:45:47 +00:00
|
|
|
end
|
|
|
|
|
2005-06-04 19:56:54 +00:00
|
|
|
###
|
2009-11-04 16:36:06 +00:00
|
|
|
#
|
2005-11-02 23:03:02 +00:00
|
|
|
# This exception is raised when there is some kind of error related to
|
|
|
|
# communication with a host.
|
2005-06-04 19:56:54 +00:00
|
|
|
#
|
|
|
|
###
|
|
|
|
module HostCommunicationError
|
2013-08-30 21:28:33 +00:00
|
|
|
def initialize(addr = nil, port = nil)
|
|
|
|
self.host = addr
|
|
|
|
self.port = port
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# This method returns a printable address and optional port associated
|
|
|
|
# with the host that triggered the exception.
|
|
|
|
#
|
|
|
|
def addr_to_s
|
|
|
|
if host and port
|
|
|
|
"(#{host}:#{port})"
|
|
|
|
elsif host
|
|
|
|
"(#{host})"
|
|
|
|
else
|
|
|
|
""
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
attr_accessor :host, :port
|
2005-06-04 19:56:54 +00:00
|
|
|
end
|
|
|
|
|
2008-11-11 05:11:40 +00:00
|
|
|
|
2005-11-02 23:03:02 +00:00
|
|
|
###
|
|
|
|
#
|
2011-08-10 00:51:23 +00:00
|
|
|
# This is a generic exception for errors that cause a connection to fail.
|
2005-11-02 23:03:02 +00:00
|
|
|
#
|
|
|
|
###
|
2008-11-11 05:11:40 +00:00
|
|
|
class ConnectionError < ::IOError
|
2013-08-30 21:28:33 +00:00
|
|
|
include SocketError
|
|
|
|
include HostCommunicationError
|
2008-11-11 05:11:40 +00:00
|
|
|
end
|
2005-06-04 19:45:47 +00:00
|
|
|
|
2008-11-11 05:11:40 +00:00
|
|
|
###
|
|
|
|
#
|
|
|
|
# This exception is raised when a connection attempt fails because the remote
|
|
|
|
# side refused the connection.
|
|
|
|
#
|
|
|
|
###
|
|
|
|
class ConnectionRefused < ConnectionError
|
2013-08-30 21:28:33 +00:00
|
|
|
def to_s
|
|
|
|
"The connection was refused by the remote host #{addr_to_s}."
|
|
|
|
end
|
2007-04-24 06:27:39 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
###
|
|
|
|
#
|
|
|
|
# This exception is raised when a connection attempt fails because the remote
|
|
|
|
# side is unreachable.
|
|
|
|
#
|
|
|
|
###
|
2008-11-11 05:11:40 +00:00
|
|
|
class HostUnreachable < ConnectionError
|
2013-08-30 21:28:33 +00:00
|
|
|
def to_s
|
|
|
|
"The host #{addr_to_s} was unreachable."
|
|
|
|
end
|
2005-06-04 19:45:47 +00:00
|
|
|
end
|
|
|
|
|
2005-11-02 23:03:02 +00:00
|
|
|
###
|
|
|
|
#
|
|
|
|
# This exception is raised when a connection attempt times out.
|
|
|
|
#
|
|
|
|
###
|
2008-11-11 05:11:40 +00:00
|
|
|
class ConnectionTimeout < ConnectionError
|
2013-08-30 21:28:33 +00:00
|
|
|
def to_s
|
|
|
|
"The connection timed out #{addr_to_s}."
|
|
|
|
end
|
2005-06-04 19:56:54 +00:00
|
|
|
end
|
|
|
|
|
2009-11-04 16:36:06 +00:00
|
|
|
|
2005-11-02 23:03:02 +00:00
|
|
|
###
|
|
|
|
#
|
|
|
|
# This exception is raised when an attempt to use an address or port that is
|
|
|
|
# already in use occurs, such as binding to a host on a given port that is
|
2011-08-10 00:51:23 +00:00
|
|
|
# already in use. Note that Windows raises this in some cases when attempting
|
|
|
|
# to connect to addresses that it can't handle, e.g. "0.0.0.0". Thus, this is
|
|
|
|
# a ConnectionError.
|
2005-11-02 23:03:02 +00:00
|
|
|
#
|
|
|
|
###
|
2011-08-10 00:51:23 +00:00
|
|
|
class AddressInUse < ConnectionError
|
2013-08-30 21:28:33 +00:00
|
|
|
include SocketError
|
|
|
|
include HostCommunicationError
|
2005-06-04 19:45:47 +00:00
|
|
|
|
2013-08-30 21:28:33 +00:00
|
|
|
def to_s
|
|
|
|
"The address is already in use #{addr_to_s}."
|
|
|
|
end
|
2005-06-04 18:55:20 +00:00
|
|
|
end
|
|
|
|
|
2005-11-02 23:03:02 +00:00
|
|
|
###
|
|
|
|
#
|
|
|
|
# This exception is raised when an unsupported internet protocol is specified.
|
|
|
|
#
|
|
|
|
###
|
2005-06-04 20:38:49 +00:00
|
|
|
class UnsupportedProtocol < ::ArgumentError
|
2013-08-30 21:28:33 +00:00
|
|
|
include SocketError
|
2005-06-04 20:38:49 +00:00
|
|
|
|
2013-08-30 21:28:33 +00:00
|
|
|
def initialize(proto = nil)
|
|
|
|
self.proto = proto
|
|
|
|
end
|
2005-06-04 20:38:49 +00:00
|
|
|
|
2013-08-30 21:28:33 +00:00
|
|
|
def to_s
|
|
|
|
"The protocol #{proto} is not supported."
|
|
|
|
end
|
2005-06-04 20:38:49 +00:00
|
|
|
|
2013-08-30 21:28:33 +00:00
|
|
|
attr_accessor :proto
|
2005-06-04 20:38:49 +00:00
|
|
|
end
|
|
|
|
|
2009-11-04 16:36:06 +00:00
|
|
|
|
|
|
|
###
|
|
|
|
#
|
|
|
|
# This exception is raised when a proxy fails to pass a connection
|
|
|
|
#
|
|
|
|
###
|
|
|
|
class ConnectionProxyError < ConnectionError
|
2013-08-30 21:28:33 +00:00
|
|
|
def initialize(host,port,ptype,reason)
|
|
|
|
super(host,port)
|
|
|
|
self.ptype = ptype
|
|
|
|
self.reason = reason
|
|
|
|
end
|
2009-11-04 16:36:06 +00:00
|
|
|
|
2013-08-30 21:28:33 +00:00
|
|
|
def to_s
|
|
|
|
self.ptype + ": " + self.reason
|
|
|
|
end
|
2009-11-04 16:36:06 +00:00
|
|
|
|
2013-08-30 21:28:33 +00:00
|
|
|
attr_accessor :ptype, :reason
|
2009-11-04 16:36:06 +00:00
|
|
|
end
|
|
|
|
|
2008-11-11 05:11:40 +00:00
|
|
|
end
|
2009-11-04 16:36:06 +00:00
|
|
|
|