From c1ed20c4afaa4715f0ec1f4f802a587b3935f48f Mon Sep 17 00:00:00 2001 From: Robey Pointer Date: Tue, 25 Jan 2005 05:17:55 +0000 Subject: [PATCH] [project @ Arch-1:robey@lag.net--2003-public%secsh--dev--1.0--patch-141] misc logging fixes change the level of some log messages so interesting stuff gets logged at info instead of debug. fix an oops where channels defaulted to being in ultra debug mode, and make this mode depend on a new Transport method: "set_hexdump". --- paramiko/auth_transport.py | 12 ++++++------ paramiko/channel.py | 2 +- paramiko/sftp.py | 2 +- paramiko/sftp_client.py | 1 + paramiko/sftp_server.py | 2 +- paramiko/transport.py | 14 +++++++++++++- 6 files changed, 23 insertions(+), 10 deletions(-) diff --git a/paramiko/auth_transport.py b/paramiko/auth_transport.py index 00aba9c..b6da9bb 100644 --- a/paramiko/auth_transport.py +++ b/paramiko/auth_transport.py @@ -326,7 +326,7 @@ class Transport (BaseTransport): self._disconnect_service_not_available() return if (self.auth_username is not None) and (self.auth_username != username): - self._log(DEBUG, 'Auth rejected because the client attempted to change username in mid-flight') + self._log(WARNING, 'Auth rejected because the client attempted to change username in mid-flight') self._disconnect_no_more_auth() return self.auth_username = username @@ -351,10 +351,10 @@ class Transport (BaseTransport): try: key = self._key_info[keytype](Message(keyblob)) except SSHException, e: - self._log(DEBUG, 'Auth rejected: public key: %s' % str(e)) + self._log(INFO, 'Auth rejected: public key: %s' % str(e)) key = None except: - self._log(DEBUG, 'Auth rejected: unsupported or mangled public key') + self._log(INFO, 'Auth rejected: unsupported or mangled public key') key = None if key is None: self._disconnect_no_more_auth() @@ -375,18 +375,18 @@ class Transport (BaseTransport): sig = Message(m.get_string()) blob = self._get_session_blob(key, service, username) if not key.verify_ssh_sig(blob, sig): - self._log(DEBUG, 'Auth rejected: invalid signature') + self._log(INFO, 'Auth rejected: invalid signature') result = AUTH_FAILED else: result = self.server_object.check_auth_none(username) # okay, send result m = Message() if result == AUTH_SUCCESSFUL: - self._log(DEBUG, 'Auth granted.') + self._log(INFO, 'Auth granted (%s).' % method) m.add_byte(chr(MSG_USERAUTH_SUCCESS)) self.authenticated = True else: - self._log(DEBUG, 'Auth rejected.') + self._log(INFO, 'Auth rejected (%s).' % method) m.add_byte(chr(MSG_USERAUTH_FAILURE)) m.add_string(self.server_object.get_allowed_auths(username)) if result == AUTH_PARTIALLY_SUCCESSFUL: diff --git a/paramiko/channel.py b/paramiko/channel.py index b41136c..978022d 100644 --- a/paramiko/channel.py +++ b/paramiko/channel.py @@ -822,7 +822,7 @@ class Channel (object): nbytes = m.get_int() try: self.lock.acquire() - if self.ultra_debug or True: + if self.ultra_debug: self._log(DEBUG, 'window up %d' % nbytes) self.out_window_size += nbytes self.out_buffer_cv.notifyAll() diff --git a/paramiko/sftp.py b/paramiko/sftp.py index d37c544..c11564a 100644 --- a/paramiko/sftp.py +++ b/paramiko/sftp.py @@ -118,7 +118,7 @@ class BaseSFTP (object): return version def _log(self, level, msg): - if type(msg) == type([]): + if issubclass(type(msg), list): for m in msg: self.logger.log(level, m) else: diff --git a/paramiko/sftp_client.py b/paramiko/sftp_client.py index 628a9b2..f40a536 100644 --- a/paramiko/sftp_client.py +++ b/paramiko/sftp_client.py @@ -53,6 +53,7 @@ class SFTPClient (BaseSFTP): transport = self.sock.get_transport() self.logger = logging.getLogger(transport.get_log_channel() + '.' + self.sock.get_name() + '.sftp') + self.ultra_debug = transport.ultra_debug self._send_version() def from_transport(selfclass, t): diff --git a/paramiko/sftp_server.py b/paramiko/sftp_server.py index e03131b..318da02 100644 --- a/paramiko/sftp_server.py +++ b/paramiko/sftp_server.py @@ -57,10 +57,10 @@ class SFTPServer (BaseSFTP, SubsystemHandler): """ BaseSFTP.__init__(self) SubsystemHandler.__init__(self, channel, name) - self.ultra_debug = True transport = channel.get_transport() self.logger = logging.getLogger(transport.get_log_channel() + '.' + channel.get_name() + '.sftp') + self.ultra_debug = transport.ultra_debug self.next_handle = 1 # map of handle-string to SFTPHandle for files & folders: self.file_table = { } diff --git a/paramiko/transport.py b/paramiko/transport.py index 5925b12..25a82dd 100644 --- a/paramiko/transport.py +++ b/paramiko/transport.py @@ -806,12 +806,24 @@ class BaseTransport (threading.Thread): """ return self.log_name + def set_hexdump(self, hexdump): + """ + Turn on/off logging a hex dump of protocol traffic at DEBUG level in + the logs. Normally you would want this off (which is the default), + but if you are debugging something, it may be useful. + + @param hexdump: C{True} to log protocol traffix (in hex) to the log; + C{False} otherwise. + @type hexdump: bool + """ + self.ultra_debug = hexdump + ### internals... def _log(self, level, msg): - if type(msg) == type([]): + if issubclass(type(msg), list): for m in msg: self.logger.log(level, m) else: