if setting the proxy password to blank, delete it from the keychain

This commit is contained in:
Mitchell Livingston 2008-06-13 04:52:46 +00:00
parent 1c38bce649
commit 4c987b7a27
4 changed files with 21 additions and 4 deletions

View File

@ -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];

View File

@ -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)

View File

@ -82,6 +82,12 @@
return [self modifyAttributeWithTag:kSecLabelItemAttr toBeString:newLabel];
}
- (void)removeFromKeychain
{
SecKeychainItemDelete(coreKeychainItem);
}
@end
@implementation EMKeychainItem (Private)

View File

@ -757,10 +757,18 @@
EMGenericKeychainItem * keychainItem = [[EMKeychainProxy sharedProxy] genericKeychainItemForService: @"Transmission:Proxy"
withUsername: @"Proxy"];
if (keychainItem)
{
if (![password isEqualToString: @""])
[keychainItem setPassword: password];
else
[keychainItem removeFromKeychain];
}
else
{
if (![password isEqualToString: @""])
[[EMKeychainProxy sharedProxy] addGenericKeychainItemForService: @"Transmission:Proxy" withUsername: @"Proxy"
password: password];
}
tr_sessionSetProxyPassword(fHandle, [password UTF8String]);
}