Skip to content

Commit ca864a1

Browse files
committed
Remove the keychain id stuff from SPDatabaseDocument. It was only proxying SPConnectionController anyway
1 parent 770c189 commit ca864a1

File tree

4 files changed

+27
-35
lines changed

4 files changed

+27
-35
lines changed

Source/SPConnectionController.h

+2
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@
208208
@property (readwrite, assign) NSInteger sshKeyLocationEnabled;
209209
@property (readwrite, retain) NSString *sshKeyLocation;
210210
@property (readwrite, retain) NSString *sshPort;
211+
@property (readwrite, copy, nonatomic) NSString *connectionKeychainID;
211212
@property (readwrite, retain) NSString *connectionKeychainItemName;
212213
@property (readwrite, retain) NSString *connectionKeychainItemAccount;
213214
@property (readwrite, retain) NSString *connectionSSHKeychainItemName;
@@ -222,6 +223,7 @@
222223
@property (readonly, assign) BOOL isEditingConnection;
223224

224225
- (NSString *)keychainPassword;
226+
- (NSString *)keychainPasswordForSSH;
225227

226228
// Connection processes
227229
- (IBAction)initiateConnection:(id)sender;

Source/SPConnectionController.m

+14-6
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ @implementation SPConnectionController
168168
@synthesize dbDocument;
169169
#endif
170170

171+
@synthesize connectionKeychainID = connectionKeychainID;
171172
@synthesize connectionKeychainItemName;
172173
@synthesize connectionKeychainItemAccount;
173174
@synthesize connectionSSHKeychainItemName;
@@ -188,6 +189,16 @@ - (NSString *)keychainPassword
188189
return kcPassword;
189190
}
190191

192+
- (NSString *)keychainPasswordForSSH
193+
{
194+
if (![self connectionKeychainItemName]) return nil;
195+
196+
// Otherwise, pull the password from the keychain using the details from this connection
197+
NSString *kcSSHPassword = [keychain getPasswordForName:connectionSSHKeychainItemName account:connectionSSHKeychainItemAccount];
198+
199+
return kcSSHPassword;
200+
}
201+
191202
#pragma mark -
192203
#pragma mark Connection processes
193204

@@ -749,7 +760,7 @@ - (void)updateFavoriteSelection:(id)sender
749760
#ifndef SP_CODA
750761

751762
// Clear the keychain referral items as appropriate
752-
if (connectionKeychainID) SPClear(connectionKeychainID);
763+
[self setConnectionKeychainID:nil];
753764
if (connectionKeychainItemName) SPClear(connectionKeychainItemName);
754765
if (connectionKeychainItemAccount) SPClear(connectionKeychainItemAccount);
755766
if (connectionSSHKeychainItemName) SPClear(connectionSSHKeychainItemName);
@@ -816,7 +827,7 @@ - (void)updateFavoriteSelection:(id)sender
816827
}
817828

818829
// Store the selected favorite ID for use with the document on connection
819-
if ([fav objectForKey:SPFavoriteIDKey]) connectionKeychainID = [[[fav objectForKey:SPFavoriteIDKey] stringValue] retain];
830+
if ([fav objectForKey:SPFavoriteIDKey]) [self setConnectionKeychainID:[[fav objectForKey:SPFavoriteIDKey] stringValue]];
820831

821832
// And the same for the SSH password
822833
connectionSSHKeychainItemName = [[keychain nameForSSHForFavoriteName:[fav objectForKey:SPFavoriteNameKey] id:[fav objectForKey:SPFavoriteIDKey]] retain];
@@ -2384,8 +2395,6 @@ - (void)addConnectionToDocument
23842395
for (NSUInteger i = 0; i < [toolbarItems count]; i++) [[toolbarItems objectAtIndex:i] setEnabled:YES];
23852396
#endif
23862397

2387-
if (connectionKeychainID) [dbDocument setKeychainID:connectionKeychainID];
2388-
23892398
// Pass the connection to the table document, allowing it to set
23902399
// up the other classes and the rest of the interface.
23912400
[dbDocument setConnection:mySQLConnection];
@@ -3179,7 +3188,6 @@ - (id)initWithDocument:(SPDatabaseDocument *)document
31793188
#endif
31803189

31813190
// Keychain references
3182-
connectionKeychainID = nil;
31833191
connectionKeychainItemName = nil;
31843192
connectionKeychainItemAccount = nil;
31853193
connectionSSHKeychainItemName = nil;
@@ -3633,7 +3641,7 @@ - (void)dealloc
36333641

36343642
SPClear(nibObjectsToRelease);
36353643

3636-
if (connectionKeychainID) SPClear(connectionKeychainID);
3644+
[self setConnectionKeychainID:nil];
36373645
if (connectionKeychainItemName) SPClear(connectionKeychainItemName);
36383646
if (connectionKeychainItemAccount) SPClear(connectionKeychainItemAccount);
36393647
if (connectionSSHKeychainItemName) SPClear(connectionSSHKeychainItemName);

Source/SPDatabaseDocument.h

-3
Original file line numberDiff line numberDiff line change
@@ -262,8 +262,6 @@
262262
NSMutableArray *runningActivitiesArray;
263263
#endif
264264

265-
NSString *keychainID;
266-
267265
#ifndef SP_CODA /* ivars */
268266
NSThread *printThread;
269267

@@ -342,7 +340,6 @@
342340
#endif
343341
- (void)setConnection:(SPMySQLConnection *)theConnection;
344342
- (SPMySQLConnection *)getConnection;
345-
@property(readwrite, copy, nonatomic) NSString *keychainID;
346343

347344
// Database methods
348345
- (IBAction)setDatabases:(id)sender;

Source/SPDatabaseDocument.m

+11-26
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,6 @@ @implementation SPDatabaseDocument
135135
@synthesize processID;
136136
@synthesize instanceId;
137137
@synthesize dbTablesTableView = dbTablesTableView;
138-
@synthesize keychainID = keychainID;
139138

140139
#pragma mark -
141140

@@ -4659,7 +4658,8 @@ - (NSDictionary *) stateIncludingDetails:(NSDictionary *)detailsToReturn
46594658
}
46604659
[connection setObject:connectionType forKey:@"type"];
46614660

4662-
if ([[self keychainID] length]) [connection setObject:[self keychainID] forKey:@"kcid"];
4661+
NSString *kcid = [connectionController connectionKeychainID];
4662+
if ([kcid length]) [connection setObject:kcid forKey:@"kcid"];
46634663
[connection setObject:[self name] forKey:@"name"];
46644664
[connection setObject:[self host] forKey:@"host"];
46654665
[connection setObject:[self user] forKey:@"user"];
@@ -4860,9 +4860,10 @@ - (BOOL)setState:(NSDictionary *)stateDetails fromFile:(BOOL)spfBased
48604860
[connectionController setSslCACertFileLocation:[connection objectForKey:@"sslCACertFileLocation"]];
48614861

48624862
// Set the keychain details if available
4863-
if ([connection objectForKey:@"kcid"] && [(NSString *)[connection objectForKey:@"kcid"] length]) {
4864-
[self setKeychainID:[connection objectForKey:@"kcid"]];
4865-
[connectionController setConnectionKeychainItemName:[keychain nameForFavoriteName:[connectionController name] id:[self keychainID]]];
4863+
NSString *kcid = (NSString *)[connection objectForKey:@"kcid"];
4864+
if ([kcid length]) {
4865+
[connectionController setConnectionKeychainID:kcid];
4866+
[connectionController setConnectionKeychainItemName:[keychain nameForFavoriteName:[connectionController name] id:kcid]];
48664867
[connectionController setConnectionKeychainItemAccount:[keychain accountForUser:[connectionController user] host:[connectionController host] database:[connection objectForKey:@"database"]]];
48674868
}
48684869

@@ -4894,8 +4895,8 @@ - (BOOL)setState:(NSDictionary *)stateDetails fromFile:(BOOL)spfBased
48944895
if ([connection objectForKey:@"ssh_password"])
48954896
[connectionController setSshPassword:[connection objectForKey:@"ssh_password"]];
48964897
else {
4897-
if ([connection objectForKey:@"kcid"] && [(NSString *)[connection objectForKey:@"kcid"] length]) {
4898-
[connectionController setConnectionSSHKeychainItemName:[keychain nameForSSHForFavoriteName:[connectionController name] id:[self keychainID]]];
4898+
if ([kcid length]) {
4899+
[connectionController setConnectionSSHKeychainItemName:[keychain nameForSSHForFavoriteName:[connectionController name] id:kcid]];
48994900
[connectionController setConnectionSSHKeychainItemAccount:[keychain accountForSSHUser:[connectionController sshUser] sshHost:[connectionController sshHost]]];
49004901
}
49014902
NSString *sshpw = [self keychainPasswordForSSHConnection:nil];
@@ -7148,25 +7149,10 @@ - (NSString *)keychainPasswordForConnection:(SPMySQLConnection *)connection auth
71487149
- (NSString *)keychainPasswordForSSHConnection:(SPMySQLConnection *)connection
71497150
{
71507151
// If no keychain item is available, return an empty password
7151-
if (![connectionController connectionKeychainItemName]) return @"";
7152+
NSString *password = [connectionController keychainPasswordForSSH];
7153+
if (!password) return @"";
71527154

7153-
// Otherwise, pull the password from the keychain using the details from this connection
7154-
SPKeychain *keychain = [[SPKeychain alloc] init];
7155-
7156-
NSString *connectionSSHKeychainItemName = [[keychain nameForSSHForFavoriteName:[connectionController name] id:[self keychainID]] retain];
7157-
NSString *connectionSSHKeychainItemAccount = [[keychain accountForSSHUser:[connectionController sshUser] sshHost:[connectionController sshHost]] retain];
7158-
NSString *sshPassword = [keychain getPasswordForName:connectionSSHKeychainItemName account:connectionSSHKeychainItemAccount];
7159-
7160-
if (!sshPassword || ![sshPassword length]) {
7161-
sshPassword = @"";
7162-
}
7163-
7164-
if (connectionSSHKeychainItemName) [connectionSSHKeychainItemName release];
7165-
if (connectionSSHKeychainItemAccount) [connectionSSHKeychainItemAccount release];
7166-
7167-
[keychain release];
7168-
7169-
return sshPassword;
7155+
return password;
71707156
}
71717157

71727158
/**
@@ -7729,7 +7715,6 @@ - (void)dealloc
77297715
if (spfPreferences) SPClear(spfPreferences);
77307716
if (spfSession) SPClear(spfSession);
77317717
if (spfDocData) SPClear(spfDocData);
7732-
[self setKeychainID:nil];
77337718
if (mainToolbar) SPClear(mainToolbar);
77347719
if (titleAccessoryView) SPClear(titleAccessoryView);
77357720
if (taskProgressWindow) SPClear(taskProgressWindow);

0 commit comments

Comments
 (0)