aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Source/SPConnectionDelegate.m24
-rw-r--r--Source/SPDatabaseDocument.m48
2 files changed, 42 insertions, 30 deletions
diff --git a/Source/SPConnectionDelegate.m b/Source/SPConnectionDelegate.m
index 9d49d298..5231c996 100644
--- a/Source/SPConnectionDelegate.m
+++ b/Source/SPConnectionDelegate.m
@@ -98,6 +98,30 @@
}
/**
+ * Invoked when the current connection needs a ssh password from the Keychain.
+ */
+- (NSString *)keychainPasswordForSSHConnection:(MCPConnection *)connection
+{
+
+ // If no keychain item is available, return an empty password
+ if (![connectionController connectionKeychainItemName]) return @"";
+
+ // Otherwise, pull the password from the keychain using the details from this connection
+ SPKeychain *keychain = [[SPKeychain alloc] init];
+ NSString *connectionSSHKeychainItemName = [[keychain nameForSSHForFavoriteName:[connectionController name] id:[self keyChainID]] retain];
+ NSString *connectionSSHKeychainItemAccount = [[keychain accountForSSHUser:[connectionController sshUser] sshHost:[connectionController sshHost]] retain];
+ NSString *sshpw = [keychain getPasswordForName:connectionSSHKeychainItemName account:connectionSSHKeychainItemAccount];
+ if (!sshpw || ![sshpw length])
+ sshpw = @"";
+
+ if(connectionSSHKeychainItemName) [connectionSSHKeychainItemName release];
+ if(connectionSSHKeychainItemAccount) [connectionSSHKeychainItemAccount release];
+ [keychain release];
+
+ return sshpw;
+}
+
+/**
* Invoked when an attempt was made to execute a query on the current connection, but the connection is not
* actually active.
*/
diff --git a/Source/SPDatabaseDocument.m b/Source/SPDatabaseDocument.m
index 781df933..32bf62d0 100644
--- a/Source/SPDatabaseDocument.m
+++ b/Source/SPDatabaseDocument.m
@@ -466,7 +466,7 @@
[connectionController setPassword:[connection objectForKey:@"password"]];
else {
NSString *pw = [self keychainPasswordForConnection:nil];
- if([pw length])
+ if(pw)
[connectionController setPassword:pw];
}
@@ -485,15 +485,9 @@
if([connection objectForKey:@"ssh_password"])
[connectionController setSshPassword:[connection objectForKey:@"ssh_password"]];
else {
- SPKeychain *keychain = [[SPKeychain alloc] init];
- NSString *connectionSSHKeychainItemName = [[keychain nameForSSHForFavoriteName:[connectionController name] id:[self keyChainID]] retain];
- NSString *connectionSSHKeychainItemAccount = [[keychain accountForSSHUser:[connectionController sshUser] sshHost:[connectionController sshHost]] retain];
- NSString *pw = [keychain getPasswordForName:connectionSSHKeychainItemName account:connectionSSHKeychainItemAccount];
- if ([pw length])
- [connectionController setSshPassword:pw];
- if(connectionSSHKeychainItemName) [connectionSSHKeychainItemName release];
- if(connectionSSHKeychainItemAccount) [connectionSSHKeychainItemAccount release];
- [keychain release];
+ NSString *sshpw = [self keychainPasswordForSSHConnection:nil];
+ if(sshpw)
+ [connectionController setSshPassword:sshpw];
}
}
@@ -549,17 +543,6 @@
if([spfSession objectForKey:@"isToolbarVisible"])
[mainToolbar setVisible:[[spfSession objectForKey:@"isToolbarVisible"] boolValue]];
- // TODO up to now it doesn't work
- if([spfSession objectForKey:@"contentSelectedIndexSet"]) {
- NSMutableIndexSet *anIndexSet = [NSMutableIndexSet indexSet];
- NSArray *items = [spfSession objectForKey:@"contentSelectedIndexSet"];
- NSUInteger i;
- for(i=0; i<[items count]; i++)
- [anIndexSet addIndex:(NSUInteger)NSArrayObjectAtIndex(items, i)];
-
- [tableContentInstance setSelectedRowIndexesToRestore:anIndexSet];
- }
-
// Set table content details for restore
if([spfSession objectForKey:@"contentSortCol"])
[tableContentInstance setSortColumnNameToRestore:[spfSession objectForKey:@"contentSortCol"] isAscending:[[spfSession objectForKey:@"contentSortCol"] boolValue]];
@@ -570,7 +553,6 @@
if([spfSession objectForKey:@"contentFilter"])
[tableContentInstance setFiltersToRestore:[spfSession objectForKey:@"contentFilter"]];
-
// Select table
[tablesListInstance selectTableAtIndex:[NSNumber numberWithInteger:[tables indexOfObject:[spfSession objectForKey:@"table"]]]];
@@ -578,6 +560,17 @@
if([spfSession objectForKey:@"connectionEncoding"] && ![[self connectionEncoding] isEqualToString:[spfSession objectForKey:@"connectionEncoding"]])
[self setConnectionEncoding:[spfSession objectForKey:@"connectionEncoding"] reloadingViews:YES];
+ // TODO up to now it doesn't work
+ if([spfSession objectForKey:@"contentSelectedIndexSet"]) {
+ NSMutableIndexSet *anIndexSet = [NSMutableIndexSet indexSet];
+ NSArray *items = [spfSession objectForKey:@"contentSelectedIndexSet"];
+ NSUInteger i;
+ for(i=0; i<[items count]; i++)
+ [anIndexSet addIndex:(NSUInteger)NSArrayObjectAtIndex(items, i)];
+
+ [tableContentInstance setSelectedRowIndexesToRestore:anIndexSet];
+ }
+
// Select view
if([[spfSession objectForKey:@"view"] isEqualToString:@"SP_VIEW_STRUCTURE"])
[self viewStructure:self];
@@ -3264,17 +3257,12 @@
[connection setObject:@"" forKey:@"password"];
if([connectionController type] == SPSSHTunnelConnection) {
- SPKeychain *keychain = [[SPKeychain alloc] init];
- NSString *connectionSSHKeychainItemName = [[keychain nameForSSHForFavoriteName:[connectionController name] id:[self keyChainID]] retain];
- NSString *connectionSSHKeychainItemAccount = [[keychain accountForSSHUser:[connectionController sshUser] sshHost:[connectionController sshHost]] retain];
- NSString *sshpw = [keychain getPasswordForName:connectionSSHKeychainItemName account:connectionSSHKeychainItemAccount];
- if (sshpw && [sshpw length])
+ NSString *sshpw = [self keychainPasswordForSSHConnection:nil];
+ if(![sshpw length]) sshpw = [connectionController sshPassword];
+ if (sshpw)
[connection setObject:sshpw forKey:@"ssh_password"];
else
[connection setObject:@"" forKey:@"ssh_password"];
- if(connectionSSHKeychainItemName) [connectionSSHKeychainItemName release];
- if(connectionSSHKeychainItemAccount) [connectionSSHKeychainItemAccount release];
- [keychain release];
}
}