From 2690a90ccb7a19b0676900f8804fb3da5f3130a6 Mon Sep 17 00:00:00 2001 From: Jeff Forcier Date: Tue, 11 Feb 2014 14:51:28 -0800 Subject: [PATCH 1/5] Bump to releases bugfix --- dev-requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dev-requirements.txt b/dev-requirements.txt index 6c242c0..331e38c 100644 --- a/dev-requirements.txt +++ b/dev-requirements.txt @@ -4,4 +4,4 @@ invoke>=0.7.0 invocations>=0.4.4 sphinx>=1.1.3 alabaster>=0.3.0 -releases>=0.5.0 +releases>=0.5.1 From 985c3069fb2ccd3488aa600af2daa22186ef162a Mon Sep 17 00:00:00 2001 From: Johan Prins Date: Sat, 15 Oct 2011 13:40:22 +0200 Subject: [PATCH 2/5] Adding banner functionality --- paramiko/auth_handler.py | 5 +++++ paramiko/transport.py | 12 ++++++++++++ 2 files changed, 17 insertions(+) diff --git a/paramiko/auth_handler.py b/paramiko/auth_handler.py index acb7c8b..da551af 100644 --- a/paramiko/auth_handler.py +++ b/paramiko/auth_handler.py @@ -45,6 +45,7 @@ class AuthHandler (object): self.authenticated = False self.auth_event = None self.auth_method = '' + self.banner = None self.password = None self.private_key = None self.interactive_handler = None @@ -62,6 +63,9 @@ class AuthHandler (object): else: return self.username + def get_banner(self): + return self.banner + def auth_none(self, username, event): self.transport.lock.acquire() try: @@ -375,6 +379,7 @@ class AuthHandler (object): def _parse_userauth_banner(self, m): banner = m.get_string() + self.banner = banner lang = m.get_string() self.transport._log(INFO, 'Auth banner: ' + banner) # who cares. diff --git a/paramiko/transport.py b/paramiko/transport.py index 6c42cc2..951e36a 100644 --- a/paramiko/transport.py +++ b/paramiko/transport.py @@ -1092,6 +1092,18 @@ class Transport (threading.Thread): return None return self.auth_handler.get_username() + def get_banner(self): + """ + Return the banner supplied by the server upon connect. If no banner is supplied, + this method returns C{None}. + + @return: server supplied banner, or C{None}. + @rtype: string + """ + if not self.active or (self.auth_handler is None): + return None + return self.auth_handler.get_banner() + def auth_none(self, username): """ Try to authenticate to the server using no authentication at all. From 3e87f4aa27844f2791210a51a3ff64f95550176a Mon Sep 17 00:00:00 2001 From: Jeff Forcier Date: Tue, 11 Feb 2014 15:02:46 -0800 Subject: [PATCH 3/5] Formatting --- paramiko/transport.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/paramiko/transport.py b/paramiko/transport.py index 951e36a..127635e 100644 --- a/paramiko/transport.py +++ b/paramiko/transport.py @@ -1094,8 +1094,8 @@ class Transport (threading.Thread): def get_banner(self): """ - Return the banner supplied by the server upon connect. If no banner is supplied, - this method returns C{None}. + Return the banner supplied by the server upon connect. If no banner is + supplied, this method returns C{None}. @return: server supplied banner, or C{None}. @rtype: string From 725b96c0aeec8169935f8e49472f872160822199 Mon Sep 17 00:00:00 2001 From: Jeff Forcier Date: Tue, 11 Feb 2014 15:02:58 -0800 Subject: [PATCH 4/5] Not a fan of pointless getters. --- paramiko/auth_handler.py | 3 --- paramiko/transport.py | 2 +- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/paramiko/auth_handler.py b/paramiko/auth_handler.py index da551af..57f25fa 100644 --- a/paramiko/auth_handler.py +++ b/paramiko/auth_handler.py @@ -63,9 +63,6 @@ class AuthHandler (object): else: return self.username - def get_banner(self): - return self.banner - def auth_none(self, username, event): self.transport.lock.acquire() try: diff --git a/paramiko/transport.py b/paramiko/transport.py index 127635e..cc81ed7 100644 --- a/paramiko/transport.py +++ b/paramiko/transport.py @@ -1102,7 +1102,7 @@ class Transport (threading.Thread): """ if not self.active or (self.auth_handler is None): return None - return self.auth_handler.get_banner() + return self.auth_handler.banner def auth_none(self, username): """ From c73616b5b34e10fa40dede6b93f98c212869b056 Mon Sep 17 00:00:00 2001 From: Jeff Forcier Date: Tue, 11 Feb 2014 15:10:39 -0800 Subject: [PATCH 5/5] Changelog re #58 --- sites/www/changelog.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sites/www/changelog.rst b/sites/www/changelog.rst index af4c69e..7247eb7 100644 --- a/sites/www/changelog.rst +++ b/sites/www/changelog.rst @@ -2,6 +2,8 @@ Changelog ========= +* :feature:`58` Allow client code to access the stored SSH server banner via + ``Transport.get_banner()``. Thanks to ``@Jhoanor`` for the patch. * :bug:`34` (PR :issue:`35`) Fix SFTP prefetching incompatibility with some SFTP servers regarding request/response ordering. Thanks to Richard Kettlewell for catch & patch.