110
113
stdout = stderr = ''
111
114
return stdout + stderr
113
def _get_vendor_by_version_string(self, version, args):
116
def _get_vendor_by_version_string(self, version, progname):
114
117
"""Return the vendor or None based on output from the subprocess.
116
119
:param version: The output of 'ssh -V' like command.
123
126
elif 'SSH Secure Shell' in version:
124
127
trace.mutter('ssh implementation is SSH Corp.')
125
128
vendor = SSHCorpSubprocessVendor()
126
# Auto-detect of plink vendor disabled, on Windows recommended
127
# default ssh-client is paramiko
128
# see https://bugs.launchpad.net/bugs/414743
129
#~elif 'plink' in version and args[0] == 'plink':
130
#~ # Checking if "plink" was the executed argument as Windows
131
#~ # sometimes reports 'ssh -V' incorrectly with 'plink' in it's
132
#~ # version. See https://bugs.launchpad.net/bzr/+bug/107155
133
#~ trace.mutter("ssh implementation is Putty's plink.")
134
#~ vendor = PLinkSubprocessVendor()
129
# As plink user prompts are not handled currently, don't auto-detect
130
# it by inspection below, but keep this vendor detection for if a path
131
# is given in BZR_SSH. See https://bugs.launchpad.net/bugs/414743
132
elif 'plink' in version and progname == 'plink':
133
# Checking if "plink" was the executed argument as Windows
134
# sometimes reports 'ssh -V' incorrectly with 'plink' in it's
135
# version. See https://bugs.launchpad.net/bzr/+bug/107155
136
trace.mutter("ssh implementation is Putty's plink.")
137
vendor = PLinkSubprocessVendor()
137
140
def _get_vendor_by_inspection(self):
138
141
"""Return the vendor or None by checking for known SSH implementations."""
139
for args in (['ssh', '-V'], ['plink', '-V']):
140
version = self._get_ssh_version_string(args)
141
vendor = self._get_vendor_by_version_string(version, args)
142
if vendor is not None:
142
version = self._get_ssh_version_string(['ssh', '-V'])
143
return self._get_vendor_by_version_string(version, "ssh")
145
def _get_vendor_from_path(self, path):
146
"""Return the vendor or None using the program at the given path"""
147
version = self._get_ssh_version_string([path, '-V'])
148
return self._get_vendor_by_version_string(version,
149
os.path.splitext(os.path.basename(path))[0])
146
151
def get_vendor(self, environment=None):
147
152
"""Find out what version of SSH is on the system.
404
409
class OpenSSHSubprocessVendor(SubprocessVendor):
405
410
"""SSH vendor that uses the 'ssh' executable from OpenSSH."""
412
executable_path = 'ssh'
407
414
def _get_vendor_specific_argv(self, username, host, port, subsystem=None,
416
args = [self.executable_path,
410
417
'-oForwardX11=no', '-oForwardAgent=no',
411
418
'-oClearAllForwardings=yes', '-oProtocol=2',
412
419
'-oNoHostAuthenticationForLocalhost=yes']
426
433
class SSHCorpSubprocessVendor(SubprocessVendor):
427
434
"""SSH vendor that uses the 'ssh' executable from SSH Corporation."""
436
executable_path = 'ssh'
429
438
def _get_vendor_specific_argv(self, username, host, port, subsystem=None,
440
args = [self.executable_path, '-x']
432
441
if port is not None:
433
442
args.extend(['-p', str(port)])
434
443
if username is not None:
439
448
args.extend([host] + command)
442
register_ssh_vendor('ssh', SSHCorpSubprocessVendor())
451
register_ssh_vendor('sshcorp', SSHCorpSubprocessVendor())
445
454
class PLinkSubprocessVendor(SubprocessVendor):
446
455
"""SSH vendor that uses the 'plink' executable from Putty."""
457
executable_path = 'plink'
448
459
def _get_vendor_specific_argv(self, username, host, port, subsystem=None,
450
args = ['plink', '-x', '-a', '-ssh', '-2', '-batch']
461
args = [self.executable_path, '-x', '-a', '-ssh', '-2', '-batch']
451
462
if port is not None:
452
463
args.extend(['-P', str(port)])
453
464
if username is not None:
627
638
'close_fds': True,
642
_subproc_weakrefs = set()
644
def _close_ssh_proc(proc):
645
for func in [proc.stdin.close, proc.stdout.close, proc.wait]:
631
652
class SSHSubprocess(object):
632
653
"""A socket-like object that talks to an ssh subprocess via pipes."""
634
655
def __init__(self, proc):
657
# Add a weakref to proc that will attempt to do the same as self.close
658
# to avoid leaving processes lingering indefinitely.
660
_subproc_weakrefs.remove(ref)
661
_close_ssh_proc(proc)
662
_subproc_weakrefs.add(weakref.ref(self, terminate))
637
664
def send(self, data):
638
665
return os.write(self.proc.stdin.fileno(), data)