~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Vincent Ladeuil
  • Date: 2009-10-06 15:58:12 UTC
  • mfrom: (4725.3.3 443041-ftp-append-bytes)
  • mto: This revision was merged to the branch mainline in revision 4729.
  • Revision ID: v.ladeuil+lp@free.fr-20091006155812-mie06vdxp373lqxd
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():