From: Justin Anderson Date: Thu, 2 Oct 2008 13:20:04 +0000 (+0000) Subject: Make enter identity dialog's smarter about matching a string with a set of favorite... X-Git-Tag: krb5-1.7-alpha1~363 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=ea05c23ca1596d0b3a0f1e0c2e00b841d942399f;p=krb5.git Make enter identity dialog's smarter about matching a string with a set of favorite options ticket:6055 git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@20808 dc483132-0cff-0310-8789-dd5450dbe970 --- diff --git a/src/kim/agent/mac/AuthenticationController.h b/src/kim/agent/mac/AuthenticationController.h index 4035668e2..c62611db7 100644 --- a/src/kim/agent/mac/AuthenticationController.h +++ b/src/kim/agent/mac/AuthenticationController.h @@ -97,4 +97,7 @@ returnCode: (int) returnCode contextInfo: (void *) contextInfo; +- (IBAction) changePasswordGearAction: (id) sender; +- (void) changePasswordThread: (NSString *) identityString; + @end diff --git a/src/kim/agent/mac/AuthenticationController.m b/src/kim/agent/mac/AuthenticationController.m index eaf4e6913..34e7662d2 100644 --- a/src/kim/agent/mac/AuthenticationController.m +++ b/src/kim/agent/mac/AuthenticationController.m @@ -370,17 +370,23 @@ - (IBAction) showTicketOptions: (id) sender { NSDictionary *options = nil; + NSString *expandedString = nil; // if this is a favorite, try to load its default options [identityField validateEditing]; - options = [favoriteOptions valueForKey:[identityField stringValue]]; + expandedString = [KIMUtilities expandedIdentity:[identityField stringValue]]; + + // edit the favorite options for this favorite identity + if (expandedString) { + options = [favoriteOptions objectForKey:expandedString]; + } + // else fallback to options passed from client + // use a copy of the current options if (!options) { options = [[[glueController valueForKeyPath:options_keypath] mutableCopy] autorelease]; } - // else fallback to options passed from client - // use a copy of the current options [ticketOptionsController setContent:options]; [ticketOptionsController setValue:[NSNumber numberWithInteger:[KIMUtilities minValidLifetime]] @@ -424,26 +430,31 @@ // discard new options [ticketOptionsController setContent:nil]; } else { - // replace existing options with new - // add to favorites if not already in list - - // replace options of existing if already in list kim_error err = KIM_NO_ERROR; kim_preferences prefs = NULL; kim_identity identity = NULL; kim_options options = NULL; + NSString *expandedString = [KIMUtilities expandedIdentity:[identityField stringValue]];; - [glueController setValue:[ticketOptionsController content] - forKeyPath:options_keypath]; - - err = kim_preferences_create(&prefs); - + // replace options if favorite exists + // add to favorites if not already in list + if (!expandedString) { + err = KIM_BAD_PRINCIPAL_STRING_ERR; + } + if (!err) { + [favoriteOptions setObject:[ticketOptionsController content] + forKey:expandedString]; + } + if (!err) { + err = kim_preferences_create(&prefs); + } if (!err) { err = kim_identity_create_from_string(&identity, [[identityField stringValue] UTF8String]); } if (!err) { options = [KIMUtilities kimOptionsForDictionary:[ticketOptionsController content]]; } + if (!identity) { err = KIM_BAD_PRINCIPAL_STRING_ERR; } if (!options) { err = KIM_BAD_OPTIONS_ERR; } @@ -453,7 +464,6 @@ if (!err && identity && options) { err = kim_preferences_add_favorite_identity(prefs, identity, options); } - if (!err) { err = kim_preferences_synchronize(prefs); } @@ -465,6 +475,40 @@ [ticketOptionsSheet orderOut:nil]; } +- (IBAction) changePasswordGearAction: (id) sender +{ + NSString *expandedString = [KIMUtilities expandedIdentity:[identityField stringValue]]; + NSLog(@"%s", __FUNCTION__); + if (expandedString && [expandedString length] > 0) { + [expandedString retain]; + [NSThread detachNewThreadSelector:@selector(changePasswordThread:) + toTarget:self + withObject:expandedString]; + } +} + +- (void) changePasswordThread: (NSString *) identityString +{ + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; + kim_error err = KIM_NO_ERROR; + kim_identity identity = NULL; + + NSLog(@"%s %@", __FUNCTION__, identityString); + if (!err) { + err = kim_identity_create_from_string(&identity, [identityString UTF8String]); + } + if (!err) { + err = kim_identity_change_password(identity); + } + + NSLog(@"%s %d", __FUNCTION__, err); + + kim_identity_free(&identity); + + [identityString release]; + [pool release]; +} + - (IBAction) cancel: (id) sender { [associatedClient didCancel]; @@ -473,11 +517,14 @@ - (IBAction) enterIdentity: (id) sender { - NSString *identityString = [glueController valueForKeyPath:identity_string_keypath]; - NSDictionary *options = [glueController valueForKeyPath:options_keypath]; + NSString *expandedString = [KIMUtilities expandedIdentity:[identityField stringValue]]; + NSDictionary *options = [favoriteOptions objectForKey:expandedString]; + if (!options) { + options = [glueController valueForKeyPath:options_keypath]; + } // the principal must already be valid to get this far - [associatedClient didEnterIdentity:identityString options:options]; + [associatedClient didEnterIdentity:expandedString options:options]; } - (IBAction) answerAuthPrompt: (id) sender diff --git a/src/kim/agent/mac/KIMUtilities.h b/src/kim/agent/mac/KIMUtilities.h index 4e448b9d5..516e8effe 100644 --- a/src/kim/agent/mac/KIMUtilities.h +++ b/src/kim/agent/mac/KIMUtilities.h @@ -82,6 +82,8 @@ NSLog(@"%s got error %@", __FUNCTION__, [KIMUtilities stringForLastKIMError:err] + (BOOL) validateIdentity: (NSString *) identityString; ++ (NSString *) expandedIdentity: (NSString *) identityString; + + (NSDictionary *) dictionaryForKimOptions: (kim_options) options; + (kim_options) kimOptionsForDictionary: (NSDictionary *) aDict; diff --git a/src/kim/agent/mac/KIMUtilities.m b/src/kim/agent/mac/KIMUtilities.m index f450cdf2b..34ff38e7f 100644 --- a/src/kim/agent/mac/KIMUtilities.m +++ b/src/kim/agent/mac/KIMUtilities.m @@ -63,6 +63,7 @@ { kim_error err = KIM_NO_ERROR; kim_identity identity = NULL; + if (!identityString || [identityString length] <= 1) { err = KIM_BAD_PRINCIPAL_STRING_ERR; } @@ -77,6 +78,34 @@ return (err == KIM_NO_ERROR); } ++ (NSString *) expandedIdentity: (NSString *) identityString +{ + NSString *result = nil; + kim_error err = KIM_NO_ERROR; + kim_identity identity = NULL; + kim_string validated_string = NULL; + + // convert to how it will actually be + // e.g. foo becomes foo@ATHENA.MIT.EDU + // for the purpose of matching to a favorite + if (!identityString) { + err = KIM_BAD_PRINCIPAL_STRING_ERR; + } + if (!err) { + err = kim_identity_create_from_string(&identity, [identityString UTF8String]); + } + if (!err && identity) { + err = kim_identity_get_display_string(identity, &validated_string); + } + if (!err && validated_string) { + result = [NSString stringWithUTF8String:validated_string]; + } + kim_identity_free(&identity); + kim_string_free(&validated_string); + + return result; +} + + (NSDictionary *) dictionaryForKimOptions: (kim_options) options { kim_error err = KIM_NO_ERROR; diff --git a/src/kim/agent/mac/resources/English.lproj/Authentication.xib b/src/kim/agent/mac/resources/English.lproj/Authentication.xib index e5273b70c..d665e878d 100644 --- a/src/kim/agent/mac/resources/English.lproj/Authentication.xib +++ b/src/kim/agent/mac/resources/English.lproj/Authentication.xib @@ -341,6 +341,7 @@ + YES Q2hhbmdlIFBhc3N3b3Jk4oCmA 2147483647 @@ -373,6 +374,7 @@ + 2 YES 1 YES @@ -386,7 +388,7 @@ NSView - + 274 YES @@ -395,7 +397,6 @@ 266 {{104, 82}, {376, 22}} - YES -1804468671 @@ -418,7 +419,6 @@ 289 {{388, 12}, {98, 32}} - YES 67239424 @@ -440,7 +440,6 @@ 289 {{295, 12}, {93, 32}} - YES 67239424 @@ -462,7 +461,6 @@ 266 {{101, 126}, {382, 41}} - YES 67239424 @@ -479,7 +477,6 @@ 268 {{17, 84}, {80, 17}} - YES 68288064 @@ -496,7 +493,6 @@ 290 {{102, 58}, {380, 18}} - YES -2080244224 @@ -524,13 +520,10 @@ 268 {{20, 126}, {64, 64}} - BadgedImageView {500, 210} - - NSView @@ -2019,7 +2012,7 @@ selection.identity_string NSContinuouslyUpdatesValue - + 2 @@ -2040,7 +2033,7 @@ selection.valid_lifetime NSContinuouslyUpdatesValue - + 2 @@ -2060,7 +2053,7 @@ selection.renewal_lifetime NSContinuouslyUpdatesValue - + 2 @@ -2083,6 +2076,14 @@ 300520 + + + changePasswordGearAction: + + + + 300522 + @@ -3121,7 +3122,7 @@ com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin - {{611, 382}, {189, 93}} + {{611, 408}, {189, 93}} com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin @@ -3201,7 +3202,7 @@ - 300520 + 300522 @@ -3217,6 +3218,7 @@ cancel: cancelTicketOptions: changePassword: + changePasswordGearAction: enterIdentity: saveTicketOptions: showTicketOptions: @@ -3234,6 +3236,7 @@ id id id + id