[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:
Robey Pointer 2004-11-01 03:43:28 +00:00
parent 44d07583bb
commit d7caa20213
3 changed files with 55 additions and 9 deletions

View File

@ -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_EOF, MSG_CHANNEL_CLOSE, MSG_CHANNEL_REQUEST, \
MSG_CHANNEL_SUCCESS, MSG_CHANNEL_FAILURE = range(90, 101) 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: # authentication request return codes:

View File

@ -24,6 +24,7 @@ L{ServerInterface} is an interface to override for server support.
import threading import threading
from common import * from common import *
import util
from transport import BaseTransport from transport import BaseTransport
from auth_transport import Transport 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. subsystem; C{False} if that subsystem can't or won't be provided.
@rtype: boolean @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: if handler_class is None:
return False return False
handler = handler_class(channel, name) handler = handler_class(channel, name, *larg, **kwarg)
handler.start() handler.start()
return True return True

View File

@ -778,9 +778,15 @@ class BaseTransport (threading.Thread):
return 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. @param name: name of the subsystem.
@type name: str @type name: str
@ -790,7 +796,7 @@ class BaseTransport (threading.Thread):
""" """
try: try:
self.lock.acquire() self.lock.acquire()
self.subsystem_table[name] = handler self.subsystem_table[name] = (handler, larg, kwarg)
finally: finally:
self.lock.release() self.lock.release()
@ -884,10 +890,14 @@ class BaseTransport (threading.Thread):
return packet return packet
def _send_message(self, data): def _send_message(self, data):
# FIXME: should we check for rekeying here too?
# encrypt this sucka # encrypt this sucka
data = str(data) 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) packet = self._build_packet(data)
if self.ultra_debug: if self.ultra_debug:
self._log(DEBUG, util.format_binary(packet, 'OUT: ')) 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._log(DEBUG, 'Rekeying (hit %d packets, %d bytes sent)' %
(self.sent_packets, self.sent_bytes)) (self.sent_packets, self.sent_bytes))
self.received_packets_overflow = 0 self.received_packets_overflow = 0
# this may do a recursive lock, but that's okay:
self._send_kex_init() self._send_kex_init()
finally: finally:
self.write_lock.release() self.write_lock.release()
@ -983,7 +994,11 @@ class BaseTransport (threading.Thread):
self._send_kex_init() self._send_kex_init()
cmd = ord(payload[0]) 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 return cmd, msg
def _set_K_H(self, k, h): def _set_K_H(self, k, h):
@ -1475,7 +1490,7 @@ class BaseTransport (threading.Thread):
try: try:
self.lock.acquire() self.lock.acquire()
if not self.subsystem_table.has_key(name): if not self.subsystem_table.has_key(name):
return None return (None, [], {})
return self.subsystem_table[name] return self.subsystem_table[name]
finally: finally:
self.lock.release() self.lock.release()