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 --- Interfaces/English.lproj/SaveSPFAccessory.xib | 341 ++++---------------------- Source/SPConnectionController.m | 7 + Source/TableDocument.h | 6 +- Source/TableDocument.m | 59 ++++- 4 files changed, 110 insertions(+), 303 deletions(-) diff --git a/Interfaces/English.lproj/SaveSPFAccessory.xib b/Interfaces/English.lproj/SaveSPFAccessory.xib index 579fe9af..b7eea9b9 100644 --- a/Interfaces/English.lproj/SaveSPFAccessory.xib +++ b/Interfaces/English.lproj/SaveSPFAccessory.xib @@ -1,14 +1,18 @@ - + 1050 - 9L30 - 677 - 949.54 - 353.00 + 10B504 + 732 + 1038.2 + 437.00 + + com.apple.InterfaceBuilder.CocoaPlugin + 732 + YES - + YES @@ -16,7 +20,7 @@ YES - + YES @@ -42,7 +46,7 @@ 268 - {{18, 33}, {177, 18}} + {{18, 34}, {177, 18}} YES @@ -51,7 +55,7 @@ Remember window state LucidaGrande - 1.300000e+01 + 13 1044 @@ -95,7 +99,7 @@ 268 - {{18, 113}, {139, 18}} + {{18, 112}, {139, 18}} YES @@ -117,7 +121,7 @@ 268 - {{18, 60}, {176, 18}} + {{18, 86}, {176, 18}} YES @@ -139,7 +143,7 @@ 268 - {{193, 59}, {138, 19}} + {{193, 85}, {138, 19}} YES @@ -148,7 +152,7 @@ LucidaGrande - 1.100000e+01 + 11 3100 @@ -173,262 +177,18 @@ YES - ti_ER - ar_LY - kok_IN - mk_MK - eo - fr_CH - sw - so_ET - gv - ar_BH - hy_AM_REVISED - it_IT - bg_BG - ro - es_HN - en_BE - is - kw_GB - kl - ga_IE - nl_NL - uk - fr_CA - sk_SK - es_AR - en_MT - fr_BE - ca - cs_CZ - fr_FR - en_ZA - sl - fa - so - pt - et_EE - eu_ES - fi - de_CH - or - gu_IN - mt_MT - nb - ms - es_CR - as_IN - ar_SA - am - pl - hu - lv - ar_DZ - ur - pt_PT - eu - so_DJ - de - en_IN - hr_HR - ar_AE - gu - lt - te_IN - ar_KW - sr_Latn - de_AT - en_US - es_PR - pl_PL - uz_Cyrl_UZ - ar_EG - it_CH - nl - haw_US - is_IS - en_IE - kl_GL - ps - zh_Hans_CN - ar - ru_UA - th_TH - fr_LU - uz_Latn_UZ - az - bn_IN - es_MX - kk_KZ - en_US_POSIX - el_GR - he - es_UY - nn_NO - sr - sk - ur_PK - es_PA - sv_FI - zh - es_DO - en_CA - en_BW - de_DE - haw - pa_IN - sq - kw - ga - ml - mt - af_ZA - az_Latn - ko_KR - fa_AF - ps_AF - be_BY - bn - it - sr_Latn_CS - zh_Hans - as - ms_MY - be - sl_SI - fa_IR - es_EC - kok - es_PY - ta_IN - am_ET - es_CO - uz_Latn - el - zh_Hant_MO - kk - kn - zh_Hant - en - es_PE - pt_BR - ar_LB - en_NZ - es_ES - en_HK - es_BO - hu_HU - sr_Cyrl - nb_NO - sv - vi - ti_ET - bg - om - de_LU - en_SG - id_ID - ur_IN - uz - da - ru_RU - es_US - es_VE - ko - ja - af - ar_YE - lt_LT - om_KE - zh_Hans_SG - es_NI - he_IL - en_PK - en_PH - az_Cyrl_AZ - en_AU - az_Cyrl - ta - ar_MA - sw_KE - tr_TR - zh_Hant_HK - en_ZW - de_BE - mk - pa - da_DK - es_GT - es - ar_IQ - az_Latn_AZ - so_SO - lv_LV - mr - te - sq_AL - ml_IN - uk_UA - hi_IN - ca_ES - ar_TN - id - om_ET - cs - fo_FO - hy_AM - en_GB - sr_Cyrl_CS - gl_ES - sw_TZ - ro_RO - cy - fr - ms_BN - so_KE - tr - gl - cy_GB - ar_OM - fo - es_CL - sv_SE - ar_JO - uz_Cyrl - zh_Hant_TW - et - hi - fi_FI - nn - th - ar_SY - ja_JP - gv_GB - hy - en_VI - kn_IN - ti - ar_QA - es_SV - hr - ru - ar_SD - mr_IN - vi_VN - nl_BE - or_IN + NSAllRomanInputSourcesLocaleIdentifier 268 - {{40, 86}, {199, 18}} + {{18, 60}, {199, 18}} YES - -1543373312 + -2080244224 0 Auto connect when opening @@ -461,7 +221,7 @@ controlColor 3 - MC42NjY2NjY2OQA + MC42NjY2NjY2ODY1AA @@ -553,7 +313,7 @@ values._dummy YES - + YES NSMultipleValuesPlaceholder NSNoSelectionPlaceholder @@ -562,10 +322,10 @@ YES - - - - + + + + 2 @@ -627,28 +387,26 @@ YES 0 - - YES - + -2 - - RmlsZSdzIE93bmVyA + + File's Owner -1 - + First Responder -3 - + Application @@ -657,14 +415,14 @@ YES - - + + - + Save SPF Accessory @@ -754,7 +512,7 @@ 37 - + 2 @@ -774,7 +532,7 @@ YES - + YES -1.IBPluginDependency -2.IBPluginDependency @@ -811,9 +569,7 @@ com.apple.InterfaceBuilder.CocoaPlugin YES - - YES - + YES @@ -858,9 +614,7 @@ YES - - YES - + YES @@ -868,9 +622,7 @@ YES - - YES - + YES @@ -885,7 +637,7 @@ NSObject YES - + YES saveConnectionAccessory saveConnectionAutoConnect @@ -927,7 +679,7 @@ NSDocument YES - + YES addConnectionToFavorites: addDatabase: @@ -1004,7 +756,7 @@ YES - + YES addDatabaseButton chooseDatabaseButton @@ -1127,6 +879,15 @@ 0 + + com.apple.InterfaceBuilder.CocoaPlugin.macosx + + + + com.apple.InterfaceBuilder.CocoaPlugin.InterfaceBuilder3 + + + YES 3 diff --git a/Source/SPConnectionController.m b/Source/SPConnectionController.m index d4c9d665..9a9d693b 100644 --- a/Source/SPConnectionController.m +++ b/Source/SPConnectionController.m @@ -450,9 +450,16 @@ NSArray *toolbarItems = [[documentWindow toolbar] items]; for (int i = 0; i < [toolbarItems count]; i++) [[toolbarItems objectAtIndex:i] setEnabled:YES]; + // Set keychain id for saving SPF files + if([self valueForKeyPath:@"selectedFavorite.id"]) + [tableDocument setKeychainID:[[self valueForKeyPath:@"selectedFavorite.id"] stringValue]]; + else + [tableDocument setKeychainID:@""]; + // Pass the connection to the table document, allowing it to set // up the other classes and the rest of the interface. [tableDocument setConnection:mySQLConnection]; + } #pragma mark - diff --git a/Source/TableDocument.h b/Source/TableDocument.h index b907ab37..3a8adbfb 100644 --- a/Source/TableDocument.h +++ b/Source/TableDocument.h @@ -144,6 +144,8 @@ enum sp_current_query_mode NSDictionary *spfSession; NSMutableDictionary *spfPreferences; NSMutableDictionary *spfDocData; + + NSString *keyChainID; } - (NSString *)getHTMLforPrint; @@ -151,9 +153,10 @@ enum sp_current_query_mode - (void)initQueryEditorWithString:(NSString *)query; - (void)initWithConnectionFile:(NSString *)path; // Connection callback and methods -- (void) setConnection:(MCPConnection *)theConnection; +- (void)setConnection:(MCPConnection *)theConnection; - (void)setShouldAutomaticallyConnect:(BOOL)shouldAutomaticallyConnect; - (BOOL)shouldAutomaticallyConnect; +- (void)setKeychainID:(NSString *)theID; // Database methods - (IBAction)setDatabases:(id)sender; @@ -219,6 +222,7 @@ enum sp_current_query_mode - (NSString *)mySQLVersion; - (NSString *)user; - (NSString *)displaySPName; +- (NSString *)keyChainID; // Notification center methods - (void)willPerformQuery:(NSNotification *)notification; 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