From: Alexandra Ellwood Date: Thu, 28 Aug 2008 16:37:34 +0000 (+0000) Subject: Additional code for KerberosAgent. Checking in so Justin can work on it X-Git-Tag: krb5-1.7-alpha1~450 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=759b3927b87a523239da832440b352d351892ce0;p=krb5.git Additional code for KerberosAgent. Checking in so Justin can work on it ticket: 6055 git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@20700 dc483132-0cff-0310-8789-dd5450dbe970 --- diff --git a/src/kim/agent/mac/Identities.h b/src/kim/agent/mac/Identities.h index 0d3cdd4e2..556d0b075 100644 --- a/src/kim/agent/mac/Identities.h +++ b/src/kim/agent/mac/Identities.h @@ -25,22 +25,30 @@ @interface Identity : NSObject { kim_identity kimIdentity; int state; - cc_time_t *expirationTime; + cc_time_t expirationTime; + int favorite; } +@property int state; +@property cc_time_t expirationTime; +@property(readonly) int favorite; + +- (id) initWithIdentity: (kim_identity) identity; +- (id) initWithFavoriteIdentity: (kim_identity) identity; + +- (BOOL) isEqualToKIMIdentity: (kim_identity) identity; @end @interface Identities : NSObject { - NSArray *identitiesArray; - NSMutableArray *favoriteIdentitiesArray; - NSMutableArray *ccacheIdentitiesArray; + NSArray *favoriteIdentities; + NSArray *identities; NSConnection *threadConnection; } +@property(readonly) NSArray *identities; - (int) update; -- (NSArray *) identities; @end diff --git a/src/kim/agent/mac/Identities.m b/src/kim/agent/mac/Identities.m index 82b926d09..a3c070731 100644 --- a/src/kim/agent/mac/Identities.m +++ b/src/kim/agent/mac/Identities.m @@ -26,21 +26,53 @@ @implementation Identity +@synthesize state; +@synthesize expirationTime; +@synthesize favorite; + +// --------------------------------------------------------------------------- + - (id) initWithIdentity: (kim_identity) identity { if ((self = [super init])) { kimIdentity = identity; state = kim_credentials_state_not_yet_valid; expirationTime = 0; + favorite = FALSE; + } + + return self; +} + +// --------------------------------------------------------------------------- + +- (id) initWithFavoriteIdentity: (kim_identity) identity +{ + if ((self = [self initWithIdentity: identity])) { + favorite = TRUE; } return self; } +// --------------------------------------------------------------------------- + +- (BOOL) isEqualToKIMIdentity: (kim_identity) identity +{ + kim_error err = KIM_NO_ERROR; + kim_comparison comparison; + + err = kim_identity_compare (kimIdentity, identity, &comparison); + + return (!err && kim_comparison_is_equal_to (comparison)); +} + @end @implementation Identities +@synthesize identities; + // --------------------------------------------------------------------------- + (void) waitForChange: (NSArray *) portArray @@ -85,109 +117,119 @@ - (id) init { - int err = 0; - - threadConnection = NULL; - favoriteIdentitiesArray = NULL; - ccacheIdentitiesArray = NULL; - - if (!err) { - self = [super init]; - if (!self) { err = ENOMEM; } - } - - if (!err) { - favoriteIdentitiesArray = [[NSMutableArray alloc] init]; - if (!favoriteIdentitiesArray) { err = ENOMEM; } - } - - if (!err) { - kim_favorite_identities favoriteIdentities = NULL; - kim_count i; - kim_count count = 0; - - err = kim_favorite_identities_create (&favoriteIdentities); + if ((self = [super init])) { + int err = 0; + NSMutableArray *newFavoriteIdentities = NULL; + threadConnection = NULL; + identities = NULL; + favoriteIdentities = NULL; + if (!err) { - err = kim_favorite_identities_get_number_of_identities (favoriteIdentities, - &count); + newFavoriteIdentities = [[[NSMutableArray alloc] init] autorelease]; + if (!newFavoriteIdentities) { err = ENOMEM; } } - for (i = 0; !err && i < count; i++) { - kim_identity kimIdentity = NULL; - Identity *identity = NULL; + if (!err) { + kim_favorite_identities kimFavoriteIdentities = NULL; + kim_count i; + kim_count count = 0; - err = kim_favorite_identities_get_identity_at_index (favoriteIdentities, - i, &kimIdentity); + err = kim_favorite_identities_create (&kimFavoriteIdentities); if (!err) { - identity = [[[Identity alloc] initWithIdentity: kimIdentity] autorelease]; - if (!identity) { err = ENOMEM; } - } - - if (!err) { - kimIdentity = NULL; /* take ownership */ - [favoriteIdentitiesArray addObject: identity]; + err = kim_favorite_identities_get_number_of_identities (kimFavoriteIdentities, + &count); } - kim_identity_free (&kimIdentity); - } + for (i = 0; !err && i < count; i++) { + kim_identity kimIdentity = NULL; + Identity *identity = NULL; + + err = kim_favorite_identities_get_identity_at_index (kimFavoriteIdentities, + i, &kimIdentity); + + if (!err) { + identity = [[[Identity alloc] initWithFavoriteIdentity: kimIdentity] autorelease]; + if (!identity) { err = ENOMEM; } + } + + if (!err) { + kimIdentity = NULL; /* take ownership */ + [newFavoriteIdentities addObject: identity]; + } + + kim_identity_free (&kimIdentity); + } - kim_favorite_identities_free (&favoriteIdentities); - } - - if (!err) { - err = [self update]; - } - - if (!err) { - NSPort *port1 = [NSPort port]; - NSPort *port2 = [NSPort port]; - if (!port1 || !port2) { err = ENOMEM; } + kim_favorite_identities_free (&kimFavoriteIdentities); + } if (!err) { - threadConnection = [[NSConnection alloc] initWithReceivePort: port1 - sendPort: port2]; - if (!threadConnection) { err = ENOMEM; } + favoriteIdentities = [[NSArray alloc] initWithArray: newFavoriteIdentities]; + if (!favoriteIdentities) { err = ENOMEM; } + } + + if (!err) { + err = [self update]; } if (!err) { - [threadConnection setRootObject: self]; + NSPort *port1 = [NSPort port]; + NSPort *port2 = [NSPort port]; + if (!port1 || !port2) { err = ENOMEM; } + + if (!err) { + threadConnection = [[NSConnection alloc] initWithReceivePort: port1 + sendPort: port2]; + if (!threadConnection) { err = ENOMEM; } + } - [NSThread detachNewThreadSelector: @selector(waitForChange:) - toTarget: [self class] - withObject: [NSArray arrayWithObjects: port2, port1, NULL]]; + if (!err) { + [threadConnection setRootObject: self]; + + [NSThread detachNewThreadSelector: @selector(waitForChange:) + toTarget: [self class] + withObject: [NSArray arrayWithObjects: port2, port1, NULL]]; + } + } + + if (err) { + [self release]; + return NULL; } } - - return err ? NULL : self; + + return self; } // --------------------------------------------------------------------------- - (void) dealloc { - if (identitiesArray ) { [identitiesArray release]; } - if (threadConnection) { [threadConnection release]; } + if (identities ) { [identities release]; } + if (favoriteIdentities) { [favoriteIdentities release]; } + if (threadConnection ) { [threadConnection release]; } [super dealloc]; } // --------------------------------------------------------------------------- -- (NSArray *) identities -{ - return identitiesArray; -} - -// --------------------------------------------------------------------------- - - (int) update { kim_error err = KIM_NO_ERROR; + NSMutableArray *newIdentities = NULL; kim_ccache_iterator iterator = NULL; - err = kim_ccache_iterator_create (&iterator); + if (!err) { + newIdentities = [NSMutableArray arrayWithArray: favoriteIdentities]; + if (!newIdentities) { err = ENOMEM; } + } + + if (!err) { + err = kim_ccache_iterator_create (&iterator); + } while (!err) { kim_ccache ccache = NULL; @@ -213,18 +255,23 @@ if (!err) { Identity *identity = NULL; - identity = [self findIdentity: kimIdentity]; - if (identity) { - [identity updateWithState: state - expirationTime: expirationTime]; - } else { - identity = [[Identity alloc] initWithIdentity: kimIdentity - state: state - expirationTime: expirationTime]; + for (Identity *i in newIdentities) { + if ([i isEqualToKIMIdentity: kimIdentity]) { identity = i; } } - - if (identity) { + + if (!identity) { + identity = [[[Identity alloc] initWithIdentity: kimIdentity] autorelease]; + if (!identity) { err = ENOMEM; } + if (!err) { + kimIdentity = NULL; /* take ownership */ + [newIdentities addObject: identity]; + } + } + + if (!err) { + [identity setState: state]; + [identity setExpirationTime: expirationTime]; } } @@ -236,6 +283,14 @@ kim_identity_free (&kimIdentity); kim_ccache_free (&ccache); } + + if (!err) { + if (identities) { [identities release]; } + + identities = [[NSArray alloc] initWithArray: newIdentities]; + if (!identities) { err = ENOMEM; } + } + kim_ccache_iterator_free (&iterator); diff --git a/src/kim/agent/mac/resources/English.lproj/Authentication.xib b/src/kim/agent/mac/resources/English.lproj/Authentication.xib index 4665e183d..67d1b41a7 100644 --- a/src/kim/agent/mac/resources/English.lproj/Authentication.xib +++ b/src/kim/agent/mac/resources/English.lproj/Authentication.xib @@ -9,6 +9,7 @@ YES + YES @@ -26,7 +27,7 @@ NSApplication - + 274 YES @@ -35,7 +36,6 @@ 282 {{101, 126}, {382, 40}} - YES 67239424 @@ -72,7 +72,6 @@ 290 {{104, 88}, {376, 22}} - YES -1804468671 @@ -103,7 +102,6 @@ 292 {{17, 90}, {82, 17}} - YES 67239424 @@ -213,7 +211,6 @@ 292 {{17, 61}, {82, 17}} - YES 67239424 @@ -277,7 +274,7 @@ 67239424 134217728 - + LucidaGrande 1.000000e+01 16 @@ -285,7 +282,7 @@ -2033434369 2 - + NSImage Gear @@ -304,6 +301,7 @@ {500, 210} + NSView @@ -386,27 +384,6 @@ - - - 292 - {{18, 16}, {51, 26}} - - YES - - 67239424 - 134217728 - - - - -2033958657 - 2 - - - - 400 - 75 - - 292 @@ -520,27 +497,6 @@ 25 - - - 292 - {{18, 16}, {51, 26}} - - YES - - 67239424 - 134217728 - - - - -2033958657 - 2 - - - - 400 - 75 - - 292 @@ -905,22 +861,6 @@ 300261 - - - menu - - - - 300270 - - - - menu - - - - 300271 - @@ -1146,7 +1086,6 @@ - @@ -1186,15 +1125,6 @@ - - 300181 - - - YES - - - - 300183 @@ -1237,11 +1167,6 @@ - - 300186 - - - 300189 @@ -1263,7 +1188,6 @@ YES - @@ -1279,15 +1203,6 @@ - - 300199 - - - YES - - - - 300201 @@ -1372,11 +1287,6 @@ - - 300204 - - - 300274 @@ -1587,9 +1497,6 @@ 300179.ImportedFromIB2 300180.IBPluginDependency 300180.ImportedFromIB2 - 300181.CustomClassName - 300181.IBPluginDependency - 300181.ImportedFromIB2 300182.IBPluginDependency 300183.IBPluginDependency 300184.IBPluginDependency @@ -1604,9 +1511,6 @@ 300196.ImportedFromIB2 300197.IBPluginDependency 300197.ImportedFromIB2 - 300199.CustomClassName - 300199.IBPluginDependency - 300199.ImportedFromIB2 300200.IBPluginDependency 300201.IBPluginDependency 300201.ImportedFromIB2 @@ -1643,9 +1547,9 @@ YES com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin - {{546, 698}, {500, 210}} + {{696, 646}, {500, 210}} com.apple.InterfaceBuilder.CocoaPlugin - {{546, 698}, {500, 210}} + {{696, 646}, {500, 210}} {{932, 664}, {484, 199}} @@ -1655,7 +1559,7 @@ {484, 199} com.apple.InterfaceBuilder.CocoaPlugin - {{492, 1049}, {203, 73}} + {{557, 1049}, {203, 73}} com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin @@ -1666,7 +1570,7 @@ com.apple.InterfaceBuilder.CocoaPlugin - {{139, 469}, {500, 210}} + {{602, 364}, {500, 210}} com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin @@ -1684,7 +1588,7 @@ com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin - {{223, 184}, {500, 210}} + {{547, 453}, {500, 210}} com.apple.InterfaceBuilder.CocoaPlugin NSSecureTextField com.apple.InterfaceBuilder.CocoaPlugin @@ -1695,15 +1599,12 @@ com.apple.InterfaceBuilder.CocoaPlugin - PopupButton - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin - {{136, 743}, {500, 210}} + {{557, 743}, {500, 210}} com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin @@ -1712,15 +1613,12 @@ com.apple.InterfaceBuilder.CocoaPlugin - PopupButton - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin - {{467, 111}, {500, 210}} + {{546, 628}, {500, 210}} com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin @@ -1789,6 +1687,14 @@ + + PopupButton + NSButton + + IBProjectSource + ../Sources/kim/agent/mac/PopupButton.h + + PopupButton NSButton diff --git a/src/kim/agent/mac/resources/English.lproj/SelectIdentity.xib b/src/kim/agent/mac/resources/English.lproj/SelectIdentity.xib index 365d3fca8..938c63362 100644 --- a/src/kim/agent/mac/resources/English.lproj/SelectIdentity.xib +++ b/src/kim/agent/mac/resources/English.lproj/SelectIdentity.xib @@ -391,75 +391,10 @@ {419, 320} {600, 622} - - - YES - cachesArray - - KerberosCacheCollection - - - - KerberosCacheCollection - - - - YES - credentialsArray - principalString - shortTimeRemainingString - - KerberosCache - - YES - YES - YES - YES - YES - - - - YES - servicePrincipalString - shortTimeRemainingString - - KerberosCredential - YES - - YES - YES - YES - YES - YES - YES - - - content - - - - 300042 - - - - content - - - - 300043 - - - - content - - - - 300044 - identityTableColumn @@ -801,30 +736,6 @@ - - 300024 - - - CacheCollectionController - - - 300023 - - - KerberosCacheCollection - - - 300022 - - - CachesController - - - 300021 - - - CredentialsController - @@ -848,14 +759,6 @@ 300009.IBShouldRemoveOnLegacySave 300018.IBPluginDependency 300019.IBPluginDependency - 300021.IBPluginDependency - 300021.ImportedFromIB2 - 300022.IBPluginDependency - 300022.ImportedFromIB2 - 300023.IBPluginDependency - 300023.ImportedFromIB2 - 300024.IBPluginDependency - 300024.ImportedFromIB2 300118.IBPluginDependency 300118.ImportedFromIB2 300152.IBPluginDependency @@ -902,21 +805,13 @@ com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin - - com.apple.InterfaceBuilder.CocoaPlugin - - com.apple.InterfaceBuilder.CocoaPlugin - - com.apple.InterfaceBuilder.CocoaPlugin - - com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin - {{623, 643}, {491, 315}} + {{606, 810}, {491, 315}} com.apple.InterfaceBuilder.CocoaPlugin - {{623, 643}, {491, 315}} + {{606, 810}, {491, 315}} {{503, 256}, {419, 465}} @@ -973,14 +868,6 @@ - - KerberosCacheCollection - NSObject - - IBProjectSource - ../../../Common/Headers/KerberosCacheCollection.h - - SelectIdentityController NSWindowController