~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2009-10-06 17:37:41 UTC
  • mfrom: (4728.1.1 integration)
  • Revision ID: pqm@pqm.ubuntu.com-20091006173741-37lpt4t94xmt9ckt
(vila) Fix gssapi ftp client mode handling

Show diffs side-by-side

added added

removed removed

Lines of Context:
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():