From c91dd638605c4e4cee9343dce11abdf498e20532 Mon Sep 17 00:00:00 2001 From: stuconnolly Date: Sun, 5 Dec 2010 15:57:15 +0000 Subject: Only access Keychain items when necessary. --- Source/SPConnectionController.m | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) (limited to 'Source') diff --git a/Source/SPConnectionController.m b/Source/SPConnectionController.m index 8c5c4896..4938c09a 100644 --- a/Source/SPConnectionController.m +++ b/Source/SPConnectionController.m @@ -892,14 +892,6 @@ static const NSString *SPExportFavoritesFilename = @"SequelProFavorites.plist"; NSInteger duplicatedFavoriteType = [[favorite objectForKey:SPFavoriteTypeKey] integerValue]; - // Select the keychain passwords for duplication - 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]; - 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]; - // Update the unique ID [favorite setObject:favoriteID forKey:SPFavoriteIDKey]; @@ -908,16 +900,28 @@ static const NSString *SPExportFavoritesFilename = @"SequelProFavorites.plist"; // 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]; + + 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]; - } - favoritePassword = nil, favoriteSSHPassword = nil; + favoriteSSHPassword = nil; + } SPTreeNode *selectedNode = [self selectedFavoriteNode]; -- cgit v1.2.3