76
76
_default_do_prefetch = (_paramiko_version >= (1, 5, 5))
81
def register_ssh_vendor(name, vendor_class):
82
"""Register lazy-loaded SSH vendor class."""
83
_ssh_vendors[name] = vendor_class
85
register_ssh_vendor('loopback', ssh.LoopbackVendor)
86
register_ssh_vendor('paramiko', ssh.ParamikoVendor)
87
register_ssh_vendor('none', ssh.ParamikoVendor)
88
register_ssh_vendor('openssh', ssh.OpenSSHSubprocessVendor)
89
register_ssh_vendor('ssh', ssh.SSHCorpSubprocessVendor)
92
def _get_ssh_vendor():
93
"""Find out what version of SSH is on the system."""
95
if _ssh_vendor is not None:
98
if 'BZR_SSH' in os.environ:
99
vendor_name = os.environ['BZR_SSH']
101
klass = _ssh_vendors[vendor_name]
103
raise UnknownSSH(vendor_name)
105
_ssh_vendor = klass()
109
p = subprocess.Popen(['ssh', '-V'],
110
stdin=subprocess.PIPE,
111
stdout=subprocess.PIPE,
112
stderr=subprocess.PIPE,
113
**ssh.os_specific_subprocess_params())
114
returncode = p.returncode
115
stdout, stderr = p.communicate()
119
if 'OpenSSH' in stderr:
120
mutter('ssh implementation is OpenSSH')
121
_ssh_vendor = ssh.OpenSSHSubprocessVendor()
122
elif 'SSH Secure Shell' in stderr:
123
mutter('ssh implementation is SSH Corp.')
124
_ssh_vendor = ssh.SSHCorpSubprocessVendor()
126
if _ssh_vendor is not None:
129
# XXX: 20051123 jamesh
130
# A check for putty's plink or lsh would go here.
132
mutter('falling back to paramiko implementation')
133
_ssh_vendor = ssh.ParamikoVendor()
137
79
def clear_connection_cache():
138
80
"""Remove all hosts from the SFTP connection cache.
910
self._original_vendor = _ssh_vendor
911
_ssh_vendor = self._vendor
851
self._original_vendor = ssh._ssh_vendor
852
ssh._ssh_vendor = self._vendor
912
853
if sys.platform == 'win32':
913
854
# Win32 needs to use the UNICODE api
914
855
self._homedir = getcwd()
956
896
self._vendor = ssh.LoopbackVendor()
958
898
def _run_server(self, sock):
899
# Re-import these as locals, so that they're still accessible during
900
# interpreter shutdown (when all module globals get set to None, leading
901
# to confusing errors like "'NoneType' object has no attribute 'error'".
959
903
class FakeChannel(object):
960
904
def get_transport(self):
1033
977
def _sftp_connect_uncached(host, port, username, password):
1034
vendor = _get_ssh_vendor()
978
vendor = ssh._get_ssh_vendor()
1035
979
sftp = vendor.connect_sftp(username, password, host, port)