~ubuntu-branches/debian/experimental/bzr/experimental

« back to all changes in this revision

Viewing changes to bzrlib/transport/ssh.py

  • Committer: Bazaar Package Importer
  • Author(s): Jelmer Vernooij, James Westby, Jelmer Vernooij
  • Date: 2009-09-08 14:14:23 UTC
  • mfrom: (1.1.59 upstream)
  • Revision ID: james.westby@ubuntu.com-20090908141423-ilpel5hy4vxhzxrl
Tags: 1.18-1
[ James Westby ]
* New upstream release.

[ Jelmer Vernooij ]
* Bump standards version to 3.8.3.
* Remove unused patch system.

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
 
20
20
import errno
21
21
import getpass
 
22
import logging
22
23
import os
23
24
import socket
24
25
import subprocess
481
482
    if _try_pkey_auth(paramiko_transport, paramiko.DSSKey, username, 'id_dsa'):
482
483
        return
483
484
 
 
485
    # If we have gotten this far, we are about to try for passwords, do an
 
486
    # auth_none check to see if it is even supported.
 
487
    supported_auth_types = []
 
488
    try:
 
489
        # Note that with paramiko <1.7.5 this logs an INFO message:
 
490
        #    Authentication type (none) not permitted.
 
491
        # So we explicitly disable the logging level for this action
 
492
        old_level = paramiko_transport.logger.level
 
493
        paramiko_transport.logger.setLevel(logging.WARNING)
 
494
        try:
 
495
            paramiko_transport.auth_none(username)
 
496
        finally:
 
497
            paramiko_transport.logger.setLevel(old_level)
 
498
    except paramiko.BadAuthenticationType, e:
 
499
        # Supported methods are in the exception
 
500
        supported_auth_types = e.allowed_types
 
501
    except paramiko.SSHException, e:
 
502
        # Don't know what happened, but just ignore it
 
503
        pass
 
504
    if 'password' not in supported_auth_types:
 
505
        raise errors.ConnectionError('Unable to authenticate to SSH host as'
 
506
            '\n  %s@%s\nsupported auth types: %s'
 
507
            % (username, host, supported_auth_types))
 
508
 
484
509
    if password:
485
510
        try:
486
511
            paramiko_transport.auth_password(username, password)
490
515
 
491
516
    # give up and ask for a password
492
517
    password = auth.get_password('ssh', host, username, port=port)
493
 
    try:
494
 
        paramiko_transport.auth_password(username, password)
495
 
    except paramiko.SSHException, e:
496
 
        raise errors.ConnectionError(
497
 
            'Unable to authenticate to SSH host as %s@%s' % (username, host), e)
 
518
    # get_password can still return None, which means we should not prompt
 
519
    if password is not None:
 
520
        try:
 
521
            paramiko_transport.auth_password(username, password)
 
522
        except paramiko.SSHException, e:
 
523
            raise errors.ConnectionError(
 
524
                'Unable to authenticate to SSH host as'
 
525
                '\n  %s@%s\n' % (username, host), e)
 
526
    else:
 
527
        raise errors.ConnectionError('Unable to authenticate to SSH host as'
 
528
                                     '  %s@%s' % (username, host))
498
529
 
499
530
 
500
531
def _try_pkey_auth(paramiko_transport, pkey_class, username, filename):