diff options
Diffstat (limited to 'src/kim/agent/mac/KIMUtilities.m')
-rw-r--r-- | src/kim/agent/mac/KIMUtilities.m | 112 |
1 files changed, 100 insertions, 12 deletions
diff --git a/src/kim/agent/mac/KIMUtilities.m b/src/kim/agent/mac/KIMUtilities.m index 9319e676ae..f450cdf2ba 100644 --- a/src/kim/agent/mac/KIMUtilities.m +++ b/src/kim/agent/mac/KIMUtilities.m @@ -1,10 +1,26 @@ -// -// KIMUtilities.m -// Kerberos5 -// -// Created by Justin Anderson on 9/28/08. -// Copyright 2008 MIT. All rights reserved. -// +/* + * Copyright 2008 Massachusetts Institute of Technology. + * All Rights Reserved. + * + * Export of this software from the United States of America may + * require a specific license from the United States Government. + * It is the responsibility of any person or organization contemplating + * export to obtain such a license before exporting. + * + * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and + * distribute this software and its documentation for any purpose and + * without fee is hereby granted, provided that the above copyright + * notice appear in all copies and that both that copyright notice and + * this permission notice appear in supporting documentation, and that + * the name of M.I.T. not be used in advertising or publicity pertaining + * to distribution of the software without specific, written prior + * permission. Furthermore if you modify this software you must label + * your software as modified software and not distribute it in such a + * fashion that it might be confused with the original M.I.T. software. + * M.I.T. makes no representations about the suitability of + * this software for any purpose. It is provided "as is" without express + * or implied warranty. + */ #import "KIMUtilities.h" @@ -29,16 +45,29 @@ realm: (NSString *) realm { kim_error err = KIM_NO_ERROR; - kim_identity identity = NULL; - NSString *principal = nil; + NSString *identityString = nil; if (!name || !realm || [name length] == 0) { err = KIM_BAD_PRINCIPAL_STRING_ERR; } if (!err) { - principal = [[NSString alloc] initWithFormat:@"%@@%@", name, realm]; - err = kim_identity_create_from_string(&identity, [principal UTF8String]); - [principal release]; + identityString = [[NSString alloc] initWithFormat:@"%@@%@", name, realm]; + err = [KIMUtilities validateIdentity:identityString]; + [identityString release]; + } + + return (err == KIM_NO_ERROR); +} + ++ (BOOL) validateIdentity: (NSString *) identityString +{ + kim_error err = KIM_NO_ERROR; + kim_identity identity = NULL; + if (!identityString || [identityString length] <= 1) { + err = KIM_BAD_PRINCIPAL_STRING_ERR; + } + if (!err) { + err = kim_identity_create_from_string(&identity, [identityString UTF8String]); } if (!identity) { err = KIM_BAD_PRINCIPAL_STRING_ERR; @@ -167,6 +196,65 @@ return options; } ++ (NSDictionary *) dictionaryForKimSelectionHints: (kim_selection_hints) hints +{ + kim_error err = KIM_NO_ERROR; + + NSMutableDictionary *newDict = [NSMutableDictionary dictionaryWithCapacity:20]; + + kim_string explanation = NULL; + kim_options options = NULL; + kim_string service_identity = NULL; + kim_string client_realm = NULL; + kim_string user = NULL; + kim_string service_realm = NULL; + kim_string service = NULL; + kim_string server = NULL; + + if (!err) { + err = kim_selection_hints_get_explanation(hints, &explanation); + [newDict setValue:(explanation) ? [NSString stringWithUTF8String:explanation] : @"" + forKey:@"explanation"]; + } + if (!err) { + err = kim_selection_hints_get_options(hints, &options); + [newDict setValue:[KIMUtilities dictionaryForKimOptions:options] + forKey:@"options"]; + } + if (!err) { + err = kim_selection_hints_get_hint(hints, kim_hint_key_client_realm, &client_realm); + [newDict setValue:(client_realm) ? [NSString stringWithUTF8String:client_realm] : @"" + forKey:@"client_realm"]; + } + if (!err) { + err = kim_selection_hints_get_hint(hints, kim_hint_key_user, &user); + [newDict setValue:(user) ? [NSString stringWithUTF8String:user] : @"" + forKey:@"user"]; + } + if (!err) { + err = kim_selection_hints_get_hint(hints, kim_hint_key_service_realm, &service_realm); + [newDict setValue:(service_realm) ? [NSString stringWithUTF8String:service_realm] : @"" + forKey:@"service_realm"]; + } + if (!err) { + err = kim_selection_hints_get_hint(hints, kim_hint_key_service, &service); + [newDict setValue:(service) ? [NSString stringWithUTF8String:service] : @"" + forKey:@"service"]; + } + if (!err) { + err = kim_selection_hints_get_hint(hints, kim_hint_key_server, &server); + [newDict setValue:(server) ? [NSString stringWithUTF8String:server] : @"" + forKey:@"server"]; + } + if (!err) { + err = kim_selection_hints_get_hint(hints, kim_hint_key_service_identity, &service_identity); + [newDict setValue:(service_identity) ? [NSString stringWithUTF8String:service_identity] : @"" + forKey:@"service_identity"]; + } + + return newDict; +} + + (NSUInteger)minValidLifetime { kim_error err = KIM_NO_ERROR; |