~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/transport/ftp/_gssapi.py

  • Committer: John Arbash Meinel
  • Date: 2009-12-10 17:16:19 UTC
  • mfrom: (4884 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4889.
  • Revision ID: john@arbash-meinel.com-20091210171619-ehdcxjbl8afhq9g1
Bring in bzr.dev 4884

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
    config,
26
26
    errors,
27
27
    )
28
 
from bzrlib.trace import info, mutter
 
28
from bzrlib.trace import mutter
29
29
from bzrlib.transport.ftp import FtpTransport
30
30
from bzrlib.transport import register_transport_proto, register_transport
31
31
 
81
81
                        if not ((resp.startswith('235 ') and rc == 1) or
82
82
                                (resp.startswith('335 ') and rc == 0)):
83
83
                            raise ftplib.error_reply, resp
84
 
            info("Authenticated as %s" % kerberos.authGSSClientUserName(
 
84
            trace.note("Authenticated as %s" % kerberos.authGSSClientUserName(
85
85
                    self.vc))
86
86
 
87
87
            # Monkey patch ftplib
97
97
 
98
98
    """
99
99
 
100
 
    def _create_connection(self, credentials=None):
101
 
        """Create a new connection with the provided credentials.
102
 
 
103
 
        :param credentials: The credentials needed to establish the connection.
104
 
 
105
 
        :return: The created connection and its associated credentials.
106
 
 
107
 
        The credentials are a tuple with the username and password. The
108
 
        password is used if GSSAPI Authentication is not available.
 
100
    connection_class = GSSAPIFtp
 
101
 
 
102
    def _login(self, connection, auth, user, password):
 
103
        """Login with GSSAPI Authentication.
 
104
 
 
105
        The password is used if GSSAPI Authentication is not available.
109
106
 
110
107
        The username and password can both be None, in which case the
111
108
        credentials specified in the URL or provided by the
112
109
        AuthenticationConfig() are used.
113
110
        """
114
 
        if credentials is None:
115
 
            user, password = self._user, self._password
116
 
        else:
117
 
            user, password = credentials
118
 
 
119
 
        auth = config.AuthenticationConfig()
120
 
        if user is None:
121
 
            user = auth.get_user('ftp', self._host, port=self._port,
122
 
                                 default=getpass.getuser())
123
 
        mutter("Constructing FTP instance against %r" %
124
 
               ((self._host, self._port, user, '********',
125
 
                self.is_active),))
126
111
        try:
127
 
            connection = GSSAPIFtp()
128
 
            connection.connect(host=self._host, port=self._port)
129
 
            try:
130
 
                connection.gssapi_login(user=user)
131
 
            except ftplib.error_perm, e:
132
 
                if user and user != 'anonymous' and \
133
 
                        password is None: # '' is a valid password
134
 
                    password = auth.get_password('ftp', self._host, user,
135
 
                                                 port=self._port)
136
 
                connection.login(user=user, passwd=password)
137
 
            connection.set_pasv(not self.is_active)
138
 
        except socket.error, e:
139
 
            raise errors.SocketConnectionError(self._host, self._port,
140
 
                                               msg='Unable to connect to',
141
 
                                               orig_error= e)
 
112
            connection.gssapi_login(user=user)
142
113
        except ftplib.error_perm, e:
143
 
            raise errors.TransportError(msg="Error setting up connection:"
144
 
                                        " %s" % str(e), orig_error=e)
145
 
        return connection, (user, password)
 
114
            super(GSSAPIFtpTransport, self)._login(connection, auth,
 
115
                                                   user, password)
146
116
 
147
117
 
148
118
def get_test_permutations():