/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: 2018-04-02 00:52:27 UTC
  • mfrom: (6939 work)
  • mto: This revision was merged to the branch mainline in revision 7274.
  • Revision ID: jelmer@jelmer.uk-20180402005227-pecflp1mvdjrjqd6
Merge trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
46
46
    from paramiko.sftp_client import SFTPClient
47
47
 
48
48
 
 
49
class StrangeHostname(errors.BzrError):
 
50
    _fmt = "Refusing to connect to strange SSH hostname %(hostname)s"
 
51
 
 
52
 
49
53
SYSTEM_HOSTKEYS = {}
50
54
BRZ_HOSTKEYS = {}
51
55
 
360
364
    # tests, but beware of using PIPE which may hang due to not being read.
361
365
    _stderr_target = None
362
366
 
 
367
    @staticmethod
 
368
    def _check_hostname(arg):
 
369
        if arg.startswith('-'):
 
370
            raise StrangeHostname(hostname=arg)
 
371
 
363
372
    def _connect(self, argv):
364
373
        # Attempt to make a socketpair to use as stdin/stdout for the SSH
365
374
        # subprocess.  We prefer sockets to pipes because they support
424
433
        if username is not None:
425
434
            args.extend(['-l', username])
426
435
        if subsystem is not None:
427
 
            args.extend(['-s', host, subsystem])
 
436
            args.extend(['-s', '--', host, subsystem])
428
437
        else:
429
 
            args.extend([host] + command)
 
438
            args.extend(['--', host] + command)
430
439
        return args
431
440
 
432
441
register_ssh_vendor('openssh', OpenSSHSubprocessVendor())
439
448
 
440
449
    def _get_vendor_specific_argv(self, username, host, port, subsystem=None,
441
450
                                  command=None):
 
451
        self._check_hostname(host)
442
452
        args = [self.executable_path, '-x']
443
453
        if port is not None:
444
454
            args.extend(['-p', str(port)])
460
470
 
461
471
    def _get_vendor_specific_argv(self, username, host, port, subsystem=None,
462
472
                                  command=None):
 
473
        self._check_hostname(host)
463
474
        args = [self.executable_path]
464
475
        if port is not None:
465
476
            args.extend(['-p', str(port)])
481
492
 
482
493
    def _get_vendor_specific_argv(self, username, host, port, subsystem=None,
483
494
                                  command=None):
 
495
        self._check_hostname(host)
484
496
        args = [self.executable_path, '-x', '-a', '-ssh', '-2', '-batch']
485
497
        if port is not None:
486
498
            args.extend(['-P', str(port)])
627
639
    config.ensure_config_dir_exists()
628
640
 
629
641
    try:
630
 
        f = open(bzr_hostkey_path, 'w')
631
 
        f.write('# SSH host keys collected by bzr\n')
632
 
        for hostname, keys in BRZ_HOSTKEYS.items():
633
 
            for keytype, key in keys.items():
634
 
                f.write('%s %s %s\n' % (hostname, keytype, key.get_base64()))
635
 
        f.close()
 
642
        with open(bzr_hostkey_path, 'w') as f:
 
643
            f.write('# SSH host keys collected by bzr\n')
 
644
            for hostname, keys in BRZ_HOSTKEYS.items():
 
645
                for keytype, key in keys.items():
 
646
                    f.write('%s %s %s\n' % (hostname, keytype, key.get_base64()))
636
647
    except IOError as e:
637
648
        trace.mutter('failed to save bzr host keys: ' + str(e))
638
649