aboutsummaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorrowanbeentje <rowan@beent.je>2012-05-09 22:45:59 +0000
committerrowanbeentje <rowan@beent.je>2012-05-09 22:45:59 +0000
commitcb23c164e9cdd7b235a7c00535fbb0f3de503aaf (patch)
tree79ce64865de05be725c9608243cf9e9585eb7fe0 /Source
parent4f8fa8da31697aceff789ca293dddd834e85e3e0 (diff)
downloadsequelpro-cb23c164e9cdd7b235a7c00535fbb0f3de503aaf.tar.gz
sequelpro-cb23c164e9cdd7b235a7c00535fbb0f3de503aaf.tar.bz2
sequelpro-cb23c164e9cdd7b235a7c00535fbb0f3de503aaf.zip
Reapply changes from r3314, r3447 and r3450 from SPFavoritesPreferencePane to SPConnectionController, fixing tweaks missed by the outline view migration; particularly addresses Lion keychain cacheing issues causing password edits to make it appear that those passwords were lost for the rest of the session.
Diffstat (limited to 'Source')
-rw-r--r--Source/SPConnectionController.m54
1 files changed, 30 insertions, 24 deletions
diff --git a/Source/SPConnectionController.m b/Source/SPConnectionController.m
index 890dc735..c9e07b31 100644
--- a/Source/SPConnectionController.m
+++ b/Source/SPConnectionController.m
@@ -1407,22 +1407,25 @@ static NSComparisonResult _compareFavoritesUsingKey(id favorite1, id favorite2,
oldKeychainName = [keychain nameForFavoriteName:[oldFavorite objectForKey:SPFavoriteNameKey] id:[newFavorite objectForKey:SPFavoriteIDKey]];
oldKeychainAccount = [keychain accountForUser:[oldFavorite objectForKey:SPFavoriteUserKey] host:oldHostnameForPassword database:[oldFavorite objectForKey:SPFavoriteDatabaseKey]];
- // Delete the old keychain item
- [keychain deletePasswordForName:oldKeychainName account:oldKeychainAccount];
-
- // Set up the new keychain name and account strings
- newKeychainName = [keychain nameForFavoriteName:[newFavorite objectForKey:SPFavoriteNameKey] id:[newFavorite objectForKey:SPFavoriteIDKey]];
- newKeychainAccount = [keychain accountForUser:[newFavorite objectForKey:SPFavoriteUserKey] host:newHostnameForPassword database:[newFavorite objectForKey:SPFavoriteDatabaseKey]];
-
- // Add the new keychain item if the password field has a value
- if ([passwordValue length]) {
- [keychain addPassword:passwordValue forName:newKeychainName account:newKeychainAccount];
+ // If there's no new password, remove the old item from the keychain
+ if (![passwordValue length]) {
+ [keychain deletePasswordForName:oldKeychainName account:oldKeychainAccount];
+
+ // Otherwise, set up the new keychain name and account strings and create or edit the item
+ } else {
+ newKeychainName = [keychain nameForFavoriteName:[newFavorite objectForKey:SPFavoriteNameKey] id:[newFavorite objectForKey:SPFavoriteIDKey]];
+ newKeychainAccount = [keychain accountForUser:[newFavorite objectForKey:SPFavoriteUserKey] host:newHostnameForPassword database:[newFavorite objectForKey:SPFavoriteDatabaseKey]];
+ if ([keychain passwordExistsForName:oldKeychainName account:oldKeychainAccount]) {
+ [keychain updateItemWithName:oldKeychainName account:oldKeychainAccount toName:newKeychainName account:newKeychainAccount password:passwordValue];
+ } else {
+ [keychain addPassword:passwordValue forName:newKeychainName account:newKeychainAccount];
+ }
}
// Synch password changes
- [standardPasswordField setStringValue:passwordValue];
- [socketPasswordField setStringValue:passwordValue];
- [sshPasswordField setStringValue:passwordValue];
+ [standardPasswordField setStringValue:passwordValue?passwordValue:@""];
+ [socketPasswordField setStringValue:passwordValue?passwordValue:@""];
+ [sshPasswordField setStringValue:passwordValue?passwordValue:@""];
passwordValue = @"";
}
@@ -1436,17 +1439,20 @@ static NSComparisonResult _compareFavoritesUsingKey(id favorite1, id favorite2,
// Get the old keychain name and account strings
oldKeychainName = [keychain nameForSSHForFavoriteName:[oldFavorite objectForKey:SPFavoriteNameKey] id:[newFavorite objectForKey:SPFavoriteIDKey]];
oldKeychainAccount = [keychain accountForSSHUser:[oldFavorite objectForKey:SPFavoriteSSHUserKey] sshHost:[oldFavorite objectForKey:SPFavoriteSSHHostKey]];
-
- // Delete the old keychain item
- [keychain deletePasswordForName:oldKeychainName account:oldKeychainAccount];
-
- // Set up the new keychain name and account strings
- newKeychainName = [keychain nameForSSHForFavoriteName:[newFavorite objectForKey:SPFavoriteNameKey] id:[newFavorite objectForKey:SPFavoriteIDKey]];
- newKeychainAccount = [keychain accountForSSHUser:[newFavorite objectForKey:SPFavoriteSSHUserKey] sshHost:[newFavorite objectForKey:SPFavoriteSSHHostKey]];
-
- // Add the new keychain item if the password field has a value
- if ([[sshPasswordField stringValue] length]) {
- [keychain addPassword:[sshSSHPasswordField stringValue] forName:newKeychainName account:newKeychainAccount];
+
+ // If there's no new password, delete the keychain item
+ if (![[sshSSHPasswordField stringValue] length]) {
+ [keychain deletePasswordForName:oldKeychainName account:oldKeychainAccount];
+
+ // Otherwise, set up the new keychain name and account strings and create or update the keychain item
+ } else {
+ newKeychainName = [keychain nameForSSHForFavoriteName:[newFavorite objectForKey:SPFavoriteNameKey] id:[newFavorite objectForKey:SPFavoriteIDKey]];
+ newKeychainAccount = [keychain accountForSSHUser:[newFavorite objectForKey:SPFavoriteSSHUserKey] sshHost:[newFavorite objectForKey:SPFavoriteSSHHostKey]];
+ if ([keychain passwordExistsForName:oldKeychainName account:oldKeychainAccount]) {
+ [keychain updateItemWithName:oldKeychainName account:oldKeychainAccount toName:newKeychainName account:newKeychainAccount password:[sshSSHPasswordField stringValue]];
+ } else {
+ [keychain addPassword:[sshSSHPasswordField stringValue] forName:newKeychainName account:newKeychainAccount];
+ }
}
}