From 4c987b7a2775c060d02ff3eb38280aea4e83c984 Mon Sep 17 00:00:00 2001 From: Mitchell Livingston Date: Fri, 13 Jun 2008 04:52:46 +0000 Subject: [PATCH] if setting the proxy password to blank, delete it from the keychain --- macosx/Controller.m | 2 +- macosx/EMKeychain/EMKeychainItem.h | 3 +++ macosx/EMKeychain/EMKeychainItem.m | 6 ++++++ macosx/PrefsController.m | 14 +++++++++++--- 4 files changed, 21 insertions(+), 4 deletions(-) diff --git a/macosx/Controller.m b/macosx/Controller.m index 3eb0dc8b3..1e6789ac2 100644 --- a/macosx/Controller.m +++ b/macosx/Controller.m @@ -228,7 +228,7 @@ static void sleepCallback(void * controller, io_service_t y, natural_t messageTy TR_DEFAULT_PROXY_TYPE, /* reset in prefs */ [fDefaults boolForKey: @"ProxyAuthorize"], [[fDefaults stringForKey: @"ProxyUsername"] UTF8String], - ""); /* reset in prefs - from Keychain (leave blank instead of NULL) */ + NULL); /* reset in prefs - from Keychain */ [NSApp setDelegate: self]; diff --git a/macosx/EMKeychain/EMKeychainItem.h b/macosx/EMKeychain/EMKeychainItem.h index 7464e403c..dad89695c 100644 --- a/macosx/EMKeychain/EMKeychainItem.h +++ b/macosx/EMKeychain/EMKeychainItem.h @@ -40,6 +40,9 @@ - (BOOL)setPassword:(NSString *)newPassword; - (BOOL)setUsername:(NSString *)newUsername; - (BOOL)setLabel:(NSString *)newLabel; + +//added by ML +- (void)removeFromKeychain; @end @interface EMKeychainItem (Private) diff --git a/macosx/EMKeychain/EMKeychainItem.m b/macosx/EMKeychain/EMKeychainItem.m index a9da29735..5cabcc7ef 100644 --- a/macosx/EMKeychain/EMKeychainItem.m +++ b/macosx/EMKeychain/EMKeychainItem.m @@ -82,6 +82,12 @@ return [self modifyAttributeWithTag:kSecLabelItemAttr toBeString:newLabel]; } + +- (void)removeFromKeychain +{ + SecKeychainItemDelete(coreKeychainItem); +} + @end @implementation EMKeychainItem (Private) diff --git a/macosx/PrefsController.m b/macosx/PrefsController.m index 9f9be34f8..3a048cafa 100644 --- a/macosx/PrefsController.m +++ b/macosx/PrefsController.m @@ -757,10 +757,18 @@ EMGenericKeychainItem * keychainItem = [[EMKeychainProxy sharedProxy] genericKeychainItemForService: @"Transmission:Proxy" withUsername: @"Proxy"]; if (keychainItem) - [keychainItem setPassword: password]; + { + if (![password isEqualToString: @""]) + [keychainItem setPassword: password]; + else + [keychainItem removeFromKeychain]; + } else - [[EMKeychainProxy sharedProxy] addGenericKeychainItemForService: @"Transmission:Proxy" withUsername: @"Proxy" - password: password]; + { + if (![password isEqualToString: @""]) + [[EMKeychainProxy sharedProxy] addGenericKeychainItemForService: @"Transmission:Proxy" withUsername: @"Proxy" + password: password]; + } tr_sessionSetProxyPassword(fHandle, [password UTF8String]); }