From 3f2838787602f50176a0ea4e15c0f69cd403920c Mon Sep 17 00:00:00 2001 From: Bibiko Date: Tue, 6 Oct 2009 14:16:39 +0000 Subject: =?UTF-8?q?=E2=80=A2=20changed=20routine=20for=20opening=20SPF=20f?= =?UTF-8?q?iles=20-=20if=20no=20passwords=20are=20stored=20inside=20the=20?= =?UTF-8?q?SPF=20file=20try=20to=20retrieve=20the=20passwords=20from=20the?= =?UTF-8?q?=20KeyChain=20-=20for=20that=20purpose=20store=20the=20key=20'k?= =?UTF-8?q?cid'=20in=20the=20SPF=20file=20if=20available=20-=20changed=20t?= =?UTF-8?q?he=20accessory=20view:=20'auto=5Fconnect'=20is=20always=20enabl?= =?UTF-8?q?ed=20(even=20no=20pw=20will=20be=20saved=20due=20to=20new=20rou?= =?UTF-8?q?tine)=20=E2=80=A2=20fixed=20issue=20for=20Open=20Recent=20of=20?= =?UTF-8?q?SQL=20files=20=E2=80=A2=20add=20a=20saved=20SPF=20file=20to=20O?= =?UTF-8?q?pen=20Recent=20list=20if=20the=20user=20saved=20an=20Untitled?= =?UTF-8?q?=20doc=20or=20saved=20an=20open=20SPF=20file=20under=20an=20oth?= =?UTF-8?q?er=20name?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/TableDocument.m | 59 ++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 47 insertions(+), 12 deletions(-) (limited to 'Source/TableDocument.m') diff --git a/Source/TableDocument.m b/Source/TableDocument.m index e8290043..10f74e67 100644 --- a/Source/TableDocument.m +++ b/Source/TableDocument.m @@ -91,6 +91,8 @@ spfPreferences = [[NSMutableDictionary alloc] init]; spfDocData = [[NSMutableDictionary alloc] init]; + keyChainID = nil; + } return self; @@ -394,8 +396,18 @@ [connectionController setHost:[connection objectForKey:@"host"]]; if([connection objectForKey:@"port"]) [connectionController setPort:[NSString stringWithFormat:@"%d", [connection objectForKey:@"port"]]]; + if([connection objectForKey:@"kcid"] && [[connection objectForKey:@"kcid"] length]) + [self setKeychainID:[connection objectForKey:@"kcid"]]; + + // Set password - if not in SPF file try to get it via the KeyChain if([connection objectForKey:@"password"]) [connectionController setPassword:[connection objectForKey:@"password"]]; + else { + NSString *pw = [self keychainPasswordForConnection:nil]; + if([pw length]) + [connectionController setPassword:pw]; + } + if(connectionType == SP_CONNECTION_SOCKET && [connection objectForKey:@"socket"]) [connectionController setSocket:[connection objectForKey:@"socket"]]; @@ -406,8 +418,22 @@ [connectionController setSshUser:[connection objectForKey:@"ssh_user"]]; if([connection objectForKey:@"ssh_port"]) [connectionController setSshPort:[NSString stringWithFormat:@"%d", [connection objectForKey:@"ssh_port"]]]; + + // Set ssh password - if not in SPF file try to get it via the KeyChain 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]; + } + } if([connection objectForKey:@"database"]) @@ -428,15 +454,10 @@ if([spf objectForKey:@"ContentFilters"]) [spfPreferences setObject:[spf objectForKey:@"ContentFilters"] forKey:@"ContentFilters"]; - [spfDocData setObject:[NSNumber numberWithBool:YES] forKey:@"save_password"]; - if(![connection objectForKey:@"password"]) { - // TODO How to set the focus to standardPasswordField in the connection nib? - // [[connectionController valueForKeyPath:@"standardPasswordField"] selectText:connectionController]; - [spfDocData setObject:[NSNumber numberWithBool:NO] forKey:@"save_password"]; - return; - } + [spfDocData setObject:[NSNumber numberWithBool:([connection objectForKey:@"password"]) ? YES : NO] forKey:@"save_password"]; [spfDocData setObject:[NSNumber numberWithBool:NO] forKey:@"auto_connect"]; + if([spf objectForKey:@"auto_connect"] && [[spf valueForKey:@"auto_connect"] boolValue]) { [spfDocData setObject:[NSNumber numberWithBool:YES] forKey:@"auto_connect"]; [connectionController initiateConnection:self]; @@ -662,6 +683,11 @@ return _shouldOpenConnectionAutomatically; } +- (void)setKeychainID:(NSString *)theID +{ + keyChainID = [[NSString stringWithString:theID] retain]; +} + #pragma mark - #pragma mark Printing @@ -2008,6 +2034,11 @@ return theUser; } +- (NSString *)keyChainID +{ + return keyChainID; +} + #pragma mark - #pragma mark Notification center methods @@ -2165,7 +2196,7 @@ - (IBAction)validateSaveConnectionAccessory:(id)sender { - [saveConnectionAutoConnect setEnabled:([saveConnectionSavePassword state] == NSOnState)]; + // [saveConnectionAutoConnect setEnabled:([saveConnectionSavePassword state] == NSOnState)]; [saveConnectionSavePasswordAlert setHidden:([saveConnectionSavePassword state] == NSOffState)]; // If user checks the Encrypt check box set focus to password field @@ -2207,7 +2238,7 @@ [errorAlert runModal]; } - [[NSDocumentController sharedDocumentController] noteNewRecentDocumentURL:[NSURL URLWithString:fileName]]; + [[NSDocumentController sharedDocumentController] noteNewRecentDocumentURL:[NSURL fileURLWithPath:fileName]]; return; } @@ -2323,7 +2354,7 @@ return NO; } - [[NSDocumentController sharedDocumentController] noteNewRecentDocumentURL:[self fileURL]]; + [[NSDocumentController sharedDocumentController] noteNewRecentDocumentURL:[NSURL fileURLWithPath:fileName]]; return YES; @@ -2350,9 +2381,11 @@ [spfdata setObject:[spfDocData_temp objectForKey:@"encrypted"] forKey:@"encrypted"]; - if([[spfDocData_temp objectForKey:@"save_password"] boolValue]) - [spfdata setObject:[spfDocData_temp objectForKey:@"auto_connect"] forKey:@"auto_connect"]; + // if([[spfDocData_temp objectForKey:@"save_password"] boolValue]) + [spfdata setObject:[spfDocData_temp objectForKey:@"auto_connect"] forKey:@"auto_connect"]; + if([[self keyChainID] length]) + [connection setObject:[self keyChainID] forKey:@"kcid"]; [connection setObject:[self name] forKey:@"name"]; [connection setObject:[self host] forKey:@"host"]; [connection setObject:[self user] forKey:@"user"]; @@ -2500,6 +2533,7 @@ [[SPQueryController sharedQueryController] registerDocumentWithFileURL:[NSURL URLWithString:[fileName stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]] andContextInfo:preferences]; [self setFileURL:[NSURL URLWithString:[fileName stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]]; + [[NSDocumentController sharedDocumentController] noteNewRecentDocumentURL:[NSURL fileURLWithPath:fileName]]; [tableWindow setTitle:[self displaySPName]]; @@ -3406,6 +3440,7 @@ if(spfSession) [spfSession release]; if(userManagerInstance) [userManagerInstance release]; if(spfDocData) [spfDocData release]; + if(keyChainID) [keyChainID release]; [super dealloc]; } -- cgit v1.2.3