2005-06-04 18:55:20 +00:00
|
|
|
#!/usr/bin/ruby
|
|
|
|
|
|
|
|
module Rex
|
|
|
|
|
|
|
|
###
|
|
|
|
#
|
|
|
|
# Exception
|
|
|
|
# ---------
|
|
|
|
#
|
|
|
|
# Base mixin for all exceptions that can be thrown from inside Rex.
|
|
|
|
#
|
|
|
|
###
|
|
|
|
module Exception
|
|
|
|
end
|
|
|
|
|
|
|
|
class TimeoutError < Interrupt
|
|
|
|
include Exception
|
2005-06-04 19:45:47 +00:00
|
|
|
|
|
|
|
def to_s
|
2005-06-04 20:40:00 +00:00
|
|
|
"Operation timed out."
|
2005-06-04 19:45:47 +00:00
|
|
|
end
|
2005-06-04 18:55:20 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
class NotImplementedError < ::NotImplementedError
|
|
|
|
include Exception
|
2005-06-04 19:45:47 +00:00
|
|
|
|
|
|
|
def to_s
|
2005-06-04 20:40:00 +00:00
|
|
|
"The requested method is not implemented."
|
2005-06-04 19:45:47 +00:00
|
|
|
end
|
2005-06-04 18:55:20 +00:00
|
|
|
end
|
|
|
|
|
2005-06-04 20:40:00 +00:00
|
|
|
class RuntimeError < ::RuntimeError
|
|
|
|
include Exception
|
|
|
|
|
2005-07-19 04:21:15 +00:00
|
|
|
# def to_s
|
|
|
|
# "A runtime error occurred."
|
|
|
|
# end
|
2005-06-04 20:40:33 +00:00
|
|
|
end
|
2005-06-04 20:40:00 +00:00
|
|
|
|
2005-06-04 18:55:20 +00:00
|
|
|
class ArgumentError < ::ArgumentError
|
|
|
|
include Exception
|
2005-06-04 19:45:47 +00:00
|
|
|
|
|
|
|
def to_s
|
2005-06-04 20:40:00 +00:00
|
|
|
"An invalid argument was specified."
|
2005-06-04 19:45:47 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2005-07-10 07:27:50 +00:00
|
|
|
class ArgumentParseError < ::ArgumentError
|
|
|
|
include Exception
|
|
|
|
|
|
|
|
def to_s
|
|
|
|
"The argument could not be parsed correctly."
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2005-07-14 20:05:41 +00:00
|
|
|
class AmbiguousArgumentError < ::RuntimeError
|
|
|
|
include Exception
|
|
|
|
|
|
|
|
def initialize(name)
|
|
|
|
@name = name
|
|
|
|
end
|
|
|
|
|
|
|
|
def to_s
|
|
|
|
"The name #{@name} is ambiguous."
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2005-06-04 19:45:47 +00:00
|
|
|
#####
|
|
|
|
#####
|
|
|
|
##
|
|
|
|
#
|
|
|
|
# Socket exceptions
|
|
|
|
#
|
|
|
|
##
|
|
|
|
#####
|
|
|
|
#####
|
|
|
|
|
|
|
|
module SocketError
|
|
|
|
include Exception
|
|
|
|
|
|
|
|
def to_s
|
2005-06-04 20:38:49 +00:00
|
|
|
"A socket error occurred."
|
2005-06-04 19:45:47 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2005-06-04 19:56:54 +00:00
|
|
|
###
|
|
|
|
#
|
|
|
|
# HostCommunicationError
|
|
|
|
# ----------------------
|
|
|
|
#
|
|
|
|
# Implements helper methods for errors that occurred when communicating to a
|
|
|
|
# host.
|
|
|
|
#
|
|
|
|
###
|
|
|
|
module HostCommunicationError
|
|
|
|
def initialize(addr = nil, port = nil)
|
|
|
|
self.host = addr
|
|
|
|
self.port = port
|
|
|
|
end
|
|
|
|
|
|
|
|
def addr_to_s
|
2005-06-04 20:38:49 +00:00
|
|
|
(host && port) ? " (#{host}:#{port})" : ""
|
2005-06-04 19:56:54 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
attr_accessor :host, :port
|
|
|
|
end
|
|
|
|
|
2005-06-04 19:45:47 +00:00
|
|
|
class ConnectionRefused < ::IOError
|
|
|
|
include SocketError
|
2005-06-04 19:56:54 +00:00
|
|
|
include HostCommunicationError
|
2005-06-04 19:45:47 +00:00
|
|
|
|
|
|
|
def to_s
|
2005-06-04 20:38:49 +00:00
|
|
|
"The connection was refused by the remote host#{addr_to_s}."
|
2005-06-04 19:45:47 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class ConnectionTimeout < ::Interrupt
|
|
|
|
include SocketError
|
2005-06-04 19:56:54 +00:00
|
|
|
include HostCommunicationError
|
|
|
|
|
|
|
|
def to_s
|
2005-06-04 20:38:49 +00:00
|
|
|
"The connection timed out#{addr_to_s}."
|
2005-06-04 19:56:54 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class AddressInUse < ::RuntimeError
|
|
|
|
include SocketError
|
|
|
|
include HostCommunicationError
|
2005-06-04 19:45:47 +00:00
|
|
|
|
|
|
|
def to_s
|
2005-06-04 20:38:49 +00:00
|
|
|
"The address is already in use#{addr_to_s}."
|
2005-06-04 19:45:47 +00:00
|
|
|
end
|
2005-06-04 18:55:20 +00:00
|
|
|
end
|
|
|
|
|
2005-06-04 20:38:49 +00:00
|
|
|
class UnsupportedProtocol < ::ArgumentError
|
|
|
|
include SocketError
|
|
|
|
|
|
|
|
def initialize(proto = nil)
|
|
|
|
self.proto = proto
|
|
|
|
end
|
|
|
|
|
|
|
|
def to_s
|
|
|
|
"The protocol #{proto} is not supported."
|
|
|
|
end
|
|
|
|
|
|
|
|
attr_accessor :proto
|
|
|
|
end
|
|
|
|
|
2005-06-04 18:55:20 +00:00
|
|
|
end # Rex
|