- Timestamp:
- 11/17/07 21:45:05 (1 year ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
Mulberry/branches/v4.1d1/Sources_Common/Mail/Control/CPasswordManager.cp
r114 r119 120 120 } 121 121 } 122 #endif123 122 124 bool CPasswordManager::GetPassword(const CINETAccount* acct, cdstring& pswd) 123 bool GetPasswordWithItem(const CINETAccount* acct, cdstring& pswd, SecKeychainItemRef* item); 124 bool GetPasswordWithItem(const CINETAccount* acct, cdstring& pswd, SecKeychainItemRef* item) 125 125 { 126 #if __dest_os == __mac_os_x127 126 cdstring server; 128 127 cdstring aname; … … 135 134 void* data = NULL; 136 135 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); 138 137 if (err == noErr) 139 138 { … … 144 143 else 145 144 return false; 145 } 146 #endif 147 148 bool CPasswordManager::GetPassword(const CINETAccount* acct, cdstring& pswd) 149 { 150 #if __dest_os == __mac_os_x 151 return GetPasswordWithItem(acct, pswd, NULL); 146 152 #else 147 153 return false; … … 154 160 // First verify its not already set 155 161 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); 157 167 return; 168 } 158 169 159 170 cdstring server; … … 164 175 GetSecurityDetails(acct, server, aname, port, protocol, authenticationType); 165 176 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) 171 179 { 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); 173 187 } 174 188 175 if (item != NULL)176 ::CFRelease(item);177 189 #else 178 190 #endif