From 6b00f5fe46c22b904ecf3f434ac859cb0fd243ca Mon Sep 17 00:00:00 2001 From: Max Date: Sun, 18 Feb 2018 02:42:37 +0100 Subject: Next step in the #2979 experiment --- Source/SPDatabaseDocument.m | 22 ++++++++++++++-------- Source/SPDatabaseStructure.m | 6 ++++-- 2 files changed, 18 insertions(+), 10 deletions(-) (limited to 'Source') diff --git a/Source/SPDatabaseDocument.m b/Source/SPDatabaseDocument.m index 2340b97e..7b1d51de 100644 --- a/Source/SPDatabaseDocument.m +++ b/Source/SPDatabaseDocument.m @@ -119,7 +119,7 @@ static int64_t SPDatabaseDocumentInstanceCounter = 0; - (void) closeAndDisconnect; -- (NSString *)keychainPasswordForConnection:(SPMySQLConnection *)connection; +- (NSString *)keychainPassword; - (NSString *)keychainPasswordForSSHConnection:(SPMySQLConnection *)connection; @end @@ -4686,7 +4686,7 @@ static int64_t SPDatabaseDocumentInstanceCounter = 0; [connection setObject:[self database] forKey:@"database"]; if (includePasswords) { - NSString *pw = [self keychainPasswordForConnection:nil]; + NSString *pw = [self keychainPassword]; if (!pw) pw = [connectionController password]; if (pw) [connection setObject:pw forKey:@"password"]; @@ -4885,9 +4885,8 @@ static int64_t SPDatabaseDocumentInstanceCounter = 0; if ([connection objectForKey:@"password"]) [connectionController setPassword:[connection objectForKey:@"password"]]; else { - NSString *pw = [self keychainPasswordForConnection:nil]; - if (pw) - [connectionController setPassword:pw]; + NSString *pw = [self keychainPassword]; + if (pw) [connectionController setPassword:pw]; } // Set the socket details, whether or not the type is a socket @@ -7150,15 +7149,22 @@ static int64_t SPDatabaseDocumentInstanceCounter = 0; /** * Invoked when the current connection needs a password from the Keychain. */ -- (NSString *)keychainPasswordForConnection:(SPMySQLConnection *)connection +- (NSString *)keychainPasswordForConnection:(SPMySQLConnection *)connection authPlugin:(NSString *)pluginName { + //TODO check plugin name to see whether we want to fetch it from keychain + return [self keychainPassword]; +} + +- (NSString *)keychainPassword +{ + NSString *kcItemName = [connectionController connectionKeychainItemName]; // If no keychain item is available, return an empty password - if (![connectionController connectionKeychainItemName]) return nil; + if (!kcItemName) return nil; // Otherwise, pull the password from the keychain using the details from this connection SPKeychain *keychain = [[SPKeychain alloc] init]; - NSString *password = [keychain getPasswordForName:[connectionController connectionKeychainItemName] account:[connectionController connectionKeychainItemAccount]]; + NSString *password = [keychain getPasswordForName:kcItemName account:[connectionController connectionKeychainItemAccount]]; [keychain release]; diff --git a/Source/SPDatabaseStructure.m b/Source/SPDatabaseStructure.m index 9289b13b..1eb4352a 100644 --- a/Source/SPDatabaseStructure.m +++ b/Source/SPDatabaseStructure.m @@ -258,6 +258,7 @@ goto cleanup_thread_and_pool; } +#if 0 // For future usage - currently unused // If the affected item name and type - for example, table type and table name - were supplied, extract it. NSString *affectedItem = nil; @@ -269,6 +270,7 @@ else affectedItem = nil; } +#endif // Delete all stored data for the database to be updated, leaving the structure key [queriedStructure removeObjectForKey:db_id]; @@ -444,9 +446,9 @@ cleanup_thread_and_pool: /** * Forward keychain password requests to the database object. */ -- (NSString *)keychainPasswordForConnection:(id)connection +- (NSString *)keychainPasswordForConnection:(id)connection authPlugin:(NSString *)pluginName { - return [delegate keychainPasswordForConnection:connection]; + return [delegate keychainPasswordForConnection:connection authPlugin:pluginName]; } #pragma mark - -- cgit v1.2.3