aboutsummaryrefslogtreecommitdiffstats
path: root/Source/SPDatabaseDocument.m
diff options
context:
space:
mode:
authorrowanbeentje <rowan@beent.je>2011-04-04 23:18:29 +0000
committerrowanbeentje <rowan@beent.je>2011-04-04 23:18:29 +0000
commit15d0b8bac7736e249e121492ea119e43b61d6bca (patch)
treef301f7f6e521ef8d47bca3e6e6af421874cb08c7 /Source/SPDatabaseDocument.m
parent53c84acb6d2bea63d29a88153a8ae2ceffb6fe0a (diff)
downloadsequelpro-15d0b8bac7736e249e121492ea119e43b61d6bca.tar.gz
sequelpro-15d0b8bac7736e249e121492ea119e43b61d6bca.tar.bz2
sequelpro-15d0b8bac7736e249e121492ea119e43b61d6bca.zip
- When restoring connections and sessions, correctly clear and restore keychain names and accounts. This addresses incorrect password use, fixing Issue #1020
Diffstat (limited to 'Source/SPDatabaseDocument.m')
-rw-r--r--Source/SPDatabaseDocument.m19
1 files changed, 18 insertions, 1 deletions
diff --git a/Source/SPDatabaseDocument.m b/Source/SPDatabaseDocument.m
index 751d7654..0d3a4fcd 100644
--- a/Source/SPDatabaseDocument.m
+++ b/Source/SPDatabaseDocument.m
@@ -42,6 +42,7 @@
#import "SPAppController.h"
#import "SPExtendedTableInfo.h"
#import "SPConnectionController.h"
+#import "SPKeychain.h"
#import "SPHistoryController.h"
#import "SPPreferenceController.h"
#import "SPUserManager.h"
@@ -4115,6 +4116,7 @@
{
NSDictionary *connection = nil;
NSInteger connectionType = -1;
+ SPKeychain *keychain = nil;
// If this document already has a connection, don't proceed.
if (mySQLConnection) return NO;
@@ -4123,6 +4125,8 @@
connection = [NSDictionary dictionaryWithDictionary:[stateDetails objectForKey:@"connection"]];
if (!connection) return NO;
+ if ([connection objectForKey:@"kcid"]) keychain = [[SPKeychain alloc] init];
+
[self updateWindowTitle:self];
// Deselect all favorites on the connection controller
@@ -4153,7 +4157,11 @@
[connectionController setSshPort:@""];
[connectionController setDatabase:@""];
[connectionController setPassword:nil];
+ [connectionController setConnectionKeychainItemName:nil];
+ [connectionController setConnectionKeychainItemAccount:nil];
[connectionController setSshPassword:nil];
+ [connectionController setConnectionSSHKeychainItemName:nil];
+ [connectionController setConnectionSSHKeychainItemAccount:nil];
// Set the correct connection type
if ([connection objectForKey:@"type"]) {
@@ -4197,8 +4205,11 @@
[connectionController setSslCACertFileLocation:[connection objectForKey:@"sslCACertFileLocation"]];
// Set the keychain details if available
- if ([connection objectForKey:@"kcid"] && [(NSString *)[connection objectForKey:@"kcid"] length])
+ if ([connection objectForKey:@"kcid"] && [(NSString *)[connection objectForKey:@"kcid"] length]) {
[self setKeychainID:[connection objectForKey:@"kcid"]];
+ [connectionController setConnectionKeychainItemName:[keychain nameForFavoriteName:[connectionController name] id:[self keyChainID]]];
+ [connectionController setConnectionKeychainItemAccount:[keychain accountForUser:[connectionController user] host:[connectionController host] database:[connection objectForKey:@"database"]]];
+ }
// Set password - if not in SPF file try to get it via the KeyChain
if ([connection objectForKey:@"password"])
@@ -4229,6 +4240,10 @@
if ([connection objectForKey:@"ssh_password"])
[connectionController setSshPassword:[connection objectForKey:@"ssh_password"]];
else {
+ if ([connection objectForKey:@"kcid"] && [(NSString *)[connection objectForKey:@"kcid"] length]) {
+ [connectionController setConnectionSSHKeychainItemName:[keychain nameForSSHForFavoriteName:[connectionController name] id:[self keyChainID]]];
+ [connectionController setConnectionSSHKeychainItemAccount:[keychain accountForSSHUser:[connectionController sshUser] sshHost:[connectionController sshHost]]];
+ }
NSString *sshpw = [self keychainPasswordForSSHConnection:nil];
if(sshpw)
[connectionController setSshPassword:sshpw];
@@ -4258,6 +4273,8 @@
[connectionController initiateConnection:self];
}
+ if (keychain) [keychain release];
+
return YES;
}