aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrowanbeentje <rowan@beent.je>2012-05-08 22:40:43 +0000
committerrowanbeentje <rowan@beent.je>2012-05-08 22:40:43 +0000
commitf78252011625ce15d860e8c2272dbd5907f1f3f9 (patch)
tree63d2fe741ee13a34a61255f312f00b494356f169
parentd8935e682e9f9430feba225e0490fed9885bc81e (diff)
downloadsequelpro-f78252011625ce15d860e8c2272dbd5907f1f3f9.tar.gz
sequelpro-f78252011625ce15d860e8c2272dbd5907f1f3f9.tar.bz2
sequelpro-f78252011625ce15d860e8c2272dbd5907f1f3f9.zip
- Fix crashes when duplicating favourites
-rw-r--r--Source/SPConnectionController.m34
1 files changed, 18 insertions, 16 deletions
diff --git a/Source/SPConnectionController.m b/Source/SPConnectionController.m
index 82b4e0c7..890dc735 100644
--- a/Source/SPConnectionController.m
+++ b/Source/SPConnectionController.m
@@ -843,26 +843,28 @@ static NSComparisonResult _compareFavoritesUsingKey(id favorite1, id favorite2,
// Create new keychain items if appropriate
if (password && [password length]) {
- NSString *keychainName = [keychain nameForFavoriteName:[favorite objectForKey:SPFavoriteNameKey] id:[favorite objectForKey:SPFavoriteIDKey]];
- NSString *keychainAccount = [keychain accountForUser:[favorite objectForKey:SPFavoriteUserKey] host:((duplicatedFavoriteType == SPSocketConnection) ? @"localhost" : [favorite objectForKey:SPFavoriteHostKey]) database:[favorite objectForKey:SPFavoriteDatabaseKey]];
- NSString *favoritePassword = [keychain getPasswordForName:keychainName account:keychainAccount];
-
- keychainName = [keychain nameForFavoriteName:[favorite objectForKey:SPFavoriteNameKey] id:[favorite objectForKey:SPFavoriteIDKey]];
-
- [keychain addPassword:favoritePassword forName:keychainName account:keychainAccount];
-
+ NSString *oldKeychainName = [keychain nameForFavoriteName:[[self selectedFavorite] objectForKey:SPFavoriteNameKey] id:[[self selectedFavorite] objectForKey:SPFavoriteIDKey]];
+ NSString *newKeychainName = [keychain nameForFavoriteName:[favorite objectForKey:SPFavoriteNameKey] id:[favorite objectForKey:SPFavoriteIDKey]];
+
+ NSString *keychainAccount = [keychain accountForUser:[favorite objectForKey:SPFavoriteUserKey] host:((duplicatedFavoriteType == SPSocketConnection) ? @"localhost" : [favorite objectForKey:SPFavoriteHostKey]) database:[favorite objectForKey:SPFavoriteDatabaseKey]];
+
+ NSString *favoritePassword = [keychain getPasswordForName:oldKeychainName account:keychainAccount];
+
+ [keychain addPassword:favoritePassword forName:newKeychainName account:keychainAccount];
+
favoritePassword = nil;
}
if (sshPassword && [sshPassword length]) {
- NSString *keychainSSHName = [keychain nameForSSHForFavoriteName:[favorite objectForKey:SPFavoriteNameKey] id:[favorite objectForKey:SPFavoriteIDKey]];
- NSString *keychainSSHAccount = [keychain accountForSSHUser:[favorite objectForKey:SPFavoriteSSHUserKey] sshHost:[favorite objectForKey:SPFavoriteSSHHostKey]];
- NSString *favoriteSSHPassword = [keychain getPasswordForName:keychainSSHName account:keychainSSHAccount];
-
- keychainSSHName = [keychain nameForSSHForFavoriteName:[favorite objectForKey:SPFavoriteNameKey] id:[favorite objectForKey:SPFavoriteIDKey]];
-
- [keychain addPassword:favoriteSSHPassword forName:keychainSSHName account:keychainSSHAccount];
-
+ NSString *oldKeychainSSHName = [keychain nameForSSHForFavoriteName:[[self selectedFavorite] objectForKey:SPFavoriteNameKey] id:[[self selectedFavorite] objectForKey:SPFavoriteIDKey]];
+ NSString *newKeychainSSHName = [keychain nameForSSHForFavoriteName:[favorite objectForKey:SPFavoriteNameKey] id:[favorite objectForKey:SPFavoriteIDKey]];
+
+ NSString *keychainSSHAccount = [keychain accountForSSHUser:[favorite objectForKey:SPFavoriteSSHUserKey] sshHost:[favorite objectForKey:SPFavoriteSSHHostKey]];
+
+ NSString *favoriteSSHPassword = [keychain getPasswordForName:oldKeychainSSHName account:keychainSSHAccount];
+
+ [keychain addPassword:favoriteSSHPassword forName:newKeychainSSHName account:keychainSSHAccount];
+
favoriteSSHPassword = nil;
}