[project @ Arch-1:robey@lag.net--2003-public%secsh--dev--1.0--patch-97]
better debugging, improve subsytem handler add a list of ssh packet names for debugging. improve the server-mode subsystem handler so it can take extra parameters (list or keyword) and pass them to the subsystem constructor. remove a misleading comment about rekeying (which was already implemented).
This commit is contained in:
parent
44d07583bb
commit
d7caa20213
|
@ -34,6 +34,36 @@ MSG_CHANNEL_OPEN, MSG_CHANNEL_OPEN_SUCCESS, MSG_CHANNEL_OPEN_FAILURE, \
|
|||
MSG_CHANNEL_EOF, MSG_CHANNEL_CLOSE, MSG_CHANNEL_REQUEST, \
|
||||
MSG_CHANNEL_SUCCESS, MSG_CHANNEL_FAILURE = range(90, 101)
|
||||
|
||||
# for debugging:
|
||||
MSG_NAMES = {
|
||||
MSG_DISCONNECT: 'disconnect',
|
||||
MSG_IGNORE: 'ignore',
|
||||
MSG_UNIMPLEMENTED: 'unimplemented',
|
||||
MSG_DEBUG: 'debug',
|
||||
MSG_SERVICE_REQUEST: 'service-request',
|
||||
MSG_SERVICE_ACCEPT: 'service-accept',
|
||||
MSG_KEXINIT: 'kexinit',
|
||||
MSG_NEWKEYS: 'newkeys',
|
||||
MSG_USERAUTH_REQUEST: 'userauth-request',
|
||||
MSG_USERAUTH_FAILURE: 'userauth-failure',
|
||||
MSG_USERAUTH_SUCCESS: 'userauth-success',
|
||||
MSG_USERAUTH_BANNER: 'userauth--banner',
|
||||
MSG_USERAUTH_PK_OK: 'userauth-pk-ok',
|
||||
MSG_GLOBAL_REQUEST: 'global-request',
|
||||
MSG_REQUEST_SUCCESS: 'request-success',
|
||||
MSG_REQUEST_FAILURE: 'request-failure',
|
||||
MSG_CHANNEL_OPEN: 'channel-open',
|
||||
MSG_CHANNEL_OPEN_SUCCESS: 'channel-open-success',
|
||||
MSG_CHANNEL_OPEN_FAILURE: 'channel-open-failure',
|
||||
MSG_CHANNEL_WINDOW_ADJUST: 'channel-window-adjust',
|
||||
MSG_CHANNEL_DATA: 'channel-data',
|
||||
MSG_CHANNEL_EXTENDED_DATA: 'channel-extended-data',
|
||||
MSG_CHANNEL_EOF: 'channel-eof',
|
||||
MSG_CHANNEL_CLOSE: 'channel-close',
|
||||
MSG_CHANNEL_REQUEST: 'channel-request',
|
||||
MSG_CHANNEL_SUCCESS: 'channel-success',
|
||||
MSG_CHANNEL_FAILURE: 'channel-failure'
|
||||
}
|
||||
|
||||
# authentication request return codes:
|
||||
|
||||
|
|
|
@ -24,6 +24,7 @@ L{ServerInterface} is an interface to override for server support.
|
|||
|
||||
import threading
|
||||
from common import *
|
||||
import util
|
||||
from transport import BaseTransport
|
||||
from auth_transport import Transport
|
||||
|
||||
|
@ -248,10 +249,10 @@ class ServerInterface (object):
|
|||
subsystem; C{False} if that subsystem can't or won't be provided.
|
||||
@rtype: boolean
|
||||
"""
|
||||
handler_class = channel.get_transport()._get_subsystem_handler(name)
|
||||
handler_class, larg, kwarg = channel.get_transport()._get_subsystem_handler(name)
|
||||
if handler_class is None:
|
||||
return False
|
||||
handler = handler_class(channel, name)
|
||||
handler = handler_class(channel, name, *larg, **kwarg)
|
||||
handler.start()
|
||||
return True
|
||||
|
||||
|
|
|
@ -778,9 +778,15 @@ class BaseTransport (threading.Thread):
|
|||
|
||||
return
|
||||
|
||||
def set_subsystem_handler(self, name, handler):
|
||||
def set_subsystem_handler(self, name, handler, *larg, **kwarg):
|
||||
"""
|
||||
Set the handler class for a subsystem in server mode.
|
||||
Set the handler class for a subsystem in server mode. If a reqeuest
|
||||
for this subsystem is made on an open ssh channel later, this handler
|
||||
will be constructed and called -- see L{SubsystemHandler} for more
|
||||
detailed documentation.
|
||||
|
||||
Any extra parameters (including keyword arguments) are saved and
|
||||
passed to the L{SubsystemHandler} constructor later.
|
||||
|
||||
@param name: name of the subsystem.
|
||||
@type name: str
|
||||
|
@ -790,7 +796,7 @@ class BaseTransport (threading.Thread):
|
|||
"""
|
||||
try:
|
||||
self.lock.acquire()
|
||||
self.subsystem_table[name] = handler
|
||||
self.subsystem_table[name] = (handler, larg, kwarg)
|
||||
finally:
|
||||
self.lock.release()
|
||||
|
||||
|
@ -884,10 +890,14 @@ class BaseTransport (threading.Thread):
|
|||
return packet
|
||||
|
||||
def _send_message(self, data):
|
||||
# FIXME: should we check for rekeying here too?
|
||||
# encrypt this sucka
|
||||
data = str(data)
|
||||
self._log(DEBUG, 'Write packet $%x, length %d' % (ord(data[0]), len(data)))
|
||||
cmd = ord(data[0])
|
||||
if cmd in MSG_NAMES:
|
||||
cmd_name = MSG_NAMES[cmd]
|
||||
else:
|
||||
cmd_name = '$%x' % cmd
|
||||
self._log(DEBUG, 'Write packet <%s>, length %d' % (cmd_name, len(data)))
|
||||
packet = self._build_packet(data)
|
||||
if self.ultra_debug:
|
||||
self._log(DEBUG, util.format_binary(packet, 'OUT: '))
|
||||
|
@ -913,6 +923,7 @@ class BaseTransport (threading.Thread):
|
|||
self._log(DEBUG, 'Rekeying (hit %d packets, %d bytes sent)' %
|
||||
(self.sent_packets, self.sent_bytes))
|
||||
self.received_packets_overflow = 0
|
||||
# this may do a recursive lock, but that's okay:
|
||||
self._send_kex_init()
|
||||
finally:
|
||||
self.write_lock.release()
|
||||
|
@ -983,7 +994,11 @@ class BaseTransport (threading.Thread):
|
|||
self._send_kex_init()
|
||||
|
||||
cmd = ord(payload[0])
|
||||
self._log(DEBUG, 'Read packet $%x, length %d' % (cmd, len(payload)))
|
||||
if cmd in MSG_NAMES:
|
||||
cmd_name = MSG_NAMES[cmd]
|
||||
else:
|
||||
cmd_name = '$%x' % cmd
|
||||
self._log(DEBUG, 'Read packet <%s>, length %d' % (cmd_name, len(payload)))
|
||||
return cmd, msg
|
||||
|
||||
def _set_K_H(self, k, h):
|
||||
|
@ -1475,7 +1490,7 @@ class BaseTransport (threading.Thread):
|
|||
try:
|
||||
self.lock.acquire()
|
||||
if not self.subsystem_table.has_key(name):
|
||||
return None
|
||||
return (None, [], {})
|
||||
return self.subsystem_table[name]
|
||||
finally:
|
||||
self.lock.release()
|
||||
|
|
Loading…
Reference in New Issue