aboutsummaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorMax <post@wickenrode.com>2018-02-28 00:42:52 +0100
committerMax <post@wickenrode.com>2018-02-28 00:48:06 +0100
commit808ae467381bf597c487fb321dbabc3ccb309b67 (patch)
tree7f4f8e235f087f597113af0de8683335ff0efb65 /Source
parentd9f773eae0bf2d158012dfe55139ffdc6b1c57ff (diff)
downloadsequelpro-808ae467381bf597c487fb321dbabc3ccb309b67.tar.gz
sequelpro-808ae467381bf597c487fb321dbabc3ccb309b67.tar.bz2
sequelpro-808ae467381bf597c487fb321dbabc3ccb309b67.zip
Reapply changes from rolled back commit that are common to master and callback-auth branches
This includes 3a944d7867c750c29e02e2619d72694bdbfb0b2a, 770c18901f82696d1233e0139e9bb3c4fbbcb90b, ca864a1f887feaf7ac6d35eeb55b265f3e630a09
Diffstat (limited to 'Source')
-rw-r--r--Source/SPConnectionController.h4
-rw-r--r--Source/SPConnectionController.m37
-rw-r--r--Source/SPDatabaseDocument.h4
-rw-r--r--Source/SPDatabaseDocument.m70
-rw-r--r--Source/SPDatabaseStructure.m2
5 files changed, 51 insertions, 66 deletions
diff --git a/Source/SPConnectionController.h b/Source/SPConnectionController.h
index 2da8f58a..9da0d996 100644
--- a/Source/SPConnectionController.h
+++ b/Source/SPConnectionController.h
@@ -208,6 +208,7 @@
@property (readwrite, assign) NSInteger sshKeyLocationEnabled;
@property (readwrite, retain) NSString *sshKeyLocation;
@property (readwrite, retain) NSString *sshPort;
+@property (readwrite, copy, nonatomic) NSString *connectionKeychainID;
@property (readwrite, retain) NSString *connectionKeychainItemName;
@property (readwrite, retain) NSString *connectionKeychainItemAccount;
@property (readwrite, retain) NSString *connectionSSHKeychainItemName;
@@ -221,6 +222,9 @@
@property (readonly, assign) BOOL isConnecting;
@property (readonly, assign) BOOL isEditingConnection;
+- (NSString *)keychainPassword;
+- (NSString *)keychainPasswordForSSH;
+
// Connection processes
- (IBAction)initiateConnection:(id)sender;
- (IBAction)cancelConnection:(id)sender;
diff --git a/Source/SPConnectionController.m b/Source/SPConnectionController.m
index 018ecf93..921d4312 100644
--- a/Source/SPConnectionController.m
+++ b/Source/SPConnectionController.m
@@ -168,6 +168,7 @@ static NSComparisonResult _compareFavoritesUsingKey(id favorite1, id favorite2,
@synthesize dbDocument;
#endif
+@synthesize connectionKeychainID = connectionKeychainID;
@synthesize connectionKeychainItemName;
@synthesize connectionKeychainItemAccount;
@synthesize connectionSSHKeychainItemName;
@@ -176,6 +177,28 @@ static NSComparisonResult _compareFavoritesUsingKey(id favorite1, id favorite2,
@synthesize isConnecting;
@synthesize isEditingConnection;
+- (NSString *)keychainPassword
+{
+ NSString *kcItemName = [self connectionKeychainItemName];
+ // If no keychain item is available, return an empty password
+ if (!kcItemName) return nil;
+
+ // Otherwise, pull the password from the keychain using the details from this connection
+ NSString *kcPassword = [keychain getPasswordForName:kcItemName account:[self connectionKeychainItemAccount]];
+
+ return kcPassword;
+}
+
+- (NSString *)keychainPasswordForSSH
+{
+ if (![self connectionKeychainItemName]) return nil;
+
+ // Otherwise, pull the password from the keychain using the details from this connection
+ NSString *kcSSHPassword = [keychain getPasswordForName:connectionSSHKeychainItemName account:connectionSSHKeychainItemAccount];
+
+ return kcSSHPassword;
+}
+
#pragma mark -
#pragma mark Connection processes
@@ -737,7 +760,7 @@ static NSComparisonResult _compareFavoritesUsingKey(id favorite1, id favorite2,
#ifndef SP_CODA
// Clear the keychain referral items as appropriate
- if (connectionKeychainID) SPClear(connectionKeychainID);
+ [self setConnectionKeychainID:nil];
if (connectionKeychainItemName) SPClear(connectionKeychainItemName);
if (connectionKeychainItemAccount) SPClear(connectionKeychainItemAccount);
if (connectionSSHKeychainItemName) SPClear(connectionSSHKeychainItemName);
@@ -804,7 +827,7 @@ static NSComparisonResult _compareFavoritesUsingKey(id favorite1, id favorite2,
}
// Store the selected favorite ID for use with the document on connection
- if ([fav objectForKey:SPFavoriteIDKey]) connectionKeychainID = [[[fav objectForKey:SPFavoriteIDKey] stringValue] retain];
+ if ([fav objectForKey:SPFavoriteIDKey]) [self setConnectionKeychainID:[[fav objectForKey:SPFavoriteIDKey] stringValue]];
// And the same for the SSH password
connectionSSHKeychainItemName = [[keychain nameForSSHForFavoriteName:[fav objectForKey:SPFavoriteNameKey] id:[fav objectForKey:SPFavoriteIDKey]] retain];
@@ -2022,7 +2045,10 @@ static NSComparisonResult _compareFavoritesUsingKey(id favorite1, id favorite2,
[connectButton display];
#endif
- [NSThread detachNewThreadWithName:SPCtxt(@"SPConnectionController MySQL connection task", dbDocument) target:self selector:@selector(initiateMySQLConnectionInBackground) object:nil];
+ [NSThread detachNewThreadWithName:SPCtxt(@"SPConnectionController MySQL connection task", dbDocument)
+ target:self
+ selector:@selector(initiateMySQLConnectionInBackground)
+ object:nil];
}
/**
@@ -2372,8 +2398,6 @@ static NSComparisonResult _compareFavoritesUsingKey(id favorite1, id favorite2,
for (NSUInteger i = 0; i < [toolbarItems count]; i++) [[toolbarItems objectAtIndex:i] setEnabled:YES];
#endif
- if (connectionKeychainID) [dbDocument setKeychainID:connectionKeychainID];
-
// Pass the connection to the table document, allowing it to set
// up the other classes and the rest of the interface.
[dbDocument setConnection:mySQLConnection];
@@ -3167,7 +3191,6 @@ static NSComparisonResult _compareFavoritesUsingKey(id favorite1, id favorite2,
#endif
// Keychain references
- connectionKeychainID = nil;
connectionKeychainItemName = nil;
connectionKeychainItemAccount = nil;
connectionSSHKeychainItemName = nil;
@@ -3621,7 +3644,7 @@ static NSComparisonResult _compareFavoritesUsingKey(id favorite1, id favorite2,
SPClear(nibObjectsToRelease);
- if (connectionKeychainID) SPClear(connectionKeychainID);
+ [self setConnectionKeychainID:nil];
if (connectionKeychainItemName) SPClear(connectionKeychainItemName);
if (connectionKeychainItemAccount) SPClear(connectionKeychainItemAccount);
if (connectionSSHKeychainItemName) SPClear(connectionSSHKeychainItemName);
diff --git a/Source/SPDatabaseDocument.h b/Source/SPDatabaseDocument.h
index de7dd55e..c89f7847 100644
--- a/Source/SPDatabaseDocument.h
+++ b/Source/SPDatabaseDocument.h
@@ -262,8 +262,6 @@
NSMutableArray *runningActivitiesArray;
#endif
- NSString *keyChainID;
-
#ifndef SP_CODA /* ivars */
NSThread *printThread;
@@ -342,7 +340,6 @@
#endif
- (void)setConnection:(SPMySQLConnection *)theConnection;
- (SPMySQLConnection *)getConnection;
-- (void)setKeychainID:(NSString *)theID;
// Database methods
- (IBAction)setDatabases:(id)sender;
@@ -451,7 +448,6 @@
- (NSString *)port;
- (NSString *)mySQLVersion;
- (NSString *)user;
-- (NSString *)keyChainID;
- (NSString *)connectionID;
#ifndef SP_CODA /* method decls */
- (NSString *)tabTitleForTooltip;
diff --git a/Source/SPDatabaseDocument.m b/Source/SPDatabaseDocument.m
index 2340b97e..41f4e078 100644
--- a/Source/SPDatabaseDocument.m
+++ b/Source/SPDatabaseDocument.m
@@ -218,8 +218,6 @@ static int64_t SPDatabaseDocumentInstanceCounter = 0;
alterDatabaseCharsetHelper = nil; //init in awakeFromNib
addDatabaseCharsetHelper = nil;
- keyChainID = nil;
-
#ifndef SP_CODA /* init ivars */
statusValues = nil;
printThread = nil;
@@ -613,14 +611,6 @@ static int64_t SPDatabaseDocumentInstanceCounter = 0;
return mySQLConnection;
}
-/**
- * Sets this connection's Keychain ID.
- */
-- (void)setKeychainID:(NSString *)theId
-{
- keyChainID = [[NSString stringWithString:theId] retain];
-}
-
#pragma mark -
#pragma mark Database methods
@@ -2863,11 +2853,6 @@ static int64_t SPDatabaseDocumentInstanceCounter = 0;
return thePort;
}
-- (NSString *)keyChainID
-{
- return keyChainID;
-}
-
- (BOOL)isSaveInBundle
{
return _isSavedInBundle;
@@ -4674,7 +4659,8 @@ static int64_t SPDatabaseDocumentInstanceCounter = 0;
}
[connection setObject:connectionType forKey:@"type"];
- if ([[self keyChainID] length]) [connection setObject:[self keyChainID] forKey:@"kcid"];
+ NSString *kcid = [connectionController connectionKeychainID];
+ if ([kcid length]) [connection setObject:kcid forKey:@"kcid"];
[connection setObject:[self name] forKey:@"name"];
[connection setObject:[self host] forKey:@"host"];
[connection setObject:[self user] forKey:@"user"];
@@ -4686,7 +4672,7 @@ static int64_t SPDatabaseDocumentInstanceCounter = 0;
[connection setObject:[self database] forKey:@"database"];
if (includePasswords) {
- NSString *pw = [self keychainPasswordForConnection:nil];
+ NSString *pw = [connectionController keychainPassword];
if (!pw) pw = [connectionController password];
if (pw) [connection setObject:pw forKey:@"password"];
@@ -4875,9 +4861,10 @@ static int64_t SPDatabaseDocumentInstanceCounter = 0;
[connectionController setSslCACertFileLocation:[connection objectForKey:@"sslCACertFileLocation"]];
// Set the keychain details if available
- if ([connection objectForKey:@"kcid"] && [(NSString *)[connection objectForKey:@"kcid"] length]) {
- [self setKeychainID:[connection objectForKey:@"kcid"]];
- [connectionController setConnectionKeychainItemName:[keychain nameForFavoriteName:[connectionController name] id:[self keyChainID]]];
+ NSString *kcid = (NSString *)[connection objectForKey:@"kcid"];
+ if ([kcid length]) {
+ [connectionController setConnectionKeychainID:kcid];
+ [connectionController setConnectionKeychainItemName:[keychain nameForFavoriteName:[connectionController name] id:kcid]];
[connectionController setConnectionKeychainItemAccount:[keychain accountForUser:[connectionController user] host:[connectionController host] database:[connection objectForKey:@"database"]]];
}
@@ -4885,9 +4872,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 = [connectionController keychainPassword];
+ if (pw) [connectionController setPassword:pw];
}
// Set the socket details, whether or not the type is a socket
@@ -4910,8 +4896,8 @@ static int64_t SPDatabaseDocumentInstanceCounter = 0;
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]]];
+ if ([kcid length]) {
+ [connectionController setConnectionSSHKeychainItemName:[keychain nameForSSHForFavoriteName:[connectionController name] id:kcid]];
[connectionController setConnectionSSHKeychainItemAccount:[keychain accountForSSHUser:[connectionController sshUser] sshHost:[connectionController sshHost]]];
}
NSString *sshpw = [self keychainPasswordForSSHConnection:nil];
@@ -7152,17 +7138,7 @@ static int64_t SPDatabaseDocumentInstanceCounter = 0;
*/
- (NSString *)keychainPasswordForConnection:(SPMySQLConnection *)connection
{
- // If no keychain item is available, return an empty password
- if (![connectionController connectionKeychainItemName]) 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]];
-
- [keychain release];
-
- return password;
+ return [connectionController keychainPassword];
}
/**
@@ -7173,25 +7149,10 @@ static int64_t SPDatabaseDocumentInstanceCounter = 0;
- (NSString *)keychainPasswordForSSHConnection:(SPMySQLConnection *)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 *sshPassword = [keychain getPasswordForName:connectionSSHKeychainItemName account:connectionSSHKeychainItemAccount];
+ NSString *password = [connectionController keychainPasswordForSSH];
+ if (!password) return @"";
- if (!sshPassword || ![sshPassword length]) {
- sshPassword = @"";
- }
-
- if (connectionSSHKeychainItemName) [connectionSSHKeychainItemName release];
- if (connectionSSHKeychainItemAccount) [connectionSSHKeychainItemAccount release];
-
- [keychain release];
-
- return sshPassword;
+ return password;
}
/**
@@ -7754,7 +7715,6 @@ static int64_t SPDatabaseDocumentInstanceCounter = 0;
if (spfPreferences) SPClear(spfPreferences);
if (spfSession) SPClear(spfSession);
if (spfDocData) SPClear(spfDocData);
- if (keyChainID) SPClear(keyChainID);
if (mainToolbar) SPClear(mainToolbar);
if (titleAccessoryView) SPClear(titleAccessoryView);
if (taskProgressWindow) SPClear(taskProgressWindow);
diff --git a/Source/SPDatabaseStructure.m b/Source/SPDatabaseStructure.m
index 9289b13b..c2b0bb59 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];