/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/transport/ssh.py

  • Committer: Jelmer Vernooij
  • Date: 2019-03-04 00:16:27 UTC
  • mfrom: (7293 work)
  • mto: This revision was merged to the branch mainline in revision 7318.
  • Revision ID: jelmer@jelmer.uk-20190304001627-v6u7o6pf97tukhek
Merge trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
147
147
    def _get_vendor_from_path(self, path):
148
148
        """Return the vendor or None using the program at the given path"""
149
149
        version = self._get_ssh_version_string([path, '-V'])
150
 
        return self._get_vendor_by_version_string(version, 
151
 
            os.path.splitext(os.path.basename(path))[0])
 
150
        return self._get_vendor_by_version_string(version,
 
151
                                                  os.path.splitext(os.path.basename(path))[0])
152
152
 
153
153
    def get_vendor(self, environment=None):
154
154
        """Find out what version of SSH is on the system.
169
169
            self._cached_ssh_vendor = vendor
170
170
        return self._cached_ssh_vendor
171
171
 
 
172
 
172
173
_ssh_vendor_manager = SSHVendorManager()
173
174
_get_ssh_vendor = _ssh_vendor_manager.get_vendor
174
175
register_default_ssh_vendor = _ssh_vendor_manager.register_default_vendor
267
268
            self._raise_connection_error(host, port=port, orig_error=e)
268
269
        return SFTPClient(SocketAsChannelAdapter(sock))
269
270
 
 
271
 
270
272
register_ssh_vendor('loopback', LoopbackVendor())
271
273
 
272
274
 
301
303
            trace.warning('Adding %s host key for %s: %s'
302
304
                          % (keytype, host, server_key_hex))
303
305
            add = getattr(BRZ_HOSTKEYS, 'add', None)
304
 
            if add is not None: # paramiko >= 1.X.X
 
306
            if add is not None:  # paramiko >= 1.X.X
305
307
                BRZ_HOSTKEYS.add(host, keytype, server_key)
306
308
            else:
307
309
                BRZ_HOSTKEYS.setdefault(host, {})[keytype] = server_key
338
340
            self._raise_connection_error(host, port=port, orig_error=e,
339
341
                                         msg='Unable to invoke remote bzr')
340
342
 
 
343
 
341
344
_ssh_connection_errors = (EOFError, OSError, IOError, socket.error)
342
345
if paramiko is not None:
343
346
    vendor = ParamikoVendor()
431
434
            args.extend(['--', host] + command)
432
435
        return args
433
436
 
 
437
 
434
438
register_ssh_vendor('openssh', OpenSSHSubprocessVendor())
435
439
 
436
440
 
453
457
            args.extend([host] + command)
454
458
        return args
455
459
 
 
460
 
456
461
register_ssh_vendor('sshcorp', SSHCorpSubprocessVendor())
457
462
 
458
463
 
475
480
            args.extend([host] + command)
476
481
        return args
477
482
 
 
483
 
478
484
register_ssh_vendor('lsh', LSHSubprocessVendor())
479
485
 
480
486
 
497
503
            args.extend([host] + command)
498
504
        return args
499
505
 
 
506
 
500
507
register_ssh_vendor('plink', PLinkSubprocessVendor())
501
508
 
502
509
 
551
558
    # requires something other than a single password, but we currently don't
552
559
    # support that.
553
560
    if ('password' not in supported_auth_types and
554
 
        'keyboard-interactive' not in supported_auth_types):
 
561
            'keyboard-interactive' not in supported_auth_types):
555
562
        raise errors.ConnectionError('Unable to authenticate to SSH host as'
556
 
            '\n  %s@%s\nsupported auth types: %s'
557
 
            % (username, host, supported_auth_types))
 
563
                                     '\n  %s@%s\nsupported auth types: %s'
 
564
                                     % (username, host, supported_auth_types))
558
565
 
559
566
    if password:
560
567
        try:
635
642
            f.write('# SSH host keys collected by bzr\n')
636
643
            for hostname, keys in BRZ_HOSTKEYS.items():
637
644
                for keytype, key in keys.items():
638
 
                    f.write('%s %s %s\n' % (hostname, keytype, key.get_base64()))
 
645
                    f.write('%s %s %s\n' %
 
646
                            (hostname, keytype, key.get_base64()))
639
647
    except IOError as e:
640
648
        trace.mutter('failed to save bzr host keys: ' + str(e))
641
649
 
665
673
                'close_fds': True,
666
674
                }
667
675
 
 
676
 
668
677
import weakref
669
678
_subproc_weakrefs = set()
670
679
 
 
680
 
671
681
def _close_ssh_proc(proc, sock):
672
682
    """Carefully close stdin/stdout and reap the SSH process.
673
683
 
728
738
        self._sock = sock
729
739
        # Add a weakref to proc that will attempt to do the same as self.close
730
740
        # to avoid leaving processes lingering indefinitely.
 
741
 
731
742
        def terminate(ref):
732
743
            _subproc_weakrefs.remove(ref)
733
744
            _close_ssh_proc(proc, sock)
766
777
 
767
778
    def close(self):
768
779
        return self.channel.close()
769
 
 
770