Show
Ignore:
Timestamp:
11/17/07 21:45:05 (1 year ago)
Author:
daboo
Message:

Fixes.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • Mulberry/branches/v4.1d1/Sources_Common/Mail/Control/CPasswordManager.cp

    r114 r119  
    120120        } 
    121121} 
    122 #endif 
    123122 
    124 bool CPasswordManager::GetPassword(const CINETAccount* acct, cdstring& pswd) 
     123bool GetPasswordWithItem(const CINETAccount* acct, cdstring& pswd, SecKeychainItemRef* item); 
     124bool GetPasswordWithItem(const CINETAccount* acct, cdstring& pswd, SecKeychainItemRef* item) 
    125125{ 
    126 #if __dest_os == __mac_os_x 
    127126        cdstring server; 
    128127        cdstring aname; 
     
    135134        void* data = NULL; 
    136135        OSStatus err = ::SecKeychainFindInternetPassword(NULL, server.length(), server.c_str(), 0, NULL, aname.length(), aname.c_str(), 
    137                                                                                                      0, NULL, port, protocol, authenticationType, &dataLen, &data, NULL); 
     136                                                                                                     0, NULL, port, protocol, authenticationType, &dataLen, &data, item); 
    138137        if (err == noErr) 
    139138        { 
     
    144143        else 
    145144                return false; 
     145} 
     146#endif 
     147 
     148bool CPasswordManager::GetPassword(const CINETAccount* acct, cdstring& pswd) 
     149{ 
     150#if __dest_os == __mac_os_x 
     151        return GetPasswordWithItem(acct, pswd, NULL); 
    146152#else 
    147153        return false; 
     
    154160        // First verify its not already set 
    155161        cdstring current_pswd; 
    156         if (GetPassword(acct, current_pswd) && (current_pswd == pswd)) 
     162        SecKeychainItemRef item = NULL; 
     163        if (GetPasswordWithItem(acct, current_pswd, &item) && (current_pswd == pswd)) 
     164        { 
     165                if (item != NULL) 
     166                        ::CFRelease(item); 
    157167                return; 
     168        } 
    158169         
    159170        cdstring server; 
     
    164175        GetSecurityDetails(acct, server, aname, port, protocol, authenticationType); 
    165176 
    166         SecKeychainItemRef item = NULL; 
    167         OSStatus err = ::SecKeychainAddInternetPassword(NULL, server.length(), server.c_str(), 0, NULL, aname.length(), aname.c_str(), 
    168                                                                                                   0, NULL, port, protocol, authenticationType, pswd.length(), pswd.c_str(), &item); 
    169                                                                                                    
    170         if (err == errSecDuplicateItem) 
     177        OSStatus err = noErr; 
     178        if (item == NULL) 
    171179        { 
    172                 err = ::SecKeychainItemModifyAttributesAndData (item, NULL, pswd.length(), pswd.c_str()); 
     180                err = ::SecKeychainAddInternetPassword(NULL, server.length(), server.c_str(), 0, NULL, aname.length(), aname.c_str(), 
     181                                                                                                  0, NULL, port, protocol, authenticationType, pswd.length(), pswd.c_str(), NULL); 
     182        } 
     183        else 
     184        { 
     185                err = ::SecKeychainItemModifyAttributesAndData(item, NULL, pswd.length(), pswd.c_str()); 
     186                ::CFRelease(item); 
    173187        } 
    174188         
    175         if (item != NULL) 
    176                 ::CFRelease(item); 
    177189#else 
    178190#endif