From: Mitchell Livingston Date: Fri, 13 Jun 2008 04:52:46 +0000 (+0000) Subject: if setting the proxy password to blank, delete it from the keychain X-Git-Tag: 1.22~7 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4c987b7a2775c060d02ff3eb38280aea4e83c984;p=transmission if setting the proxy password to blank, delete it from the keychain --- 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]); }