Changeset 4153 in subversion


Ignore:
Timestamp:
Oct 28, 2010 12:35:49 PM (3 years ago)
Author:
alec
Message:
  • Close properly IMAP connection when login fails
  • Don't use LOGIN when server sent LOGINDISABLED
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/roundcubemail/program/include/rcube_imap_generic.php

    r4152 r4153  
    681681        } 
    682682 
    683             $message = "INITIAL: $auth_method\n"; 
    684  
    685683            $result = false; 
    686684 
     
    738736            if (!preg_match('/^\* (OK|PREAUTH)/i', $line)) { 
    739737                    if ($line) 
    740                             $this->error = sprintf("Wrong startup greeting (%s:%d): %s", $host, $this->prefs['port'], $line); 
     738                            $error = sprintf("Wrong startup greeting (%s:%d): %s", $host, $this->prefs['port'], $line); 
    741739                    else 
    742                             $this->error = sprintf("Empty startup greeting (%s:%d)", $host, $this->prefs['port']); 
    743                 $this->errornum = self::ERROR_BAD; 
     740                            $error = sprintf("Empty startup greeting (%s:%d)", $host, $this->prefs['port']); 
     741 
     742                $this->set_error(self::ERROR_BAD, $error); 
     743            $this->close(); 
    744744                return false; 
    745745            } 
     
    750750            } 
    751751 
    752             $this->message .= $line; 
     752            $this->message = $line; 
    753753 
    754754            // TLS connection 
     
    758758 
    759759                if ($res[0] != self::ERROR_OK) { 
     760                    $this->close(); 
    760761                    return false; 
    761762                } 
     
    763764                            if (!stream_socket_enable_crypto($this->fp, true, STREAM_CRYPTO_METHOD_TLS_CLIENT)) { 
    764765                                    $this->set_error(self::ERROR_BAD, "Unable to negotiate TLS"); 
     766                    $this->close(); 
    765767                                    return false; 
    766768                            } 
     
    791793            } 
    792794        else { 
     795            // Prevent from sending credentials in plain text when connection is not secure 
     796                    if ($auth_method == 'LOGIN' && $this->getCapability('LOGINDISABLED')) { 
     797                            $this->set_error(self::ERROR_BAD, "Login disabled by IMAP server"); 
     798                $this->close(); 
     799                            return false; 
     800            } 
    793801            // replace AUTH with CRAM-MD5 for backward compat. 
    794802            $auth_methods[] = $auth_method == 'AUTH' ? 'CRAM-MD5' : $auth_method; 
     
    830838 
    831839        // Close connection 
    832         @fclose($this->fp); 
    833         $this->fp = false; 
    834  
    835             return false; 
     840        $this->close(); 
     841 
     842        return false; 
    836843    } 
    837844 
     
    843850    function close() 
    844851    { 
    845             if ($this->logged && $this->putLine($this->next_tag() . ' LOGOUT')) { 
    846                     if (!feof($this->fp)) 
    847                             fgets($this->fp, 1024); 
    848             } 
     852            if ($this->putLine($this->next_tag() . ' LOGOUT')) { 
     853            $this->readReply(); 
     854        } 
     855 
    849856                @fclose($this->fp); 
    850857                $this->fp = false; 
Note: See TracChangeset for help on using the changeset viewer.