diff options
author | Tom Yu <tlyu@mit.edu> | 2009-10-31 00:48:38 +0000 |
---|---|---|
committer | Tom Yu <tlyu@mit.edu> | 2009-10-31 00:48:38 +0000 |
commit | 02d6bcbc98a214e7aeaaa9f45f0db8784a7b743b (patch) | |
tree | 61b9147863cd8be3eff63903dc36cae168254bd5 /src/kim | |
parent | 162ab371748cba0cc6f172419bd6e71fa04bb878 (diff) | |
download | krb5-02d6bcbc98a214e7aeaaa9f45f0db8784a7b743b.tar.gz krb5-02d6bcbc98a214e7aeaaa9f45f0db8784a7b743b.tar.xz krb5-02d6bcbc98a214e7aeaaa9f45f0db8784a7b743b.zip |
make mark-cstyle
make reindent
git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@23100 dc483132-0cff-0310-8789-dd5450dbe970
Diffstat (limited to 'src/kim')
51 files changed, 3719 insertions, 3727 deletions
diff --git a/src/kim/agent/mac/AuthenticationController.h b/src/kim/agent/mac/AuthenticationController.h index ba0b21223d..03b76ce53f 100644 --- a/src/kim/agent/mac/AuthenticationController.h +++ b/src/kim/agent/mac/AuthenticationController.h @@ -6,7 +6,7 @@ * 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 @@ -30,9 +30,9 @@ @interface AuthenticationController : NSWindowController { IPCClient *associatedClient; - + IBOutlet KerberosTimeFormatter *lifetimeFormatter; - + IBOutlet NSView *containerView; IBOutlet NSView *identityView; IBOutlet NSView *passwordView; @@ -46,30 +46,30 @@ IBOutlet BadgedImageView *samBadge; IBOutlet BadgedImageView *changePasswordBadge; IBOutlet BadgedImageView *errorBadge; - + IBOutlet NSProgressIndicator *enterSpinny; IBOutlet NSProgressIndicator *passwordSpinny; IBOutlet NSProgressIndicator *samSpinny; IBOutlet NSProgressIndicator *changePasswordSpinny; - + // Controls that need to be made key IBOutlet NSTextField *identityField; IBOutlet NSTextField *passwordField; IBOutlet NSTextField *samPromptField; IBOutlet NSTextField *oldPasswordField; - + // Other controls of interest IBOutlet NSButton *rememberPasswordInKeychainCheckBox; - + IBOutlet NSObjectController *glueController; IBOutlet NSWindow *ticketOptionsSheet; IBOutlet NSObjectController *ticketOptionsController; BOOL visibleAsSheet; - + IBOutlet NSSlider *validLifetimeSlider; IBOutlet NSSlider *renewableLifetimeSlider; - + NSMutableArray *favoriteIdentities; NSMutableDictionary *favoriteOptions; } @@ -102,11 +102,11 @@ - (IBAction) cancelAuthSheet: (id) sender; -- (void) authSheetDidEnd: (NSWindow *) sheet - returnCode: (int) returnCode +- (void) authSheetDidEnd: (NSWindow *) sheet + returnCode: (int) returnCode contextInfo: (void *) contextInfo; -- (void) ticketOptionsSheetDidEnd: (NSWindow *) sheet - returnCode: (int) returnCode +- (void) ticketOptionsSheetDidEnd: (NSWindow *) sheet + returnCode: (int) returnCode contextInfo: (void *) contextInfo; - (IBAction) changePasswordGearAction: (id) sender; diff --git a/src/kim/agent/mac/BadgedImageView.h b/src/kim/agent/mac/BadgedImageView.h index 4fba86727c..489a90954b 100644 --- a/src/kim/agent/mac/BadgedImageView.h +++ b/src/kim/agent/mac/BadgedImageView.h @@ -6,7 +6,7 @@ * 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 diff --git a/src/kim/agent/mac/IPCClient.h b/src/kim/agent/mac/IPCClient.h index 0bea6000b1..a700a6a53a 100644 --- a/src/kim/agent/mac/IPCClient.h +++ b/src/kim/agent/mac/IPCClient.h @@ -6,7 +6,7 @@ * 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 @@ -59,11 +59,11 @@ - (kim_error) handleError: (NSDictionary *) info; - (void) didCancel; -- (void) didSelectIdentity: (NSString *) identityString - options: (NSDictionary *) options +- (void) didSelectIdentity: (NSString *) identityString + options: (NSDictionary *) options wantsChangePassword: (BOOL) wantsChangePassword; -- (void) didEnterIdentity: (NSString *) identityString - options: (NSDictionary *) options +- (void) didEnterIdentity: (NSString *) identityString + options: (NSDictionary *) options wantsChangePassword: (BOOL) wantsChangePassword; - (void) didPromptForAuth: (NSString *) responseString saveResponse: (NSNumber *) saveResponse; - (void) didChangePassword: (NSString *) oldPassword diff --git a/src/kim/agent/mac/Identities.h b/src/kim/agent/mac/Identities.h index 712abb31cb..72f735522b 100644 --- a/src/kim/agent/mac/Identities.h +++ b/src/kim/agent/mac/Identities.h @@ -6,7 +6,7 @@ * 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 diff --git a/src/kim/agent/mac/KIMUtilities.h b/src/kim/agent/mac/KIMUtilities.h index 6575ca7124..adbc159141 100644 --- a/src/kim/agent/mac/KIMUtilities.h +++ b/src/kim/agent/mac/KIMUtilities.h @@ -6,7 +6,7 @@ * 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 diff --git a/src/kim/agent/mac/KerberosAgentController.h b/src/kim/agent/mac/KerberosAgentController.h index 8769611634..c6fae86706 100644 --- a/src/kim/agent/mac/KerberosAgentController.h +++ b/src/kim/agent/mac/KerberosAgentController.h @@ -6,7 +6,7 @@ * 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 diff --git a/src/kim/agent/mac/KerberosAgentListener.h b/src/kim/agent/mac/KerberosAgentListener.h index 2d9378aff5..4e0dc3dbbc 100644 --- a/src/kim/agent/mac/KerberosAgentListener.h +++ b/src/kim/agent/mac/KerberosAgentListener.h @@ -6,7 +6,7 @@ * 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 @@ -46,7 +46,7 @@ path: (kim_string) path; // contains reply_port -+ (void) didAddClient: (NSDictionary *) info ++ (void) didAddClient: (NSDictionary *) info error: (int32_t) error; + (void) enterIdentityWithClientPort: (mach_port_t) client_port @@ -54,7 +54,7 @@ options: (kim_options) options; // contains reply_port, kim_identity -+ (void) didEnterIdentity: (NSDictionary *) info ++ (void) didEnterIdentity: (NSDictionary *) info error: (int32_t) error; + (void) selectIdentityWithClientPort: (mach_port_t) client_port @@ -62,21 +62,21 @@ hints: (kim_selection_hints) hints; // contains reply_port, kim_identity -+ (void) didSelectIdentity: (NSDictionary *) info ++ (void) didSelectIdentity: (NSDictionary *) info error: (int32_t) error; + (void) promptForAuthWithClientPort: (mach_port_t) client_port replyPort: (mach_port_t) reply_port identity: (kim_string) identity_string promptType: (uint32_t) prompt_type - allowSave: (kim_boolean) allow_save + allowSave: (kim_boolean) allow_save hideReply: (kim_boolean) hide_reply title: (kim_string) title message: (kim_string) message description: (kim_string) description; // contains reply_port, (string) prompt_response -+ (void) didPromptForAuth: (NSDictionary *) info ++ (void) didPromptForAuth: (NSDictionary *) info error: (int32_t) error; + (void) changePasswordWithClientPort: (mach_port_t) client_port @@ -85,7 +85,7 @@ expired: (kim_boolean) expired; // contains reply_port, old password, new password, verify password -+ (void) didChangePassword: (NSDictionary *) info ++ (void) didChangePassword: (NSDictionary *) info error: (int32_t) error; + (void) handleErrorWithClientPort: (mach_port_t) client_port @@ -96,7 +96,7 @@ description: (kim_string) description; // contains reply_port -+ (void) didHandleError: (NSDictionary *) info ++ (void) didHandleError: (NSDictionary *) info error: (int32_t) error; diff --git a/src/kim/agent/mac/KerberosFormatters.h b/src/kim/agent/mac/KerberosFormatters.h index 104ea5f42c..7dd28b7ab2 100644 --- a/src/kim/agent/mac/KerberosFormatters.h +++ b/src/kim/agent/mac/KerberosFormatters.h @@ -6,7 +6,7 @@ * 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 @@ -35,7 +35,7 @@ - (NSString *)stringForObjectValue:(id)anObject; -- (NSAttributedString *)attributedStringForObjectValue:(id)anObject +- (NSAttributedString *)attributedStringForObjectValue:(id)anObject withDefaultAttributes:(NSDictionary *)attributes; - (NSString *) stringForLifetime: (time_t) lifetime; @@ -43,11 +43,11 @@ @end @interface KerberosFavoriteFormatter : NSFormatter { - + } - (NSString *)stringForObjectValue:(id)anObject; -- (NSAttributedString *)attributedStringForObjectValue:(id)anObject +- (NSAttributedString *)attributedStringForObjectValue:(id)anObject withDefaultAttributes:(NSDictionary *)attributes; @end diff --git a/src/kim/agent/mac/PopupButton.h b/src/kim/agent/mac/PopupButton.h index 5ced9513ee..823ecb26e5 100644 --- a/src/kim/agent/mac/PopupButton.h +++ b/src/kim/agent/mac/PopupButton.h @@ -6,7 +6,7 @@ * 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 diff --git a/src/kim/agent/mac/SelectIdentityController.h b/src/kim/agent/mac/SelectIdentityController.h index 4d744ba08e..b5f0bceb2b 100644 --- a/src/kim/agent/mac/SelectIdentityController.h +++ b/src/kim/agent/mac/SelectIdentityController.h @@ -6,7 +6,7 @@ * 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 @@ -31,17 +31,17 @@ @interface SelectIdentityController : NSWindowController { IPCClient *associatedClient; - + IBOutlet KerberosTimeFormatter *shortTimeFormatter; IBOutlet KerberosTimeFormatter *longTimeFormatter; - + IBOutlet NSObjectController *identitiesController; IBOutlet NSArrayController *identityArrayController; IBOutlet BadgedImageView *kerberosIconImageView; IBOutlet NSTextField *headerTextField; IBOutlet NSTextField *explanationTextField; - + IBOutlet NSScrollView *identityTableScrollView; IBOutlet NSTableView *identityTableView; IBOutlet NSButton *addIdentityButton; @@ -51,9 +51,9 @@ Identities *identities; NSTimer *refreshTimer; - + IBOutlet NSObjectController *glueController; - + IBOutlet NSWindow *ticketOptionsWindow; IBOutlet NSObjectController *identityOptionsController; IBOutlet NSTextField *identityField; @@ -61,7 +61,7 @@ IBOutlet NSSlider *validLifetimeSlider; IBOutlet NSSlider *renewableLifetimeSlider; - + IBOutlet NSBox *ticketOptionsBox; IBOutlet NSButton *ticketOptionsOkButton; IBOutlet NSButton *ticketOptionsToggleButton; diff --git a/src/kim/agent/mac/ServerDemux.h b/src/kim/agent/mac/ServerDemux.h index 39fd281078..b454376caf 100644 --- a/src/kim/agent/mac/ServerDemux.h +++ b/src/kim/agent/mac/ServerDemux.h @@ -6,7 +6,7 @@ * 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 @@ -30,34 +30,34 @@ int32_t kim_agent_listen_loop (void); -int32_t kim_handle_reply_init (mach_port_t in_reply_port, +int32_t kim_handle_reply_init (mach_port_t in_reply_port, int32_t in_error); -int32_t kim_handle_reply_enter_identity (mach_port_t in_reply_port, +int32_t kim_handle_reply_enter_identity (mach_port_t in_reply_port, kim_identity in_identity, kim_options in_options, kim_boolean in_change_password, int32_t in_error); -int32_t kim_handle_reply_select_identity (mach_port_t in_reply_port, +int32_t kim_handle_reply_select_identity (mach_port_t in_reply_port, kim_identity in_identity, kim_options in_options, kim_boolean in_change_password, int32_t in_error); -int32_t kim_handle_reply_auth_prompt (mach_port_t in_reply_port, +int32_t kim_handle_reply_auth_prompt (mach_port_t in_reply_port, kim_string in_prompt_response, kim_boolean in_allow_save_response, int32_t in_error); -int32_t kim_handle_reply_change_password (mach_port_t in_reply_port, +int32_t kim_handle_reply_change_password (mach_port_t in_reply_port, kim_string in_old_password, kim_string in_new_password, kim_string in_vfy_password, int32_t in_error); -int32_t kim_handle_reply_handle_error (mach_port_t in_reply_port, +int32_t kim_handle_reply_handle_error (mach_port_t in_reply_port, int32_t in_error); -int32_t kim_handle_reply_fini (mach_port_t in_reply_port, +int32_t kim_handle_reply_fini (mach_port_t in_reply_port, int32_t in_error); diff --git a/src/kim/lib/kim_ccache.c b/src/kim/lib/kim_ccache.c index cf6a18315e..6e48eda43c 100644 --- a/src/kim/lib/kim_ccache.c +++ b/src/kim/lib/kim_ccache.c @@ -6,7 +6,7 @@ * 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 @@ -40,35 +40,35 @@ kim_error kim_ccache_iterator_create (kim_ccache_iterator *out_ccache_iterator) { kim_error err = kim_library_init (); kim_ccache_iterator ccache_iterator = NULL; - + if (!err && !out_ccache_iterator) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { ccache_iterator = malloc (sizeof (*ccache_iterator)); - if (ccache_iterator) { + if (ccache_iterator) { *ccache_iterator = kim_ccache_iterator_initializer; } else { - err = KIM_OUT_OF_MEMORY_ERR; + err = KIM_OUT_OF_MEMORY_ERR; } } - + if (!err) { err = krb5_error (NULL, krb5_init_context (&ccache_iterator->context)); } - + if (!err) { err = krb5_error (ccache_iterator->context, krb5_cccol_cursor_new (ccache_iterator->context, &ccache_iterator->cursor)); } - - if (!err) { + + if (!err) { *out_ccache_iterator = ccache_iterator; ccache_iterator = NULL; } - + kim_ccache_iterator_free (&ccache_iterator); - + return check_error (err); } @@ -79,54 +79,54 @@ kim_error kim_ccache_iterator_next (kim_ccache_iterator in_ccache_iterator, { kim_error err = KIM_NO_ERROR; krb5_ccache ccache = NULL; - + if (!err && !in_ccache_iterator) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !out_ccache ) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { - err = krb5_cccol_cursor_next (in_ccache_iterator->context, + err = krb5_cccol_cursor_next (in_ccache_iterator->context, in_ccache_iterator->cursor, &ccache); if (err == KRB5_CC_END) { ccache = NULL; /* out of ccaches */ err = KIM_NO_ERROR; - } + } } - + if (!err && ccache && in_ccache_iterator->first) { krb5_principal principal = NULL; - + /* krb5 API is sneaky and returns a single empty ccache if the * cache collection is empty. Check for it: */ err = krb5_error (in_ccache_iterator->context, - krb5_cc_get_principal (in_ccache_iterator->context, - ccache, + krb5_cc_get_principal (in_ccache_iterator->context, + ccache, &principal)); - + if (err) { krb5_cc_close (in_ccache_iterator->context, ccache); ccache = NULL; err = KIM_NO_ERROR; } - - if (principal) { krb5_free_principal (in_ccache_iterator->context, + + if (principal) { krb5_free_principal (in_ccache_iterator->context, principal); } } - + if (!err) { in_ccache_iterator->first = 0; - + if (ccache) { err = kim_ccache_create_from_krb5_ccache (out_ccache, - in_ccache_iterator->context, + in_ccache_iterator->context, ccache); } else { *out_ccache = NULL; /* no more ccaches */ - } + } } - + if (ccache) { krb5_cc_close (in_ccache_iterator->context, ccache); } - + return check_error (err); } @@ -135,12 +135,12 @@ kim_error kim_ccache_iterator_next (kim_ccache_iterator in_ccache_iterator, void kim_ccache_iterator_free (kim_ccache_iterator *io_ccache_iterator) { if (io_ccache_iterator && *io_ccache_iterator) { - if ((*io_ccache_iterator)->context) { + if ((*io_ccache_iterator)->context) { if ((*io_ccache_iterator)->cursor) { - krb5_cccol_cursor_free ((*io_ccache_iterator)->context, + krb5_cccol_cursor_free ((*io_ccache_iterator)->context, &(*io_ccache_iterator)->cursor); } - krb5_free_context ((*io_ccache_iterator)->context); + krb5_free_context ((*io_ccache_iterator)->context); } free (*io_ccache_iterator); *io_ccache_iterator = NULL; @@ -165,16 +165,16 @@ static kim_error kim_ccache_create_resolve_name (kim_string *out_resolve_name, kim_string in_type) { kim_error err = KIM_NO_ERROR; - + if (!err && !out_resolve_name) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !in_name ) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !in_type ) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { - err = kim_string_create_from_format (out_resolve_name, "%s:%s", + err = kim_string_create_from_format (out_resolve_name, "%s:%s", in_type, in_name); } - + return check_error (err); } @@ -186,23 +186,23 @@ static inline kim_error kim_ccache_allocate (kim_ccache *out_ccache) { kim_error err = kim_library_init (); kim_ccache ccache = NULL; - + if (!err && !out_ccache) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { ccache = malloc (sizeof (*ccache)); if (!ccache) { err = KIM_OUT_OF_MEMORY_ERR; } } - + if (!err) { *ccache = kim_ccache_initializer; *out_ccache = ccache; ccache = NULL; } - + kim_ccache_free (&ccache); - - return check_error (err); + + return check_error (err); } /* ------------------------------------------------------------------------ */ @@ -227,27 +227,27 @@ kim_error kim_ccache_create_new_with_password (kim_ccache *out_ccache, kim_error err = KIM_NO_ERROR; kim_credential credential = NULL; kim_identity client_identity = NULL; - + if (!err && !out_ccache) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { - err = kim_credential_create_new_with_password (&credential, - in_client_identity, + err = kim_credential_create_new_with_password (&credential, + in_client_identity, in_options, in_password); } - + if (!err) { err = kim_credential_get_client_identity (credential, &client_identity); } - + if (!err) { err = kim_credential_store (credential, client_identity, out_ccache); } - + kim_identity_free (&client_identity); kim_credential_free (&credential); - + return check_error (err); } @@ -272,20 +272,20 @@ kim_error kim_ccache_create_new_if_needed_with_password (kim_ccache *out_ccach { kim_error err = KIM_NO_ERROR; kim_ccache ccache = NULL; - + if (!err && !out_ccache ) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !in_client_identity) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { kim_credential_state state; - - err = kim_ccache_create_from_client_identity (&ccache, + + err = kim_ccache_create_from_client_identity (&ccache, in_client_identity); - + if (!err) { err = kim_ccache_get_state (ccache, &state); } - + if (!err && state != kim_credentials_state_valid) { if (state == kim_credentials_state_needs_validation) { err = kim_ccache_validate (ccache, in_options); @@ -294,23 +294,23 @@ kim_error kim_ccache_create_new_if_needed_with_password (kim_ccache *out_ccach ccache = NULL; } } - + if (!ccache) { /* ccache does not already exist, create a new one */ - err = kim_ccache_create_new_with_password (&ccache, - in_client_identity, - in_options, + err = kim_ccache_create_new_with_password (&ccache, + in_client_identity, + in_options, in_password); - } + } } - + if (!err) { *out_ccache = ccache; ccache = NULL; } - + kim_ccache_free (&ccache); - + return check_error (err); } @@ -320,62 +320,62 @@ kim_error kim_ccache_create_from_client_identity (kim_ccache *out_ccache, kim_identity in_client_identity) { kim_error err = KIM_NO_ERROR; - + if (!err && !out_ccache) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err && in_client_identity) { kim_ccache_iterator iterator = NULL; kim_boolean found = FALSE; err = kim_ccache_iterator_create (&iterator); - + while (!err && !found) { kim_ccache ccache = NULL; kim_identity identity = NULL; kim_comparison comparison; - + err = kim_ccache_iterator_next (iterator, &ccache); - + if (!err && !ccache) { kim_string string = NULL; - - err = kim_identity_get_display_string (in_client_identity, + + err = kim_identity_get_display_string (in_client_identity, &string); - + if (!err) { - err = kim_error_set_message_for_code (KIM_NO_SUCH_PRINCIPAL_ERR, + err = kim_error_set_message_for_code (KIM_NO_SUCH_PRINCIPAL_ERR, string); } - + kim_string_free (&string); } - + if (!err) { err = kim_ccache_get_client_identity (ccache, &identity); } - + if (!err) { - err = kim_identity_compare (in_client_identity, identity, + err = kim_identity_compare (in_client_identity, identity, &comparison); } - + if (!err && kim_comparison_is_equal_to (comparison)) { found = 1; *out_ccache = ccache; ccache = NULL; } - + kim_identity_free (&identity); kim_ccache_free (&ccache); } - + kim_ccache_iterator_free (&iterator); - + } else if (!err) { /* in_client_identity is NULL, get default ccache */ err = kim_ccache_create_from_default (out_ccache); } - + return check_error (err); } @@ -391,25 +391,25 @@ kim_error kim_ccache_create_from_keytab (kim_ccache *out_ccache, kim_error err = KIM_NO_ERROR; kim_credential credential = NULL; kim_identity client_identity = NULL; - + if (!err && !out_ccache) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { - err = kim_credential_create_from_keytab (&credential, in_identity, + err = kim_credential_create_from_keytab (&credential, in_identity, in_options, in_keytab); } - + if (!err) { err = kim_credential_get_client_identity (credential, &client_identity); } - + if (!err) { err = kim_credential_store (credential, client_identity, out_ccache); } - + kim_identity_free (&client_identity); kim_credential_free (&credential); - + return check_error (err); } @@ -421,29 +421,29 @@ kim_error kim_ccache_create_from_default (kim_ccache *out_ccache) { kim_error err = KIM_NO_ERROR; kim_ccache ccache = NULL; - + if (!err && !out_ccache) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { err = kim_ccache_allocate (&ccache); } - + if (!err) { err = krb5_error (NULL, krb5_init_context (&ccache->context)); } - + if (!err) { err = krb5_error (ccache->context, krb5_cc_default (ccache->context, &ccache->ccache)); } - + if (!err) { *out_ccache = ccache; ccache = NULL; } - + kim_ccache_free (&ccache); - + return check_error (err); } @@ -454,31 +454,31 @@ kim_error kim_ccache_create_from_display_name (kim_ccache *out_ccache, { kim_error err = KIM_NO_ERROR; kim_ccache ccache = NULL; - + if (!err && !out_ccache ) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !in_display_name) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { err = kim_ccache_allocate (&ccache); } - + if (!err) { err = krb5_error (NULL, krb5_init_context (&ccache->context)); } - + if (!err) { err = krb5_error (ccache->context, - krb5_cc_resolve (ccache->context, in_display_name, + krb5_cc_resolve (ccache->context, in_display_name, &ccache->ccache)); } - + if (!err) { *out_ccache = ccache; ccache = NULL; } - + kim_ccache_free (&ccache); - + return check_error (err); } @@ -490,21 +490,21 @@ kim_error kim_ccache_create_from_type_and_name (kim_ccache *out_ccache, { kim_error err = KIM_NO_ERROR; kim_string resolve_name = NULL; - + if (!err && !out_ccache) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !in_name ) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !in_type ) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { err = kim_ccache_create_resolve_name (&resolve_name, in_name, in_type); } - + if (!err) { err = kim_ccache_create_from_display_name (out_ccache, resolve_name); } - + kim_string_free (&resolve_name); - + return check_error (err); } @@ -515,18 +515,18 @@ kim_error kim_ccache_create_from_krb5_ccache (kim_ccache *out_ccache, krb5_ccache in_krb5_ccache) { kim_error err = KIM_NO_ERROR; - + if (!err && !out_ccache ) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !in_krb5_ccache ) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !in_krb5_context) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { kim_string type = krb5_cc_get_type (in_krb5_context, in_krb5_ccache); kim_string name = krb5_cc_get_name (in_krb5_context, in_krb5_ccache); - + err = kim_ccache_create_from_type_and_name (out_ccache, type, name); } - + return check_error (err); } @@ -538,25 +538,25 @@ kim_error kim_ccache_copy (kim_ccache *out_ccache, kim_error err = KIM_NO_ERROR; kim_string name = NULL; kim_string type = NULL; - + if (!err && !out_ccache) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !in_ccache ) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { err = kim_ccache_get_name (in_ccache, &name); } - + if (!err) { err = kim_ccache_get_type (in_ccache, &type); } - + if (!err) { err = kim_ccache_create_from_type_and_name (out_ccache, type, name); } - + kim_string_free (&name); kim_string_free (&type); - + return check_error (err); } @@ -569,28 +569,28 @@ kim_error kim_ccache_compare (kim_ccache in_ccache, kim_comparison *out_comparison) { kim_error err = KIM_NO_ERROR; - + if (!err && !in_ccache ) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !in_compare_to_ccache) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !out_comparison ) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { - const char *type = krb5_cc_get_type (in_ccache->context, + const char *type = krb5_cc_get_type (in_ccache->context, in_ccache->ccache); - const char *compare_to_type = krb5_cc_get_type (in_compare_to_ccache->context, + const char *compare_to_type = krb5_cc_get_type (in_compare_to_ccache->context, in_compare_to_ccache->ccache); - const char *name = krb5_cc_get_name (in_ccache->context, + const char *name = krb5_cc_get_name (in_ccache->context, in_ccache->ccache); - const char *compare_to_name = krb5_cc_get_name (in_compare_to_ccache->context, + const char *compare_to_name = krb5_cc_get_name (in_compare_to_ccache->context, in_compare_to_ccache->ccache); - + *out_comparison = strcmp (type, compare_to_type); - + if (*out_comparison == 0) { *out_comparison = strcmp (name, compare_to_name); } } - + return check_error (err); } @@ -602,23 +602,23 @@ kim_error kim_ccache_get_krb5_ccache (kim_ccache in_ccache, { kim_error err = KIM_NO_ERROR; kim_string resolve_name = NULL; - + if (!err && !in_ccache ) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !in_krb5_context) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !out_krb5_ccache) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { err = kim_ccache_get_display_name (in_ccache, &resolve_name); } - + if (!err) { err = krb5_error (in_krb5_context, - krb5_cc_resolve (in_krb5_context, resolve_name, + krb5_cc_resolve (in_krb5_context, resolve_name, out_krb5_ccache)); } - + kim_string_free (&resolve_name); - + return check_error (err); } @@ -628,15 +628,15 @@ kim_error kim_ccache_get_type (kim_ccache in_ccache, kim_string *out_type) { kim_error err = KIM_NO_ERROR; - + if (!err && !in_ccache) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !out_type ) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { - err = kim_string_copy (out_type, krb5_cc_get_type (in_ccache->context, + err = kim_string_copy (out_type, krb5_cc_get_type (in_ccache->context, in_ccache->ccache)); } - + return check_error (err); } @@ -646,15 +646,15 @@ kim_error kim_ccache_get_name (kim_ccache in_ccache, kim_string *out_name) { kim_error err = KIM_NO_ERROR; - + if (!err && !in_ccache) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !out_name ) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { - err = kim_string_copy (out_name, krb5_cc_get_name (in_ccache->context, + err = kim_string_copy (out_name, krb5_cc_get_name (in_ccache->context, in_ccache->ccache)); } - + return check_error (err); } @@ -664,19 +664,19 @@ kim_error kim_ccache_get_display_name (kim_ccache in_ccache, kim_string *out_display_name) { kim_error err = KIM_NO_ERROR; - + if (!err && !in_ccache ) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !out_display_name) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { - kim_string type = krb5_cc_get_type (in_ccache->context, + kim_string type = krb5_cc_get_type (in_ccache->context, in_ccache->ccache); - kim_string name = krb5_cc_get_name (in_ccache->context, + kim_string name = krb5_cc_get_name (in_ccache->context, in_ccache->ccache); - + err = kim_ccache_create_resolve_name (out_display_name, name, type); } - + return check_error (err); } @@ -687,25 +687,25 @@ kim_error kim_ccache_get_client_identity (kim_ccache in_ccache, { kim_error err = KIM_NO_ERROR; krb5_principal principal = NULL; - + if (!err && !in_ccache ) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !out_client_identity) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { err = krb5_error (in_ccache->context, - krb5_cc_get_principal (in_ccache->context, - in_ccache->ccache, + krb5_cc_get_principal (in_ccache->context, + in_ccache->ccache, &principal)); } - + if (!err) { err = kim_identity_create_from_krb5_principal (out_client_identity, - in_ccache->context, + in_ccache->context, principal); } - + if (principal) { krb5_free_principal (in_ccache->context, principal); } - + return check_error (err); } @@ -723,110 +723,110 @@ static kim_error kim_ccache_get_dominant_credential (kim_ccache in_cc kim_boolean dominant_is_tgt = FALSE; kim_credential_state dominant_state = kim_credentials_state_valid; kim_credential dominant_credential = NULL; - + if (!err && !in_ccache) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { err = kim_credential_iterator_create (&iterator, in_ccache); } - + while (!err && !out_of_credentials && !found_valid_tgt) { kim_credential credential = NULL; - + err = kim_credential_iterator_next (iterator, &credential); - + if (!err && !credential) { out_of_credentials = TRUE; - + } else if (!err) { kim_credential_state state = kim_credentials_state_valid; kim_boolean is_tgt = FALSE; - + err = kim_credential_get_state (credential, &state); - + if (!err) { kim_identity service_identity = NULL; - - err = kim_credential_get_service_identity (credential, + + err = kim_credential_get_service_identity (credential, &service_identity); - + if (!err) { err = kim_identity_is_tgt_service (service_identity, &is_tgt); } - + kim_identity_free (&service_identity); } - + if (!err) { - /* There are three cases where we replace: + /* There are three cases where we replace: * 1) We don't have a dominant yet * 2) This is a tgt and dominant isn't * 3) Both are tgts but this is valid and dominant isn't */ - - if ((!dominant_credential) /* 1 */ || + + if ((!dominant_credential) /* 1 */ || (is_tgt && !dominant_is_tgt) /* 2 */ || - (is_tgt && dominant_is_tgt && /* 3 */ + (is_tgt && dominant_is_tgt && /* 3 */ state == kim_credentials_state_valid && dominant_state != kim_credentials_state_valid)) { /* replace */ kim_credential_free (&dominant_credential); - + dominant_credential = credential; credential = NULL; /* take ownership */ - + dominant_is_tgt = is_tgt; dominant_state = state; } - - if (dominant_is_tgt && + + if (dominant_is_tgt && dominant_state == kim_credentials_state_valid) { /* Since we will never replace a valid tgt, stop here */ found_valid_tgt = TRUE; } } } - + kim_credential_free (&credential); } - + if (!err && !dominant_credential) { kim_identity identity = NULL; kim_string identity_string = NULL; - + err = kim_ccache_get_client_identity (in_ccache, &identity); - + if (!err) { - err = kim_identity_get_display_string (identity, + err = kim_identity_get_display_string (identity, &identity_string); } - + if (!err) { - err = kim_error_set_message_for_code (KIM_NO_CREDENTIALS_ERR, + err = kim_error_set_message_for_code (KIM_NO_CREDENTIALS_ERR, identity_string); - } + } kim_string_free (&identity_string); kim_identity_free (&identity); } - + if (!err) { if (out_is_tgt) { *out_is_tgt = dominant_is_tgt; } - + if (out_state) { *out_state = dominant_state; } - + if (out_credential) { *out_credential = dominant_credential; dominant_credential = NULL; /* take ownership */ } } - + kim_credential_free (&dominant_credential); kim_credential_iterator_free (&iterator); - + return check_error (err); } @@ -839,57 +839,57 @@ kim_error kim_ccache_get_valid_credential (kim_ccache in_ccache, kim_boolean is_tgt = FALSE; kim_credential_state state = kim_credentials_state_valid; kim_credential credential = NULL; - + if (!err && !in_ccache ) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !out_credential) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { - err = kim_ccache_get_dominant_credential (in_ccache, + err = kim_ccache_get_dominant_credential (in_ccache, &state, &is_tgt, &credential); } - + if (!err && state != kim_credentials_state_valid) { kim_identity identity = NULL; kim_string identity_string = NULL; - + err = kim_ccache_get_client_identity (in_ccache, &identity); - + if (!err) { - err = kim_identity_get_display_string (identity, + err = kim_identity_get_display_string (identity, &identity_string); } - + if (!err) { if (state == kim_credentials_state_expired) { - err = kim_error_set_message_for_code (KIM_CREDENTIALS_EXPIRED_ERR, + err = kim_error_set_message_for_code (KIM_CREDENTIALS_EXPIRED_ERR, identity_string); - + } else if (state == kim_credentials_state_not_yet_valid || state == kim_credentials_state_needs_validation) { - err = kim_error_set_message_for_code (KIM_NEEDS_VALIDATION_ERR, + err = kim_error_set_message_for_code (KIM_NEEDS_VALIDATION_ERR, identity_string); - + } else if (state == kim_credentials_state_address_mismatch) { - err = kim_error_set_message_for_code (KIM_BAD_IP_ADDRESS_ERR, - identity_string); + err = kim_error_set_message_for_code (KIM_BAD_IP_ADDRESS_ERR, + identity_string); } else { /* just default to this */ - err = kim_error_set_message_for_code (KIM_NEEDS_VALIDATION_ERR, + err = kim_error_set_message_for_code (KIM_NEEDS_VALIDATION_ERR, identity_string); } } - + kim_string_free (&identity_string); kim_identity_free (&identity); } - + if (!err) { *out_credential = credential; credential = NULL; /* take ownership */ } - + kim_credential_free (&credential); - + return check_error (err); } @@ -899,16 +899,16 @@ kim_error kim_ccache_get_state (kim_ccache in_ccache, kim_credential_state *out_state) { kim_error err = KIM_NO_ERROR; - + if (!err && !in_ccache) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !out_state) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { - err = kim_ccache_get_dominant_credential (in_ccache, + err = kim_ccache_get_dominant_credential (in_ccache, out_state, NULL, NULL); } - - return check_error (err); + + return check_error (err); } /* ------------------------------------------------------------------------ */ @@ -918,21 +918,21 @@ kim_error kim_ccache_get_start_time (kim_ccache in_ccache, { kim_error err = KIM_NO_ERROR; kim_credential credential = NULL; - + if (!err && !in_ccache ) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !out_start_time) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { - err = kim_ccache_get_dominant_credential (in_ccache, NULL, NULL, + err = kim_ccache_get_dominant_credential (in_ccache, NULL, NULL, &credential); } - + if (!err) { err = kim_credential_get_start_time (credential, out_start_time); } - + kim_credential_free (&credential); - + return check_error (err); } @@ -943,22 +943,22 @@ kim_error kim_ccache_get_expiration_time (kim_ccache in_ccache, { kim_error err = KIM_NO_ERROR; kim_credential credential = NULL; - + if (!err && !in_ccache ) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !out_expiration_time) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { - err = kim_ccache_get_dominant_credential (in_ccache, NULL, NULL, + err = kim_ccache_get_dominant_credential (in_ccache, NULL, NULL, &credential); } - + if (!err) { - err = kim_credential_get_expiration_time (credential, + err = kim_credential_get_expiration_time (credential, out_expiration_time); } - + kim_credential_free (&credential); - + return check_error (err); } @@ -969,22 +969,22 @@ kim_error kim_ccache_get_renewal_expiration_time (kim_ccache in_ccache, { kim_error err = KIM_NO_ERROR; kim_credential credential = NULL; - + if (!err && !in_ccache ) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !out_renewal_expiration_time) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { - err = kim_ccache_get_dominant_credential (in_ccache, NULL, NULL, + err = kim_ccache_get_dominant_credential (in_ccache, NULL, NULL, &credential); } - + if (!err) { - err = kim_credential_get_renewal_expiration_time (credential, + err = kim_credential_get_renewal_expiration_time (credential, out_renewal_expiration_time); } - + kim_credential_free (&credential); - + return check_error (err); } @@ -995,21 +995,21 @@ kim_error kim_ccache_get_options (kim_ccache in_ccache, { kim_error err = KIM_NO_ERROR; kim_credential credential = NULL; - + if (!err && !in_ccache ) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !out_options) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { - err = kim_ccache_get_dominant_credential (in_ccache, NULL, NULL, + err = kim_ccache_get_dominant_credential (in_ccache, NULL, NULL, &credential); } - + if (!err) { err = kim_credential_get_options (credential, out_options); } - + kim_credential_free (&credential); - + return check_error (err); } @@ -1020,104 +1020,104 @@ kim_error kim_ccache_get_options (kim_ccache in_ccache, kim_error kim_ccache_set_default (kim_ccache io_ccache) { kim_error err = KIM_NO_ERROR; - + if (!err && !io_ccache) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { char *environment_ccache_name = getenv ("KRB5CCNAME"); - + if (environment_ccache_name) { kim_ccache environment_ccache = NULL; kim_comparison comparison; - + err = kim_ccache_create_from_display_name (&environment_ccache, environment_ccache_name); - + if (!err) { - err = kim_ccache_compare (io_ccache, + err = kim_ccache_compare (io_ccache, environment_ccache, &comparison); } - + if (!err && !kim_comparison_is_equal_to (comparison)) { krb5_principal client_principal = NULL; - /* KRB5CCNAME is set and does not point to this ccache. + /* KRB5CCNAME is set and does not point to this ccache. * Move the creds and make this kim_ccache_t object refer to that ccache. */ - + err = krb5_error (io_ccache->context, - krb5_cc_get_principal (io_ccache->context, - io_ccache->ccache, + krb5_cc_get_principal (io_ccache->context, + io_ccache->ccache, &client_principal)); - + if (!err) { err = krb5_error (io_ccache->context, - krb5_cc_initialize (environment_ccache->context, - environment_ccache->ccache, + krb5_cc_initialize (environment_ccache->context, + environment_ccache->ccache, client_principal)); } - + if (!err) { err = krb5_error (io_ccache->context, - krb5_cc_copy_creds (io_ccache->context, - io_ccache->ccache, + krb5_cc_copy_creds (io_ccache->context, + io_ccache->ccache, environment_ccache->ccache)); } - - if (client_principal) { krb5_free_principal (io_ccache->context, + + if (client_principal) { krb5_free_principal (io_ccache->context, client_principal); } - + if (!err) { kim_ccache_destroy (&io_ccache); io_ccache = environment_ccache; environment_ccache = NULL; /* take ownership */ } } - + kim_ccache_free (&environment_ccache); - + } else { #ifdef USE_CCAPI kim_string type = NULL; kim_string name = NULL; cc_context_t cc_context = NULL; cc_ccache_t cc_ccache = NULL; - + err = kim_ccache_get_type (io_ccache, &type); - + if (!err && strcmp (type, "API")) { #endif kim_string display_name = NULL; /* Not a CCAPI ccache; can't set to default */ - + err = kim_ccache_get_display_name (io_ccache, &display_name); - + if (!err) { - err = kim_error_set_message_for_code (KIM_CANT_BECOME_DEFAULT_ERR, + err = kim_error_set_message_for_code (KIM_CANT_BECOME_DEFAULT_ERR, display_name); } - + kim_string_free (&display_name); #ifdef USE_CCAPI } - + if (!err) { err = kim_ccache_get_name (io_ccache, &name); } - + /* get a CCAPI ccache for this cache */ if (!err) { err = cc_initialize (&cc_context, ccapi_version_4, NULL, NULL); } - + if (!err) { err = cc_context_open_ccache (cc_context, name, &cc_ccache); } - + if (!err) { err = cc_ccache_set_default (cc_ccache); } - + if (cc_context) { cc_context_release (cc_context); } if (cc_ccache ) { cc_ccache_release (cc_ccache); } kim_string_free (&name); @@ -1125,7 +1125,7 @@ kim_error kim_ccache_set_default (kim_ccache io_ccache) #endif } } - + return check_error (err); } @@ -1140,20 +1140,20 @@ kim_error kim_ccache_verify (kim_ccache in_ccache, { kim_error err = KIM_NO_ERROR; kim_credential credential = NULL; - + if (!err && !in_ccache) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { err = kim_ccache_get_valid_credential (in_ccache, &credential); } - + if (!err) { - err = kim_credential_verify (credential, in_service_identity, + err = kim_credential_verify (credential, in_service_identity, in_keytab, in_fail_if_no_service_key); } - + kim_credential_free (&credential); - + return check_error (err); } @@ -1167,28 +1167,28 @@ kim_error kim_ccache_renew (kim_ccache in_ccache, kim_error err = KIM_NO_ERROR; kim_credential credential = NULL; kim_identity client_identity = NULL; - + if (!err && !in_ccache) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { err = kim_ccache_get_valid_credential (in_ccache, &credential); } - + if (!err) { err = kim_credential_renew (&credential, in_options); } - + if (!err) { err = kim_ccache_get_client_identity (in_ccache, &client_identity); } - + if (!err) { err = kim_credential_store (credential, client_identity, NULL); } - + kim_identity_free (&client_identity); kim_credential_free (&credential); - + return check_error (err); } @@ -1200,28 +1200,28 @@ kim_error kim_ccache_validate (kim_ccache in_ccache, kim_error err = KIM_NO_ERROR; kim_credential credential = NULL; kim_identity client_identity = NULL; - + if (!err && !in_ccache) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { err = kim_ccache_get_valid_credential (in_ccache, &credential); } - + if (!err) { err = kim_credential_validate (&credential, in_options); } - + if (!err) { err = kim_ccache_get_client_identity (in_ccache, &client_identity); } - + if (!err) { err = kim_credential_store (credential, client_identity, NULL); } - + kim_identity_free (&client_identity); kim_credential_free (&credential); - + return check_error (err); } @@ -1232,18 +1232,18 @@ kim_error kim_ccache_validate (kim_ccache in_ccache, kim_error kim_ccache_destroy (kim_ccache *io_ccache) { kim_error err = KIM_NO_ERROR; - + if (io_ccache && *io_ccache) { err = krb5_error ((*io_ccache)->context, - krb5_cc_destroy ((*io_ccache)->context, + krb5_cc_destroy ((*io_ccache)->context, (*io_ccache)->ccache)); - - if (!err) { - (*io_ccache)->ccache = NULL; + + if (!err) { + (*io_ccache)->ccache = NULL; kim_ccache_free (io_ccache); } } - + return check_error (err); } @@ -1252,14 +1252,13 @@ kim_error kim_ccache_destroy (kim_ccache *io_ccache) void kim_ccache_free (kim_ccache *io_ccache) { if (io_ccache && *io_ccache) { - if ((*io_ccache)->context) { + if ((*io_ccache)->context) { if ((*io_ccache)->ccache) { krb5_cc_close ((*io_ccache)->context, (*io_ccache)->ccache); } - krb5_free_context ((*io_ccache)->context); + krb5_free_context ((*io_ccache)->context); } free (*io_ccache); *io_ccache = NULL; } } - diff --git a/src/kim/lib/kim_credential.c b/src/kim/lib/kim_credential.c index 8d2c1ee608..fe910cf042 100644 --- a/src/kim/lib/kim_credential.c +++ b/src/kim/lib/kim_credential.c @@ -8,7 +8,7 @@ * 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 @@ -43,42 +43,42 @@ kim_error kim_credential_iterator_create (kim_credential_iterator *out_credentia { kim_error err = kim_library_init (); kim_credential_iterator credential_iterator = NULL; - + if (!err && !out_credential_iterator) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !in_ccache ) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { credential_iterator = malloc (sizeof (*credential_iterator)); - if (credential_iterator) { + if (credential_iterator) { *credential_iterator = kim_credential_iterator_initializer; } else { - err = KIM_OUT_OF_MEMORY_ERR; + err = KIM_OUT_OF_MEMORY_ERR; } } - + if (!err) { err = krb5_error (NULL, krb5_init_context (&credential_iterator->context)); } - + if (!err) { err = kim_ccache_get_krb5_ccache (in_ccache, credential_iterator->context, &credential_iterator->ccache); } - + if (!err) { /* Turn off OPENCLOSE mode */ err = krb5_error (credential_iterator->context, krb5_cc_get_flags (credential_iterator->context, credential_iterator->ccache, &credential_iterator->old_flags)); - + if (!err && credential_iterator->old_flags & KRB5_TC_OPENCLOSE) { krb5_flags new_flags = credential_iterator->old_flags & ~KRB5_TC_OPENCLOSE; - + err = krb5_error (credential_iterator->context, - krb5_cc_set_flags (credential_iterator->context, - credential_iterator->ccache, + krb5_cc_set_flags (credential_iterator->context, + credential_iterator->ccache, new_flags)); if (err == KRB5_FCC_NOFILE) { err = KIM_NO_ERROR; } } @@ -86,18 +86,18 @@ kim_error kim_credential_iterator_create (kim_credential_iterator *out_credentia if (!err) { err = krb5_error (credential_iterator->context, - krb5_cc_start_seq_get (credential_iterator->context, + krb5_cc_start_seq_get (credential_iterator->context, credential_iterator->ccache, &credential_iterator->cursor)); } - + if (!err) { *out_credential_iterator = credential_iterator; credential_iterator = NULL; } - + kim_credential_iterator_free (&credential_iterator); - + return check_error (err); } @@ -107,33 +107,33 @@ kim_error kim_credential_iterator_next (kim_credential_iterator in_credential_i kim_credential *out_credential) { kim_error err = KIM_NO_ERROR; - + if (!err && !in_credential_iterator) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !out_credential ) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { krb5_creds creds; - - krb5_error_code terr = krb5_cc_next_cred (in_credential_iterator->context, + + krb5_error_code terr = krb5_cc_next_cred (in_credential_iterator->context, in_credential_iterator->ccache, &in_credential_iterator->cursor, &creds); - + if (!terr) { err = kim_credential_create_from_krb5_creds (out_credential, in_credential_iterator->context, &creds); - + krb5_free_cred_contents (in_credential_iterator->context, &creds); - + } else if (terr == KRB5_CC_END) { *out_credential = NULL; /* no more ccaches */ - + } else { err = krb5_error (in_credential_iterator->context, terr); } } - + return check_error (err); } @@ -142,21 +142,21 @@ kim_error kim_credential_iterator_next (kim_credential_iterator in_credential_i void kim_credential_iterator_free (kim_credential_iterator *io_credential_iterator) { if (io_credential_iterator && *io_credential_iterator) { - if ((*io_credential_iterator)->context) { + if ((*io_credential_iterator)->context) { if ((*io_credential_iterator)->ccache) { if ((*io_credential_iterator)->cursor) { - krb5_cc_end_seq_get ((*io_credential_iterator)->context, + krb5_cc_end_seq_get ((*io_credential_iterator)->context, (*io_credential_iterator)->ccache, &(*io_credential_iterator)->cursor); - krb5_cc_set_flags ((*io_credential_iterator)->context, - (*io_credential_iterator)->ccache, + krb5_cc_set_flags ((*io_credential_iterator)->context, + (*io_credential_iterator)->ccache, (*io_credential_iterator)->old_flags); } - krb5_cc_close ((*io_credential_iterator)->context, + krb5_cc_close ((*io_credential_iterator)->context, (*io_credential_iterator)->ccache); } - krb5_free_context ((*io_credential_iterator)->context); + krb5_free_context ((*io_credential_iterator)->context); } free (*io_credential_iterator); *io_credential_iterator = NULL; @@ -180,23 +180,23 @@ static inline kim_error kim_credential_allocate (kim_credential *out_credential) { kim_error err = kim_library_init (); kim_credential credential = NULL; - + if (!err && !out_credential) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { credential = malloc (sizeof (*credential)); if (!credential) { err = KIM_OUT_OF_MEMORY_ERR; } } - + if (!err) { *credential = kim_credential_initializer; *out_credential = credential; credential = NULL; } - + kim_credential_free (&credential); - - return check_error (err); + + return check_error (err); } /* ------------------------------------------------------------------------ */ @@ -220,34 +220,34 @@ static void kim_credential_remember_prefs (kim_identity in_identity, kim_preferences prefs = NULL; kim_boolean remember_identity = 0; kim_boolean remember_options = 0; - + err = kim_preferences_create (&prefs); - + if (!err && in_options) { - err = kim_preferences_get_remember_options (prefs, + err = kim_preferences_get_remember_options (prefs, &remember_options); } - + if (!err && in_identity) { - err = kim_preferences_get_remember_client_identity (prefs, + err = kim_preferences_get_remember_client_identity (prefs, &remember_identity); } - + if (!err && remember_options) { err = kim_preferences_set_options (prefs, in_options); } - + if (!err && remember_identity) { err = kim_preferences_set_client_identity (prefs, in_identity); - - } - + + } + if (!err && (remember_options || remember_identity)) { err = kim_preferences_synchronize (prefs); } - + kim_preferences_free (&prefs); - + check_error (err); } @@ -266,15 +266,15 @@ kim_error kim_credential_create_new_with_password (kim_credential *out_credentia kim_boolean done_with_identity = 0; if (!err && !out_credential) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { err = kim_credential_allocate (&credential); } - + if (!err) { err = krb5_error (NULL, krb5_init_context (&credential->context)); } - + if (!err) { if (in_options) { options = in_options; @@ -282,48 +282,48 @@ kim_error kim_credential_create_new_with_password (kim_credential *out_credentia err = kim_options_create (&options); } } - + if (!err) { err = kim_ui_init (&context); if (!err) { ui_inited = 1; } } - + while (!err && !done_with_identity) { kim_identity identity = in_identity; kim_boolean done_with_credentials = 0; if (identity) { done_with_identity = 1; - + } else while (!err && !identity) { kim_boolean user_wants_change_password = 0; - - err = kim_ui_enter_identity (&context, options, - &identity, + + err = kim_ui_enter_identity (&context, options, + &identity, &user_wants_change_password); - + if (!err && user_wants_change_password) { - err = kim_identity_change_password_common (identity, 0, - &context, + err = kim_identity_change_password_common (identity, 0, + &context, NULL); - + /* reenter enter_identity so just forget this identity * even if we got an error */ - if (err == KIM_USER_CANCELED_ERR || - err == KIM_DUPLICATE_UI_REQUEST_ERR) { - err = KIM_NO_ERROR; + if (err == KIM_USER_CANCELED_ERR || + err == KIM_DUPLICATE_UI_REQUEST_ERR) { + err = KIM_NO_ERROR; } - + kim_identity_free (&identity); } - + } - + if (!err) { context.identity = identity; /* used by kim_ui_prompter */ } - - while (!err && !done_with_credentials) { + + while (!err && !done_with_credentials) { krb5_creds creds; kim_boolean free_creds = 0; kim_count prompt_count; @@ -331,149 +331,149 @@ kim_error kim_credential_create_new_with_password (kim_credential *out_credentia krb5_get_init_creds_opt *opts = kim_options_init_cred_options (options); char *service = kim_options_service_name (options); kim_time start_time = kim_options_start_time (options); - + /* set counter to zero so we can tell if we got prompted */ context.prompt_count = 0; context.password_to_save = NULL; - + err = krb5_error (credential->context, - krb5_get_init_creds_password (credential->context, + krb5_get_init_creds_password (credential->context, &creds, principal, - (char *) in_password, - kim_ui_prompter, + (char *) in_password, + kim_ui_prompter, &context, - start_time, - service, + start_time, + service, opts)); - + prompt_count = context.prompt_count; /* remember if we got prompts */ if (!err) { free_creds = 1; } - + if (!err) { err = krb5_error (credential->context, krb5_copy_creds (credential->context, - &creds, + &creds, &credential->creds)); } - + if (!err && context.password_to_save) { /* If we were successful, save any password we got */ err = kim_os_identity_set_saved_password (identity, context.password_to_save); - - - } - + + + } + if (err == KRB5KDC_ERR_KEY_EXP) { kim_string new_password = NULL; - - err = kim_identity_change_password_common (identity, 1, - &context, + + err = kim_identity_change_password_common (identity, 1, + &context, &new_password); - + if (!err) { /* set counter to zero so we can tell if we got prompted */ context.prompt_count = 0; - + err = krb5_error (credential->context, - krb5_get_init_creds_password (credential->context, + krb5_get_init_creds_password (credential->context, &creds, principal, - (char *) new_password, - kim_ui_prompter, + (char *) new_password, + kim_ui_prompter, &context, - start_time, - service, + start_time, + service, opts)); - + prompt_count = context.prompt_count; /* remember if we got prompts */ if (!err) { free_creds = 1; } - + if (!err) { err = krb5_error (credential->context, krb5_copy_creds (credential->context, - &creds, + &creds, &credential->creds)); - } + } } - + kim_string_free (&new_password); } - - if (!err || err == KIM_USER_CANCELED_ERR || + + if (!err || err == KIM_USER_CANCELED_ERR || err == KIM_DUPLICATE_UI_REQUEST_ERR) { /* new creds obtained or the user gave up */ done_with_credentials = 1; - + if (!err) { /* remember identity and options if the user wanted to */ kim_credential_remember_prefs (identity, options); } - - if (err == KIM_DUPLICATE_UI_REQUEST_ERR) { + + if (err == KIM_DUPLICATE_UI_REQUEST_ERR) { kim_ccache ccache = NULL; - /* credential for this identity was obtained, but via a different + /* credential for this identity was obtained, but via a different * dialog. Find it. */ - - err = kim_ccache_create_from_client_identity (&ccache, + + err = kim_ccache_create_from_client_identity (&ccache, identity); - + if (!err) { - err = kim_ccache_get_valid_credential (ccache, + err = kim_ccache_get_valid_credential (ccache, &credential); } - + kim_ccache_free (&ccache); - } - + } + } else if (prompt_count) { - /* User was prompted and might have entered bad info + /* User was prompted and might have entered bad info * so report error and try again. */ - - err = kim_ui_handle_kim_error (&context, identity, + + err = kim_ui_handle_kim_error (&context, identity, kim_ui_error_type_authentication, err); } - - if (err == KRB5KRB_AP_ERR_BAD_INTEGRITY || + + if (err == KRB5KRB_AP_ERR_BAD_INTEGRITY || err == KRB5KDC_ERR_PREAUTH_FAILED || err == KIM_BAD_PASSWORD_ERR || err == KIM_PREAUTH_FAILED_ERR) { /* if the password could have failed, remove any saved ones * or the user will get stuck. */ kim_os_identity_remove_saved_password (identity); } - + if (free_creds) { krb5_free_cred_contents (credential->context, &creds); } } - + if (!err || err == KIM_USER_CANCELED_ERR) { /* identity obtained or the user gave up */ done_with_identity = 1; - + } else if (!in_identity) { /* User entered an identity so report error and try again */ - err = kim_ui_handle_kim_error (&context, identity, + err = kim_ui_handle_kim_error (&context, identity, kim_ui_error_type_authentication, err); - } - + } + if (identity != in_identity) { kim_identity_free (&identity); } } - + if (ui_inited) { kim_error fini_err = kim_ui_fini (&context); if (!err) { err = check_error (fini_err); } } - + if (!err) { *out_credential = credential; credential = NULL; } - + if (options != in_options) { kim_options_free (&options); } kim_credential_free (&credential); - + return check_error (err); } @@ -493,91 +493,91 @@ kim_error kim_credential_create_from_keytab (kim_credential *out_credential, kim_boolean free_creds = FALSE; krb5_principal principal = NULL; kim_options options = in_options; - + if (!err && !out_credential) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { err = kim_credential_allocate (&credential); } - + if (!err) { err = krb5_error (NULL, krb5_init_context (&credential->context)); } - + if (!err && !options) { err = kim_options_create (&options); } - + if (!err) { if (in_keytab) { err = krb5_error (credential->context, - krb5_kt_resolve (credential->context, + krb5_kt_resolve (credential->context, in_keytab, &keytab)); } else { err = krb5_error (credential->context, krb5_kt_default (credential->context, &keytab)); } } - + if (!err) { if (in_identity) { - err = kim_identity_get_krb5_principal (in_identity, - credential->context, + err = kim_identity_get_krb5_principal (in_identity, + credential->context, &principal); } else { krb5_kt_cursor cursor = NULL; krb5_keytab_entry entry; kim_boolean entry_allocated = FALSE; - + err = krb5_error (credential->context, - krb5_kt_start_seq_get (credential->context, - keytab, + krb5_kt_start_seq_get (credential->context, + keytab, &cursor)); - + if (!err) { err = krb5_error (credential->context, - krb5_kt_next_entry (credential->context, - keytab, - &entry, + krb5_kt_next_entry (credential->context, + keytab, + &entry, &cursor)); entry_allocated = (err == KIM_NO_ERROR); /* remember to free later */ } - + if (!err) { err = krb5_error (credential->context, - krb5_copy_principal (credential->context, - entry.principal, + krb5_copy_principal (credential->context, + entry.principal, &principal)); } - + if (entry_allocated) { krb5_free_keytab_entry_contents (credential->context, &entry); } if (cursor ) { krb5_kt_end_seq_get (credential->context, keytab, &cursor); } } } - + if (!err) { krb5_get_init_creds_opt *opts = kim_options_init_cred_options (options); char *service = kim_options_service_name (options); kim_time start_time = kim_options_start_time (options); - + err = krb5_error (credential->context, - krb5_get_init_creds_keytab (credential->context, - &creds, - principal, - keytab, - start_time, - service, + krb5_get_init_creds_keytab (credential->context, + &creds, + principal, + keytab, + start_time, + service, opts)); if (!err) { free_creds = TRUE; } } - + if (!err) { err = krb5_error (credential->context, krb5_copy_creds (credential->context, - &creds, + &creds, &credential->creds)); } - + if (principal ) { krb5_free_principal (credential->context, principal); } if (free_creds) { krb5_free_cred_contents (credential->context, &creds); } @@ -585,10 +585,10 @@ kim_error kim_credential_create_from_keytab (kim_credential *out_credential, *out_credential = credential; credential = NULL; } - + if (options != in_options) { kim_options_free (&options); } kim_credential_free (&credential); - + return check_error (err); } @@ -602,33 +602,33 @@ kim_error kim_credential_create_from_krb5_creds (kim_credential *out_credential, { kim_error err = KIM_NO_ERROR; kim_credential credential = NULL; - + if (!err && !out_credential ) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !in_krb5_creds ) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !in_krb5_context) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { err = kim_credential_allocate (&credential); } - + if (!err) { - err = krb5_error (in_krb5_context, + err = krb5_error (in_krb5_context, krb5_copy_context (in_krb5_context, &credential->context)); } - + if (!err) { err = krb5_error (credential->context, - krb5_copy_creds (credential->context, - in_krb5_creds, + krb5_copy_creds (credential->context, + in_krb5_creds, &credential->creds)); } - + if (!err) { *out_credential = credential; credential = NULL; } - + return check_error (err); } /* ------------------------------------------------------------------------ */ @@ -644,76 +644,76 @@ kim_error kim_credential_create_for_change_password (kim_credential *out_creden kim_string realm = NULL; kim_string service = NULL; kim_string service_format = "kadmin/changepw@%s"; - + if (!err && !out_credential ) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !in_identity ) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !in_old_password ) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !out_user_was_prompted) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { err = kim_credential_allocate (&credential); } - + if (!err) { err = krb5_error (NULL, krb5_init_context (&credential->context)); } - + if (!err) { err = kim_identity_get_realm (in_identity, &realm); } - + if (!err) { err = kim_string_create_from_format (&service, service_format, realm); } - + if (!err) { krb5_creds creds; kim_boolean free_creds = 0; krb5_principal principal = kim_identity_krb5_principal (in_identity); krb5_get_init_creds_opt opts; - + krb5_get_init_creds_opt_init (&opts); krb5_get_init_creds_opt_set_tkt_life (&opts, 5*60); krb5_get_init_creds_opt_set_renew_life (&opts, 0); krb5_get_init_creds_opt_set_forwardable (&opts, 0); krb5_get_init_creds_opt_set_proxiable (&opts, 0); - + /* set counter to zero so we can tell if we got prompted */ - in_ui_context->prompt_count = 0; + in_ui_context->prompt_count = 0; in_ui_context->identity = in_identity; err = krb5_error (credential->context, - krb5_get_init_creds_password (credential->context, + krb5_get_init_creds_password (credential->context, &creds, principal, - (char *) in_old_password, - kim_ui_prompter, - in_ui_context, 0, - (char *) service, - &opts)); - + (char *) in_old_password, + kim_ui_prompter, + in_ui_context, 0, + (char *) service, + &opts)); + if (!err) { free_creds = 1; } - + if (!err) { err = krb5_error (credential->context, krb5_copy_creds (credential->context, - &creds, + &creds, &credential->creds)); } - + if (free_creds) { krb5_free_cred_contents (credential->context, &creds); } } - + if (!err) { *out_user_was_prompted = (in_ui_context->prompt_count > 0); *out_credential = credential; credential = NULL; } - + kim_string_free (&realm); kim_string_free (&service); kim_credential_free (&credential); - + return check_error (err); } @@ -724,32 +724,32 @@ kim_error kim_credential_copy (kim_credential *out_credential, { kim_error err = KIM_NO_ERROR; kim_credential credential = NULL; - + if (!err && !out_credential) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !in_credential ) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { err = kim_credential_allocate (&credential); } - + if (!err) { - err = krb5_error (in_credential->context, + err = krb5_error (in_credential->context, krb5_copy_context (in_credential->context, &credential->context)); } - + if (!err) { err = krb5_error (credential->context, - krb5_copy_creds (credential->context, - in_credential->creds, + krb5_copy_creds (credential->context, + in_credential->creds, &credential->creds)); } - + if (!err) { *out_credential = credential; credential = NULL; } - + return check_error (err); } @@ -760,18 +760,18 @@ kim_error kim_credential_get_krb5_creds (kim_credential in_credential, krb5_creds **out_krb5_creds) { kim_error err = KIM_NO_ERROR; - + if (!err && !in_credential ) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !in_krb5_context) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !out_krb5_creds ) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { err = krb5_error (in_krb5_context, - krb5_copy_creds (in_krb5_context, - in_credential->creds, + krb5_copy_creds (in_krb5_context, + in_credential->creds, out_krb5_creds)); } - + return check_error (err); } @@ -781,16 +781,16 @@ kim_error kim_credential_get_client_identity (kim_credential in_credential, kim_identity *out_client_identity) { kim_error err = KIM_NO_ERROR; - + if (!err && !in_credential ) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !out_client_identity) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { err = kim_identity_create_from_krb5_principal (out_client_identity, in_credential->context, in_credential->creds->client); } - + return check_error (err); } @@ -800,16 +800,16 @@ kim_error kim_credential_get_service_identity (kim_credential in_credential, kim_identity *out_service_identity) { kim_error err = KIM_NO_ERROR; - + if (!err && !in_credential ) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !out_service_identity) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { err = kim_identity_create_from_krb5_principal (out_service_identity, in_credential->context, in_credential->creds->server); } - + return check_error (err); } @@ -820,20 +820,20 @@ kim_error kim_credential_is_tgt (kim_credential in_credential, { kim_error err = KIM_NO_ERROR; kim_identity service = NULL; - + if (!err && !in_credential) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !out_is_tgt ) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { err = kim_credential_get_service_identity (in_credential, &service); } - + if (!err) { err = kim_identity_is_tgt_service (service, out_is_tgt); } - + kim_identity_free (&service); - + return check_error (err); } @@ -846,70 +846,70 @@ kim_error kim_credential_get_state (kim_credential in_credential, kim_time expiration_time = 0; kim_time start_time = 0; krb5_timestamp now = 0; - + if (!err && !in_credential) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !out_state ) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { err = kim_credential_get_expiration_time (in_credential, &expiration_time); } - + if (!err) { err = kim_credential_get_start_time (in_credential, &start_time); } - + if (!err) { krb5_int32 usec; - + err = krb5_error (in_credential->context, - krb5_us_timeofday (in_credential->context, + krb5_us_timeofday (in_credential->context, &now, &usec)); } - + if (!err) { *out_state = kim_credentials_state_valid; - + if (expiration_time <= now) { *out_state = kim_credentials_state_expired; - - } else if ((in_credential->creds->ticket_flags & TKT_FLG_POSTDATED) && + + } else if ((in_credential->creds->ticket_flags & TKT_FLG_POSTDATED) && (in_credential->creds->ticket_flags & TKT_FLG_INVALID)) { - if (start_time > now) { + if (start_time > now) { *out_state = kim_credentials_state_not_yet_valid; } else { *out_state = kim_credentials_state_needs_validation; } - + } else if (in_credential->creds->addresses) { /* ticket contains addresses */ krb5_address **laddresses = NULL; - - krb5_error_code code = krb5_os_localaddr (in_credential->context, + + krb5_error_code code = krb5_os_localaddr (in_credential->context, &laddresses); if (!code) { laddresses = NULL; } - + if (laddresses) { /* assume valid if the local host has no addresses */ kim_boolean found_match = FALSE; kim_count i = 0; - + for (i = 0; in_credential->creds->addresses[i]; i++) { - if (!krb5_address_search (in_credential->context, - in_credential->creds->addresses[i], + if (!krb5_address_search (in_credential->context, + in_credential->creds->addresses[i], laddresses)) { found_match = TRUE; break; } } - + if (!found_match) { *out_state = kim_credentials_state_address_mismatch; } } - - if (laddresses) { krb5_free_addresses (in_credential->context, + + if (laddresses) { krb5_free_addresses (in_credential->context, laddresses); } } } - + return check_error (err); } @@ -919,16 +919,16 @@ kim_error kim_credential_get_start_time (kim_credential in_credential, kim_time *out_start_time) { kim_error err = KIM_NO_ERROR; - + if (!err && !in_credential ) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !out_start_time) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { - *out_start_time = (in_credential->creds->times.starttime ? + *out_start_time = (in_credential->creds->times.starttime ? in_credential->creds->times.starttime : in_credential->creds->times.authtime); } - + return check_error (err); } @@ -938,13 +938,13 @@ kim_error kim_credential_get_expiration_time (kim_credential in_credential, kim_time *out_expiration_time) { kim_error err = KIM_NO_ERROR; - + if (!err && !in_credential) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { *out_expiration_time = in_credential->creds->times.endtime; } - + return check_error (err); } @@ -954,10 +954,10 @@ kim_error kim_credential_get_renewal_expiration_time (kim_credential in_credent kim_time *out_renewal_expiration_time) { kim_error err = KIM_NO_ERROR; - + if (!err && !in_credential ) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !out_renewal_expiration_time) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { if (in_credential->creds->ticket_flags & TKT_FLG_RENEWABLE) { *out_renewal_expiration_time = in_credential->creds->times.renew_till; @@ -965,7 +965,7 @@ kim_error kim_credential_get_renewal_expiration_time (kim_credential in_credent *out_renewal_expiration_time = 0; } } - + return check_error (err); } @@ -977,95 +977,95 @@ kim_error kim_credential_get_options (kim_credential in_credential, kim_error err = KIM_NO_ERROR; kim_options options = NULL; krb5_creds *creds = NULL; - + if (!err && !in_credential) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !out_options ) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { creds = in_credential->creds; - + err = kim_options_create (&options); } - + if (!err) { err = kim_options_set_start_time (options, creds->times.starttime); } - + if (!err) { kim_lifetime lifetime = (creds->times.endtime - (creds->times.starttime ? creds->times.starttime : creds->times.authtime)); - + err = kim_options_set_lifetime (options, lifetime); } - + if (!err) { kim_boolean renewable = (creds->ticket_flags & TKT_FLG_RENEWABLE); - + err = kim_options_set_renewable (options, renewable); } - + if (!err) { kim_lifetime rlifetime = (creds->ticket_flags & TKT_FLG_RENEWABLE ? creds->times.renew_till - (creds->times.starttime ? creds->times.starttime : creds->times.authtime) : 0); - + err = kim_options_set_renewal_lifetime (options, rlifetime); } - + if (!err) { kim_boolean forwardable = (creds->ticket_flags & TKT_FLG_FORWARDABLE); - + err = kim_options_set_forwardable (options, forwardable); } - + if (!err) { kim_boolean proxiable = (creds->ticket_flags & TKT_FLG_PROXIABLE); - + err = kim_options_set_proxiable (options, proxiable); } - + if (!err) { kim_boolean addressless = (!creds->addresses || !creds->addresses[0]); err = kim_options_set_addressless (options, addressless); } - + if (!err) { kim_boolean is_tgt = 0; kim_string service = NULL; /* tgt service */ - + err = kim_credential_is_tgt (in_credential, &is_tgt); - + if (!err && !is_tgt) { kim_identity identity = NULL; - + err = kim_credential_get_service_identity (in_credential, &identity); - + if (!err) { err = kim_identity_get_string (identity, &service); } kim_identity_free (&identity); } - + if (!err) { err = kim_options_set_service_name (options, service); } - + kim_string_free (&service); } - + if (!err) { *out_options = options; options = NULL; } - + kim_options_free (&options); - + return check_error (err); } @@ -1078,70 +1078,70 @@ kim_error kim_credential_store (kim_credential in_credential, kim_error err = KIM_NO_ERROR; krb5_ccache k5ccache = NULL; kim_boolean destroy_ccache_on_error = FALSE; - + if (!err && !in_credential) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !in_identity ) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { char *environment_ccache = getenv ("KRB5CCNAME"); - + if (environment_ccache) { err = krb5_error (in_credential->context, - krb5_cc_resolve (in_credential->context, - environment_ccache, + krb5_cc_resolve (in_credential->context, + environment_ccache, &k5ccache)); - + } else { kim_ccache ccache = NULL; - - err = kim_ccache_create_from_client_identity (&ccache, + + err = kim_ccache_create_from_client_identity (&ccache, in_identity); - + if (!err) { - err = kim_ccache_get_krb5_ccache (ccache, - in_credential->context, + err = kim_ccache_get_krb5_ccache (ccache, + in_credential->context, &k5ccache); - + } else if (err == KIM_NO_SUCH_PRINCIPAL_ERR) { /* Nothing to replace, create a new ccache */ err = krb5_error (in_credential->context, - krb5_cc_new_unique (in_credential->context, + krb5_cc_new_unique (in_credential->context, "API", NULL, &k5ccache)); if (!err) { destroy_ccache_on_error = TRUE; } } - + kim_ccache_free (&ccache); } } - + if (!err) { krb5_principal principal = kim_identity_krb5_principal (in_identity); - + err = krb5_error (in_credential->context, - krb5_cc_initialize (in_credential->context, + krb5_cc_initialize (in_credential->context, k5ccache, principal)); } - + if (!err) { err = krb5_error (in_credential->context, - krb5_cc_store_cred (in_credential->context, + krb5_cc_store_cred (in_credential->context, k5ccache, in_credential->creds)); } - + if (!err && out_ccache) { - err = kim_ccache_create_from_krb5_ccache (out_ccache, - in_credential->context, + err = kim_ccache_create_from_krb5_ccache (out_ccache, + in_credential->context, k5ccache); } - - if (k5ccache) { + + if (k5ccache) { if (err && destroy_ccache_on_error) { - krb5_cc_destroy (in_credential->context, k5ccache); + krb5_cc_destroy (in_credential->context, k5ccache); } else { - krb5_cc_close (in_credential->context, k5ccache); + krb5_cc_close (in_credential->context, k5ccache); } } - + return check_error (err); } @@ -1157,89 +1157,89 @@ kim_error kim_credential_verify (kim_credential in_credential, kim_error err = KIM_NO_ERROR; krb5_context scontext = NULL; krb5_keytab keytab = NULL; - + if (!err && !in_credential) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { err = krb5_error (NULL, krb5_init_secure_context (&scontext)); } - + if (in_keytab) { - err = krb5_error (scontext, + err = krb5_error (scontext, krb5_kt_resolve (scontext, in_keytab, &keytab)); } - + if (!err) { krb5_principal sprincipal = NULL; krb5_verify_init_creds_opt options; - + /* That's "no key == fail" not "no fail" >.< */ krb5_verify_init_creds_opt_init (&options); krb5_verify_init_creds_opt_set_ap_req_nofail (&options, in_fail_if_no_service_key); - - if (in_service_identity) { - sprincipal = kim_identity_krb5_principal (in_service_identity); + + if (in_service_identity) { + sprincipal = kim_identity_krb5_principal (in_service_identity); } - + err = krb5_error (scontext, - krb5_verify_init_creds (scontext, - in_credential->creds, + krb5_verify_init_creds (scontext, + in_credential->creds, sprincipal, keytab, NULL /* don't store creds in ccache */, &options)); - + if (err && !in_service_identity && in_fail_if_no_service_key) { /* If the service principal wasn't specified but we are supposed to - * fail without a key we should walk the keytab trying to find one + * fail without a key we should walk the keytab trying to find one * that succeeds. */ krb5_error_code terr = 0; kim_boolean verified = 0; krb5_kt_cursor cursor = NULL; krb5_keytab_entry entry; - - + + if (!keytab) { terr = krb5_kt_default (scontext, &keytab); } - + if (!terr) { terr = krb5_kt_start_seq_get (scontext, keytab, &cursor); } - + while (!terr && !verified) { kim_boolean free_entry = 0; - + terr = krb5_kt_next_entry (scontext, keytab, &entry, &cursor); free_entry = !terr; /* remember to free */ - + if (!terr) { terr = krb5_verify_init_creds (scontext, in_credential->creds, - entry.principal /* get principal for the 1st entry */, + entry.principal /* get principal for the 1st entry */, keytab, NULL /* don't store creds in ccache */, &options); } - + if (!terr) { verified = 1; } - + if (free_entry) { krb5_free_keytab_entry_contents (scontext, &entry); } } - + if (!terr && verified) { /* We found a key that verified! */ err = KIM_NO_ERROR; } - + if (cursor) { krb5_kt_end_seq_get (scontext, keytab, &cursor); } } } - + if (keytab ) { krb5_kt_close (scontext, keytab); } if (scontext) { krb5_free_context (scontext); } - + return check_error (err); } @@ -1253,71 +1253,71 @@ kim_error kim_credential_renew (kim_credential *io_credential, kim_error err = KIM_NO_ERROR; kim_string service_name = NULL; krb5_ccache ccache = NULL; - + if (!err && !io_credential) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { kim_options options = in_options; - + if (!options) { err = kim_options_create (&options); } - + if (!err) { err = kim_options_get_service_name (options, &service_name); } - + if (options != in_options) { kim_options_free (&options); } } - + if (!err) { err = krb5_error ((*io_credential)->context, - krb5_cc_new_unique ((*io_credential)->context, - "MEMORY", NULL, + krb5_cc_new_unique ((*io_credential)->context, + "MEMORY", NULL, &ccache)); } - + if (!err) { err = krb5_error ((*io_credential)->context, - krb5_cc_initialize ((*io_credential)->context, ccache, + krb5_cc_initialize ((*io_credential)->context, ccache, (*io_credential)->creds->client)); } - + if (!err) { err = krb5_error ((*io_credential)->context, - krb5_cc_store_cred ((*io_credential)->context, ccache, + krb5_cc_store_cred ((*io_credential)->context, ccache, (*io_credential)->creds)); } - + if (!err) { krb5_creds creds; krb5_creds *renewed_creds = NULL; kim_boolean free_creds = 0; - + err = krb5_error ((*io_credential)->context, - krb5_get_renewed_creds ((*io_credential)->context, + krb5_get_renewed_creds ((*io_credential)->context, &creds, (*io_credential)->creds->client, ccache, (char *) service_name)); if (!err) { free_creds = 1; } - + if (!err) { err = krb5_error ((*io_credential)->context, - krb5_copy_creds ((*io_credential)->context, + krb5_copy_creds ((*io_credential)->context, &creds, &renewed_creds)); } - + if (!err) { /* replace the credentials */ - krb5_free_creds ((*io_credential)->context, (*io_credential)->creds); + krb5_free_creds ((*io_credential)->context, (*io_credential)->creds); (*io_credential)->creds = renewed_creds; } - + if (free_creds) { krb5_free_cred_contents ((*io_credential)->context, &creds); } } - + if (ccache) { krb5_cc_destroy ((*io_credential)->context, ccache); } kim_string_free (&service_name); - + return check_error (err); } @@ -1329,73 +1329,73 @@ kim_error kim_credential_validate (kim_credential *io_credential, kim_error err = KIM_NO_ERROR; kim_string service_name = NULL; krb5_ccache ccache = NULL; - + if (!err && !io_credential) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { kim_options options = in_options; - + if (!options) { err = kim_options_create (&options); } - + if (!err) { err = kim_options_get_service_name (options, &service_name); } - + if (options != in_options) { kim_options_free (&options); } } - + if (!err) { err = krb5_error ((*io_credential)->context, - krb5_cc_new_unique ((*io_credential)->context, - "MEMORY", NULL, + krb5_cc_new_unique ((*io_credential)->context, + "MEMORY", NULL, &ccache)); } - + if (!err) { err = krb5_error ((*io_credential)->context, - krb5_cc_initialize ((*io_credential)->context, ccache, + krb5_cc_initialize ((*io_credential)->context, ccache, (*io_credential)->creds->client)); } - + if (!err) { err = krb5_error ((*io_credential)->context, - krb5_cc_store_cred ((*io_credential)->context, ccache, + krb5_cc_store_cred ((*io_credential)->context, ccache, (*io_credential)->creds)); } - + if (!err) { krb5_creds creds; krb5_creds *validated_creds = NULL; kim_boolean free_creds = 0; - + err = krb5_error ((*io_credential)->context, - krb5_get_validated_creds ((*io_credential)->context, - &creds, - (*io_credential)->creds->client, - ccache, + krb5_get_validated_creds ((*io_credential)->context, + &creds, + (*io_credential)->creds->client, + ccache, (char *) service_name)); if (!err) { free_creds = 1; } - + if (!err) { err = krb5_error ((*io_credential)->context, - krb5_copy_creds ((*io_credential)->context, + krb5_copy_creds ((*io_credential)->context, &creds, &validated_creds)); } - + if (!err) { /* replace the credentials */ - krb5_free_creds ((*io_credential)->context, (*io_credential)->creds); + krb5_free_creds ((*io_credential)->context, (*io_credential)->creds); (*io_credential)->creds = validated_creds; } - + if (free_creds) { krb5_free_cred_contents ((*io_credential)->context, &creds); } } - + if (ccache) { krb5_cc_destroy ((*io_credential)->context, ccache); } kim_string_free (&service_name); - + return check_error (err); } diff --git a/src/kim/lib/kim_debug.c b/src/kim/lib/kim_debug.c index 645a51f434..1fe6582934 100644 --- a/src/kim/lib/kim_debug.c +++ b/src/kim/lib/kim_debug.c @@ -8,7 +8,7 @@ * 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 @@ -28,49 +28,49 @@ /* ------------------------------------------------------------------------ */ -kim_error _check_error (kim_error in_err, - kim_string in_function, - kim_string in_file, +kim_error _check_error (kim_error in_err, + kim_string in_function, + kim_string in_file, int in_line) { if (in_err) { - kim_debug_printf ("%s(): got %d ('%s') at %s: %d", - in_function, in_err, kim_error_message (in_err), + kim_debug_printf ("%s(): got %d ('%s') at %s: %d", + in_function, in_err, kim_error_message (in_err), in_file, in_line); } - + return in_err; } /* ------------------------------------------------------------------------ */ -void __kim_debug_printf (kim_string in_function, - kim_string in_format, +void __kim_debug_printf (kim_string in_function, + kim_string in_format, ...) { kim_error err = KIM_NO_ERROR; kim_string format = NULL; kim_string string = NULL; - + if (!err && !in_function) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !in_format ) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { - err = kim_string_create_from_format (&format, "%s(): %s", + err = kim_string_create_from_format (&format, "%s(): %s", in_function, in_format); } - + if (!err) { va_list args; va_start (args, in_format); err = kim_string_create_from_format_va (&string, format, args); va_end (args); } - + if (!err) { kim_os_debug_print (string); } - + kim_string_free (&format); kim_string_free (&string); } diff --git a/src/kim/lib/kim_debug_private.h b/src/kim/lib/kim_debug_private.h index f9b67f0d96..451bf34d47 100644 --- a/src/kim/lib/kim_debug_private.h +++ b/src/kim/lib/kim_debug_private.h @@ -8,7 +8,7 @@ * 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 @@ -25,13 +25,13 @@ */ #define kim_debug_printf(format, ...) __kim_debug_printf(__FUNCTION__, format, ## __VA_ARGS__) -void __kim_debug_printf (kim_string in_function, - kim_string in_format, +void __kim_debug_printf (kim_string in_function, + kim_string in_format, ...); -kim_error _check_error (kim_error in_err, - kim_string in_function, - kim_string in_file, +kim_error _check_error (kim_error in_err, + kim_string in_function, + kim_string in_file, int in_line); #define check_error(err) _check_error(err, __FUNCTION__, __FILE__, __LINE__) diff --git a/src/kim/lib/kim_error_message.c b/src/kim/lib/kim_error_message.c index 6a891aa482..d07ad1933b 100644 --- a/src/kim/lib/kim_error_message.c +++ b/src/kim/lib/kim_error_message.c @@ -48,13 +48,13 @@ static kim_error kim_error_set_message (kim_error in_error, { int lock_err = 0; kim_error err = KIM_NO_ERROR; - kim_last_error last_error = NULL; - + kim_last_error last_error = NULL; + err = lock_err = k5_mutex_lock (&kim_error_lock); - + if (!err) { last_error = k5_getspecific (K5_KEY_KIM_ERROR_MESSAGE); - + if (!last_error) { last_error = malloc (sizeof (*last_error)); if (!last_error) { @@ -65,15 +65,15 @@ static kim_error kim_error_set_message (kim_error in_error, } } } - + if (!err) { strncpy (last_error->message, in_message, sizeof (last_error->message)); last_error->message[sizeof (last_error->message)-1] = '\0'; last_error->code = in_error; } - + if (!lock_err) { k5_mutex_unlock (&kim_error_lock); } - + return err; } @@ -82,7 +82,7 @@ static kim_error kim_error_set_message (kim_error in_error, static void kim_error_free_message (void *io_error) { kim_last_error error = io_error; - + if (error) { if (error->message) { free (error->message); @@ -110,14 +110,14 @@ static kim_error kim_error_remap (kim_error in_error) switch (in_error) { case KRB5KRB_AP_ERR_BAD_INTEGRITY: return KIM_BAD_PASSWORD_ERR; - + case KRB5KDC_ERR_PREAUTH_FAILED: return KIM_PREAUTH_FAILED_ERR; - + case KRB5KRB_AP_ERR_SKEW: return KIM_CLOCK_SKEW_ERR; } - + return in_error; } @@ -126,43 +126,43 @@ static kim_error kim_error_remap (kim_error in_error) kim_string kim_error_message (kim_error in_error) { int lock_err = 0; - kim_last_error last_error = NULL; + kim_last_error last_error = NULL; kim_string message = NULL; - + lock_err = k5_mutex_lock (&kim_error_lock); - + if (!lock_err) { last_error = k5_getspecific (K5_KEY_KIM_ERROR_MESSAGE); if (last_error && last_error->code == in_error) { message = last_error->message; } } - + if (!lock_err) { k5_mutex_unlock (&kim_error_lock); } - - return message ? message : error_message (kim_error_remap (in_error)); + + return message ? message : error_message (kim_error_remap (in_error)); } #pragma mark -- Generic Functions -- /* ------------------------------------------------------------------------ */ -kim_error kim_error_set_message_for_code (kim_error in_error, +kim_error kim_error_set_message_for_code (kim_error in_error, ...) { kim_error err = KIM_NO_ERROR; va_list args; - + va_start (args, in_error); err = kim_error_set_message_for_code_va (in_error, args); va_end (args); - - return check_error (err); + + return check_error (err); } /* ------------------------------------------------------------------------ */ -kim_error kim_error_set_message_for_code_va (kim_error in_code, +kim_error kim_error_set_message_for_code_va (kim_error in_code, va_list in_args) { kim_error err = KIM_NO_ERROR; @@ -170,44 +170,44 @@ kim_error kim_error_set_message_for_code_va (kim_error in_code, if (!kim_error_is_builtin (code)) { kim_string message = NULL; - - err = kim_string_create_from_format_va_retcode (&message, - error_message (code), + + err = kim_string_create_from_format_va_retcode (&message, + error_message (code), in_args); - + if (!err) { err = kim_error_set_message (code, message); } - + kim_string_free (&message); } - + return err ? err : code; } /* ------------------------------------------------------------------------ */ -kim_error kim_error_set_message_for_krb5_error (krb5_context in_context, +kim_error kim_error_set_message_for_krb5_error (krb5_context in_context, krb5_error_code in_code) { kim_error err = KIM_NO_ERROR; krb5_error_code code = kim_error_remap (in_code); - + if (code != in_code) { /* error was remapped to a KIM error */ err = kim_error_set_message (code, error_message (code)); } else if (!kim_error_is_builtin (code)) { const char *message = krb5_get_error_message (in_context, code); - + if (message) { err = kim_error_set_message (code, message); - + krb5_free_error_message (in_context, message); } } - + return err ? err : code; } @@ -218,16 +218,16 @@ kim_error kim_error_set_message_for_krb5_error (krb5_context in_context, int kim_error_initialize (void) { int err = 0; - + if (!err) { err = k5_mutex_finish_init (&kim_error_lock); } - + if (!err) { - err = k5_key_register (K5_KEY_KIM_ERROR_MESSAGE, + err = k5_key_register (K5_KEY_KIM_ERROR_MESSAGE, kim_error_free_message); } - + return err; } @@ -238,8 +238,7 @@ void kim_error_terminate (void) if (!INITIALIZER_RAN (kim_error_initialize) || PROGRAM_EXITING ()) { return; } - + k5_key_delete (K5_KEY_KIM_ERROR_MESSAGE); k5_mutex_destroy (&kim_error_lock); } - diff --git a/src/kim/lib/kim_error_private.h b/src/kim/lib/kim_error_private.h index 72e409954a..e4aa272ebe 100644 --- a/src/kim/lib/kim_error_private.h +++ b/src/kim/lib/kim_error_private.h @@ -29,11 +29,11 @@ #include <kim/kim.h> -kim_error kim_error_set_message_for_code (kim_error in_code, +kim_error kim_error_set_message_for_code (kim_error in_code, ...); -kim_error kim_error_set_message_for_code_va (kim_error in_code, +kim_error kim_error_set_message_for_code_va (kim_error in_code, va_list in_args); -kim_error kim_error_set_message_for_krb5_error (krb5_context in_context, +kim_error kim_error_set_message_for_krb5_error (krb5_context in_context, krb5_error_code in_code); #define krb5_error(context,code) kim_error_set_message_for_krb5_error(context, code) diff --git a/src/kim/lib/kim_identity.c b/src/kim/lib/kim_identity.c index 2a1ad5e3ff..60572639e8 100644 --- a/src/kim/lib/kim_identity.c +++ b/src/kim/lib/kim_identity.c @@ -8,7 +8,7 @@ * 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 @@ -43,23 +43,23 @@ static inline kim_error kim_identity_allocate (kim_identity *out_identity) { kim_error err = kim_library_init (); kim_identity identity = NULL; - + if (!err && !out_identity) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { identity = malloc (sizeof (*identity)); if (!identity) { err = KIM_OUT_OF_MEMORY_ERR; } } - + if (!err) { *identity = kim_identity_initializer; *out_identity = identity; identity = NULL; } - + kim_identity_free (&identity); - - return check_error (err); + + return check_error (err); } /* ------------------------------------------------------------------------ */ @@ -69,60 +69,60 @@ kim_error kim_identity_create_from_string (kim_identity *out_identity, { kim_error err = KIM_NO_ERROR; kim_identity identity = NULL; - + if (!err && !out_identity) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !in_string ) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { err = kim_identity_allocate (&identity); } - + if (!err) { err = krb5_error (NULL, krb5_init_context (&identity->context)); } - + if (!err) { krb5_error_code code = krb5_parse_name (identity->context, in_string, &identity->principal); if (code == KRB5_PARSE_MALFORMED) { - err = kim_error_set_message_for_code (KIM_BAD_PRINCIPAL_STRING_ERR, + err = kim_error_set_message_for_code (KIM_BAD_PRINCIPAL_STRING_ERR, in_string); } else if (code) { err = krb5_error (identity->context, code); } } - + if (!err) { *out_identity = identity; identity = NULL; } - + if (identity) { kim_identity_free (&identity); } - + return check_error (err); } /* ------------------------------------------------------------------------ */ kim_error kim_identity_create_from_components (kim_identity *out_identity, - kim_string in_realm, + kim_string in_realm, kim_string in_1st_component, ...) { kim_error err = KIM_NO_ERROR; kim_identity identity = NULL; - + if (!err && !out_identity ) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !in_realm ) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !in_1st_component) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { err = kim_identity_allocate (&identity); } - + if (!err) { err = krb5_error (NULL, krb5_init_context (&identity->context)); } - + if (!err) { va_list args; @@ -135,15 +135,15 @@ kim_error kim_identity_create_from_components (kim_identity *out_identity, in_1st_component, args)); va_end (args); - } + } if (!err) { *out_identity = identity; identity = NULL; } - + kim_identity_free (&identity); - + return check_error (err); } @@ -155,40 +155,40 @@ kim_error kim_identity_create_from_krb5_principal (kim_identity *out_identity, { kim_error err = KIM_NO_ERROR; kim_identity identity = NULL; - + if (!err && !out_identity ) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !in_krb5_principal) { err = check_error (KIM_NULL_PARAMETER_ERR); } /* KLCreatePrincipalFromKerberos5Principal passes NULL in_krb5_context */ - + if (!err) { err = kim_identity_allocate (&identity); } - + if (!err) { if (in_krb5_context) { - err = krb5_error (in_krb5_context, + err = krb5_error (in_krb5_context, krb5_copy_context (in_krb5_context, &identity->context)); } else { - err = krb5_error (NULL, + err = krb5_error (NULL, krb5_init_context (&identity->context)); } } - + if (!err) { err = krb5_error (identity->context, - krb5_copy_principal (identity->context, - in_krb5_principal, + krb5_copy_principal (identity->context, + in_krb5_principal, &identity->principal)); } - + if (!err) { *out_identity = identity; identity = NULL; } - + kim_identity_free (&identity); - + return check_error (err); } @@ -199,33 +199,33 @@ kim_error kim_identity_copy (kim_identity *out_identity, { kim_error err = KIM_NO_ERROR; kim_identity identity = KIM_IDENTITY_ANY; - + if (!err && !out_identity) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err && in_identity != KIM_IDENTITY_ANY) { err = kim_identity_allocate (&identity); - + if (!err) { - err = krb5_error (in_identity->context, + err = krb5_error (in_identity->context, krb5_copy_context (in_identity->context, &identity->context)); } - + if (!err) { err = krb5_error (identity->context, - krb5_copy_principal (identity->context, - in_identity->principal, + krb5_copy_principal (identity->context, + in_identity->principal, &identity->principal)); } } - + if (!err) { *out_identity = identity; identity = NULL; } - + kim_identity_free (&identity); - + return check_error (err); } @@ -236,35 +236,35 @@ kim_error kim_identity_compare (kim_identity in_identity, kim_comparison *out_comparison) { kim_error err = KIM_NO_ERROR; - + if (!err && !in_identity ) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !in_compare_to_identity) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !out_comparison ) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { - if (krb5_principal_compare (in_identity->context, - in_identity->principal, + if (krb5_principal_compare (in_identity->context, + in_identity->principal, in_compare_to_identity->principal)) { *out_comparison = 0; } else { kim_string string = NULL; kim_string compare_to_string = NULL; - + err = kim_identity_get_string (in_identity, &string); - + if (!err) { err = kim_identity_get_string (in_compare_to_identity, &compare_to_string); } - + if (!err) { err = kim_string_compare (string, compare_to_string, out_comparison); } - + kim_string_free (&string); kim_string_free (&compare_to_string); } } - + return check_error (err); } @@ -275,23 +275,23 @@ kim_error kim_identity_get_string (kim_identity in_identity, { kim_error err = KIM_NO_ERROR; char *unparsed_name = NULL; - + if (!err && !in_identity) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !out_string ) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { err = krb5_error (in_identity->context, - krb5_unparse_name (in_identity->context, - in_identity->principal, + krb5_unparse_name (in_identity->context, + in_identity->principal, &unparsed_name)); } - + if (!err) { err = kim_string_copy (out_string, unparsed_name); } - + if (unparsed_name) { krb5_free_unparsed_name (in_identity->context, unparsed_name); } - + return check_error (err); } @@ -302,22 +302,22 @@ kim_error kim_identity_get_display_string (kim_identity in_identity, { kim_error err = KIM_NO_ERROR; kim_string string = NULL; - + if (!err && !in_identity ) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !out_display_string) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { err = kim_identity_get_string (in_identity, &string); } - + if (!err) { kim_count i, j; kim_count length = strlen (string) + 1; /* Copy the '\0' */ char *display_string = (char *) string; /* so we can modify it */ - + /* In place copy, skipping escaped separators. * Note that we do not want to remove other escaped characters - * (tab, break, newline, NULL) because they are less readable + * (tab, break, newline, NULL) because they are less readable * when unescaped (and NULL isn't a valid string character). */ for (i = 0, j = 0; i < length; i++) { if (string[i] == '\\') { @@ -327,16 +327,16 @@ kim_error kim_identity_get_display_string (kim_identity in_identity, continue; /* skip the '\' */ } } - + display_string[j++] = string[i]; /* Copy this char */ - } - + } + *out_display_string = string; string = NULL; } - + if (string) { kim_string_free (&string); } - + return check_error (err); } @@ -346,16 +346,16 @@ kim_error kim_identity_get_realm (kim_identity in_identity, kim_string *out_realm_string) { kim_error err = KIM_NO_ERROR; - + if (!err && !in_identity ) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !out_realm_string) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { krb5_data *realm = krb5_princ_realm (in_identity->context, in_identity->principal); - + err = kim_string_create_from_buffer (out_realm_string, realm->data, realm->length); } - + return check_error (err); } @@ -365,14 +365,14 @@ kim_error kim_identity_get_number_of_components (kim_identity in_identity, kim_count *out_number_of_components) { kim_error err = KIM_NO_ERROR; - + if (!err && !in_identity ) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !out_number_of_components) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { *out_number_of_components = krb5_princ_size (in_identity->context, in_identity->principal); } - + return check_error (err); } @@ -384,22 +384,22 @@ kim_error kim_identity_get_component_at_index (kim_identity in_identity, { kim_error err = KIM_NO_ERROR; krb5_data *component = NULL; - + if (!err && !in_identity ) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !out_component_string) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { krb5_int32 i = in_index; component = krb5_princ_component (in_identity->context, in_identity->principal, i); - if (!component) { - err = kim_error_set_message_for_code (KIM_BAD_COMPONENT_INDEX_ERR, i); + if (!component) { + err = kim_error_set_message_for_code (KIM_BAD_COMPONENT_INDEX_ERR, i); } } - + if (!err) { err = kim_string_create_from_buffer (out_component_string, component->data, component->length); } - + return check_error (err); } @@ -411,46 +411,46 @@ kim_error kim_identity_get_components_string (kim_identity in_identity, kim_error err = KIM_NO_ERROR; kim_string components = NULL; kim_count count, i; - + if (!err && !in_identity ) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !out_components) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { err = kim_identity_get_number_of_components (in_identity, &count); } - + if (!err) { err = kim_identity_get_component_at_index (in_identity, 0, &components); } - + for (i = 1; !err && i < count; i++) { kim_string new_components = NULL; kim_string component = NULL; - + err = kim_identity_get_component_at_index (in_identity, i, &component); - + if (!err) { err = kim_string_create_from_format (&new_components, "%s/%s", components, component); } - + if (!err) { kim_string_free (&components); components = new_components; new_components = NULL; } - + if (component ) { kim_string_free (&component); } if (new_components) { kim_string_free (&new_components); } } - + if (!err) { *out_components = components; components = NULL; } - + if (components) { kim_string_free (&components); } - + return check_error (err); } @@ -461,18 +461,18 @@ kim_error kim_identity_get_krb5_principal (kim_identity in_identity, krb5_principal *out_krb5_principal) { kim_error err = KIM_NO_ERROR; - + if (!err && !in_identity ) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !in_krb5_context ) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !out_krb5_principal) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { err = krb5_error (in_krb5_context, - krb5_copy_principal (in_krb5_context, - in_identity->principal, + krb5_copy_principal (in_krb5_context, + in_identity->principal, out_krb5_principal)); - } - + } + return check_error (err); } @@ -493,20 +493,20 @@ kim_error kim_identity_is_tgt_service (kim_identity in_identity, kim_boolean *out_is_tgt_service) { kim_error err = KIM_NO_ERROR; - + if (!err && !in_identity ) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !out_is_tgt_service) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { kim_count count = krb5_princ_size (in_identity->context, in_identity->principal); krb5_data *name = krb5_princ_name (in_identity->context, in_identity->principal); - + /* krbtgt/<REALM1>@<REALM2> (usually REALM1 == REALM2, but not always) */ *out_is_tgt_service = ((count == 2) && (strlen (KRB5_TGS_NAME) == name->length) && (strncmp (name->data, KRB5_TGS_NAME, name->length) == 0)); } - + return check_error (err); } @@ -526,13 +526,13 @@ kim_error kim_identity_change_password_with_credential (kim_identity in_ident int rejected_err = 0; krb5_data message_data; krb5_data description_data; - + if (!err && !in_identity ) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !in_credential ) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !in_new_password ) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !in_ui_context ) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !out_rejected_err) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { err = kim_credential_get_krb5_creds (in_credential, in_identity->context, @@ -540,68 +540,68 @@ kim_error kim_identity_change_password_with_credential (kim_identity in_ident } if (!err) { - if (krb5_principal_compare (in_identity->context, + if (krb5_principal_compare (in_identity->context, in_identity->principal, creds->client)) { /* Same principal, change the password normally */ err = krb5_error (in_identity->context, - krb5_change_password (in_identity->context, - creds, - (char *) in_new_password, - &rejected_err, - &message_data, + krb5_change_password (in_identity->context, + creds, + (char *) in_new_password, + &rejected_err, + &message_data, &description_data)); } else { /* Different principal, use set change password protocol */ err = krb5_error (in_identity->context, - krb5_set_password (in_identity->context, - creds, - (char *) in_new_password, + krb5_set_password (in_identity->context, + creds, + (char *) in_new_password, in_identity->principal, - &rejected_err, - &message_data, + &rejected_err, + &message_data, &description_data)); } - + } - + if (!err && rejected_err) { kim_string rejected_message = NULL; kim_string rejected_description = NULL; - + if (message_data.data && message_data.length > 0) { - err = kim_string_create_from_buffer (&rejected_message, - message_data.data, + err = kim_string_create_from_buffer (&rejected_message, + message_data.data, message_data.length); } else { err = kim_os_string_create_localized (&rejected_message, "Kerberos Change Password Failed:"); } - + if (!err) { if (description_data.data && description_data.length > 0) { err = kim_string_create_from_buffer (&rejected_description, - description_data.data, + description_data.data, description_data.length); } else { err = kim_os_string_create_localized (&rejected_description, "New password rejected."); } } - + if (!err && in_ui_context->type != kim_ui_type_cli) { char *c; - + // replace all \n and \r characters with spaces for (c = (char *) rejected_message; *c != '\0'; c++) { if ((*c == '\n') || (*c == '\r')) { *c = ' '; } } - + for (c = (char *) rejected_description; *c != '\0'; c++) { if ((*c == '\n') || (*c == '\r')) { *c = ' '; } } } - + if (!err) { if (out_rejected_message) { *out_rejected_message = rejected_message; @@ -612,21 +612,21 @@ kim_error kim_identity_change_password_with_credential (kim_identity in_ident rejected_description = NULL; } } - + kim_string_free (&rejected_message); kim_string_free (&rejected_description); - + krb5_free_data_contents (in_identity->context, &message_data); krb5_free_data_contents (in_identity->context, &description_data); } - + if (!err) { /* do this after reporting errors so we don't double report rejection */ *out_rejected_err = rejected_err; } - + if (creds) { krb5_free_creds (in_identity->context, creds); } - + return check_error (err); } @@ -639,10 +639,10 @@ kim_error kim_identity_change_password_common (kim_identity in_identity, { kim_error err = KIM_NO_ERROR; kim_boolean done = 0; - + if (!err && !in_identity ) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !in_ui_context) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + while (!err && !done) { char *old_password = NULL; char *new_password = NULL; @@ -651,28 +651,28 @@ kim_error kim_identity_change_password_common (kim_identity in_identity, kim_string rejected_message = NULL; kim_string rejected_description = NULL; kim_boolean was_prompted = 0; /* ignore because we always prompt */ - + err = kim_ui_change_password (in_ui_context, in_identity, in_old_password_expired, &old_password, &new_password, &verify_password); - + if (!err) { kim_comparison comparison; - - err = kim_string_compare (new_password, - verify_password, + + err = kim_string_compare (new_password, + verify_password, &comparison); if (!err && !kim_comparison_is_equal_to (comparison)) { err = check_error (KIM_PASSWORD_MISMATCH_ERR); } } - + if (!err) { kim_credential credential = NULL; - + if (in_ui_context->type == kim_ui_type_cli && in_ui_context->tcontext) { /* command line has already gotten the credentials for us */ credential = (kim_credential) in_ui_context->tcontext; @@ -683,74 +683,74 @@ kim_error kim_identity_change_password_common (kim_identity in_identity, in_ui_context, &was_prompted); } - + if (!err) { err = kim_identity_change_password_with_credential (in_identity, - credential, + credential, new_password, in_ui_context, &rejected_err, &rejected_message, &rejected_description); - } - + } + kim_credential_free (&credential); - if (in_ui_context->type == kim_ui_type_cli) { + if (in_ui_context->type == kim_ui_type_cli) { in_ui_context->tcontext = NULL; /* just freed our creds */ } } - + if (!err && rejected_err) { /* Password rejected, report it to the user */ err = kim_ui_handle_error (in_ui_context, in_identity, rejected_err, - rejected_message, + rejected_message, rejected_description); - - } else if (err && err != KIM_USER_CANCELED_ERR && + + } else if (err && err != KIM_USER_CANCELED_ERR && err != KIM_DUPLICATE_UI_REQUEST_ERR) { /* New creds failed, report error to user. * Overwrite error so we loop and let the user try again. * The user always gets prompted so we always loop. */ - err = kim_ui_handle_kim_error (in_ui_context, in_identity, + err = kim_ui_handle_kim_error (in_ui_context, in_identity, kim_ui_error_type_change_password, err); - + } else { /* password change succeeded or the user gave up */ done = 1; - + if (!err && out_new_password) { err = kim_string_copy (out_new_password, new_password); } - + if (!err) { kim_error terr = KIM_NO_ERROR; kim_string saved_password = NULL; - - terr = kim_os_identity_get_saved_password (in_identity, + + terr = kim_os_identity_get_saved_password (in_identity, &saved_password); - if (!terr) { + if (!terr) { /* We changed the password and the user had their * old password saved. Update it. */ terr = kim_os_identity_set_saved_password (in_identity, new_password); } - + kim_string_free (&saved_password); } if (err == KIM_DUPLICATE_UI_REQUEST_ERR) { err = KIM_NO_ERROR; } } - + kim_string_free (&rejected_message); kim_string_free (&rejected_description); - + kim_ui_free_string (in_ui_context, &old_password); kim_ui_free_string (in_ui_context, &new_password); - kim_ui_free_string (in_ui_context, &verify_password); + kim_ui_free_string (in_ui_context, &verify_password); } - + return check_error (err); } @@ -763,22 +763,22 @@ kim_error kim_identity_change_password (kim_identity in_identity) kim_boolean ui_inited = 0; if (!err && !in_identity) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { err = kim_ui_init (&context); if (!err) { ui_inited = 1; } } - + if (!err) { - err = kim_identity_change_password_common (in_identity, 0, + err = kim_identity_change_password_common (in_identity, 0, &context, NULL); } - + if (ui_inited) { kim_error fini_err = kim_ui_fini (&context); if (!err) { err = check_error (fini_err); } } - + return check_error (err); } @@ -786,16 +786,16 @@ kim_error kim_identity_change_password (kim_identity in_identity) void kim_identity_free (kim_identity *io_identity) { - if (io_identity && *io_identity) { + if (io_identity && *io_identity) { kim_identity identity = *io_identity; - - if (identity->context) { - if (identity->principal) { - krb5_free_principal (identity->context, identity->principal); + + if (identity->context) { + if (identity->principal) { + krb5_free_principal (identity->context, identity->principal); } krb5_free_context (identity->context); } - + free (identity); *io_identity = NULL; } diff --git a/src/kim/lib/kim_library.c b/src/kim/lib/kim_library.c index 0272aa7fd1..78996d8fa4 100644 --- a/src/kim/lib/kim_library.c +++ b/src/kim/lib/kim_library.c @@ -8,7 +8,7 @@ * 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 @@ -47,7 +47,7 @@ static int kim_error_init (void) { add_error_table (&et_KIM_error_table); #if KIM_TO_KLL_SHIM - add_error_table (&et_KLL_error_table); + add_error_table (&et_KLL_error_table); #endif return 0; } @@ -93,23 +93,23 @@ MAKE_FINI_FUNCTION(kim_thread_fini); static int kim_thread_init (void) { kim_error err = KIM_NO_ERROR; - + if (!err) { err = k5_mutex_finish_init (&g_allow_home_directory_access_mutex); } - + if (!err) { err = k5_mutex_finish_init (&g_allow_automatic_prompting_mutex); } - + if (!err) { err = k5_mutex_finish_init (&g_ui_environment_mutex); } - + if (!err) { err = k5_mutex_finish_init (&g_application_name_mutex); } - + return err; } @@ -120,7 +120,7 @@ static void kim_thread_fini (void) if (!INITIALIZER_RAN (kim_thread_init) || PROGRAM_EXITING ()) { return; } - + k5_mutex_destroy (&g_allow_home_directory_access_mutex); k5_mutex_destroy (&g_allow_automatic_prompting_mutex); k5_mutex_destroy (&g_ui_environment_mutex); @@ -135,16 +135,16 @@ kim_error kim_library_set_allow_home_directory_access (kim_boolean in_allow_acce { kim_error err = CALL_INIT_FUNCTION (kim_thread_init); kim_error mutex_err = KIM_NO_ERROR; - + if (!err) { mutex_err = k5_mutex_lock (&g_allow_home_directory_access_mutex); if (mutex_err) { err = mutex_err; } } - + if (!err) { g_allow_home_directory_access = in_allow_access; } - + if (!mutex_err) { k5_mutex_unlock (&g_allow_home_directory_access_mutex); } return check_error (err); } @@ -155,18 +155,18 @@ static kim_error kim_library_get_allow_home_directory_access (kim_boolean *out_a { kim_error err = CALL_INIT_FUNCTION (kim_thread_init); kim_error mutex_err = KIM_NO_ERROR; - + if (!err && !out_allow_access) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { mutex_err = k5_mutex_lock (&g_allow_home_directory_access_mutex);; if (mutex_err) { err = mutex_err; } } - + if (!err) { *out_allow_access = g_allow_home_directory_access; } - + if (!mutex_err) { k5_mutex_unlock (&g_allow_home_directory_access_mutex); } return check_error (err); } @@ -177,7 +177,7 @@ kim_boolean kim_library_allow_home_directory_access (void) { kim_boolean allow_access = FALSE; kim_error err = kim_library_get_allow_home_directory_access (&allow_access); - + return !err ? allow_access : FALSE; } @@ -191,16 +191,16 @@ kim_error kim_library_set_allow_automatic_prompting (kim_boolean in_allow_automa { kim_error err = CALL_INIT_FUNCTION (kim_thread_init); kim_error mutex_err = KIM_NO_ERROR; - + if (!err) { mutex_err = k5_mutex_lock (&g_allow_automatic_prompting_mutex); if (mutex_err) { err = mutex_err; } } - + if (!err) { g_allow_automatic_prompting = in_allow_automatic_prompting; } - + if (!mutex_err) { k5_mutex_unlock (&g_allow_automatic_prompting_mutex); } return check_error (err); } @@ -211,18 +211,18 @@ static kim_error kim_library_get_allow_automatic_prompting (kim_boolean *out_all { kim_error err = CALL_INIT_FUNCTION (kim_thread_init); kim_error mutex_err = KIM_NO_ERROR; - + if (!err && !out_allow_automatic_prompting) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { mutex_err = k5_mutex_lock (&g_allow_automatic_prompting_mutex);; if (mutex_err) { err = mutex_err; } } - + if (!err) { *out_allow_automatic_prompting = g_allow_automatic_prompting; } - + if (!mutex_err) { k5_mutex_unlock (&g_allow_automatic_prompting_mutex); } return check_error (err); } @@ -234,45 +234,45 @@ kim_boolean kim_library_allow_automatic_prompting (void) kim_boolean allow_automatic_prompting = TRUE; kim_error err = kim_library_get_allow_automatic_prompting (&allow_automatic_prompting); if (err) { allow_automatic_prompting = TRUE; } - + if (allow_automatic_prompting && getenv ("KERBEROSLOGIN_NEVER_PROMPT")) { kim_debug_printf ("KERBEROSLOGIN_NEVER_PROMPT is set."); allow_automatic_prompting = FALSE; } - + if (allow_automatic_prompting && getenv ("KIM_NEVER_PROMPT")) { kim_debug_printf ("KIM_NEVER_PROMPT is set."); allow_automatic_prompting = FALSE; } - + if (allow_automatic_prompting && !kim_os_library_caller_uses_gui ()) { kim_debug_printf ("Caller is not using gui."); allow_automatic_prompting = FALSE; } if (allow_automatic_prompting) { - /* Make sure there is at least 1 config file. We don't support DNS + /* Make sure there is at least 1 config file. We don't support DNS * domain-realm lookup, so if there is no config, Kerberos won't work. */ - + kim_boolean kerberos_config_exists = FALSE; char **files = NULL; profile_t profile = NULL; - + if (krb5_get_default_config_files (&files) == 0) { if (profile_init ((const_profile_filespec_t *) files, &profile) == 0) { kerberos_config_exists = TRUE; } } - + if (!kerberos_config_exists) { kim_debug_printf ("No valid config file."); allow_automatic_prompting = FALSE; } - + if (profile) { profile_abandon (profile); } - if (files ) { krb5_free_config_files (files); } + if (files ) { krb5_free_config_files (files); } } - + return allow_automatic_prompting; } @@ -284,16 +284,16 @@ kim_error kim_library_set_ui_environment (kim_ui_environment in_ui_environment) { kim_error err = CALL_INIT_FUNCTION (kim_thread_init); kim_error mutex_err = KIM_NO_ERROR; - + if (!err) { mutex_err = k5_mutex_lock (&g_ui_environment_mutex); if (mutex_err) { err = mutex_err; } } - + if (!err) { g_ui_environment = in_ui_environment; } - + if (!mutex_err) { k5_mutex_unlock (&g_ui_environment_mutex); } return check_error (err); } @@ -304,18 +304,18 @@ static kim_error kim_library_get_ui_environment (kim_ui_environment *out_ui_envi { kim_error err = CALL_INIT_FUNCTION (kim_thread_init); kim_error mutex_err = KIM_NO_ERROR; - + if (!err && !out_ui_environment) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { mutex_err = k5_mutex_lock (&g_ui_environment_mutex);; if (mutex_err) { err = mutex_err; } } - + if (!err) { *out_ui_environment = g_ui_environment; } - + if (!mutex_err) { k5_mutex_unlock (&g_ui_environment_mutex); } return check_error (err); } @@ -326,13 +326,13 @@ kim_ui_environment kim_library_ui_environment (void) { kim_error err = KIM_NO_ERROR; kim_ui_environment ui_environment = KIM_UI_ENVIRONMENT_AUTO; - + err = kim_library_get_ui_environment (&ui_environment); - + if (!err && ui_environment == KIM_UI_ENVIRONMENT_AUTO) { ui_environment = kim_os_library_get_ui_environment (); } - + return !err ? ui_environment : KIM_UI_ENVIRONMENT_NONE; } @@ -344,15 +344,15 @@ kim_error kim_library_set_application_name (kim_string in_application_name) { kim_error err = CALL_INIT_FUNCTION (kim_thread_init); kim_error mutex_err = KIM_NO_ERROR; - + if (!err) { mutex_err = k5_mutex_lock (&g_application_name_mutex); if (mutex_err) { err = mutex_err; } } - + if (!err) { kim_string old_application_name = g_application_name; - + if (in_application_name) { err = kim_string_copy (&g_application_name, in_application_name); } else { @@ -361,7 +361,7 @@ kim_error kim_library_set_application_name (kim_string in_application_name) if (!err) { kim_string_free (&old_application_name); } } - + if (!mutex_err) { k5_mutex_unlock (&g_application_name_mutex); } return check_error (err); } @@ -373,31 +373,31 @@ kim_error kim_library_get_application_name (kim_string *out_application_name) kim_error err = CALL_INIT_FUNCTION (kim_thread_init); kim_error mutex_err = KIM_NO_ERROR; kim_string application_name = NULL; - + if (!err && !out_application_name) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { mutex_err = k5_mutex_lock (&g_application_name_mutex); if (mutex_err) { err = mutex_err; } } - + if (!err && g_application_name) { err = kim_string_copy (&application_name, g_application_name); } - + if (!mutex_err) { k5_mutex_unlock (&g_application_name_mutex); } - + if (!err && !application_name) { err = kim_os_library_get_caller_name (&application_name); } - + if (!err) { *out_application_name = application_name; application_name = NULL; - + } - + kim_string_free (&application_name); - + return check_error (err); } diff --git a/src/kim/lib/kim_library_private.h b/src/kim/lib/kim_library_private.h index 146474b0e8..75ea4fd3e9 100644 --- a/src/kim/lib/kim_library_private.h +++ b/src/kim/lib/kim_library_private.h @@ -8,7 +8,7 @@ * 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 diff --git a/src/kim/lib/kim_options.c b/src/kim/lib/kim_options.c index 5c45fb35a8..989c163fa4 100644 --- a/src/kim/lib/kim_options.c +++ b/src/kim/lib/kim_options.c @@ -8,7 +8,7 @@ * 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 @@ -41,10 +41,10 @@ struct kim_options_opaque { krb5_get_init_creds_opt *init_cred_options; }; -struct kim_options_opaque kim_options_initializer = { -0, -kim_default_lifetime, -kim_default_renewable, +struct kim_options_opaque kim_options_initializer = { +0, +kim_default_lifetime, +kim_default_renewable, kim_default_renewal_lifetime, kim_default_forwardable, kim_default_proxiable, @@ -59,23 +59,23 @@ static inline kim_error kim_options_allocate (kim_options *out_options) { kim_error err = kim_library_init (); kim_options options = NULL; - + if (!err && !out_options) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { options = malloc (sizeof (*options)); if (!options) { err = KIM_OUT_OF_MEMORY_ERR; } } - + if (!err) { *options = kim_options_initializer; *out_options = options; options = NULL; } - + kim_options_free (&options); - - return check_error (err); + + return check_error (err); } /* ------------------------------------------------------------------------ */ @@ -92,29 +92,29 @@ kim_error kim_options_create (kim_options *out_options) kim_error err = KIM_NO_ERROR; kim_preferences preferences = NULL; kim_options options = KIM_OPTIONS_DEFAULT; - + if (!err && !out_options) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { err = kim_preferences_create (&preferences); } - + if (!err) { err = kim_preferences_get_options (preferences, &options); } - + if (!err && !options) { err = kim_options_allocate (&options); } - + if (!err) { *out_options = options; options = NULL; /* caller takes ownership */ } - + kim_options_free (&options); kim_preferences_free (&preferences); - + return check_error (err); } @@ -125,12 +125,12 @@ kim_error kim_options_copy (kim_options *out_options, { kim_error err = KIM_NO_ERROR; kim_options options = KIM_OPTIONS_DEFAULT; - + if (!err && !out_options) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err && in_options != KIM_OPTIONS_DEFAULT) { err = kim_options_allocate (&options); - + if (!err) { options->start_time = in_options->start_time; options->lifetime = in_options->lifetime; @@ -139,21 +139,21 @@ kim_error kim_options_copy (kim_options *out_options, options->forwardable = in_options->forwardable; options->proxiable = in_options->proxiable; options->addressless = in_options->addressless; - + if (in_options->service_name) { - err = kim_string_copy (&options->service_name, + err = kim_string_copy (&options->service_name, in_options->service_name); } } } - + if (!err) { *out_options = options; options = NULL; } - + kim_options_free (&options); - + return check_error (err); } @@ -163,13 +163,13 @@ kim_error kim_options_set_start_time (kim_options io_options, kim_time in_start_time) { kim_error err = KIM_NO_ERROR; - + if (!err && !io_options) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { io_options->start_time = in_start_time; } - + return check_error (err); } @@ -179,14 +179,14 @@ kim_error kim_options_get_start_time (kim_options in_options, kim_time *out_start_time) { kim_error err = KIM_NO_ERROR; - + if (!err && !in_options ) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !out_start_time) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { *out_start_time = in_options->start_time; } - + return check_error (err); } @@ -196,13 +196,13 @@ kim_error kim_options_set_lifetime (kim_options io_options, kim_lifetime in_lifetime) { kim_error err = KIM_NO_ERROR; - + if (!err && !io_options) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { io_options->lifetime = in_lifetime; } - + return check_error (err); } @@ -212,14 +212,14 @@ kim_error kim_options_get_lifetime (kim_options in_options, kim_lifetime *out_lifetime) { kim_error err = KIM_NO_ERROR; - + if (!err && !in_options ) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !out_lifetime) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { *out_lifetime = in_options->lifetime; } - + return check_error (err); } @@ -229,13 +229,13 @@ kim_error kim_options_set_renewable (kim_options io_options, kim_boolean in_renewable) { kim_error err = KIM_NO_ERROR; - + if (!err && !io_options) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { io_options->renewable = in_renewable; } - + return check_error (err); } @@ -245,14 +245,14 @@ kim_error kim_options_get_renewable (kim_options in_options, kim_boolean *out_renewable) { kim_error err = KIM_NO_ERROR; - + if (!err && !in_options ) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !out_renewable) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { *out_renewable = in_options->renewable; } - + return check_error (err); } @@ -262,13 +262,13 @@ kim_error kim_options_set_renewal_lifetime (kim_options io_options, kim_lifetime in_renewal_lifetime) { kim_error err = KIM_NO_ERROR; - + if (!err && !io_options) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { io_options->renewal_lifetime = in_renewal_lifetime; } - + return check_error (err); } @@ -278,14 +278,14 @@ kim_error kim_options_get_renewal_lifetime (kim_options in_options, kim_lifetime *out_renewal_lifetime) { kim_error err = KIM_NO_ERROR; - + if (!err && !in_options ) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !out_renewal_lifetime) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { *out_renewal_lifetime = in_options->renewal_lifetime; } - + return check_error (err); } @@ -295,13 +295,13 @@ kim_error kim_options_set_forwardable (kim_options io_options, kim_boolean in_forwardable) { kim_error err = KIM_NO_ERROR; - + if (!err && !io_options) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { io_options->forwardable = in_forwardable; } - + return check_error (err); } @@ -311,14 +311,14 @@ kim_error kim_options_get_forwardable (kim_options in_options, kim_boolean *out_forwardable) { kim_error err = KIM_NO_ERROR; - + if (!err && !in_options ) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !out_forwardable) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { *out_forwardable = in_options->forwardable; } - + return check_error (err); } @@ -328,13 +328,13 @@ kim_error kim_options_set_proxiable (kim_options io_options, kim_boolean in_proxiable) { kim_error err = KIM_NO_ERROR; - + if (!err && !io_options) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { io_options->proxiable = in_proxiable; } - + return check_error (err); } @@ -344,14 +344,14 @@ kim_error kim_options_get_proxiable (kim_options in_options, kim_boolean *out_proxiable) { kim_error err = KIM_NO_ERROR; - + if (!err && !in_options ) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !out_proxiable) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { *out_proxiable = in_options->proxiable; } - + return check_error (err); } @@ -361,13 +361,13 @@ kim_error kim_options_set_addressless (kim_options io_options, kim_boolean in_addressless) { kim_error err = KIM_NO_ERROR; - + if (!err && !io_options) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { io_options->addressless = in_addressless; } - + return check_error (err); } @@ -377,14 +377,14 @@ kim_error kim_options_get_addressless (kim_options in_options, kim_boolean *out_addressless) { kim_error err = KIM_NO_ERROR; - + if (!err && !in_options ) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !out_addressless) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { *out_addressless = in_options->addressless; } - + return check_error (err); } @@ -394,9 +394,9 @@ kim_error kim_options_set_service_name (kim_options io_options, kim_string in_service_name) { kim_error err = KIM_NO_ERROR; - + if (!err && !io_options) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { kim_string_free (&io_options->service_name); if (in_service_name) { @@ -405,7 +405,7 @@ kim_error kim_options_set_service_name (kim_options io_options, io_options->service_name = kim_empty_string; } } - + return check_error (err); } @@ -415,19 +415,19 @@ kim_error kim_options_get_service_name (kim_options in_options, kim_string *out_service_name) { kim_error err = KIM_NO_ERROR; - + if (!err && !in_options ) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !out_service_name) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { - if (in_options->service_name && + if (in_options->service_name && in_options->service_name != kim_empty_string) { err = kim_string_copy (out_service_name, in_options->service_name); } else { *out_service_name = NULL; } } - + return check_error (err); } @@ -465,64 +465,64 @@ krb5_get_init_creds_opt *kim_options_init_cred_options (kim_options in_options) { kim_error err = KIM_NO_ERROR; krb5_address **addresses = NULL; - + if (!err && !in_options) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err && !in_options->init_cred_context) { err = krb5_error (NULL, krb5_init_context (&in_options->init_cred_context)); } - + if (!err && !in_options->addressless) { - err = krb5_error (in_options->init_cred_context, - krb5_os_localaddr (in_options->init_cred_context, + err = krb5_error (in_options->init_cred_context, + krb5_os_localaddr (in_options->init_cred_context, &addresses)); } - + if (!err && !in_options->init_cred_options) { err = krb5_error (in_options->init_cred_context, - krb5_get_init_creds_opt_alloc (in_options->init_cred_context, + krb5_get_init_creds_opt_alloc (in_options->init_cred_context, &in_options->init_cred_options)); } - + if (!err) { - krb5_get_init_creds_opt_set_tkt_life (in_options->init_cred_options, + krb5_get_init_creds_opt_set_tkt_life (in_options->init_cred_options, in_options->lifetime); - krb5_get_init_creds_opt_set_renew_life (in_options->init_cred_options, + krb5_get_init_creds_opt_set_renew_life (in_options->init_cred_options, in_options->renewable ? in_options->renewal_lifetime : 0); - krb5_get_init_creds_opt_set_forwardable (in_options->init_cred_options, + krb5_get_init_creds_opt_set_forwardable (in_options->init_cred_options, in_options->forwardable); - krb5_get_init_creds_opt_set_proxiable (in_options->init_cred_options, + krb5_get_init_creds_opt_set_proxiable (in_options->init_cred_options, in_options->proxiable); - krb5_get_init_creds_opt_set_address_list (in_options->init_cred_options, + krb5_get_init_creds_opt_set_address_list (in_options->init_cred_options, addresses); addresses = NULL; } - - if (addresses) { krb5_free_addresses (in_options->init_cred_context, + + if (addresses) { krb5_free_addresses (in_options->init_cred_context, addresses); } - - return !check_error (err) ? in_options->init_cred_options : NULL; + + return !check_error (err) ? in_options->init_cred_options : NULL; } /* ------------------------------------------------------------------------ */ void kim_options_free (kim_options *io_options) { - if (io_options && *io_options) { - kim_string_free (&(*io_options)->service_name); + if (io_options && *io_options) { + kim_string_free (&(*io_options)->service_name); if ((*io_options)->init_cred_context) { if ((*io_options)->init_cred_options) { if ((*io_options)->init_cred_options->address_list) { - krb5_free_addresses ((*io_options)->init_cred_context, + krb5_free_addresses ((*io_options)->init_cred_context, (*io_options)->init_cred_options->address_list); } - krb5_get_init_creds_opt_free ((*io_options)->init_cred_context, + krb5_get_init_creds_opt_free ((*io_options)->init_cred_context, (*io_options)->init_cred_options); } krb5_free_context ((*io_options)->init_cred_context); } - + free (*io_options); *io_options = NULL; } @@ -539,47 +539,47 @@ kim_error kim_options_write_to_stream (kim_options in_options, kim_options options = in_options; if (!err && !io_stream ) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err && !in_options) { err = kim_options_create (&options); } - + if (!err) { err = krb5int_ipc_stream_write_int64 (io_stream, options->start_time); } - + if (!err) { err = krb5int_ipc_stream_write_int64 (io_stream, options->lifetime); } - + if (!err) { err = krb5int_ipc_stream_write_int32 (io_stream, options->renewable); } - + if (!err) { - err = krb5int_ipc_stream_write_int64 (io_stream, + err = krb5int_ipc_stream_write_int64 (io_stream, options->renewal_lifetime); } - + if (!err) { err = krb5int_ipc_stream_write_int32 (io_stream, options->forwardable); } - + if (!err) { err = krb5int_ipc_stream_write_int32 (io_stream, options->proxiable); } - + if (!err) { err = krb5int_ipc_stream_write_int32 (io_stream, options->addressless); } - + if (!err) { err = krb5int_ipc_stream_write_string (io_stream, options->service_name); } - + if (options != in_options) { kim_options_free (&options); } - - return check_error (err); + + return check_error (err); } /* ------------------------------------------------------------------------ */ @@ -588,43 +588,43 @@ kim_error kim_options_read_from_stream (kim_options io_options, k5_ipc_stream io_stream) { kim_error err = KIM_NO_ERROR; - + if (!err && !io_options) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !io_stream ) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { err = krb5int_ipc_stream_read_int64 (io_stream, &io_options->start_time); } - + if (!err) { err = krb5int_ipc_stream_read_int64 (io_stream, &io_options->lifetime); } - + if (!err) { err = krb5int_ipc_stream_read_int32 (io_stream, &io_options->renewable); } - + if (!err) { - err = krb5int_ipc_stream_read_int64 (io_stream, + err = krb5int_ipc_stream_read_int64 (io_stream, &io_options->renewal_lifetime); } - + if (!err) { err = krb5int_ipc_stream_read_int32 (io_stream, &io_options->forwardable); } - + if (!err) { err = krb5int_ipc_stream_read_int32 (io_stream, &io_options->proxiable); } - + if (!err) { err = krb5int_ipc_stream_read_int32 (io_stream, &io_options->addressless); } - + if (!err) { char *service_name = NULL; err = krb5int_ipc_stream_read_string (io_stream, &service_name); - + if (!err) { kim_string_free (&io_options->service_name); if (service_name[0]) { @@ -633,21 +633,21 @@ kim_error kim_options_read_from_stream (kim_options io_options, io_options->service_name = kim_empty_string; } } - + krb5int_ipc_stream_free_string (service_name); } - - return check_error (err); + + return check_error (err); } /* ------------------------------------------------------------------------ */ kim_error kim_options_create_from_stream (kim_options *out_options, - k5_ipc_stream io_stream) + k5_ipc_stream io_stream) { kim_error err = KIM_NO_ERROR; kim_options options = NULL; - + if (!err && !out_options) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !io_stream ) { err = check_error (KIM_NULL_PARAMETER_ERR); } @@ -658,13 +658,13 @@ kim_error kim_options_create_from_stream (kim_options *out_options, if (!err) { kim_options_read_from_stream (options, io_stream); } - + if (!err) { *out_options = options; options = NULL; } - - kim_options_free (&options); - + + kim_options_free (&options); + return check_error (err); } diff --git a/src/kim/lib/kim_preferences.c b/src/kim/lib/kim_preferences.c index a9bd6ce559..19ee9030bb 100644 --- a/src/kim/lib/kim_preferences.c +++ b/src/kim/lib/kim_preferences.c @@ -8,7 +8,7 @@ * 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 @@ -53,14 +53,14 @@ struct kim_preferences_opaque { const struct kim_favorites_opaque kim_default_favorites = { 0, NULL, NULL }; -struct kim_preferences_opaque kim_preferences_initializer = { -KIM_OPTIONS_DEFAULT, +struct kim_preferences_opaque kim_preferences_initializer = { +KIM_OPTIONS_DEFAULT, FALSE, -kim_default_remember_options, +kim_default_remember_options, FALSE, -kim_default_client_identity, +kim_default_client_identity, FALSE, -kim_default_remember_client_identity, +kim_default_remember_client_identity, FALSE, kim_default_minimum_lifetime, kim_default_maximum_lifetime, @@ -79,13 +79,13 @@ static kim_error kim_favorites_resize (kim_favorites io_favorites, kim_count in_new_count) { kim_error err = KIM_NO_ERROR; - + if (!err && !io_favorites) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err && io_favorites->count != in_new_count) { kim_identity *identities = NULL; kim_options *options = NULL; - + if (in_new_count == 0) { if (io_favorites->identities) { free (io_favorites->identities); @@ -97,22 +97,22 @@ static kim_error kim_favorites_resize (kim_favorites io_favorites, if (!io_favorites->identities) { identities = malloc (sizeof (*identities) * in_new_count); } else { - identities = realloc (io_favorites->identities, + identities = realloc (io_favorites->identities, sizeof (*identities) * in_new_count); } if (!identities) { err = KIM_OUT_OF_MEMORY_ERR; } - + if (!err) { if (!io_favorites->options) { options = malloc (sizeof (*options) * in_new_count); } else { - options = realloc (io_favorites->options, + options = realloc (io_favorites->options, sizeof (*options) * in_new_count); } if (!options) { err = KIM_OUT_OF_MEMORY_ERR; } } } - + if (!err) { io_favorites->count = in_new_count; io_favorites->identities = identities; @@ -120,12 +120,12 @@ static kim_error kim_favorites_resize (kim_favorites io_favorites, identities = NULL; options = NULL; } - + if (identities) { free (identities); } if (options ) { free (options); } } - - return check_error (err); + + return check_error (err); } /* ------------------------------------------------------------------------ */ @@ -134,28 +134,28 @@ static kim_error kim_favorites_copy (kim_favorites in_favorites, kim_favorites io_favorites) { kim_error err = KIM_NO_ERROR; - + if (!err && !in_favorites) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !io_favorites) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { err = kim_favorites_resize (io_favorites, in_favorites->count); } - + if (!err) { kim_count i; - + for (i = 0; !err && i < io_favorites->count; i++) { - err = kim_identity_copy (&io_favorites->identities[i], + err = kim_identity_copy (&io_favorites->identities[i], in_favorites->identities[i]); - + if (!err) { - err = kim_options_copy (&io_favorites->options[i], + err = kim_options_copy (&io_favorites->options[i], in_favorites->options[i]); } } } - + return check_error (err); } @@ -165,14 +165,14 @@ kim_error kim_favorites_get_number_of_identities (kim_favorites in_favorites, kim_count *out_number_of_identities) { kim_error err = KIM_NO_ERROR; - + if (!err && !in_favorites ) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !out_number_of_identities) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { *out_number_of_identities = in_favorites->count; } - + return check_error (err); } @@ -186,39 +186,39 @@ kim_error kim_favorites_get_identity_at_index (kim_favorites in_favorites, kim_error err = KIM_NO_ERROR; kim_identity identity = NULL; kim_options options = KIM_OPTIONS_DEFAULT; - + if (!err && !in_favorites) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !out_identity) { err = check_error (KIM_NULL_PARAMETER_ERR); } /* out_options may be NULL */ - + if (!err) { if (in_index >= in_favorites->count) { - err = kim_error_set_message_for_code (KIM_BAD_IDENTITY_INDEX_ERR, + err = kim_error_set_message_for_code (KIM_BAD_IDENTITY_INDEX_ERR, in_index); } } - + if (!err) { err = kim_identity_copy (&identity, in_favorites->identities[in_index]); } - + if (!err && in_favorites->options[in_index]) { err = kim_options_copy (&options, in_favorites->options[in_index]); } - + if (!err) { *out_identity = identity; identity = NULL; - + if (out_options) { *out_options = options; options = NULL; } } - + kim_identity_free (&identity); kim_options_free (&options); - + return check_error (err); } @@ -232,78 +232,78 @@ kim_error kim_favorites_add_identity (kim_favorites io_favorites, kim_identity identity = NULL; kim_options options = KIM_OPTIONS_DEFAULT; kim_count insert_at = 0; - + if (!err && !io_favorites) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !in_identity ) { err = check_error (KIM_NULL_PARAMETER_ERR); } /* in_options may be KIM_OPTIONS_DEFAULT (NULL) */ - + if (!err) { err = kim_identity_copy (&identity, in_identity); } - + if (!err) { err = kim_options_copy (&options, in_options); } - + if (!err) { kim_count i; - + for (i = 0; !err && i < io_favorites->count; i++) { kim_comparison comparison = 0; - + err = kim_identity_compare (io_favorites->identities[i], - in_identity, + in_identity, &comparison); - + if (!err) { if (kim_comparison_is_greater_than (comparison)) { /* insert before the first entry that is greater than us */ - break; - + break; + } else if (kim_comparison_is_equal_to (comparison)) { /* already in list */ kim_string display_string = NULL; - - err = kim_identity_get_display_string (in_identity, + + err = kim_identity_get_display_string (in_identity, &display_string); - + if (!err) { - err = kim_error_set_message_for_code (KIM_IDENTITY_ALREADY_IN_LIST_ERR, + err = kim_error_set_message_for_code (KIM_IDENTITY_ALREADY_IN_LIST_ERR, display_string); } - + kim_string_free (&display_string); } } } - + insert_at = i; /* Remember where we are going to insert */ } - + if (!err) { - err = kim_favorites_resize (io_favorites, + err = kim_favorites_resize (io_favorites, io_favorites->count + 1); } - + if (!err) { kim_count move_count = io_favorites->count - 1 - insert_at; - + memmove (&io_favorites->identities[insert_at + 1], &io_favorites->identities[insert_at], move_count * sizeof (*io_favorites->identities)); io_favorites->identities[insert_at] = identity; identity = NULL; - + memmove (&io_favorites->options[insert_at + 1], &io_favorites->options[insert_at], move_count * sizeof (*io_favorites->options)); io_favorites->options[insert_at] = options; options = NULL; } - + kim_options_free (&options); kim_identity_free (&identity); - + return check_error (err); } @@ -315,56 +315,56 @@ kim_error kim_favorites_remove_identity (kim_favorites io_favorites, kim_error err = KIM_NO_ERROR; kim_boolean found = 0; kim_count i; - + if (!err && !io_favorites) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !in_identity ) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { for (i = 0; !err && !found && i < io_favorites->count; i++) { kim_identity identity = io_favorites->identities[i]; kim_options options = io_favorites->options[i]; kim_comparison comparison; - + err = kim_identity_compare (in_identity, identity, &comparison); - + if (!err && kim_comparison_is_equal_to (comparison)) { kim_error terr = KIM_NO_ERROR; kim_count new_count = io_favorites->count - 1; - + found = 1; - - memmove (&io_favorites->identities[i], + + memmove (&io_favorites->identities[i], &io_favorites->identities[i + 1], (new_count - i) * sizeof (*io_favorites->identities)); - - memmove (&io_favorites->options[i], + + memmove (&io_favorites->options[i], &io_favorites->options[i + 1], (new_count - i) * sizeof (*io_favorites->options)); - + terr = kim_favorites_resize (io_favorites, new_count); if (terr) { kim_debug_printf ("failed to resize list to %d. Continuing.", new_count); } - + kim_options_free (&options); kim_identity_free (&identity); } } } - + if (!err && !found) { kim_string display_string = NULL; - + err = kim_identity_get_display_string (in_identity, &display_string); - + if (!err) { - err = kim_error_set_message_for_code (KIM_IDENTITY_NOT_IN_LIST_ERR, + err = kim_error_set_message_for_code (KIM_IDENTITY_NOT_IN_LIST_ERR, display_string); } - + kim_string_free (&display_string); } - + return check_error (err); } @@ -373,12 +373,12 @@ kim_error kim_favorites_remove_identity (kim_favorites io_favorites, kim_error kim_favorites_remove_all_identities (kim_favorites io_favorites) { kim_error err = KIM_NO_ERROR; - + if (!err && !io_favorites) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { kim_count i; - + for (i = 0; i < io_favorites->count; i++) { kim_identity_free (&io_favorites->identities[i]); kim_options_free (&io_favorites->options[i]); @@ -389,7 +389,7 @@ kim_error kim_favorites_remove_all_identities (kim_favorites io_favorites) io_favorites->identities = NULL; io_favorites->options = NULL; } - + return check_error (err); } @@ -398,7 +398,7 @@ kim_error kim_favorites_remove_all_identities (kim_favorites io_favorites) static void kim_favorites_free (kim_favorites io_favorites) { kim_count i; - + for (i = 0; i < io_favorites->count; i++) { kim_identity_free (&io_favorites->identities[i]); kim_options_free (&io_favorites->options[i]); @@ -414,91 +414,91 @@ static void kim_favorites_free (kim_favorites io_favorites) static kim_error kim_preferences_read (kim_preferences in_preferences) { kim_error err = KIM_NO_ERROR; - + if (!err && !in_preferences) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { kim_options options = NULL; - + err = kim_os_preferences_get_options_for_key (kim_preference_key_options, &options); - + if (!err) { kim_options_free (&in_preferences->options); in_preferences->options = options; } } - + if (!err) { err = kim_os_preferences_get_boolean_for_key (kim_preference_key_remember_options, kim_default_remember_options, &in_preferences->remember_options); } - + if (!err) { kim_identity default_identity = kim_default_client_identity; kim_identity identity = NULL; - + err = kim_os_identity_create_for_username (&default_identity); - + if (!err) { err = kim_os_preferences_get_identity_for_key (kim_preference_key_client_identity, default_identity, &identity); } - + if (!err) { kim_identity_free (&in_preferences->client_identity); in_preferences->client_identity = identity; identity = NULL; } - + kim_identity_free (&default_identity); kim_identity_free (&identity); } - + if (!err) { err = kim_os_preferences_get_boolean_for_key (kim_preference_key_remember_client_identity, kim_default_remember_client_identity, &in_preferences->remember_client_identity); } - + if (!err) { struct kim_favorites_opaque favorites = kim_default_favorites; - + err = kim_os_preferences_get_favorites_for_key (kim_preference_key_favorites, &favorites); - + if (!err) { kim_favorites_remove_all_identities (&in_preferences->favorites); in_preferences->favorites = favorites; } } - + if (!err) { err = kim_os_preferences_get_lifetime_for_key (kim_preference_key_minimum_lifetime, kim_default_minimum_lifetime, &in_preferences->minimum_lifetime); } - + if (!err) { err = kim_os_preferences_get_lifetime_for_key (kim_preference_key_maximum_lifetime, kim_default_maximum_lifetime, &in_preferences->maximum_lifetime); } - + if (!err) { err = kim_os_preferences_get_lifetime_for_key (kim_preference_key_minimum_renewal_lifetime, kim_default_minimum_renewal_lifetime, &in_preferences->minimum_renewal_lifetime); } - + if (!err) { err = kim_os_preferences_get_lifetime_for_key (kim_preference_key_maximum_renewal_lifetime, kim_default_maximum_renewal_lifetime, &in_preferences->maximum_renewal_lifetime); } - + return check_error (err); } @@ -507,60 +507,60 @@ static kim_error kim_preferences_read (kim_preferences in_preferences) static kim_error kim_preferences_write (kim_preferences in_preferences) { kim_error err = KIM_NO_ERROR; - + if (!err && !in_preferences) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err && in_preferences->options_changed) { err = kim_os_preferences_set_options_for_key (kim_preference_key_options, - in_preferences->options); + in_preferences->options); } - + if (!err && in_preferences->remember_options_changed) { - err = kim_os_preferences_set_boolean_for_key (kim_preference_key_remember_options, + err = kim_os_preferences_set_boolean_for_key (kim_preference_key_remember_options, in_preferences->remember_options); } - + if (!err && in_preferences->client_identity_changed) { kim_identity default_identity = kim_default_client_identity; - + err = kim_os_identity_create_for_username (&default_identity); - + if (!err) { - err = kim_os_preferences_set_identity_for_key (kim_preference_key_client_identity, + err = kim_os_preferences_set_identity_for_key (kim_preference_key_client_identity, in_preferences->client_identity); } - + kim_identity_free (&default_identity); } - + if (!err && in_preferences->remember_client_identity_changed) { - err = kim_os_preferences_set_boolean_for_key (kim_preference_key_remember_client_identity, + err = kim_os_preferences_set_boolean_for_key (kim_preference_key_remember_client_identity, in_preferences->remember_client_identity); } - + if (!err && in_preferences->favorites_changed) { - err = kim_os_preferences_set_favorites_for_key (kim_preference_key_favorites, + err = kim_os_preferences_set_favorites_for_key (kim_preference_key_favorites, &in_preferences->favorites); } - + if (!err && in_preferences->lifetime_range_changed) { - err = kim_os_preferences_set_lifetime_for_key (kim_preference_key_minimum_lifetime, + err = kim_os_preferences_set_lifetime_for_key (kim_preference_key_minimum_lifetime, in_preferences->minimum_lifetime); if (!err) { - err = kim_os_preferences_set_lifetime_for_key (kim_preference_key_maximum_lifetime, + err = kim_os_preferences_set_lifetime_for_key (kim_preference_key_maximum_lifetime, in_preferences->maximum_lifetime); } } - + if (!err && in_preferences->renewal_lifetime_range_changed) { - err = kim_os_preferences_set_lifetime_for_key (kim_preference_key_minimum_renewal_lifetime, + err = kim_os_preferences_set_lifetime_for_key (kim_preference_key_minimum_renewal_lifetime, in_preferences->minimum_renewal_lifetime); if (!err) { - err = kim_os_preferences_set_lifetime_for_key (kim_preference_key_maximum_renewal_lifetime, + err = kim_os_preferences_set_lifetime_for_key (kim_preference_key_maximum_renewal_lifetime, in_preferences->maximum_renewal_lifetime); } } - + if (!err) { in_preferences->options_changed = 0; in_preferences->remember_options_changed = 0; @@ -570,7 +570,7 @@ static kim_error kim_preferences_write (kim_preferences in_preferences) in_preferences->renewal_lifetime_range_changed = 0; in_preferences->favorites_changed = 0; } - + return check_error (err); } @@ -582,23 +582,23 @@ static inline kim_error kim_preferences_allocate (kim_preferences *out_preferenc { kim_error err = kim_library_init (); kim_preferences preferences = NULL; - + if (!err && !out_preferences) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { preferences = malloc (sizeof (*preferences)); if (!preferences) { err = KIM_OUT_OF_MEMORY_ERR; } } - + if (!err) { *preferences = kim_preferences_initializer; *out_preferences = preferences; preferences = NULL; } - + kim_preferences_free (&preferences); - - return check_error (err); + + return check_error (err); } /* ------------------------------------------------------------------------ */ @@ -607,25 +607,25 @@ kim_error kim_preferences_create (kim_preferences *out_preferences) { kim_error err = KIM_NO_ERROR; kim_preferences preferences = NULL; - + if (!err && !out_preferences) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { err = kim_preferences_allocate (&preferences); } - + if (!err) { err = kim_preferences_read (preferences); } - + if (!err) { *out_preferences = preferences; preferences = NULL; } - + kim_preferences_free (&preferences); - - + + return check_error (err); } @@ -636,37 +636,37 @@ kim_error kim_preferences_copy (kim_preferences *out_preferences, { kim_error err = KIM_NO_ERROR; kim_preferences preferences = NULL; - + if (!err && !out_preferences) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !in_preferences ) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { err = kim_preferences_allocate (&preferences); } - + if (!err) { preferences->remember_options = in_preferences->remember_options; err = kim_options_copy (&preferences->options, in_preferences->options); } - + if (!err) { preferences->remember_client_identity = in_preferences->remember_client_identity; err = kim_identity_copy (&preferences->client_identity, in_preferences->client_identity); } - + if (!err) { - err = kim_favorites_copy (&preferences->favorites, + err = kim_favorites_copy (&preferences->favorites, &in_preferences->favorites); } - + if (!err) { *out_preferences = preferences; preferences = NULL; } - + kim_preferences_free (&preferences); - - + + return check_error (err); } @@ -677,20 +677,20 @@ kim_error kim_preferences_set_options (kim_preferences io_preferences, { kim_error err = KIM_NO_ERROR; kim_options options = NULL; - + if (!err && !io_preferences) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !in_options ) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { err = kim_options_copy (&options, in_options); } - + if (!err) { kim_options_free (&io_preferences->options); io_preferences->options = options; io_preferences->options_changed = TRUE; } - + return check_error (err); } @@ -700,14 +700,14 @@ kim_error kim_preferences_get_options (kim_preferences in_preferences, kim_options *out_options) { kim_error err = KIM_NO_ERROR; - + if (!err && !in_preferences) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !out_options ) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { err = kim_options_copy (out_options, in_preferences->options); } - + return check_error (err); } @@ -717,14 +717,14 @@ kim_error kim_preferences_set_remember_options (kim_preferences io_preferences, kim_boolean in_remember_options) { kim_error err = KIM_NO_ERROR; - + if (!err && !io_preferences) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { io_preferences->remember_options = in_remember_options; io_preferences->remember_options_changed = TRUE; } - + return check_error (err); } @@ -734,14 +734,14 @@ kim_error kim_preferences_get_remember_options (kim_preferences in_preferences, kim_boolean *out_remember_options) { kim_error err = KIM_NO_ERROR; - + if (!err && !in_preferences ) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !out_remember_options) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { *out_remember_options = in_preferences->remember_options; } - + return check_error (err); } @@ -752,20 +752,20 @@ kim_error kim_preferences_set_client_identity (kim_preferences io_preferences, { kim_error err = KIM_NO_ERROR; kim_identity identity = KIM_IDENTITY_ANY; - + if (!err && !io_preferences ) { err = check_error (KIM_NULL_PARAMETER_ERR); } /* in_client_identity may be KIM_IDENTITY_ANY */ - + if (!err && in_client_identity) { err = kim_identity_copy (&identity, in_client_identity); } - + if (!err) { kim_identity_free (&io_preferences->client_identity); io_preferences->client_identity = identity; io_preferences->client_identity_changed = TRUE; } - + return check_error (err); } @@ -775,14 +775,14 @@ kim_error kim_preferences_get_client_identity (kim_preferences in_preferences, kim_identity *out_client_identity) { kim_error err = KIM_NO_ERROR; - + if (!err && !in_preferences ) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !out_client_identity) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { err = kim_identity_copy (out_client_identity, in_preferences->client_identity); } - + return check_error (err); } @@ -792,14 +792,14 @@ kim_error kim_preferences_set_remember_client_identity (kim_preferences io_prefe kim_boolean in_remember_client_identity) { kim_error err = KIM_NO_ERROR; - + if (!err && !io_preferences) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { io_preferences->remember_client_identity = in_remember_client_identity; io_preferences->remember_client_identity_changed = TRUE; } - + return check_error (err); } @@ -809,14 +809,14 @@ kim_error kim_preferences_get_remember_client_identity (kim_preferences in_pref kim_boolean *out_remember_client_identity) { kim_error err = KIM_NO_ERROR; - + if (!err && !in_preferences ) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !out_remember_client_identity) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { *out_remember_client_identity = in_preferences->remember_client_identity; } - + return check_error (err); } @@ -826,14 +826,14 @@ kim_error kim_preferences_set_minimum_lifetime (kim_preferences io_preferences, kim_lifetime in_minimum_lifetime) { kim_error err = KIM_NO_ERROR; - + if (!err && !io_preferences) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { io_preferences->minimum_lifetime = in_minimum_lifetime; io_preferences->lifetime_range_changed = TRUE; } - + return check_error (err); } @@ -843,14 +843,14 @@ kim_error kim_preferences_get_minimum_lifetime (kim_preferences in_preferences, kim_lifetime *out_minimum_lifetime) { kim_error err = KIM_NO_ERROR; - + if (!err && !in_preferences ) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !out_minimum_lifetime) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { *out_minimum_lifetime = in_preferences->minimum_lifetime; } - + return check_error (err); } @@ -860,14 +860,14 @@ kim_error kim_preferences_set_maximum_lifetime (kim_preferences io_preferences, kim_lifetime in_maximum_lifetime) { kim_error err = KIM_NO_ERROR; - + if (!err && !io_preferences) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { io_preferences->maximum_lifetime = in_maximum_lifetime; io_preferences->lifetime_range_changed = TRUE; } - + return check_error (err); } @@ -877,14 +877,14 @@ kim_error kim_preferences_get_maximum_lifetime (kim_preferences in_preferences, kim_lifetime *out_maximum_lifetime) { kim_error err = KIM_NO_ERROR; - + if (!err && !in_preferences ) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !out_maximum_lifetime) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { *out_maximum_lifetime = in_preferences->maximum_lifetime; } - + return check_error (err); } @@ -894,14 +894,14 @@ kim_error kim_preferences_set_minimum_renewal_lifetime (kim_preferences io_prefe kim_lifetime in_minimum_renewal_lifetime) { kim_error err = KIM_NO_ERROR; - + if (!err && !io_preferences) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { io_preferences->minimum_renewal_lifetime = in_minimum_renewal_lifetime; io_preferences->renewal_lifetime_range_changed = TRUE; } - + return check_error (err); } @@ -911,14 +911,14 @@ kim_error kim_preferences_get_minimum_renewal_lifetime (kim_preferences in_pref kim_lifetime *out_minimum_renewal_lifetime) { kim_error err = KIM_NO_ERROR; - + if (!err && !in_preferences ) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !out_minimum_renewal_lifetime) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { *out_minimum_renewal_lifetime = in_preferences->minimum_renewal_lifetime; } - + return check_error (err); } @@ -928,14 +928,14 @@ kim_error kim_preferences_set_maximum_renewal_lifetime (kim_preferences io_prefe kim_lifetime in_maximum_renewal_lifetime) { kim_error err = KIM_NO_ERROR; - + if (!err && !io_preferences) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { io_preferences->maximum_renewal_lifetime = in_maximum_renewal_lifetime; io_preferences->renewal_lifetime_range_changed = TRUE; } - + return check_error (err); } @@ -945,14 +945,14 @@ kim_error kim_preferences_get_maximum_renewal_lifetime (kim_preferences in_pref kim_lifetime *out_maximum_renewal_lifetime) { kim_error err = KIM_NO_ERROR; - + if (!err && !in_preferences ) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !out_maximum_renewal_lifetime) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { *out_maximum_renewal_lifetime = in_preferences->maximum_renewal_lifetime; } - + return check_error (err); } @@ -973,18 +973,18 @@ kim_error kim_preferences_get_favorite_identity_at_index (kim_preferences in_pr kim_options *out_options) { kim_error err = KIM_NO_ERROR; - + if (!err && !in_preferences) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !out_identity ) { err = check_error (KIM_NULL_PARAMETER_ERR); } /* out_options may be NULL */ - + if (!err) { err = kim_favorites_get_identity_at_index (&in_preferences->favorites, in_index, out_identity, out_options); } - + return check_error (err); } @@ -995,20 +995,20 @@ kim_error kim_preferences_add_favorite_identity (kim_preferences io_preferences, kim_options in_options) { kim_error err = KIM_NO_ERROR; - + if (!err && !io_preferences) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !in_identity ) { err = check_error (KIM_NULL_PARAMETER_ERR); } /* in_options may be KIM_OPTIONS_DEFAULT (NULL) */ - + if (!err) { err = kim_favorites_add_identity (&io_preferences->favorites, in_identity, in_options); } - + if (!err) { io_preferences->favorites_changed = 1; } - + return check_error (err); } @@ -1018,19 +1018,19 @@ kim_error kim_preferences_remove_favorite_identity (kim_preferences io_preferenc kim_identity in_identity) { kim_error err = KIM_NO_ERROR; - + if (!err && !io_preferences) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !in_identity ) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { err = kim_favorites_remove_identity (&io_preferences->favorites, in_identity); } - + if (!err) { io_preferences->favorites_changed = 1; } - + return check_error (err); } @@ -1039,17 +1039,17 @@ kim_error kim_preferences_remove_favorite_identity (kim_preferences io_preferenc kim_error kim_preferences_remove_all_favorite_identities (kim_preferences io_preferences) { kim_error err = KIM_NO_ERROR; - + if (!err && !io_preferences) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { err = kim_favorites_remove_all_identities (&io_preferences->favorites); } - + if (!err) { io_preferences->favorites_changed = 1; } - + return check_error (err); } @@ -1058,17 +1058,17 @@ kim_error kim_preferences_remove_all_favorite_identities (kim_preferences io_pre kim_error kim_preferences_synchronize (kim_preferences in_preferences) { kim_error err = KIM_NO_ERROR; - + if (!err && !in_preferences) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { err = kim_preferences_write (in_preferences); } - + if (!err) { err = kim_preferences_read (in_preferences); } - + return check_error (err); } @@ -1085,4 +1085,3 @@ void kim_preferences_free (kim_preferences *io_preferences) *io_preferences = NULL; } } - diff --git a/src/kim/lib/kim_preferences_private.h b/src/kim/lib/kim_preferences_private.h index 2390988296..1b7e247d77 100644 --- a/src/kim/lib/kim_preferences_private.h +++ b/src/kim/lib/kim_preferences_private.h @@ -90,37 +90,37 @@ kim_error kim_favorites_remove_all_identities (kim_favorites io_favorites); /* OS-specific functions to be implemented per-platform */ -kim_error kim_os_preferences_get_options_for_key (kim_preference_key in_key, +kim_error kim_os_preferences_get_options_for_key (kim_preference_key in_key, kim_options *out_options); -kim_error kim_os_preferences_set_options_for_key (kim_preference_key in_key, +kim_error kim_os_preferences_set_options_for_key (kim_preference_key in_key, kim_options in_options); -kim_error kim_os_preferences_get_identity_for_key (kim_preference_key in_key, +kim_error kim_os_preferences_get_identity_for_key (kim_preference_key in_key, kim_identity in_hardcoded_default, kim_identity *out_identity); -kim_error kim_os_preferences_set_identity_for_key (kim_preference_key in_key, +kim_error kim_os_preferences_set_identity_for_key (kim_preference_key in_key, kim_identity in_identity); -kim_error kim_os_preferences_get_favorites_for_key (kim_preference_key in_key, +kim_error kim_os_preferences_get_favorites_for_key (kim_preference_key in_key, kim_favorites io_favorites); -kim_error kim_os_preferences_set_favorites_for_key (kim_preference_key in_key, +kim_error kim_os_preferences_set_favorites_for_key (kim_preference_key in_key, kim_favorites in_favorites); -kim_error kim_os_preferences_get_lifetime_for_key (kim_preference_key in_key, +kim_error kim_os_preferences_get_lifetime_for_key (kim_preference_key in_key, kim_lifetime in_hardcoded_default, kim_lifetime *out_lifetime); -kim_error kim_os_preferences_set_lifetime_for_key (kim_preference_key in_key, +kim_error kim_os_preferences_set_lifetime_for_key (kim_preference_key in_key, kim_lifetime in_lifetime); -kim_error kim_os_preferences_get_boolean_for_key (kim_preference_key in_key, +kim_error kim_os_preferences_get_boolean_for_key (kim_preference_key in_key, kim_boolean in_hardcoded_default, kim_boolean *out_boolean); -kim_error kim_os_preferences_set_boolean_for_key (kim_preference_key in_key, +kim_error kim_os_preferences_set_boolean_for_key (kim_preference_key in_key, kim_boolean in_boolean); #endif /* KIM_PREFERENCES_PRIVATE_H */ diff --git a/src/kim/lib/kim_selection_hints.c b/src/kim/lib/kim_selection_hints.c index 3704d87e99..6aba4420d9 100644 --- a/src/kim/lib/kim_selection_hints.c +++ b/src/kim/lib/kim_selection_hints.c @@ -6,7 +6,7 @@ * 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 @@ -40,7 +40,7 @@ struct kim_selection_hints_opaque { kim_string server; }; -struct kim_selection_hints_opaque kim_selection_hints_initializer = { +struct kim_selection_hints_opaque kim_selection_hints_initializer = { NULL, kim_empty_string, KIM_OPTIONS_DEFAULT, @@ -60,23 +60,23 @@ static inline kim_error kim_selection_hints_allocate (kim_selection_hints *out_s { kim_error err = kim_library_init (); kim_selection_hints selection_hints = NULL; - + if (!err && !out_selection_hints) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { selection_hints = malloc (sizeof (*selection_hints)); if (!selection_hints) { err = KIM_OUT_OF_MEMORY_ERR; } } - + if (!err) { *selection_hints = kim_selection_hints_initializer; *out_selection_hints = selection_hints; selection_hints = NULL; } - + kim_selection_hints_free (&selection_hints); - - return check_error (err); + + return check_error (err); } /* ------------------------------------------------------------------------ */ @@ -86,27 +86,27 @@ kim_error kim_selection_hints_create (kim_selection_hints *out_selection_hints, { kim_error err = KIM_NO_ERROR; kim_selection_hints selection_hints = NULL; - + if (!err && !out_selection_hints ) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !in_application_identifier) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { err = kim_selection_hints_allocate (&selection_hints); } - + if (!err) { - err = kim_string_copy (&selection_hints->application_identifier, + err = kim_string_copy (&selection_hints->application_identifier, in_application_identifier); } - + if (!err) { *out_selection_hints = selection_hints; selection_hints = NULL; } - + kim_selection_hints_free (&selection_hints); - - return check_error (err); + + return check_error (err); } /* ------------------------------------------------------------------------ */ @@ -116,70 +116,70 @@ kim_error kim_selection_hints_copy (kim_selection_hints *out_selection_hints, { kim_error err = KIM_NO_ERROR; kim_selection_hints selection_hints = NULL; - + if (!err && !out_selection_hints) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !in_selection_hints ) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { err = kim_selection_hints_allocate (&selection_hints); } - + if (!err) { - err = kim_string_copy (&selection_hints->application_identifier, + err = kim_string_copy (&selection_hints->application_identifier, in_selection_hints->application_identifier); } - + if (!err && in_selection_hints->explanation) { - err = kim_string_copy (&selection_hints->explanation, + err = kim_string_copy (&selection_hints->explanation, in_selection_hints->explanation); } - + if (!err && in_selection_hints->options) { - err = kim_options_copy (&selection_hints->options, + err = kim_options_copy (&selection_hints->options, in_selection_hints->options); } - + if (!err && in_selection_hints->service_identity) { - err = kim_string_copy (&selection_hints->service_identity, + err = kim_string_copy (&selection_hints->service_identity, in_selection_hints->service_identity); } - + if (!err && in_selection_hints->client_realm) { - err = kim_string_copy (&selection_hints->client_realm, + err = kim_string_copy (&selection_hints->client_realm, in_selection_hints->client_realm); } - + if (!err && in_selection_hints->user) { - err = kim_string_copy (&selection_hints->user, + err = kim_string_copy (&selection_hints->user, in_selection_hints->user); } - + if (!err && in_selection_hints->service_realm) { - err = kim_string_copy (&selection_hints->service_realm, + err = kim_string_copy (&selection_hints->service_realm, in_selection_hints->service_realm); } - + if (!err && in_selection_hints->service) { - err = kim_string_copy (&selection_hints->service, + err = kim_string_copy (&selection_hints->service, in_selection_hints->service); } - + if (!err && in_selection_hints->server) { - err = kim_string_copy (&selection_hints->server, + err = kim_string_copy (&selection_hints->server, in_selection_hints->server); } - + if (!err) { selection_hints->allow_user_interaction = in_selection_hints->allow_user_interaction; selection_hints->use_cached_results = in_selection_hints->use_cached_results; - + *out_selection_hints = selection_hints; selection_hints = NULL; } - + kim_selection_hints_free (&selection_hints); - - return check_error (err); + + return check_error (err); } /* ------------------------------------------------------------------------ */ @@ -189,48 +189,48 @@ kim_error kim_selection_hints_set_hint (kim_selection_hints io_selection_hints, kim_string in_hint_string) { kim_error err = KIM_NO_ERROR; - + if (!err && !io_selection_hints) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !in_hint_key ) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !in_hint_string ) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { if (!strcmp (in_hint_key, kim_hint_key_client_realm)) { kim_string_free (&io_selection_hints->client_realm); - err = kim_string_copy (&io_selection_hints->client_realm, + err = kim_string_copy (&io_selection_hints->client_realm, in_hint_string); - + } else if (!strcmp (in_hint_key, kim_hint_key_user)) { kim_string_free (&io_selection_hints->user); - err = kim_string_copy (&io_selection_hints->user, + err = kim_string_copy (&io_selection_hints->user, in_hint_string); - + } else if (!strcmp (in_hint_key, kim_hint_key_service_realm)) { kim_string_free (&io_selection_hints->service_realm); - err = kim_string_copy (&io_selection_hints->service_realm, + err = kim_string_copy (&io_selection_hints->service_realm, in_hint_string); - + } else if (!strcmp (in_hint_key, kim_hint_key_service)) { kim_string_free (&io_selection_hints->service); - err = kim_string_copy (&io_selection_hints->service, + err = kim_string_copy (&io_selection_hints->service, in_hint_string); - + } else if (!strcmp (in_hint_key, kim_hint_key_server)) { kim_string_free (&io_selection_hints->server); - err = kim_string_copy (&io_selection_hints->server, + err = kim_string_copy (&io_selection_hints->server, in_hint_string); - + } else if (!strcmp (in_hint_key, kim_hint_key_service_identity)) { kim_string_free (&io_selection_hints->service_identity); - err = kim_string_copy (&io_selection_hints->service_identity, + err = kim_string_copy (&io_selection_hints->service_identity, in_hint_string); - + } else { err = kim_error_set_message_for_code (KIM_UNSUPPORTED_HINT_ERR, in_hint_key); } } - + return check_error (err); } @@ -242,36 +242,36 @@ kim_error kim_selection_hints_get_hint (kim_selection_hints in_selection_hints, { kim_error err = KIM_NO_ERROR; kim_string hint = NULL; - + if (!err && !in_selection_hints) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !in_hint_key ) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !out_hint_string ) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { if (!strcmp (in_hint_key, kim_hint_key_client_realm)) { hint = in_selection_hints->client_realm; - + } else if (!strcmp (in_hint_key, kim_hint_key_user)) { hint = in_selection_hints->user; - + } else if (!strcmp (in_hint_key, kim_hint_key_service_realm)) { hint = in_selection_hints->service_realm; - + } else if (!strcmp (in_hint_key, kim_hint_key_service)) { hint = in_selection_hints->service; - + } else if (!strcmp (in_hint_key, kim_hint_key_server)) { hint = in_selection_hints->server; - + } else if (!strcmp (in_hint_key, kim_hint_key_service_identity)) { hint = in_selection_hints->service_identity; - + } else { err = kim_error_set_message_for_code (KIM_UNSUPPORTED_HINT_ERR, in_hint_key); } } - + if (!err) { if (hint && hint != kim_empty_string) { err = kim_string_copy (out_hint_string, hint); @@ -279,7 +279,7 @@ kim_error kim_selection_hints_get_hint (kim_selection_hints in_selection_hints, *out_hint_string = NULL; } } - + return check_error (err); } @@ -289,14 +289,14 @@ kim_error kim_selection_hints_set_explanation (kim_selection_hints io_selection_ kim_string in_explanation) { kim_error err = KIM_NO_ERROR; - + if (!err && !io_selection_hints) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !in_explanation ) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { err = kim_string_copy (&io_selection_hints->explanation, in_explanation); } - + return check_error (err); } @@ -306,19 +306,19 @@ kim_error kim_selection_hints_get_explanation (kim_selection_hints in_selection kim_string *out_explanation) { kim_error err = KIM_NO_ERROR; - + if (!err && !in_selection_hints) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !out_explanation ) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { - if (in_selection_hints->explanation && + if (in_selection_hints->explanation && in_selection_hints->explanation != kim_empty_string) { err = kim_string_copy (out_explanation, in_selection_hints->explanation); } else { *out_explanation = NULL; } } - + return check_error (err); } @@ -328,19 +328,19 @@ kim_error kim_selection_hints_get_application_id (kim_selection_hints in_select kim_string *out_application_id) { kim_error err = KIM_NO_ERROR; - + if (!err && !in_selection_hints) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !out_application_id) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { if (in_selection_hints->application_identifier) { - err = kim_string_copy (out_application_id, + err = kim_string_copy (out_application_id, in_selection_hints->application_identifier); } else { *out_application_id = NULL; } } - + return check_error (err); } @@ -350,14 +350,14 @@ kim_error kim_selection_hints_set_options (kim_selection_hints io_selection_hint kim_options in_options) { kim_error err = KIM_NO_ERROR; - + if (!err && !io_selection_hints) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !in_options ) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { err = kim_options_copy (&io_selection_hints->options, in_options); } - + return check_error (err); } @@ -367,14 +367,14 @@ kim_error kim_selection_hints_get_options (kim_selection_hints in_selection_hin kim_options *out_options) { kim_error err = KIM_NO_ERROR; - + if (!err && !in_selection_hints) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !out_options ) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { err = kim_options_copy (out_options, in_selection_hints->options); } - + return check_error (err); } @@ -384,13 +384,13 @@ kim_error kim_selection_hints_set_allow_user_interaction (kim_selection_hints io kim_boolean in_allow_user_interaction) { kim_error err = KIM_NO_ERROR; - + if (!err && !io_selection_hints ) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { io_selection_hints->allow_user_interaction = in_allow_user_interaction; } - + return check_error (err); } @@ -400,14 +400,14 @@ kim_error kim_selection_hints_get_allow_user_interaction (kim_selection_hints i kim_boolean *out_allow_user_interaction) { kim_error err = KIM_NO_ERROR; - + if (!err && !in_selection_hints ) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !out_allow_user_interaction) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { *out_allow_user_interaction = in_selection_hints->allow_user_interaction; } - + return check_error (err); } @@ -417,13 +417,13 @@ kim_error kim_selection_hints_set_remember_identity (kim_selection_hints io_sele kim_boolean in_use_cached_results) { kim_error err = KIM_NO_ERROR; - + if (!err && !io_selection_hints ) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { io_selection_hints->use_cached_results = in_use_cached_results; } - + return check_error (err); } @@ -433,14 +433,14 @@ kim_error kim_selection_hints_get_remember_identity (kim_selection_hints in_sel kim_boolean *out_use_cached_results) { kim_error err = KIM_NO_ERROR; - + if (!err && !in_selection_hints ) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !out_use_cached_results) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { *out_use_cached_results = in_selection_hints->use_cached_results; } - + return check_error (err); } @@ -452,56 +452,56 @@ kim_error kim_selection_hints_get_identity (kim_selection_hints in_selection_hi kim_error err = KIM_NO_ERROR; kim_identity identity = NULL; kim_ccache ccache = NULL; - + if (!err && !in_selection_hints) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !out_identity ) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err && in_selection_hints->use_cached_results) { err = kim_os_selection_hints_lookup_identity (in_selection_hints, &identity); } - + if (!err && !identity && in_selection_hints->allow_user_interaction) { kim_ui_context context; - + err = kim_ui_init (&context); - + while (!err && !identity) { kim_boolean user_wants_change_password = 0; - err = kim_ui_select_identity (&context, - in_selection_hints, + err = kim_ui_select_identity (&context, + in_selection_hints, &identity, &user_wants_change_password); - + if (!err && user_wants_change_password) { - err = kim_identity_change_password_common (identity, 0, - &context, + err = kim_identity_change_password_common (identity, 0, + &context, NULL); - + /* reenter select_identity so just forget this identity * even if we got an error */ - if (err == KIM_USER_CANCELED_ERR || + if (err == KIM_USER_CANCELED_ERR || err == KIM_DUPLICATE_UI_REQUEST_ERR) { err = KIM_NO_ERROR; } kim_identity_free (&identity); } - + } - + if (context.initialized) { kim_error terr = KIM_NO_ERROR; terr = kim_ui_fini (&context); err = (terr != KIM_NO_ERROR) ? terr : err; } } - + if (!err) { *out_identity = identity; identity = NULL; } - + kim_identity_free (&identity); kim_ccache_free (&ccache); - + return check_error (err); } @@ -511,15 +511,15 @@ kim_error kim_selection_hints_remember_identity (kim_selection_hints in_selectio kim_identity in_identity) { kim_error err = KIM_NO_ERROR; - + if (!err && !in_selection_hints) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !in_identity ) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { - err = kim_os_selection_hints_remember_identity (in_selection_hints, + err = kim_os_selection_hints_remember_identity (in_selection_hints, in_identity); } - + return check_error (err); } @@ -528,13 +528,13 @@ kim_error kim_selection_hints_remember_identity (kim_selection_hints in_selectio kim_error kim_selection_hints_forget_identity (kim_selection_hints in_selection_hints) { kim_error err = KIM_NO_ERROR; - + if (!err && !in_selection_hints) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { err = kim_os_selection_hints_forget_identity (in_selection_hints); } - + return check_error (err); } @@ -544,10 +544,10 @@ kim_error kim_selection_hints_get_preference_strings (kim_selection_hints kim_selection_hints_preference_strings *io_preference_strings) { kim_error err = KIM_NO_ERROR; - + if (!err && !in_selection_hints ) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !io_preference_strings) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { io_preference_strings->application_identifier = in_selection_hints->application_identifier; io_preference_strings->service_identity = in_selection_hints->service_identity; @@ -557,7 +557,7 @@ kim_error kim_selection_hints_get_preference_strings (kim_selection_hints io_preference_strings->service = in_selection_hints->service; io_preference_strings->server = in_selection_hints->server; } - + return check_error (err); } @@ -588,56 +588,56 @@ kim_error kim_selection_hints_write_to_stream (kim_selection_hints in_selection_ k5_ipc_stream io_stream) { kim_error err = KIM_NO_ERROR; - + if (!err && !in_selection_hints) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !io_stream ) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err) { - err = krb5int_ipc_stream_write_string (io_stream, + err = krb5int_ipc_stream_write_string (io_stream, in_selection_hints->application_identifier); } - + if (!err) { - err = krb5int_ipc_stream_write_string (io_stream, + err = krb5int_ipc_stream_write_string (io_stream, in_selection_hints->explanation); } - + if (!err) { - err = kim_options_write_to_stream (in_selection_hints->options, + err = kim_options_write_to_stream (in_selection_hints->options, io_stream); } - + if (!err) { - err = krb5int_ipc_stream_write_string (io_stream, + err = krb5int_ipc_stream_write_string (io_stream, in_selection_hints->service_identity); } - + if (!err) { - err = krb5int_ipc_stream_write_string (io_stream, + err = krb5int_ipc_stream_write_string (io_stream, in_selection_hints->client_realm); } - + if (!err) { - err = krb5int_ipc_stream_write_string (io_stream, + err = krb5int_ipc_stream_write_string (io_stream, in_selection_hints->user); } - + if (!err) { - err = krb5int_ipc_stream_write_string (io_stream, + err = krb5int_ipc_stream_write_string (io_stream, in_selection_hints->service_realm); } - + if (!err) { - err = krb5int_ipc_stream_write_string (io_stream, + err = krb5int_ipc_stream_write_string (io_stream, in_selection_hints->service); } - + if (!err) { - err = krb5int_ipc_stream_write_string (io_stream, + err = krb5int_ipc_stream_write_string (io_stream, in_selection_hints->server); } - - return check_error (err); + + return check_error (err); } /* ------------------------------------------------------------------------ */ @@ -646,114 +646,114 @@ kim_error kim_selection_hints_read_from_stream (kim_selection_hints io_selection k5_ipc_stream io_stream) { kim_error err = KIM_NO_ERROR; - + if (!err && !io_selection_hints) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !io_stream ) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { char *application_identifier = NULL; err = krb5int_ipc_stream_read_string (io_stream, &application_identifier); - + if (!err) { - err = kim_string_copy (&io_selection_hints->application_identifier, + err = kim_string_copy (&io_selection_hints->application_identifier, application_identifier); } - + krb5int_ipc_stream_free_string (application_identifier); } - + if (!err) { char *explanation = NULL; err = krb5int_ipc_stream_read_string (io_stream, &explanation); - + if (!err) { - err = kim_string_copy (&io_selection_hints->explanation, + err = kim_string_copy (&io_selection_hints->explanation, explanation); } - + krb5int_ipc_stream_free_string (explanation); } - + if (!err) { if (io_selection_hints->options) { - err = kim_options_read_from_stream (io_selection_hints->options, + err = kim_options_read_from_stream (io_selection_hints->options, io_stream); } else { - err = kim_options_create_from_stream (&io_selection_hints->options, + err = kim_options_create_from_stream (&io_selection_hints->options, io_stream); } } - + if (!err) { char *service_identity = NULL; err = krb5int_ipc_stream_read_string (io_stream, &service_identity); - + if (!err) { - err = kim_string_copy (&io_selection_hints->service_identity, + err = kim_string_copy (&io_selection_hints->service_identity, service_identity); } - + krb5int_ipc_stream_free_string (service_identity); } - + if (!err) { char *client_realm = NULL; err = krb5int_ipc_stream_read_string (io_stream, &client_realm); - + if (!err) { - err = kim_string_copy (&io_selection_hints->client_realm, + err = kim_string_copy (&io_selection_hints->client_realm, client_realm); } - + krb5int_ipc_stream_free_string (client_realm); } - + if (!err) { char *user = NULL; err = krb5int_ipc_stream_read_string (io_stream, &user); - + if (!err) { err = kim_string_copy (&io_selection_hints->user, user); } - + krb5int_ipc_stream_free_string (user); } - + if (!err) { char *service_realm = NULL; err = krb5int_ipc_stream_read_string (io_stream, &service_realm); - + if (!err) { - err = kim_string_copy (&io_selection_hints->service_realm, + err = kim_string_copy (&io_selection_hints->service_realm, service_realm); } - + krb5int_ipc_stream_free_string (service_realm); } - + if (!err) { char *service = NULL; err = krb5int_ipc_stream_read_string (io_stream, &service); - + if (!err) { err = kim_string_copy (&io_selection_hints->service, service); } - + krb5int_ipc_stream_free_string (service); } - + if (!err) { char *server = NULL; err = krb5int_ipc_stream_read_string (io_stream, &server); - + if (!err) { err = kim_string_copy (&io_selection_hints->server, server); } - + krb5int_ipc_stream_free_string (server); } - - return check_error (err); + + return check_error (err); } /* ------------------------------------------------------------------------ */ @@ -763,25 +763,24 @@ kim_error kim_selection_hints_create_from_stream (kim_selection_hints *out_selec { kim_error err = KIM_NO_ERROR; kim_selection_hints selection_hints = NULL; - + if (!err && !out_selection_hints) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !io_stream ) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { err = kim_selection_hints_allocate (&selection_hints); } - + if (!err) { err = kim_selection_hints_read_from_stream (selection_hints, io_stream); } - + if (!err) { *out_selection_hints = selection_hints; selection_hints = NULL; } - + kim_selection_hints_free (&selection_hints); - - return check_error (err); -} + return check_error (err); +} diff --git a/src/kim/lib/kim_string.c b/src/kim/lib/kim_string.c index 8b9af7010e..6cf18c46e0 100644 --- a/src/kim/lib/kim_string.c +++ b/src/kim/lib/kim_string.c @@ -30,87 +30,87 @@ const char kim_empty_string[1] = ""; /* ------------------------------------------------------------------------ */ -kim_error kim_string_create_from_format (kim_string *out_string, +kim_error kim_string_create_from_format (kim_string *out_string, kim_string in_format, ...) { kim_error err = kim_library_init (); va_list args; - + va_start (args, in_format); err = kim_string_create_from_format_va (out_string, in_format, args); va_end (args); - - return check_error (err); + + return check_error (err); } /* ------------------------------------------------------------------------ */ -kim_error kim_string_create_from_format_va_retcode (kim_string *out_string, +kim_error kim_string_create_from_format_va_retcode (kim_string *out_string, kim_string in_format, va_list in_args) { kim_error err = kim_library_init (); - + int count = vasprintf ((char **) out_string, in_format, in_args); if (count < 0) { err = check_error (KIM_OUT_OF_MEMORY_ERR); } - + return err; } /* ------------------------------------------------------------------------ */ -kim_error kim_string_create_from_format_va (kim_string *out_string, +kim_error kim_string_create_from_format_va (kim_string *out_string, kim_string in_format, va_list in_args) { kim_error err = kim_library_init (); kim_string string = NULL; - + if (!err && !out_string) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !in_format ) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { - err = kim_string_create_from_format_va_retcode (&string, - in_format, + err = kim_string_create_from_format_va_retcode (&string, + in_format, in_args); } - + if (!err) { *out_string = string; string = NULL; } - + if (string) { kim_string_free (&string); } - + return check_error (err); } /* ------------------------------------------------------------------------ */ -kim_error kim_string_create_from_buffer (kim_string *out_string, - const char *in_buffer, +kim_error kim_string_create_from_buffer (kim_string *out_string, + const char *in_buffer, kim_count in_length) { kim_error err = kim_library_init (); kim_string string = NULL; - + if (!err && !out_string) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !in_buffer ) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { string = calloc (in_length + 1, sizeof (char *)); if (!string) { err = check_error (KIM_OUT_OF_MEMORY_ERR); } } - + if (!err) { memcpy ((char *) string, in_buffer, in_length * sizeof (char)); *out_string = string; string = NULL; } - + kim_string_free (&string); - + return check_error (err); } @@ -128,20 +128,20 @@ kim_error kim_string_create_for_last_error (kim_string *out_string, /* ------------------------------------------------------------------------ */ -kim_error kim_string_copy (kim_string *out_string, +kim_error kim_string_copy (kim_string *out_string, kim_string in_string) { kim_error err = kim_library_init (); kim_string string = NULL; - + if (!err && !out_string) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !in_string ) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { if (in_string[0]) { string = calloc (strlen (in_string) + 1, sizeof (char *)); if (!string) { err = check_error (KIM_OUT_OF_MEMORY_ERR); } - + if (!err) { strncpy ((char *) string, in_string, strlen (in_string) + 1); } @@ -149,25 +149,25 @@ kim_error kim_string_copy (kim_string *out_string, string = kim_empty_string; } } - + if (!err) { *out_string = string; string = NULL; } - + kim_string_free (&string); - + return check_error (err); } /* ------------------------------------------------------------------------ */ -kim_error kim_string_compare (kim_string in_string, +kim_error kim_string_compare (kim_string in_string, kim_string in_compare_to_string, kim_comparison *out_comparison) { - return kim_os_string_compare (in_string, - in_compare_to_string, + return kim_os_string_compare (in_string, + in_compare_to_string, 0, /* case sensitive */ out_comparison); } @@ -176,7 +176,7 @@ kim_error kim_string_compare (kim_string in_string, void kim_string_free (kim_string *io_string) { - if (io_string && *io_string && *io_string != kim_empty_string) { + if (io_string && *io_string && *io_string != kim_empty_string) { free ((char *) *io_string); *io_string = NULL; } diff --git a/src/kim/lib/kim_string_private.h b/src/kim/lib/kim_string_private.h index 6f4e0ad360..f6dba79750 100644 --- a/src/kim/lib/kim_string_private.h +++ b/src/kim/lib/kim_string_private.h @@ -40,20 +40,20 @@ static inline kim_count kim_string_buflen (kim_string in_string) /* ------------------------------------------------------------------------ */ -kim_error kim_string_create_from_format (kim_string *out_string, +kim_error kim_string_create_from_format (kim_string *out_string, kim_string in_format, ...); -kim_error kim_string_create_from_format_va_retcode (kim_string *out_string, +kim_error kim_string_create_from_format_va_retcode (kim_string *out_string, kim_string in_format, va_list in_args); -kim_error kim_string_create_from_format_va (kim_string *out_string, +kim_error kim_string_create_from_format_va (kim_string *out_string, kim_string in_format, va_list in_args); -kim_error kim_string_create_from_buffer (kim_string *out_string, - const char *in_buffer, +kim_error kim_string_create_from_buffer (kim_string *out_string, + const char *in_buffer, kim_count in_length); /* OS-specific because it should use UTF8-safe sorting where possible */ diff --git a/src/kim/lib/kim_ui.c b/src/kim/lib/kim_ui.c index 0bac3d8190..b0e93f0943 100644 --- a/src/kim/lib/kim_ui.c +++ b/src/kim/lib/kim_ui.c @@ -33,7 +33,7 @@ static kim_prompt_type kim_ui_ptype2ktype (krb5_prompt_type type) { if (type == KRB5_PROMPT_TYPE_PASSWORD) { return kim_prompt_type_password; - + } else if (type == KRB5_PROMPT_TYPE_PREAUTH) { return kim_prompt_type_preauth; } @@ -47,42 +47,42 @@ static kim_prompt_type kim_ui_ptype2ktype (krb5_prompt_type type) static kim_error kim_ui_init_lazy (kim_ui_context *io_context) { kim_error err = KIM_NO_ERROR; - + if (!err && !io_context) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err && !io_context->initialized) { #ifdef KIM_BUILTIN_UI kim_ui_environment environment = kim_library_ui_environment (); - + if (environment == KIM_UI_ENVIRONMENT_GUI) { #endif /* KIM_BUILTIN_UI */ io_context->type = kim_ui_type_gui_plugin; - + err = kim_ui_plugin_init (io_context); -#ifdef KIM_BUILTIN_UI - if (err) { +#ifdef KIM_BUILTIN_UI + if (err) { io_context->type = kim_ui_type_gui_builtin; - + err = kim_os_ui_gui_init (io_context); } - + } else if (environment == KIM_UI_ENVIRONMENT_CLI) { io_context->type = kim_ui_type_cli; - - err = kim_ui_cli_init (io_context); - + + err = kim_ui_cli_init (io_context); + } else { io_context->type = kim_ui_type_none; - + err = check_error (KIM_NO_UI_ERR); } #endif /* KIM_BUILTIN_UI */ if (!err) { io_context->initialized = 1; - } + } } - + return check_error (err); } @@ -93,9 +93,9 @@ static kim_error kim_ui_init_lazy (kim_ui_context *io_context) kim_error kim_ui_init (kim_ui_context *io_context) { kim_error err = KIM_NO_ERROR; - + if (!err && !io_context) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { /* Lazy initialization so we only actually initialize if a prompt * gets called. This is important because krb5_get_init_creds_* @@ -105,7 +105,7 @@ kim_error kim_ui_init (kim_ui_context *io_context) io_context->prompt_count = 0; io_context->password_to_save = NULL; } - + return check_error (err); } @@ -117,42 +117,42 @@ kim_error kim_ui_enter_identity (kim_ui_context *in_context, kim_boolean *out_change_password) { kim_error err = KIM_NO_ERROR; - + if (!err && !in_context ) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !out_identity ) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !out_change_password) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { err = kim_ui_init_lazy (in_context); } - + if (!err) { if (in_context->type == kim_ui_type_gui_plugin) { - err = kim_ui_plugin_enter_identity (in_context, + err = kim_ui_plugin_enter_identity (in_context, io_options, out_identity, out_change_password); - + #ifdef KIM_BUILTIN_UI } else if (in_context->type == kim_ui_type_gui_builtin) { - err = kim_os_ui_gui_enter_identity (in_context, + err = kim_os_ui_gui_enter_identity (in_context, io_options, out_identity, out_change_password); - + } else if (in_context->type == kim_ui_type_cli) { - err = kim_ui_cli_enter_identity (in_context, + err = kim_ui_cli_enter_identity (in_context, io_options, out_identity, out_change_password); - + #endif /* KIM_BUILTIN_UI */ - + } else { err = check_error (KIM_NO_UI_ERR); } } - + return check_error (err); } @@ -164,43 +164,43 @@ kim_error kim_ui_select_identity (kim_ui_context *in_context, kim_boolean *out_change_password) { kim_error err = KIM_NO_ERROR; - + if (!err && !in_context ) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !io_hints ) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !out_identity ) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !out_change_password) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { err = kim_ui_init_lazy (in_context); } - + if (!err) { if (in_context->type == kim_ui_type_gui_plugin) { - err = kim_ui_plugin_select_identity (in_context, + err = kim_ui_plugin_select_identity (in_context, io_hints, out_identity, out_change_password); - + #ifdef KIM_BUILTIN_UI } else if (in_context->type == kim_ui_type_gui_builtin) { - err = kim_os_ui_gui_select_identity (in_context, + err = kim_os_ui_gui_select_identity (in_context, io_hints, out_identity, out_change_password); - + } else if (in_context->type == kim_ui_type_cli) { - err = kim_ui_cli_select_identity (in_context, + err = kim_ui_cli_select_identity (in_context, io_hints, out_identity, out_change_password); - + #endif /* KIM_BUILTIN_UI */ - + } else { err = check_error (KIM_NO_UI_ERR); } } - + return check_error (err); } @@ -218,42 +218,42 @@ krb5_error_code kim_ui_prompter (krb5_context in_krb5_context, krb5_prompt_type *types = NULL; kim_ui_context *context = (kim_ui_context *) in_context; int i; - + if (!err && !in_krb5_context) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !in_context ) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !in_prompts ) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { types = krb5_get_prompt_types (in_krb5_context); if (!types) { err = check_error (KIM_NULL_PARAMETER_ERR); } } - + for (i = 0; !err && i < in_num_prompts; i++) { char *reply = NULL; kim_prompt_type type = kim_ui_ptype2ktype (types[i]); kim_boolean got_saved_password = 0; - + if (type == kim_prompt_type_password) { /* Check for saved password on OSes that support it */ kim_error terr = KIM_NO_ERROR; - - terr = kim_os_identity_get_saved_password (context->identity, + + terr = kim_os_identity_get_saved_password (context->identity, (kim_string *) &reply); if (!terr && reply) { got_saved_password = 1; } } - + if (!got_saved_password) { kim_boolean save_reply = FALSE; kim_boolean allow_save_password = kim_os_identity_allow_save_password (); - + context->prompt_count++; err = kim_ui_init_lazy (in_context); if (!err) { if (context->type == kim_ui_type_gui_plugin) { - err = kim_ui_plugin_auth_prompt (context, - context->identity, + err = kim_ui_plugin_auth_prompt (context, + context->identity, type, allow_save_password, in_prompts[i].hidden, @@ -262,11 +262,11 @@ krb5_error_code kim_ui_prompter (krb5_context in_krb5_context, in_prompts[i].prompt, &reply, &save_reply); - + #ifdef KIM_BUILTIN_UI } else if (context->type == kim_ui_type_gui_builtin) { - err = kim_os_ui_gui_auth_prompt (context, - context->identity, + err = kim_os_ui_gui_auth_prompt (context, + context->identity, type, allow_save_password, in_prompts[i].hidden, @@ -275,10 +275,10 @@ krb5_error_code kim_ui_prompter (krb5_context in_krb5_context, in_prompts[i].prompt, &reply, &save_reply); - + } else if (context->type == kim_ui_type_cli) { - err = kim_ui_cli_auth_prompt (context, - context->identity, + err = kim_ui_cli_auth_prompt (context, + context->identity, type, allow_save_password, in_prompts[i].hidden, @@ -288,12 +288,12 @@ krb5_error_code kim_ui_prompter (krb5_context in_krb5_context, &reply, &save_reply); #endif /* KIM_BUILTIN_UI */ - + } else { err = check_error (KIM_NO_UI_ERR); } } - + if (!err && type == kim_prompt_type_password) { kim_string_free (&context->password_to_save); @@ -302,21 +302,21 @@ krb5_error_code kim_ui_prompter (krb5_context in_krb5_context, } } } - + if (!err) { uint32_t reply_len = strlen (reply); - + if ((reply_len + 1) > in_prompts[i].reply->length) { kim_debug_printf ("%s(): reply %d is too long (is %d, should be %d)\n", - __FUNCTION__, i, + __FUNCTION__, i, reply_len, in_prompts[i].reply->length); reply_len = in_prompts[i].reply->length; } - + memmove (in_prompts[i].reply->data, reply, reply_len + 1); in_prompts[i].reply->length = reply_len; } - + /* Clean up reply buffer. Saved passwords are allocated by KIM. */ if (reply) { if (got_saved_password) { @@ -327,7 +327,7 @@ krb5_error_code kim_ui_prompter (krb5_context in_krb5_context, } } } - + return check_error (err); } @@ -341,49 +341,49 @@ kim_error kim_ui_change_password (kim_ui_context *in_context, char **out_verify_password) { kim_error err = KIM_NO_ERROR; - + if (!err && !in_context ) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !in_identity ) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !out_old_password ) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !out_new_password ) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !out_verify_password) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { err = kim_ui_init_lazy (in_context); } if (!err) { if (in_context->type == kim_ui_type_gui_plugin) { - err = kim_ui_plugin_change_password (in_context, - in_identity, + err = kim_ui_plugin_change_password (in_context, + in_identity, in_old_password_expired, out_old_password, out_new_password, out_verify_password); - + #ifdef KIM_BUILTIN_UI } else if (in_context->type == kim_ui_type_gui_builtin) { - err = kim_os_ui_gui_change_password (in_context, - in_identity, + err = kim_os_ui_gui_change_password (in_context, + in_identity, in_old_password_expired, out_old_password, out_new_password, out_verify_password); - + } else if (in_context->type == kim_ui_type_cli) { err = kim_ui_cli_change_password (in_context, - in_identity, + in_identity, in_old_password_expired, out_old_password, out_new_password, out_verify_password); #endif /* KIM_BUILTIN_UI */ - + } else { err = check_error (KIM_NO_UI_ERR); } } - + return check_error (err); } @@ -396,44 +396,44 @@ kim_error kim_ui_handle_error (kim_ui_context *in_context, kim_string in_error_description) { kim_error err = KIM_NO_ERROR; - + if (!err && !in_context ) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !in_error_message ) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !in_error_description) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { err = kim_ui_init_lazy (in_context); } - + if (!err) { if (in_context->type == kim_ui_type_gui_plugin) { - err = kim_ui_plugin_handle_error (in_context, - in_identity, + err = kim_ui_plugin_handle_error (in_context, + in_identity, in_error, in_error_message, in_error_description); - + #ifdef KIM_BUILTIN_UI } else if (in_context->type == kim_ui_type_gui_builtin) { - err = kim_os_ui_gui_handle_error (in_context, - in_identity, + err = kim_os_ui_gui_handle_error (in_context, + in_identity, in_error, in_error_message, in_error_description); - + } else if (in_context->type == kim_ui_type_cli) { - err = kim_ui_cli_handle_error (in_context, - in_identity, + err = kim_ui_cli_handle_error (in_context, + in_identity, in_error, in_error_message, in_error_description); -#endif /* KIM_BUILTIN_UI */ - +#endif /* KIM_BUILTIN_UI */ + } else { err = check_error (KIM_NO_UI_ERR); } } - + return check_error (err); } @@ -443,24 +443,24 @@ void kim_ui_free_string (kim_ui_context *in_context, char **io_string) { kim_error err = kim_ui_init_lazy (in_context); - + if (!err && in_context && io_string && *io_string) { /* most ui strings are auth information so zero before freeing */ memset (*io_string, '\0', strlen (*io_string)); - + if (in_context->type == kim_ui_type_gui_plugin) { - kim_ui_plugin_free_string (in_context, + kim_ui_plugin_free_string (in_context, io_string); - + #ifdef KIM_BUILTIN_UI } else if (in_context->type == kim_ui_type_gui_builtin) { - kim_os_ui_gui_free_string (in_context, + kim_os_ui_gui_free_string (in_context, io_string); - + } else if (in_context->type == kim_ui_type_cli) { - kim_ui_cli_free_string (in_context, + kim_ui_cli_free_string (in_context, io_string); -#endif /* KIM_BUILTIN_UI */ +#endif /* KIM_BUILTIN_UI */ } } } @@ -470,28 +470,28 @@ void kim_ui_free_string (kim_ui_context *in_context, kim_error kim_ui_fini (kim_ui_context *io_context) { kim_error err = KIM_NO_ERROR; - + if (!err && !io_context) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err && io_context->initialized) { if (io_context->type == kim_ui_type_gui_plugin) { err = kim_ui_plugin_fini (io_context); - + #ifdef KIM_BUILTIN_UI } else if (io_context->type == kim_ui_type_gui_builtin) { err = kim_os_ui_gui_fini (io_context); - + } else if (io_context->type == kim_ui_type_cli) { err = kim_ui_cli_fini (io_context); #endif /* KIM_BUILTIN_UI */ - + } else { err = check_error (KIM_NO_UI_ERR); } - + kim_string_free (&io_context->password_to_save); } - + return check_error (err); } @@ -508,43 +508,43 @@ kim_error kim_ui_handle_kim_error (kim_ui_context *in_context, kim_error err = KIM_NO_ERROR; kim_string message = NULL; kim_string description = NULL; - + if (!err) { /* Do this first so last error doesn't get overwritten */ err = kim_string_create_for_last_error (&description, in_error); } - + if (!err && !in_context) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { kim_string key = NULL; - + switch (in_type) { case kim_ui_error_type_authentication: key = "Kerberos Login Failed:"; break; - + case kim_ui_error_type_change_password: key = "Kerberos Change Password Failed:"; break; - + case kim_ui_error_type_selection: case kim_ui_error_type_generic: default: key = "Kerberos Operation Failed:"; break; } - + err = kim_os_string_create_localized (&message, key); } - + if (!err) { err = kim_ui_handle_error (in_context, in_identity, - in_error, message, description); + in_error, message, description); } - + kim_string_free (&description); kim_string_free (&message); - + return check_error (err); } diff --git a/src/kim/lib/kim_ui_cli.c b/src/kim/lib/kim_ui_cli.c index 0bb5eebbba..0b258c3b51 100644 --- a/src/kim/lib/kim_ui_cli.c +++ b/src/kim/lib/kim_ui_cli.c @@ -30,8 +30,8 @@ // --------------------------------------------------------------------------- -static kim_error kim_ui_cli_read_string (kim_string *out_string, - kim_boolean in_hide_reply, +static kim_error kim_ui_cli_read_string (kim_string *out_string, + kim_boolean in_hide_reply, const char *in_format, ...) { kim_error err = KIM_NO_ERROR; @@ -40,30 +40,30 @@ static kim_error kim_ui_cli_read_string (kim_string *out_string, char prompt_string [BUFSIZ]; krb5_data reply_data; char reply_string [BUFSIZ]; - + if (!err && !out_string) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !in_format ) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { err = krb5_init_context (&k5context); } - + if (!err) { unsigned int count; va_list args; - + va_start (args, in_format); - count = vsnprintf (prompt_string, sizeof (prompt_string), + count = vsnprintf (prompt_string, sizeof (prompt_string), in_format, args); va_end (args); - + if (count > sizeof (prompt_string)) { - kim_debug_printf ("%s(): WARNING! Prompt should be %d characters\n", + kim_debug_printf ("%s(): WARNING! Prompt should be %d characters\n", __FUNCTION__, count); prompt_string [sizeof (prompt_string) - 1] = '\0'; } } - + if (!err) { /* Build the prompt structures */ prompts[0].prompt = prompt_string; @@ -71,21 +71,21 @@ static kim_error kim_ui_cli_read_string (kim_string *out_string, prompts[0].reply = &reply_data; prompts[0].reply->data = reply_string; prompts[0].reply->length = sizeof (reply_string); - + err = krb5_prompter_posix (k5context, NULL, NULL, NULL, 1, prompts); - if (err == KRB5_LIBOS_PWDINTR || err == KRB5_LIBOS_CANTREADPWD) { - err = check_error (KIM_USER_CANCELED_ERR); + if (err == KRB5_LIBOS_PWDINTR || err == KRB5_LIBOS_CANTREADPWD) { + err = check_error (KIM_USER_CANCELED_ERR); } } - + if (!err) { - err = kim_string_create_from_buffer (out_string, - prompts[0].reply->data, + err = kim_string_create_from_buffer (out_string, + prompts[0].reply->data, prompts[0].reply->length); } - + if (k5context) { krb5_free_context (k5context); } - + return check_error (err); } @@ -96,7 +96,7 @@ kim_error kim_ui_cli_init (kim_ui_context *io_context) if (io_context) { io_context->tcontext = NULL; } - + return KIM_NO_ERROR; } @@ -110,32 +110,32 @@ kim_error kim_ui_cli_enter_identity (kim_ui_context *in_context, kim_error err = KIM_NO_ERROR; kim_string enter_identity_string = NULL; kim_string identity_string = NULL; - + if (!err && !io_options ) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !out_identity ) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !out_change_password) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { - err = kim_os_string_create_localized (&enter_identity_string, + err = kim_os_string_create_localized (&enter_identity_string, "Please enter your Kerberos identity"); } - + if (!err) { - err = kim_ui_cli_read_string (&identity_string, + err = kim_ui_cli_read_string (&identity_string, 0, enter_identity_string); } - + if (!err) { err = kim_identity_create_from_string (out_identity, identity_string); } - + if (!err) { *out_change_password = 0; } - + kim_string_free (&identity_string); kim_string_free (&enter_identity_string); - + return check_error (err); } @@ -148,27 +148,27 @@ kim_error kim_ui_cli_select_identity (kim_ui_context *in_context, { kim_error err = KIM_NO_ERROR; kim_options options = NULL; - + if (!err && !io_hints ) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !out_identity ) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !out_change_password) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { err = kim_selection_hints_get_options (io_hints, &options); } - + if (!err) { - err = kim_ui_cli_enter_identity (in_context, options, + err = kim_ui_cli_enter_identity (in_context, options, out_identity, out_change_password); } - + if (!err) { err = kim_selection_hints_set_options (io_hints, options); } - + kim_options_free (&options); - + return check_error (err); } @@ -177,8 +177,8 @@ kim_error kim_ui_cli_select_identity (kim_ui_context *in_context, kim_error kim_ui_cli_auth_prompt (kim_ui_context *in_context, kim_identity in_identity, kim_prompt_type in_type, - kim_boolean in_allow_save_reply, - kim_boolean in_hide_reply, + kim_boolean in_allow_save_reply, + kim_boolean in_hide_reply, kim_string in_title, kim_string in_message, kim_string in_description, @@ -186,33 +186,33 @@ kim_error kim_ui_cli_auth_prompt (kim_ui_context *in_context, kim_boolean *out_save_reply) { kim_error err = KIM_NO_ERROR; - + if (!err && !in_identity) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !out_reply ) { err = check_error (KIM_NULL_PARAMETER_ERR); } /* in_title, in_message or in_description may be NULL */ - + if (!err) { if (in_type == kim_prompt_type_password) { kim_string enter_password_format = NULL; kim_string identity_string = NULL; - - err = kim_os_string_create_localized (&enter_password_format, + + err = kim_os_string_create_localized (&enter_password_format, "Please enter the password for %s"); - + if (!err) { - err = kim_identity_get_display_string (in_identity, + err = kim_identity_get_display_string (in_identity, &identity_string); } - + if (!err) { - err = kim_ui_cli_read_string ((kim_string *) out_reply, - 1, enter_password_format, + err = kim_ui_cli_read_string ((kim_string *) out_reply, + 1, enter_password_format, identity_string); - } - + } + kim_string_free (&identity_string); kim_string_free (&enter_password_format); - + } else { krb5_context k5context = NULL; krb5_prompt prompts[1]; @@ -228,28 +228,28 @@ kim_error kim_ui_cli_auth_prompt (kim_ui_context *in_context, err = krb5_init_context (&k5context); if (!err) { - err = krb5_prompter_posix (k5context, in_context, in_title, + err = krb5_prompter_posix (k5context, in_context, in_title, in_message, 1, prompts); - if (err == KRB5_LIBOS_PWDINTR || err == KRB5_LIBOS_CANTREADPWD) { - err = check_error (KIM_USER_CANCELED_ERR); + if (err == KRB5_LIBOS_PWDINTR || err == KRB5_LIBOS_CANTREADPWD) { + err = check_error (KIM_USER_CANCELED_ERR); } } - + if (!err) { - err = kim_string_create_from_buffer ((kim_string *) out_reply, - prompts[0].reply->data, + err = kim_string_create_from_buffer ((kim_string *) out_reply, + prompts[0].reply->data, prompts[0].reply->length); if (!err) { /* always allow password saving */ - *out_save_reply = (in_allow_save_reply && + *out_save_reply = (in_allow_save_reply && in_type == kim_prompt_type_password); } } - + if (k5context) { krb5_free_context (k5context); } } } - + return check_error (err); } @@ -264,58 +264,58 @@ static kim_error kim_ui_cli_ask_change_password (kim_string in_identity_string) kim_string unknown_response = NULL; kim_boolean done = 0; kim_comparison no_comparison, yes_comparison; - + if (!err) { - err = kim_os_string_create_localized (&ask_change_password, - "Your password has expired, would you like to change it? (yes/no)"); + err = kim_os_string_create_localized (&ask_change_password, + "Your password has expired, would you like to change it? (yes/no)"); } - + if (!err) { - err = kim_os_string_create_localized (&yes, "yes"); + err = kim_os_string_create_localized (&yes, "yes"); } - + if (!err) { - err = kim_os_string_create_localized (&no, "no"); + err = kim_os_string_create_localized (&no, "no"); } - + if (!err) { - err = kim_os_string_create_localized (&unknown_response, - "%s is not a response I understand. Please try again."); + err = kim_os_string_create_localized (&unknown_response, + "%s is not a response I understand. Please try again."); } - + while (!err && !done) { kim_string answer = NULL; - + err = kim_ui_cli_read_string (&answer, 0, ask_change_password); - + if (!err) { - err = kim_os_string_compare (answer, no, - 1 /* case insensitive */, + err = kim_os_string_compare (answer, no, + 1 /* case insensitive */, &no_comparison); } - + if (!err && kim_comparison_is_equal_to (no_comparison)) { err = check_error (KIM_USER_CANCELED_ERR); } if (!err) { - err = kim_os_string_compare (answer, yes, - 1 /* case insensitive */, + err = kim_os_string_compare (answer, yes, + 1 /* case insensitive */, &yes_comparison); } - + if (!err) { if (kim_comparison_is_equal_to (yes_comparison)) { done = 1; } else { fprintf (stdout, unknown_response, answer); - fprintf (stdout, "\n"); + fprintf (stdout, "\n"); } } - + kim_string_free (&answer); } - + kim_string_free (&ask_change_password); kim_string_free (&yes); kim_string_free (&no); @@ -342,7 +342,7 @@ kim_error kim_ui_cli_change_password (kim_ui_context *in_context, kim_string new_password = NULL; kim_string verify_password = NULL; kim_boolean done = 0; - + if (!err && !in_identity ) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !out_old_password ) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !out_new_password ) { err = check_error (KIM_NULL_PARAMETER_ERR); } @@ -355,36 +355,36 @@ kim_error kim_ui_cli_change_password (kim_ui_context *in_context, if (!err && in_old_password_expired) { err = kim_ui_cli_ask_change_password (identity_string); } - + if (!err) { - err = kim_os_string_create_localized (&enter_old_password_format, + err = kim_os_string_create_localized (&enter_old_password_format, "Please enter the old password for %s"); } - + if (!err) { - err = kim_os_string_create_localized (&enter_new_password_format, + err = kim_os_string_create_localized (&enter_new_password_format, "Please enter the new password for %s"); } - + if (!err) { - err = kim_os_string_create_localized (&enter_verify_password_format, + err = kim_os_string_create_localized (&enter_verify_password_format, "Verifying, please re-enter the new password for %s again"); } - + while (!err && !done) { kim_boolean was_prompted = 0; /* ignore because we always prompt */ - + kim_string_free (&old_password); - err = kim_ui_cli_read_string (&old_password, - 1, enter_old_password_format, + err = kim_ui_cli_read_string (&old_password, + 1, enter_old_password_format, identity_string); - + if (!err && strlen (old_password) < 1) { /* Empty password: Synthesize bad password err */ - err = KRB5KRB_AP_ERR_BAD_INTEGRITY; + err = KRB5KRB_AP_ERR_BAD_INTEGRITY; } - + if (!err) { err = kim_credential_create_for_change_password ((kim_credential *) &in_context->tcontext, in_identity, @@ -392,10 +392,10 @@ kim_error kim_ui_cli_change_password (kim_ui_context *in_context, in_context, &was_prompted); } - + if (err && err != KIM_USER_CANCELED_ERR) { /* new creds failed, report error to user */ - err = kim_ui_handle_kim_error (in_context, in_identity, + err = kim_ui_handle_kim_error (in_context, in_identity, kim_ui_error_type_change_password, err); @@ -403,19 +403,19 @@ kim_error kim_ui_cli_change_password (kim_ui_context *in_context, done = 1; } } - + if (!err) { - err = kim_ui_cli_read_string (&new_password, - 1, enter_new_password_format, + err = kim_ui_cli_read_string (&new_password, + 1, enter_new_password_format, identity_string); - } - + } + if (!err) { - err = kim_ui_cli_read_string (&verify_password, - 1, enter_verify_password_format, + err = kim_ui_cli_read_string (&verify_password, + 1, enter_verify_password_format, identity_string); - } - + } + if (!err) { *out_old_password = (char *) old_password; old_password = NULL; @@ -424,7 +424,7 @@ kim_error kim_ui_cli_change_password (kim_ui_context *in_context, *out_verify_password = (char *) verify_password; verify_password = NULL; } - + kim_string_free (&old_password); kim_string_free (&new_password); kim_string_free (&verify_password); @@ -432,7 +432,7 @@ kim_error kim_ui_cli_change_password (kim_ui_context *in_context, kim_string_free (&enter_old_password_format); kim_string_free (&enter_new_password_format); kim_string_free (&enter_verify_password_format); - + return check_error (err); } @@ -445,14 +445,14 @@ kim_error kim_ui_cli_handle_error (kim_ui_context *in_context, kim_string in_error_description) { kim_error err = KIM_NO_ERROR; - + if (!err && !in_error_message ) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !in_error_description) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { fprintf (stdout, "%s\n%s\n\n", in_error_message, in_error_description); } - + return check_error (err); } @@ -471,7 +471,7 @@ kim_error kim_ui_cli_fini (kim_ui_context *io_context) if (io_context) { kim_credential_free ((kim_credential *) &io_context->tcontext); } - + return KIM_NO_ERROR; } diff --git a/src/kim/lib/kim_ui_cli_private.h b/src/kim/lib/kim_ui_cli_private.h index 26970cf793..b66527a9b9 100644 --- a/src/kim/lib/kim_ui_cli_private.h +++ b/src/kim/lib/kim_ui_cli_private.h @@ -49,8 +49,8 @@ kim_error kim_ui_cli_select_identity (kim_ui_context *in_context, kim_error kim_ui_cli_auth_prompt (kim_ui_context *in_context, kim_identity in_identity, kim_prompt_type in_type, - kim_boolean in_allow_save_reply, - kim_boolean in_hide_reply, + kim_boolean in_allow_save_reply, + kim_boolean in_hide_reply, kim_string in_title, kim_string in_message, kim_string in_description, diff --git a/src/kim/lib/kim_ui_gui_private.h b/src/kim/lib/kim_ui_gui_private.h index ecb324339e..2f0bdbc4a9 100644 --- a/src/kim/lib/kim_ui_gui_private.h +++ b/src/kim/lib/kim_ui_gui_private.h @@ -49,8 +49,8 @@ kim_error kim_os_ui_gui_select_identity (kim_ui_context *in_context, kim_error kim_os_ui_gui_auth_prompt (kim_ui_context *in_context, kim_identity in_identity, kim_prompt_type in_type, - kim_boolean in_allow_save_reply, - kim_boolean in_hide_reply, + kim_boolean in_allow_save_reply, + kim_boolean in_hide_reply, kim_string in_title, kim_string in_message, kim_string in_description, diff --git a/src/kim/lib/kim_ui_plugin.c b/src/kim/lib/kim_ui_plugin.c index c307dd1899..94a455c040 100644 --- a/src/kim/lib/kim_ui_plugin.c +++ b/src/kim/lib/kim_ui_plugin.c @@ -50,15 +50,15 @@ struct kim_ui_plugin_context { static void kim_ui_plugin_context_free (kim_ui_plugin_context *io_context) { - if (io_context && *io_context) { + if (io_context && *io_context) { if ((*io_context)->ftables) { krb5int_free_plugin_dir_data ((*io_context)->ftables); } - if (PLUGIN_DIR_OPEN (&(*io_context)->plugins)) { - krb5int_close_plugin_dirs (&(*io_context)->plugins); + if (PLUGIN_DIR_OPEN (&(*io_context)->plugins)) { + krb5int_close_plugin_dirs (&(*io_context)->plugins); } - if ((*io_context)->kcontext) { - krb5_free_context ((*io_context)->kcontext); + if ((*io_context)->kcontext) { + krb5_free_context ((*io_context)->kcontext); } free (*io_context); *io_context = NULL; @@ -71,31 +71,31 @@ static kim_error kim_ui_plugin_context_allocate (kim_ui_plugin_context *out_cont { kim_error err = KIM_NO_ERROR; kim_ui_plugin_context context = NULL; - + if (!err && !out_context) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { context = malloc (sizeof (*context)); if (!context) { err = KIM_OUT_OF_MEMORY_ERR; } } - + if (!err) { err = krb5_error (NULL, krb5_init_context (&context->kcontext)); } - + if (!err) { PLUGIN_DIR_INIT(&context->plugins); context->ftable = NULL; context->ftables = NULL; context->plugin_context = NULL; - + *out_context = context; context = NULL; } - + kim_ui_plugin_context_free (&context); - - return check_error (err); + + return check_error (err); } #pragma mark - @@ -106,60 +106,60 @@ kim_error kim_ui_plugin_init (kim_ui_context *io_context) { kim_error err = KIM_NO_ERROR; kim_ui_plugin_context context = NULL; - + if (!err && !io_context) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { err = kim_ui_plugin_context_allocate (&context); } - + if (!err) { PLUGIN_DIR_INIT(&context->plugins); err = krb5_error (context->kcontext, - krb5int_open_plugin_dirs (kim_ui_plugin_dirs, - kim_ui_plugin_files, - &context->plugins, + krb5int_open_plugin_dirs (kim_ui_plugin_dirs, + kim_ui_plugin_files, + &context->plugins, &context->kcontext->err)); } - + if (!err) { err = krb5_error (context->kcontext, krb5int_get_plugin_dir_data (&context->plugins, "kim_ui_0", - &context->ftables, + &context->ftables, &context->kcontext->err)); } - + if (!err && context->ftables) { int i; - + for (i = 0; context->ftables[i]; i++) { struct kim_ui_plugin_ftable_v0 *ftable = context->ftables[i]; context->plugin_context = NULL; - + err = ftable->init (&context->plugin_context); - + if (!err) { context->ftable = ftable; break; /* use first plugin that initializes correctly */ } - + err = KIM_NO_ERROR; /* ignore failed plugins */ } } - + if (!err && !context->ftable) { err = check_error (KRB5_PLUGIN_NO_HANDLE); } - + if (!err) { io_context->tcontext = context; context = NULL; } - + kim_ui_plugin_context_free (&context); - + return check_error (err); } @@ -171,12 +171,12 @@ kim_error kim_ui_plugin_enter_identity (kim_ui_context *in_context, kim_boolean *out_change_password) { kim_error err = KIM_NO_ERROR; - + if (!err && !in_context ) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !io_options ) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !out_identity ) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !out_change_password) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { kim_ui_plugin_context context = (kim_ui_plugin_context) in_context->tcontext; @@ -185,7 +185,7 @@ kim_error kim_ui_plugin_enter_identity (kim_ui_context *in_context, out_identity, out_change_password); } - + return check_error (err); } @@ -197,21 +197,21 @@ kim_error kim_ui_plugin_select_identity (kim_ui_context *in_context, kim_boolean *out_change_password) { kim_error err = KIM_NO_ERROR; - + if (!err && !in_context ) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !io_hints ) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !out_identity ) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !out_change_password) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { kim_ui_plugin_context context = (kim_ui_plugin_context) in_context->tcontext; - + err = context->ftable->select_identity (context->plugin_context, - io_hints, + io_hints, out_identity, out_change_password); } - + return check_error (err); } @@ -220,8 +220,8 @@ kim_error kim_ui_plugin_select_identity (kim_ui_context *in_context, kim_error kim_ui_plugin_auth_prompt (kim_ui_context *in_context, kim_identity in_identity, kim_prompt_type in_type, - kim_boolean in_allow_save_reply, - kim_boolean in_hide_reply, + kim_boolean in_allow_save_reply, + kim_boolean in_hide_reply, kim_string in_title, kim_string in_message, kim_string in_description, @@ -229,17 +229,17 @@ kim_error kim_ui_plugin_auth_prompt (kim_ui_context *in_context, kim_boolean *out_save_reply) { kim_error err = KIM_NO_ERROR; - + if (!err && !in_context ) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !in_identity) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !out_reply ) { err = check_error (KIM_NULL_PARAMETER_ERR); } /* in_title, in_message or in_description may be NULL */ - + if (!err) { kim_ui_plugin_context context = (kim_ui_plugin_context) in_context->tcontext; - + err = context->ftable->auth_prompt (context->plugin_context, - in_identity, + in_identity, in_type, in_allow_save_reply, in_hide_reply, @@ -249,7 +249,7 @@ kim_error kim_ui_plugin_auth_prompt (kim_ui_context *in_context, out_reply, out_save_reply); } - + return check_error (err); } @@ -263,24 +263,24 @@ kim_error kim_ui_plugin_change_password (kim_ui_context *in_context, char **out_verify_password) { kim_error err = KIM_NO_ERROR; - + if (!err && !in_context ) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !in_identity ) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !out_old_password ) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !out_new_password ) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !out_verify_password) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { kim_ui_plugin_context context = (kim_ui_plugin_context) in_context->tcontext; - + err = context->ftable->change_password (context->plugin_context, - in_identity, + in_identity, in_old_password_expired, out_old_password, out_new_password, out_verify_password); } - + return check_error (err); } @@ -293,21 +293,21 @@ kim_error kim_ui_plugin_handle_error (kim_ui_context *in_context, kim_string in_error_description) { kim_error err = KIM_NO_ERROR; - + if (!err && !in_context ) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !in_error_message ) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !in_error_description) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { kim_ui_plugin_context context = (kim_ui_plugin_context) in_context->tcontext; - + err = context->ftable->handle_error (context->plugin_context, - in_identity, + in_identity, in_error, in_error_message, in_error_description); } - + return check_error (err); } @@ -317,14 +317,14 @@ void kim_ui_plugin_free_string (kim_ui_context *in_context, char **io_string) { kim_error err = KIM_NO_ERROR; - + if (!err && !in_context) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !io_string ) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { kim_ui_plugin_context context = (kim_ui_plugin_context) in_context->tcontext; - - context->ftable->free_string (context->plugin_context, + + context->ftable->free_string (context->plugin_context, io_string); } } @@ -334,12 +334,12 @@ void kim_ui_plugin_free_string (kim_ui_context *in_context, kim_error kim_ui_plugin_fini (kim_ui_context *io_context) { kim_error err = KIM_NO_ERROR; - + if (!err && !io_context) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { kim_ui_plugin_context context = (kim_ui_plugin_context) io_context->tcontext; - + if (context) { err = context->ftable->fini (context->plugin_context); } @@ -349,6 +349,6 @@ kim_error kim_ui_plugin_fini (kim_ui_context *io_context) io_context->tcontext = NULL; } } - + return check_error (err); } diff --git a/src/kim/lib/kim_ui_plugin_private.h b/src/kim/lib/kim_ui_plugin_private.h index 397a7ad910..9248e08dff 100644 --- a/src/kim/lib/kim_ui_plugin_private.h +++ b/src/kim/lib/kim_ui_plugin_private.h @@ -48,8 +48,8 @@ kim_error kim_ui_plugin_select_identity (kim_ui_context *in_context, kim_error kim_ui_plugin_auth_prompt (kim_ui_context *in_context, kim_identity in_identity, kim_prompt_type in_type, - kim_boolean in_allow_save_reply, - kim_boolean in_hide_reply, + kim_boolean in_allow_save_reply, + kim_boolean in_hide_reply, kim_string in_title, kim_string in_message, kim_string in_description, diff --git a/src/kim/lib/mac/KerberosLogin.c b/src/kim/lib/mac/KerberosLogin.c index de05e57ddb..73d9b80562 100644 --- a/src/kim/lib/mac/KerberosLogin.c +++ b/src/kim/lib/mac/KerberosLogin.c @@ -8,7 +8,7 @@ * 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 @@ -34,8 +34,8 @@ #include "k5-thread.h" #include <time.h> -/* - * Deprecated Error codes +/* + * Deprecated Error codes */ enum { /* Carbon Dialog errors */ @@ -44,7 +44,7 @@ enum { klNotInForegroundErr, klNoAppearanceErr, klFatalDialogErr, - klCarbonUnavailableErr + klCarbonUnavailableErr }; krb5_get_init_creds_opt *__KLLoginOptionsGetKerberos5Options (KLLoginOptions ioOptions); @@ -57,33 +57,33 @@ char *__KLLoginOptionsGetServiceName (KLLoginOptions ioOptions); static KLStatus kl_check_error_ (kim_error inError, const char *function, const char *file, int line) { kim_error err = inError; - + switch (err) { case ccNoError: err = klNoErr; break; - + case ccErrBadName: err = klPrincipalDoesNotExistErr; break; - + case ccErrCCacheNotFound: err = klCacheDoesNotExistErr; break; - + case ccErrCredentialsNotFound: err = klNoCredentialsErr; break; - + case KIM_OUT_OF_MEMORY_ERR: case ccErrNoMem: err = klMemFullErr; break; - + case ccErrBadCredentialsVersion: err = klInvalidVersionErr; break; - + case KIM_NULL_PARAMETER_ERR: case ccErrBadParam: case ccIteratorEnd: @@ -103,19 +103,19 @@ static KLStatus kl_check_error_ (kim_error inError, const char *function, const case ccErrNeverDefault: err = klParameterErr; break; - + case KIM_USER_CANCELED_ERR: case KRB5_LIBOS_PWDINTR: err = klUserCanceledErr; break; } - + if (err) { - kim_debug_printf ("%s() remapped %d to %d ('%s') at %s: %d", - function, inError, err, kim_error_message (err), + kim_debug_printf ("%s() remapped %d to %d ('%s') at %s: %d", + function, inError, err, kim_error_message (err), file, line); } - + return err; } #define kl_check_error(err) kl_check_error_(err, __FUNCTION__, __FILE__, __LINE__) @@ -126,9 +126,9 @@ KLStatus KLAcquireTickets (KLPrincipal inPrincipal, KLPrincipal *outPrincipal, char **outCredCacheName) { - return kl_check_error (KLAcquireInitialTickets (inPrincipal, - NULL, - outPrincipal, + return kl_check_error (KLAcquireInitialTickets (inPrincipal, + NULL, + outPrincipal, outCredCacheName)); } @@ -138,9 +138,9 @@ KLStatus KLAcquireNewTickets (KLPrincipal inPrincipal, KLPrincipal *outPrincipal, char **outCredCacheName) { - return kl_check_error (KLAcquireNewInitialTickets (inPrincipal, - NULL, - outPrincipal, + return kl_check_error (KLAcquireNewInitialTickets (inPrincipal, + NULL, + outPrincipal, outCredCacheName)); } @@ -151,9 +151,9 @@ KLStatus KLAcquireTicketsWithPassword (KLPrincipal inPrincipal, const char *inPassword, char **outCredCacheName) { - return kl_check_error (KLAcquireInitialTicketsWithPassword (inPrincipal, - inLoginOptions, - inPassword, + return kl_check_error (KLAcquireInitialTicketsWithPassword (inPrincipal, + inLoginOptions, + inPassword, outCredCacheName)); } @@ -164,9 +164,9 @@ KLStatus KLAcquireNewTicketsWithPassword (KLPrincipal inPrincipal, const char *inPassword, char **outCredCacheName) { - return kl_check_error (KLAcquireNewInitialTicketsWithPassword (inPrincipal, - inLoginOptions, - inPassword, + return kl_check_error (KLAcquireNewInitialTicketsWithPassword (inPrincipal, + inLoginOptions, + inPassword, outCredCacheName)); } @@ -201,21 +201,21 @@ KLStatus KLAcquireInitialTickets (KLPrincipal inPrincipal, kim_ccache ccache = NULL; kim_string name = NULL; kim_identity identity = NULL; - + if (!err) { - err = kim_ccache_create_new_if_needed (&ccache, + err = kim_ccache_create_new_if_needed (&ccache, inPrincipal, inLoginOptions); } - + if (!err && outPrincipal) { err = kim_ccache_get_client_identity (ccache, &identity); } - + if (!err && outCredCacheName) { err = kim_ccache_get_display_name (ccache, &name); } - + if (!err) { if (outPrincipal) { *outPrincipal = identity; @@ -226,11 +226,11 @@ KLStatus KLAcquireInitialTickets (KLPrincipal inPrincipal, name = NULL; } } - + kim_string_free (&name); - kim_identity_free (&identity); + kim_identity_free (&identity); kim_ccache_free (&ccache); - + return kl_check_error (err); } @@ -245,17 +245,17 @@ KLStatus KLAcquireNewInitialTickets (KLPrincipal inPrincipal, kim_ccache ccache = NULL; kim_string name = NULL; kim_identity identity = NULL; - + err = kim_ccache_create_new (&ccache, inPrincipal, inLoginOptions); - + if (!err && outPrincipal) { err = kim_ccache_get_client_identity (ccache, &identity); } - + if (!err && outCredCacheName) { err = kim_ccache_get_display_name (ccache, &name); } - + if (!err) { if (outPrincipal) { *outPrincipal = identity; @@ -266,11 +266,11 @@ KLStatus KLAcquireNewInitialTickets (KLPrincipal inPrincipal, name = NULL; } } - + kim_string_free (&name); - kim_identity_free (&identity); + kim_identity_free (&identity); kim_ccache_free (&ccache); - + return kl_check_error (err); } @@ -280,15 +280,15 @@ KLStatus KLDestroyTickets (KLPrincipal inPrincipal) { kim_error err = KIM_NO_ERROR; kim_ccache ccache = NULL; - + if (!err) { err = kim_ccache_create_from_client_identity (&ccache, inPrincipal); } - + if (!err) { err = kim_ccache_destroy (&ccache); } - + return kl_check_error (err); } @@ -308,21 +308,21 @@ KLStatus KLAcquireInitialTicketsWithPassword (KLPrincipal inPrincipal, { kim_error err = KIM_NO_ERROR; kim_ccache ccache = NULL; - + if (!err) { - err = kim_ccache_create_new_if_needed_with_password (&ccache, + err = kim_ccache_create_new_if_needed_with_password (&ccache, inPrincipal, inLoginOptions, inPassword); } - + if (!err && outCredCacheName) { - err = kim_ccache_get_display_name (ccache, + err = kim_ccache_get_display_name (ccache, (kim_string *) outCredCacheName); - } - + } + kim_ccache_free (&ccache); - + return kl_check_error (err); } @@ -335,19 +335,19 @@ KLStatus KLAcquireNewInitialTicketsWithPassword (KLPrincipal inPrincipal, { kim_error err = KIM_NO_ERROR; kim_ccache ccache = NULL; - - err = kim_ccache_create_new_with_password (&ccache, - inPrincipal, + + err = kim_ccache_create_new_with_password (&ccache, + inPrincipal, inLoginOptions, inPassword); - + if (!err && outCredCacheName) { - err = kim_ccache_get_display_name (ccache, + err = kim_ccache_get_display_name (ccache, (kim_string *) outCredCacheName); - } - + } + kim_ccache_free (&ccache); - + return kl_check_error (err); } @@ -365,20 +365,20 @@ KLStatus KLAcquireNewInitialTicketCredentialsWithPassword (KLPrincipal inPr kim_error err = KIM_NO_ERROR; kim_credential credential = NULL; krb5_creds *creds = NULL; - + if (!err) { err = kim_credential_create_new_with_password (&credential, inPrincipal, inLoginOptions, inPassword); } - + if (!err) { - err = kim_credential_get_krb5_creds (credential, + err = kim_credential_get_krb5_creds (credential, inV5Context, &creds); } - + if (!err) { *outGotV5Credentials = 1; *outGotV4Credentials = 0; @@ -386,9 +386,9 @@ KLStatus KLAcquireNewInitialTicketCredentialsWithPassword (KLPrincipal inPr free (creds); /* eeeew */ creds = NULL; } - + kim_credential_free (&credential); - + return kl_check_error (err); } @@ -403,23 +403,23 @@ KLStatus KLStoreNewInitialTicketCredentials (KLPrincipal inPrincipal, kim_error err = KIM_NO_ERROR; kim_credential credential = NULL; kim_ccache ccache = NULL; - + err = kim_credential_create_from_krb5_creds (&credential, - inV5Context, + inV5Context, inV5Credentials); - + if (!err) { err = kim_credential_store (credential, inPrincipal, &ccache); } - + if (!err && outCredCacheName) { - err = kim_ccache_get_display_name (ccache, + err = kim_ccache_get_display_name (ccache, (kim_string *) outCredCacheName); - } - + } + kim_ccache_free (&ccache); kim_credential_free (&credential); - + return kl_check_error (err); } @@ -431,23 +431,23 @@ KLStatus KLVerifyInitialTickets (KLPrincipal inPrincipal, { kim_error err = KIM_NO_ERROR; kim_ccache ccache = NULL; - + err = kim_ccache_create_from_client_identity (&ccache, inPrincipal); - + if (!err) { - err = kim_ccache_verify (ccache, - KIM_IDENTITY_ANY, - NULL, + err = kim_ccache_verify (ccache, + KIM_IDENTITY_ANY, + NULL, inFailIfNoHostKey); } - + if (!err && outCredCacheName) { - err = kim_ccache_get_display_name (ccache, + err = kim_ccache_get_display_name (ccache, (kim_string *) outCredCacheName); - } - + } + kim_ccache_free (&ccache); - + return kl_check_error (err); } @@ -460,23 +460,23 @@ KLStatus KLVerifyInitialTicketCredentials (void *inV4Credentials, kim_error err = KIM_NO_ERROR; kim_credential credential = NULL; krb5_context context = NULL; - + err = krb5_error (NULL, krb5_init_context (&context)); - + if (!err) { err = kim_credential_create_from_krb5_creds (&credential, - context, + context, inV5Credentials); } - + if (!err) { - err = kim_credential_verify (credential, KIM_IDENTITY_ANY, + err = kim_credential_verify (credential, KIM_IDENTITY_ANY, NULL, inFailIfNoHostKey); } - + if (context) { krb5_free_context (context); } kim_credential_free (&credential); - + return kl_check_error (err); } @@ -489,19 +489,19 @@ KLStatus KLAcquireNewInitialTicketsWithKeytab (KLPrincipal inPrincipal, { kim_error err = KIM_NO_ERROR; kim_ccache ccache = NULL; - - err = kim_ccache_create_from_keytab (&ccache, - inPrincipal, + + err = kim_ccache_create_from_keytab (&ccache, + inPrincipal, inLoginOptions, inKeytabName); - + if (!err && outCredCacheName) { - err = kim_ccache_get_display_name (ccache, + err = kim_ccache_get_display_name (ccache, (kim_string *) outCredCacheName); - } - + } + kim_ccache_free (&ccache); - + return kl_check_error (err); } @@ -516,21 +516,21 @@ KLStatus KLRenewInitialTickets (KLPrincipal inPrincipal, kim_ccache ccache = NULL; kim_string name = NULL; kim_identity identity = NULL; - + err = kim_ccache_create_from_client_identity (&ccache, inPrincipal); - + if (!err) { err = kim_ccache_renew (ccache, inLoginOptions); } - + if (!err && outPrincipal) { err = kim_ccache_get_client_identity (ccache, &identity); } - + if (!err && outCredCacheName) { err = kim_ccache_get_display_name (ccache, &name); } - + if (!err) { if (outPrincipal) { *outPrincipal = identity; @@ -541,11 +541,11 @@ KLStatus KLRenewInitialTickets (KLPrincipal inPrincipal, name = NULL; } } - + kim_string_free (&name); kim_identity_free (&identity); kim_ccache_free (&ccache); - + return kl_check_error (err); } @@ -557,20 +557,20 @@ KLStatus KLValidateInitialTickets (KLPrincipal inPrincipal, { kim_error err = KIM_NO_ERROR; kim_ccache ccache = NULL; - + err = kim_ccache_create_from_client_identity (&ccache, inPrincipal); - + if (!err) { err = kim_ccache_validate (ccache, inLoginOptions); } - + if (!err && outCredCacheName) { - err = kim_ccache_get_display_name (ccache, + err = kim_ccache_get_display_name (ccache, (kim_string *) outCredCacheName); - } - + } + kim_ccache_free (&ccache); - + return kl_check_error (err); } @@ -586,7 +586,7 @@ MAKE_FINI_FUNCTION(kim_change_time_fini); static int kim_change_time_init (void) { g_kl_change_time = time (NULL); - + return k5_mutex_finish_init(&g_change_time_mutex); } @@ -597,7 +597,7 @@ static void kim_change_time_fini (void) if (!INITIALIZER_RAN (kim_change_time_init) || PROGRAM_EXITING ()) { return; } - + k5_mutex_destroy(&g_change_time_mutex); } @@ -609,9 +609,9 @@ KLStatus KLLastChangedTime (KLTime *outLastChangedTime) kim_error mutex_err = KIM_NO_ERROR; cc_context_t context = NULL; cc_time_t ccChangeTime = 0; - + if (!err && !outLastChangedTime) { err = kl_check_error (klParameterErr); } - + if (!err) { mutex_err = k5_mutex_lock (&g_change_time_mutex); if (mutex_err) { err = mutex_err; } @@ -620,11 +620,11 @@ KLStatus KLLastChangedTime (KLTime *outLastChangedTime) if (!err) { err = cc_initialize (&context, ccapi_version_4, NULL, NULL); } - + if (!err) { err = cc_context_get_change_time (context, &ccChangeTime); } - + if (!err) { /* cc_context_get_change_time returns 0 if there are no tickets * but KLLastChangedTime always returned the current time. So @@ -638,13 +638,13 @@ KLStatus KLLastChangedTime (KLTime *outLastChangedTime) } g_cc_change_time = ccChangeTime; } - + *outLastChangedTime = g_kl_change_time; } - + if (context ) { cc_context_release (context); } if (!mutex_err) { k5_mutex_unlock (&g_change_time_mutex); } - + return kl_check_error (err); } @@ -661,29 +661,29 @@ KLStatus KLCacheHasValidTickets (KLPrincipal inPrincipal, kim_credential_state state = kim_credentials_state_valid; kim_identity identity = NULL; kim_string name = NULL; - + if (!outFoundValidTickets) { err = kl_check_error (klParameterErr); } - + if (!err) { err = kim_ccache_create_from_client_identity (&ccache, inPrincipal); } - + if (!err) { err = kim_ccache_get_state (ccache, &state); } - + if (!err && outPrincipal) { err = kim_ccache_get_client_identity (ccache, &identity); if (err) { err = KIM_NO_ERROR; identity = NULL; - } + } } - + if (!err && outCredCacheName) { err = kim_ccache_get_display_name (ccache, &name); } - + if (!err) { *outFoundValidTickets = (state == kim_credentials_state_valid); if (outPrincipal) { @@ -695,11 +695,11 @@ KLStatus KLCacheHasValidTickets (KLPrincipal inPrincipal, name = NULL; } } - + kim_string_free (&name); kim_identity_free (&identity); kim_ccache_free (&ccache); - + return kl_check_error (err); } @@ -712,21 +712,21 @@ KLStatus KLTicketStartTime (KLPrincipal inPrincipal, kim_error err = KIM_NO_ERROR; kim_ccache ccache = NULL; kim_time start_time = 0; - + if (!err) { err = kim_ccache_create_from_client_identity (&ccache, inPrincipal); } - + if (!err) { err = kim_ccache_get_start_time (ccache, &start_time); } - + if (!err) { *outStartTime = start_time; } - + kim_ccache_free (&ccache); - + return kl_check_error (err); } @@ -739,21 +739,21 @@ KLStatus KLTicketExpirationTime (KLPrincipal inPrincipal, kim_error err = KIM_NO_ERROR; kim_ccache ccache = NULL; kim_time expiration_time = 0; - + if (!err) { err = kim_ccache_create_from_client_identity (&ccache, inPrincipal); } - + if (!err) { err = kim_ccache_get_expiration_time (ccache, &expiration_time); } - + if (!err) { *outExpirationTime = expiration_time; } - + kim_ccache_free (&ccache); - + return kl_check_error (err); } @@ -763,17 +763,17 @@ KLStatus KLSetSystemDefaultCache (KLPrincipal inPrincipal) { kim_error err = KIM_NO_ERROR; kim_ccache ccache = NULL; - + if (!err) { err = kim_ccache_create_from_client_identity (&ccache, inPrincipal); } - + if (!err) { err = kim_ccache_set_default (ccache); } - + kim_ccache_free (&ccache); - + return kl_check_error (err); } @@ -786,15 +786,15 @@ KLStatus KLHandleError (KLStatus inError, kim_error err = KIM_NO_ERROR; kim_ui_context context; kim_boolean ui_inited = 0; - + if (!err) { err = kim_ui_init (&context); if (!err) { ui_inited = 1; } } - + if (!err) { int type = kim_ui_error_type_generic; - + switch (inDialogIdentifier) { case loginLibrary_LoginDialog: type = kim_ui_error_type_authentication; @@ -806,16 +806,16 @@ KLStatus KLHandleError (KLStatus inError, type = kim_ui_error_type_generic; break; } - - err = kim_ui_handle_kim_error (&context, + + err = kim_ui_handle_kim_error (&context, KIM_IDENTITY_ANY, type, inError); } - + if (ui_inited) { kim_error fini_err = kim_ui_fini (&context); if (!err) { err = kl_check_error (fini_err); } } - + return kl_check_error (err); } @@ -853,36 +853,36 @@ KLStatus KLChangePasswordWithPasswords (KLPrincipal inPrincipal, kim_error rejected_err = KIM_NO_ERROR; kim_string rejected_message = NULL; kim_string rejected_description = NULL; - + if (!inOldPassword) { err = kl_check_error (klParameterErr); } if (!inNewPassword) { err = kl_check_error (klParameterErr); } if (!outRejected ) { err = kl_check_error (klParameterErr); } - + if (!err) { err = kim_ui_init (&context); if (!err) { ui_inited = 1; } } - + if (!err) { kim_boolean was_prompted = 0; - + err = kim_credential_create_for_change_password (&credential, inPrincipal, inOldPassword, &context, &was_prompted); } - + if (!err) { err = kim_identity_change_password_with_credential (inPrincipal, - credential, + credential, inNewPassword, &context, &rejected_err, &rejected_message, &rejected_description); - } - + } + if (!err) { *outRejected = (rejected_err != 0); if (rejected_err) { @@ -896,16 +896,16 @@ KLStatus KLChangePasswordWithPasswords (KLPrincipal inPrincipal, } } } - + if (ui_inited) { kim_error fini_err = kim_ui_fini (&context); if (!err) { err = kl_check_error (fini_err); } } - + kim_string_free (&rejected_message); kim_string_free (&rejected_description); kim_credential_free (&credential); - + return kl_check_error (err); } @@ -949,23 +949,23 @@ KLStatus KLGetDefaultLoginOption (const KLDefaultLoginOption inOption, kim_preferences prefs = NULL; KLSize targetSize = 0; KLBoolean returnSizeOnly = (ioBuffer == NULL); - + if (!ioBufferSize) { err = kl_check_error (klParameterErr); } - + if (!err) { err = kim_preferences_create (&prefs); } - + if (!err && inOption == loginOption_LoginName) { kim_identity identity = NULL; kim_string string = ""; - + err = kim_preferences_get_client_identity (prefs, &identity); - + if (!err && identity) { err = kim_identity_get_components_string (identity, &string); } - + if (!err) { targetSize = strlen (string); if (!returnSizeOnly) { @@ -976,12 +976,12 @@ KLStatus KLGetDefaultLoginOption (const KLDefaultLoginOption inOption, } } } - + if (string && string[0]) { kim_string_free (&string); } - + } else if (!err && inOption == loginOption_LoginInstance) { targetSize = 0; /* Deprecated */ - + } else if (!err && (inOption == loginOption_ShowOptions || inOption == loginOption_RememberShowOptions || inOption == loginOption_LongTicketLifetimeDisplay || @@ -989,25 +989,25 @@ KLStatus KLGetDefaultLoginOption (const KLDefaultLoginOption inOption, inOption == loginOption_RememberExtras || inOption == loginOption_RememberPassword)) { targetSize = sizeof(KLBoolean); - + if (!returnSizeOnly) { kim_boolean boolean = 0; - + if (inOption == loginOption_ShowOptions || inOption == loginOption_RememberShowOptions || inOption == loginOption_LongTicketLifetimeDisplay) { boolean = 1; /* Deprecated */ - + } else if (inOption == loginOption_RememberPrincipal) { err = kim_preferences_get_remember_client_identity (prefs, &boolean); - + } else if (inOption == loginOption_RememberExtras) { err = kim_preferences_get_remember_options (prefs, &boolean); - + } else if (inOption == loginOption_RememberPassword) { boolean = kim_os_identity_allow_save_password (); } - + if (!err) { if (*ioBufferSize < targetSize) { err = kl_check_error (klBufferTooSmallErr); @@ -1016,29 +1016,29 @@ KLStatus KLGetDefaultLoginOption (const KLDefaultLoginOption inOption, } } } - + } else if (!err && (inOption == loginOption_MinimalTicketLifetime || inOption == loginOption_MaximalTicketLifetime || inOption == loginOption_MinimalRenewableLifetime || inOption == loginOption_MaximalRenewableLifetime)) { targetSize = sizeof(KLLifetime); - + if (!returnSizeOnly) { kim_lifetime lifetime = 0; - + if (inOption == loginOption_MinimalTicketLifetime) { err = kim_preferences_get_minimum_lifetime (prefs, &lifetime); - + } else if (inOption == loginOption_MaximalTicketLifetime) { err = kim_preferences_get_maximum_lifetime (prefs, &lifetime); - + } else if (inOption == loginOption_MinimalRenewableLifetime) { err = kim_preferences_get_minimum_renewal_lifetime (prefs, &lifetime); - + } else if (inOption == loginOption_MaximalRenewableLifetime) { err = kim_preferences_get_maximum_renewal_lifetime (prefs, &lifetime); - } - + } + if (!err) { if (*ioBufferSize < targetSize) { err = kl_check_error (klBufferTooSmallErr); @@ -1047,32 +1047,32 @@ KLStatus KLGetDefaultLoginOption (const KLDefaultLoginOption inOption, } } } - + } else if (!err && (inOption == loginOption_DefaultRenewableTicket || inOption == loginOption_DefaultForwardableTicket || inOption == loginOption_DefaultProxiableTicket || inOption == loginOption_DefaultAddresslessTicket)) { targetSize = sizeof(KLBoolean); - + if (!returnSizeOnly) { kim_options options = NULL; kim_boolean boolean = 0; - + err = kim_preferences_get_options (prefs, &options); - + if (!err && inOption == loginOption_DefaultRenewableTicket) { err = kim_options_get_renewable (options, &boolean); - + } else if (!err && inOption == loginOption_DefaultForwardableTicket) { err = kim_options_get_forwardable (options, &boolean); - + } else if (!err && inOption == loginOption_DefaultProxiableTicket) { err = kim_options_get_proxiable (options, &boolean); - + } else if (!err && inOption == loginOption_DefaultAddresslessTicket) { err = kim_options_get_addressless (options, &boolean); - } - + } + if (!err) { if (*ioBufferSize < targetSize) { err = kl_check_error (klBufferTooSmallErr); @@ -1080,28 +1080,28 @@ KLStatus KLGetDefaultLoginOption (const KLDefaultLoginOption inOption, *(KLBoolean *)ioBuffer = boolean; } } - + kim_options_free (&options); } - - + + } else if (!err && (inOption == loginOption_DefaultTicketLifetime || inOption == loginOption_DefaultRenewableLifetime)) { targetSize = sizeof(KLLifetime); - + if (!returnSizeOnly) { kim_options options = NULL; kim_lifetime lifetime = 0; - + err = kim_preferences_get_options (prefs, &options); - + if (!err && inOption == loginOption_DefaultTicketLifetime) { err = kim_options_get_lifetime (options, &lifetime); - + } else if (!err && inOption == loginOption_DefaultRenewableLifetime) { err = kim_options_get_renewal_lifetime (options, &lifetime); - } - + } + if (!err) { if (*ioBufferSize < targetSize) { err = kl_check_error (klBufferTooSmallErr); @@ -1109,18 +1109,18 @@ KLStatus KLGetDefaultLoginOption (const KLDefaultLoginOption inOption, *(KLLifetime *)ioBuffer = lifetime; } } - + kim_options_free (&options); } - - } else { + + } else { err = kl_check_error (klInvalidOptionErr); } - + if (!err) { *ioBufferSize = targetSize; } - + return kl_check_error (err); } @@ -1132,56 +1132,56 @@ KLStatus KLSetDefaultLoginOption (const KLDefaultLoginOption inOption, { KLStatus err = klNoErr; kim_preferences prefs = NULL; - + if (inBuffer == NULL) { err = kl_check_error (klParameterErr); } if (inBufferSize < 0) { err = kl_check_error (klParameterErr); } - + if (!err) { err = kim_preferences_create (&prefs); } - + if (!err && inOption == loginOption_LoginName) { kim_identity old_identity = NULL; kim_identity new_identity = NULL; kim_string new_identity_string = NULL; kim_string realm = NULL; kim_string components = NULL; - + err = kim_string_create_from_buffer (&components, inBuffer, inBufferSize); - + if (!err) { err = kim_preferences_get_client_identity (prefs, &old_identity); - + if (!err && old_identity) { err = kim_identity_get_realm (old_identity, &realm); } } - + if (!err && realm) { - err = kim_string_create_from_format (&new_identity_string, + err = kim_string_create_from_format (&new_identity_string, "%s@%s", components, realm); } - + if (!err) { err = kim_identity_create_from_string (&new_identity, (new_identity_string ? new_identity_string : components)); } - + if (!err) { err = kim_preferences_set_client_identity (prefs, new_identity); } - + kim_string_free (&components); kim_string_free (&realm); kim_string_free (&new_identity_string); kim_identity_free (&old_identity); kim_identity_free (&new_identity); - + } else if (!err && inOption == loginOption_LoginInstance) { /* Ignored */ - + } else if (!err && (inOption == loginOption_ShowOptions || inOption == loginOption_RememberShowOptions || inOption == loginOption_LongTicketLifetimeDisplay || @@ -1193,14 +1193,14 @@ KLStatus KLSetDefaultLoginOption (const KLDefaultLoginOption inOption, } else if (inBufferSize < sizeof (KLBoolean)) { err = kl_check_error (klBufferTooSmallErr); } - + if (!err && inOption == loginOption_RememberPrincipal) { err = kim_preferences_set_remember_client_identity (prefs, *(KLBoolean *)inBuffer); - + } else if (!err && inOption == loginOption_RememberExtras) { err = kim_preferences_set_remember_options (prefs, *(KLBoolean *)inBuffer); } - + } else if (!err && (inOption == loginOption_MinimalTicketLifetime || inOption == loginOption_MaximalTicketLifetime || inOption == loginOption_MinimalRenewableLifetime || @@ -1210,92 +1210,92 @@ KLStatus KLSetDefaultLoginOption (const KLDefaultLoginOption inOption, } else if (inBufferSize < sizeof (KLLifetime)) { err = kl_check_error (klBufferTooSmallErr); } - + if (!err && inOption == loginOption_MinimalTicketLifetime) { err = kim_preferences_set_minimum_lifetime (prefs, *(KLLifetime *)inBuffer); - + } else if (!err && inOption == loginOption_MaximalTicketLifetime) { err = kim_preferences_set_maximum_lifetime (prefs, *(KLLifetime *)inBuffer); - + } else if (!err && inOption == loginOption_MinimalRenewableLifetime) { err = kim_preferences_set_minimum_renewal_lifetime (prefs, *(KLLifetime *)inBuffer); - + } else if (!err && inOption == loginOption_MaximalRenewableLifetime) { err = kim_preferences_set_maximum_renewal_lifetime (prefs, *(KLLifetime *)inBuffer); - } - + } + } else if (!err && (inOption == loginOption_DefaultRenewableTicket || inOption == loginOption_DefaultForwardableTicket || inOption == loginOption_DefaultProxiableTicket || inOption == loginOption_DefaultAddresslessTicket)) { kim_options options = NULL; - + if (inBufferSize > sizeof (KLBoolean)) { err = kl_check_error (klBufferTooLargeErr); } else if (inBufferSize < sizeof (KLBoolean)) { err = kl_check_error (klBufferTooSmallErr); } - + if (!err) { err = kim_preferences_get_options (prefs, &options); } - + if (!err && inOption == loginOption_DefaultRenewableTicket) { err = kim_options_set_renewable (options, *(KLBoolean *)inBuffer); - + } else if (!err && inOption == loginOption_DefaultForwardableTicket) { err = kim_options_set_forwardable (options, *(KLBoolean *)inBuffer); - + } else if (!err && inOption == loginOption_DefaultProxiableTicket) { err = kim_options_set_proxiable (options, *(KLBoolean *)inBuffer); - + } else if (!err && inOption == loginOption_DefaultAddresslessTicket) { err = kim_options_set_addressless (options, *(KLBoolean *)inBuffer); - } - + } + if (!err) { err = kim_preferences_set_options (prefs, options); } - + kim_options_free (&options); - + } else if (!err && (inOption == loginOption_DefaultTicketLifetime || inOption == loginOption_DefaultRenewableLifetime)) { kim_options options = NULL; - + if (inBufferSize > sizeof (KLLifetime)) { err = kl_check_error (klBufferTooLargeErr); } else if (inBufferSize < sizeof (KLLifetime)) { err = kl_check_error (klBufferTooSmallErr); } - + if (!err) { err = kim_preferences_get_options (prefs, &options); } - + if (!err && inOption == loginOption_DefaultTicketLifetime) { err = kim_options_set_lifetime (options, *(KLLifetime *)inBuffer); - + } else if (!err && inOption == loginOption_DefaultRenewableLifetime) { err = kim_options_set_renewal_lifetime (options, *(KLLifetime *)inBuffer); - } - + } + if (!err) { err = kim_preferences_set_options (prefs, options); } - + kim_options_free (&options); - - } else { + + } else { err = kl_check_error (klInvalidOptionErr); } - + if (!err) { err = kim_preferences_synchronize (prefs); - } - + } + kim_preferences_free (&prefs); - + return kl_check_error (err); } @@ -1308,11 +1308,11 @@ KLStatus KLFindKerberosRealmByName (const char *inRealmName, { kim_error err = KIM_NO_ERROR; char *realm = NULL; - + if (!err) { err = KLGetKerberosDefaultRealmByName (&realm); } - + if (!err) { if (!strcmp (inRealmName, realm)) { *outIndex = 0; @@ -1320,9 +1320,9 @@ KLStatus KLFindKerberosRealmByName (const char *inRealmName, err = kl_check_error (klRealmDoesNotExistErr); } } - + kim_string_free ((kim_string *) &realm); - + return kl_check_error (err); } @@ -1332,14 +1332,14 @@ KLStatus KLGetKerberosRealm (KLIndex inIndex, char **outRealmName) { kim_error err = KIM_NO_ERROR; - + if (!outRealmName) { err = kl_check_error (klParameterErr); } if (!err && inIndex != 0) { err = kl_check_error (klRealmDoesNotExistErr); } - + if (!err) { err = KLGetKerberosDefaultRealmByName (outRealmName); } - + return kl_check_error (err); } @@ -1385,13 +1385,13 @@ KLSize KLCountKerberosRealms (void) KLStatus KLGetKerberosDefaultRealm(KLIndex *outIndex) { kim_error err = KIM_NO_ERROR; - + if (!outIndex) { err = kl_check_error (klParameterErr); } - + if (!err) { *outIndex = 0; } - + return kl_check_error (klNoErr); } @@ -1402,24 +1402,24 @@ KLStatus KLGetKerberosDefaultRealmByName (char **outRealmName) kim_error err = KIM_NO_ERROR; krb5_context context = NULL; char *realm = NULL; - + if (!outRealmName) { err = kl_check_error (klParameterErr); } - + if (!err) { err = krb5_init_context (&context); } - + if (!err) { err = krb5_get_default_realm(context, &realm); } - + if (!err) { err = kim_string_copy ((kim_string *) outRealmName, realm); } - + if (realm ) { krb5_free_default_realm (context, realm); } if (context) { krb5_free_context (context); } - + return kl_check_error (err); } @@ -1449,14 +1449,14 @@ KLStatus KLCreatePrincipalFromTriplet (const char *inName, if (inInstance && strlen (inInstance) > 0) { return kl_check_error (kim_identity_create_from_components (outPrincipal, inRealm, - inName, + inName, inInstance, NULL)); } else { return kl_check_error (kim_identity_create_from_components (outPrincipal, inRealm, - inName, - NULL)); + inName, + NULL)); } } @@ -1466,7 +1466,7 @@ KLStatus KLCreatePrincipalFromString (const char *inFullPrincipal, KLKerberosVersion inKerberosVersion, KLPrincipal *outPrincipal) { - return kl_check_error (kim_identity_create_from_string (outPrincipal, + return kl_check_error (kim_identity_create_from_string (outPrincipal, inFullPrincipal)); } @@ -1475,7 +1475,7 @@ KLStatus KLCreatePrincipalFromString (const char *inFullPrincipal, KLStatus KLCreatePrincipalFromKerberos5Principal (krb5_principal inKerberos5Principal, KLPrincipal *outPrincipal) { - return kl_check_error (kim_identity_create_from_krb5_principal (outPrincipal, + return kl_check_error (kim_identity_create_from_krb5_principal (outPrincipal, NULL, /* context */ inKerberos5Principal)); } @@ -1500,29 +1500,29 @@ KLStatus KLGetTripletFromPrincipal (KLPrincipal inPrincipal, kim_string instance = NULL; kim_string realm = NULL; kim_count count = 0; - + if (!inPrincipal) { return kl_check_error (klBadPrincipalErr); } if (!outName ) { return kl_check_error (klParameterErr); } if (!outInstance) { return kl_check_error (klParameterErr); } if (!outRealm ) { return kl_check_error (klParameterErr); } - + if (!err) { err = kim_identity_get_number_of_components (inPrincipal, &count); if (!err && count > 2) { err = kl_check_error (klBadPrincipalErr); } } - + if (!err) { err = kim_identity_get_realm (inPrincipal, &realm); } - + if (!err) { err = kim_identity_get_component_at_index (inPrincipal, 0, &name); } - + if (!err && count > 1) { err = kim_identity_get_component_at_index (inPrincipal, 1, &instance); } - + if (!err) { *outName = (char *) name; name = NULL; @@ -1531,11 +1531,11 @@ KLStatus KLGetTripletFromPrincipal (KLPrincipal inPrincipal, *outRealm = (char *) realm; realm = NULL; } - + kim_string_free (&name); kim_string_free (&instance); kim_string_free (&realm); - + return kl_check_error (err); } @@ -1545,7 +1545,7 @@ KLStatus KLGetStringFromPrincipal (KLPrincipal inPrincipal, KLKerberosVersion inKerberosVersion, char **outFullPrincipal) { - return kl_check_error (kim_identity_get_string (inPrincipal, + return kl_check_error (kim_identity_get_string (inPrincipal, (kim_string *) outFullPrincipal)); } @@ -1555,7 +1555,7 @@ KLStatus KLGetDisplayStringFromPrincipal (KLPrincipal inPrincipal, KLKerberosVersion inKerberosVersion, char **outFullPrincipal) { - return kl_check_error (kim_identity_get_display_string (inPrincipal, + return kl_check_error (kim_identity_get_display_string (inPrincipal, (kim_string *) outFullPrincipal)); } @@ -1567,14 +1567,14 @@ KLStatus KLComparePrincipal (KLPrincipal inFirstPrincipal, { kim_error err = KIM_NO_ERROR; kim_comparison comparison; - - err = kim_identity_compare (inFirstPrincipal, inSecondPrincipal, + + err = kim_identity_compare (inFirstPrincipal, inSecondPrincipal, &comparison); - + if (!err) { *outAreEquivalent = kim_comparison_is_equal_to (comparison); } - + return kl_check_error (err); } @@ -1625,13 +1625,13 @@ KLStatus KLLoginOptionsSetRenewableLifetime (KLLoginOptions ioOptions, KLLifetime inRenewableLifetime) { KLStatus err = klNoErr; - + err = kim_options_set_renewable (ioOptions, inRenewableLifetime > 0); - + if (!err && inRenewableLifetime > 0) { err = kim_options_set_renewal_lifetime (ioOptions, inRenewableLifetime); - } - + } + return kl_check_error (err); } @@ -1733,7 +1733,7 @@ KLStatus __KLSetPromptMechanism (KLPromptMechanism inPromptMechanism) KLPromptMechanism __KLPromptMechanism (void) { kim_ui_environment environment = kim_library_ui_environment (); - + if (environment == KIM_UI_ENVIRONMENT_GUI) { return klPromptMechanism_GUI; } else if (environment == KIM_UI_ENVIRONMENT_CLI) { @@ -1759,7 +1759,7 @@ KLStatus __KLCreatePrincipalFromTriplet (const char *inName, { return kl_check_error (kim_identity_create_from_components (outPrincipal, inRealm, - inName, + inName, inInstance, NULL)); } @@ -1772,7 +1772,7 @@ KLStatus __KLGetTripletFromPrincipal (KLPrincipal inPrincipal, char **outInstance, char **outRealm) { - return KLGetTripletFromPrincipal (inPrincipal, + return KLGetTripletFromPrincipal (inPrincipal, outName, outInstance, outRealm); } @@ -1782,17 +1782,17 @@ KLStatus __KLCreatePrincipalFromKerberos5Principal (krb5_principal inPrincipal, KLPrincipal *outPrincipal) { return KLCreatePrincipalFromKerberos5Principal (inPrincipal, outPrincipal); - + } /* ------------------------------------------------------------------------ */ -KLStatus __KLGetKerberos5PrincipalFromPrincipal (KLPrincipal inPrincipal, - krb5_context inContext, +KLStatus __KLGetKerberos5PrincipalFromPrincipal (KLPrincipal inPrincipal, + krb5_context inContext, krb5_principal *outKrb5Principal) { - return kl_check_error (kim_identity_get_krb5_principal (inPrincipal, - inContext, + return kl_check_error (kim_identity_get_krb5_principal (inPrincipal, + inContext, outKrb5Principal)); } @@ -1802,8 +1802,8 @@ KLBoolean __KLPrincipalIsTicketGrantingService (KLPrincipal inPrincipal) { kim_boolean is_tgt = FALSE; kim_error err = kim_identity_is_tgt_service (inPrincipal, &is_tgt); - - return !err ? is_tgt : FALSE; + + return !err ? is_tgt : FALSE; } /* ------------------------------------------------------------------------ */ diff --git a/src/kim/lib/mac/KerberosLogin.h b/src/kim/lib/mac/KerberosLogin.h index 8dc49e18d5..6d98c18783 100644 --- a/src/kim/lib/mac/KerberosLogin.h +++ b/src/kim/lib/mac/KerberosLogin.h @@ -6,7 +6,7 @@ * 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 @@ -51,7 +51,7 @@ extern "C" { # pragma pack(push,2) #endif -/* +/* * Kerberos version constants */ enum { @@ -62,8 +62,8 @@ enum { }; typedef int32_t KLEKerberosVersion; -/* - * Dialog identifier constants +/* + * Dialog identifier constants */ enum { loginLibrary_LoginDialog, @@ -76,35 +76,35 @@ enum { typedef int32_t KLEDialogIdentifiers; -/* - * Option identifier constants +/* + * Option identifier constants */ enum { /* Initial values and ranges */ loginOption_LoginName = 'name', loginOption_LoginInstance = 'inst', - + loginOption_RememberPrincipal = 'prin', loginOption_RememberExtras = 'extr', - + loginOption_MinimalTicketLifetime = '-lif', loginOption_MaximalTicketLifetime = '+lif', loginOption_DefaultTicketLifetime = '0lif', - + loginOption_DefaultRenewableTicket = '0rtx', loginOption_MinimalRenewableLifetime = '-rlf', loginOption_MaximalRenewableLifetime = '+rlf', loginOption_DefaultRenewableLifetime = '0rlf', - + loginOption_DefaultForwardableTicket = '0fwd', loginOption_DefaultProxiableTicket = '0prx', - loginOption_DefaultAddresslessTicket = '0adr' + loginOption_DefaultAddresslessTicket = '0adr' }; typedef int32_t KLEDefaultLoginOptions; -/* - * Realm list constants +/* + * Realm list constants */ enum { realmList_Start = 0, @@ -115,12 +115,12 @@ typedef int32_t KLERealmListIndexes; #define klFirstError 19276 #define klLastError 19876 -/* - * Error codes +/* + * Error codes */ enum { klNoErr = 0, - + /* Parameter errors */ klParameterErr = 19276, klBadPrincipalErr, @@ -129,13 +129,13 @@ enum { klInvalidVersionErr, klCapsLockErr, klBadV5ContextErr, - + /* Get/SetKerberosOption errors */ klBufferTooSmallErr = 19376, klBufferTooLargeErr, klInvalidOptionErr, klBadOptionValueErr, - + /* Runtime Login errors */ klUserCanceledErr = 19476, klMemFullErr, @@ -152,17 +152,17 @@ enum { klCacheDoesNotExistErr, klNoHostnameErr, klCredentialsNeedValidationErr, - + /* Password changing errors */ klPasswordMismatchErr = 19576, klInsecurePasswordErr, klPasswordChangeFailedErr, - + /* Login IPC errors */ klCantContactServerErr = 19776, klCantDisplayUIErr, klServerInsecureErr - + }; typedef int32_t KLEStatus; @@ -203,30 +203,30 @@ typedef kim_options KLLoginOptions; KLStatus KLAcquireTickets (KLPrincipal inPrincipal, KLPrincipal *outPrincipal, - char **outCredCacheName) + char **outCredCacheName) KERBEROSLOGIN_DEPRECATED; KLStatus KLAcquireNewTickets (KLPrincipal inPrincipal, KLPrincipal *outPrincipal, - char **outCredCacheName) + char **outCredCacheName) KERBEROSLOGIN_DEPRECATED; KLStatus KLAcquireTicketsWithPassword (KLPrincipal inPrincipal, KLLoginOptions inLoginOptions, const char *inPassword, - char **outCredCacheName) + char **outCredCacheName) KERBEROSLOGIN_DEPRECATED; KLStatus KLAcquireNewTicketsWithPassword (KLPrincipal inPrincipal, KLLoginOptions inLoginOptions, const char *inPassword, - char **outCredCacheName) + char **outCredCacheName) KERBEROSLOGIN_DEPRECATED; -KLStatus KLSetApplicationOptions (const void *inAppOptions) +KLStatus KLSetApplicationOptions (const void *inAppOptions) KERBEROSLOGIN_DEPRECATED; -KLStatus KLGetApplicationOptions (void *outAppOptions) +KLStatus KLGetApplicationOptions (void *outAppOptions) KERBEROSLOGIN_DEPRECATED; diff --git a/src/kim/lib/mac/KerberosLoginPrivate.h b/src/kim/lib/mac/KerberosLoginPrivate.h index 52e10fcd1d..09048397f9 100644 --- a/src/kim/lib/mac/KerberosLoginPrivate.h +++ b/src/kim/lib/mac/KerberosLoginPrivate.h @@ -6,7 +6,7 @@ * 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 @@ -62,7 +62,7 @@ typedef krb5_error_code (*KLPrompterProcPtr) (krb5_context context, KLStatus __KLSetApplicationPrompter (KLPrompterProcPtr inPrompter); #endif /* KERBEROSLOGIN_DEPRECATED */ - + /*****************/ /*** Functions ***/ /*****************/ @@ -93,8 +93,8 @@ KLStatus __KLGetTripletFromPrincipal (KLPrincipal inPrincipal, KLStatus __KLCreatePrincipalFromKerberos5Principal (krb5_principal inPrincipal, KLPrincipal *outPrincipal); -KLStatus __KLGetKerberos5PrincipalFromPrincipal (KLPrincipal inPrincipal, - krb5_context inContext, +KLStatus __KLGetKerberos5PrincipalFromPrincipal (KLPrincipal inPrincipal, + krb5_context inContext, krb5_principal *outKrb5Principal); KLStatus __KLGetRealmFromPrincipal (KLPrincipal inPrincipal, char **outRealm); @@ -120,4 +120,3 @@ KLStatus __KLRemoveKeychainPasswordForPrincipal (KLPrincipal inPrincipal); #endif #endif /* __KERBEROSLOGINPRIVATE__ */ - diff --git a/src/kim/lib/mac/kim_os_debug.c b/src/kim/lib/mac/kim_os_debug.c index e4236872f7..b4d0db21ca 100644 --- a/src/kim/lib/mac/kim_os_debug.c +++ b/src/kim/lib/mac/kim_os_debug.c @@ -8,7 +8,7 @@ * 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 diff --git a/src/kim/lib/mac/kim_os_identity.c b/src/kim/lib/mac/kim_os_identity.c index a9c92d73ab..c0f97b4fe0 100644 --- a/src/kim/lib/mac/kim_os_identity.c +++ b/src/kim/lib/mac/kim_os_identity.c @@ -8,7 +8,7 @@ * 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 @@ -36,38 +36,38 @@ kim_boolean kim_os_identity_allow_save_password (void) { kim_boolean disabled = 0; CFPropertyListRef disable_pref = NULL; - - disable_pref = CFPreferencesCopyValue (CFSTR ("SavePasswordDisabled"), + + disable_pref = CFPreferencesCopyValue (CFSTR ("SavePasswordDisabled"), KIM_PREFERENCES_FILE, kCFPreferencesAnyUser, kCFPreferencesAnyHost); if (!disable_pref) { - disable_pref = CFPreferencesCopyValue (CFSTR ("SavePasswordDisabled"), + disable_pref = CFPreferencesCopyValue (CFSTR ("SavePasswordDisabled"), KIM_PREFERENCES_FILE, kCFPreferencesAnyUser, - kCFPreferencesCurrentHost); + kCFPreferencesCurrentHost); } - + if (!disable_pref) { - disable_pref = CFPreferencesCopyValue (CFSTR ("SavePasswordDisabled"), + disable_pref = CFPreferencesCopyValue (CFSTR ("SavePasswordDisabled"), KA_PREFERENCES_FILE, kCFPreferencesAnyUser, - kCFPreferencesAnyHost); + kCFPreferencesAnyHost); } - + if (!disable_pref) { - disable_pref = CFPreferencesCopyValue (CFSTR ("SavePasswordDisabled"), + disable_pref = CFPreferencesCopyValue (CFSTR ("SavePasswordDisabled"), KA_PREFERENCES_FILE, kCFPreferencesAnyUser, - kCFPreferencesCurrentHost); + kCFPreferencesCurrentHost); } - disabled = (disable_pref && + disabled = (disable_pref && CFGetTypeID (disable_pref) == CFBooleanGetTypeID () && CFBooleanGetValue (disable_pref)); - + if (disable_pref) { CFRelease (disable_pref); } - + return !disabled; } @@ -81,47 +81,47 @@ kim_error kim_os_identity_get_saved_password (kim_identity in_identity, kim_string name = NULL; void *buffer = NULL; UInt32 length = 0; - + if (!err && !in_identity ) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !out_password) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err && !kim_library_allow_home_directory_access ()) { err = check_error (ENOENT); /* simulate no password found */ } - + if (!err && !kim_os_identity_allow_save_password ()) { err = kim_os_identity_remove_saved_password (in_identity); if (!err) { err = check_error (ENOENT); /* simulate no password found */ } } - + if (!err) { err = kim_identity_get_components_string (in_identity, &name); } - + if (!err) { err = kim_identity_get_realm (in_identity, &realm); } - + if (!err) { - err = SecKeychainFindGenericPassword (nil, + err = SecKeychainFindGenericPassword (nil, strlen (realm), realm, strlen (name), name, - &length, &buffer, + &length, &buffer, nil); - + if (!err && !buffer) { err = check_error (ENOENT); } } - + if (!err) { err = kim_string_create_from_buffer (out_password, buffer, length); } - + kim_string_free (&name); kim_string_free (&realm); if (buffer) { SecKeychainItemFreeContent (NULL, buffer); } - + return check_error (err); } @@ -133,63 +133,63 @@ kim_error kim_os_identity_set_saved_password (kim_identity in_identity, kim_error err = KIM_NO_ERROR; kim_string realm = NULL; kim_string name = NULL; - + if (!err && !in_identity) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !in_password) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err && !kim_library_allow_home_directory_access ()) { return KIM_NO_ERROR; /* simulate no error */ } - + if (!err && !kim_os_identity_allow_save_password ()) { return kim_os_identity_remove_saved_password (in_identity); } - + if (!err) { err = kim_identity_get_components_string (in_identity, &name); } - + if (!err) { err = kim_identity_get_realm (in_identity, &realm); } - + if (!err) { SecKeychainItemRef itemRef = NULL; UInt32 namelen = strlen (name); UInt32 realmlen = strlen (realm); - + /* Add the password to the keychain */ - err = SecKeychainAddGenericPassword (nil, + err = SecKeychainAddGenericPassword (nil, realmlen, realm, namelen, name, strlen (in_password), in_password, - &itemRef); - + &itemRef); + if (err == errSecDuplicateItem) { /* We've already stored a password for this principal * but it might have changed so update it */ void *buffer = NULL; UInt32 length = 0; - - err = SecKeychainFindGenericPassword (nil, + + err = SecKeychainFindGenericPassword (nil, realmlen, realm, namelen, name, - &length, &buffer, + &length, &buffer, &itemRef); - + if (!err) { SecKeychainAttribute attrs[] = { { kSecAccountItemAttr, namelen, (char *) name }, { kSecServiceItemAttr, realmlen, (char *) realm } }; UInt32 count = sizeof(attrs) / sizeof(attrs[0]); const SecKeychainAttributeList attrList = { count, attrs }; - + err = SecKeychainItemModifyAttributesAndData (itemRef, &attrList, - strlen (in_password), + strlen (in_password), in_password); } - + } else if (!err) { /* We added a new entry, add a descriptive label */ SecKeychainAttributeList *copiedAttrs = NULL; @@ -197,50 +197,50 @@ kim_error kim_os_identity_set_saved_password (kim_identity in_identity, UInt32 tag = 7; UInt32 format = CSSM_DB_ATTRIBUTE_FORMAT_STRING; kim_string label = NULL; - + attrInfo.count = 1; attrInfo.tag = &tag; attrInfo.format = &format; - - err = SecKeychainItemCopyAttributesAndData (itemRef, &attrInfo, - NULL, &copiedAttrs, + + err = SecKeychainItemCopyAttributesAndData (itemRef, &attrInfo, + NULL, &copiedAttrs, 0, NULL); - + if (!err) { /* Label format used by Apple patches */ - err = kim_string_create_from_format (&label, "%s (%s)", + err = kim_string_create_from_format (&label, "%s (%s)", realm, name); } - + if (!err) { SecKeychainAttributeList attrList; SecKeychainAttribute attr; - + /* Copy the tag they gave us and copy in our label */ attr.tag = copiedAttrs->attr->tag; attr.length = strlen (label); attr.data = (char *) label; - + attrList.count = 1; attrList.attr = &attr; - + /* And modify. */ - err = SecKeychainItemModifyAttributesAndData (itemRef, &attrList, + err = SecKeychainItemModifyAttributesAndData (itemRef, &attrList, 0, NULL); } - + if (label ) { kim_string_free (&label); } - if (copiedAttrs) { SecKeychainItemFreeAttributesAndData (copiedAttrs, NULL); } + if (copiedAttrs) { SecKeychainItemFreeAttributesAndData (copiedAttrs, NULL); } } - + if (itemRef) { CFRelease (itemRef); } } - + kim_string_free (&name); kim_string_free (&realm); - + return check_error (err); -} +} /* ------------------------------------------------------------------------ */ @@ -249,58 +249,58 @@ kim_error kim_os_identity_remove_saved_password (kim_identity in_identity) kim_error err = KIM_NO_ERROR; kim_string realm = NULL; kim_string name = NULL; - + if (!err && !in_identity) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err && !kim_library_allow_home_directory_access ()) { return KIM_NO_ERROR; /* simulate no error */ } - + if (!err) { err = kim_identity_get_components_string (in_identity, &name); } - + if (!err) { err = kim_identity_get_realm (in_identity, &realm); } - + if (!err) { SecKeychainItemRef itemRef = NULL; UInt32 namelen = strlen (name); UInt32 realmlen = strlen (realm); void *buffer = NULL; UInt32 length = 0; - - err = SecKeychainFindGenericPassword (nil, + + err = SecKeychainFindGenericPassword (nil, realmlen, realm, namelen, name, - &length, &buffer, + &length, &buffer, &itemRef); - + if (!err) { err = SecKeychainItemDelete (itemRef); - + } else if (err == errSecItemNotFound) { err = KIM_NO_ERROR; /* No password not an error */ } - + if (itemRef) { CFRelease (itemRef); } } - + kim_string_free (&name); kim_string_free (&realm); - + return check_error (err); -} +} /* ------------------------------------------------------------------------ */ kim_error kim_os_identity_create_for_username (kim_identity *out_identity) { kim_error err = KIM_NO_ERROR; - + if (!err && !out_identity) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { struct passwd *pw = getpwuid (getuid ()); if (pw) { @@ -310,5 +310,5 @@ kim_error kim_os_identity_create_for_username (kim_identity *out_identity) } } - return check_error (err); + return check_error (err); } diff --git a/src/kim/lib/mac/kim_os_library.c b/src/kim/lib/mac/kim_os_library.c index f3b2690843..edecf2be05 100644 --- a/src/kim/lib/mac/kim_os_library.c +++ b/src/kim/lib/mac/kim_os_library.c @@ -8,7 +8,7 @@ * 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 @@ -44,11 +44,11 @@ MAKE_FINI_FUNCTION(kim_os_library_thread_fini); static int kim_os_library_thread_init (void) { kim_error err = KIM_NO_ERROR; - + if (!err) { err = k5_mutex_finish_init (&g_bundle_lookup_mutex); } - + return err; } @@ -69,11 +69,11 @@ static void kim_os_library_thread_fini (void) kim_error kim_os_library_lock_for_bundle_lookup (void) { kim_error err = CALL_INIT_FUNCTION (kim_os_library_thread_init); - + if (!err) { err = k5_mutex_lock (&g_bundle_lookup_mutex); } - + return err; } @@ -82,11 +82,11 @@ kim_error kim_os_library_lock_for_bundle_lookup (void) kim_error kim_os_library_unlock_for_bundle_lookup (void) { kim_error err = CALL_INIT_FUNCTION (kim_os_library_thread_init); - + if (!err) { err = k5_mutex_unlock (&g_bundle_lookup_mutex); } - + return err; } @@ -97,20 +97,20 @@ kim_error kim_os_library_unlock_for_bundle_lookup (void) kim_boolean kim_os_library_caller_uses_gui (void) { kim_boolean caller_uses_gui = 0; - - /* Check for the HIToolbox (Carbon) or AppKit (Cocoa). + + /* Check for the HIToolbox (Carbon) or AppKit (Cocoa). * If either is loaded, we are a GUI app! */ CFBundleRef appKitBundle = CFBundleGetBundleWithIdentifier (CFSTR ("com.apple.AppKit")); CFBundleRef hiToolBoxBundle = CFBundleGetBundleWithIdentifier (CFSTR ("com.apple.HIToolbox")); - + if (hiToolBoxBundle && CFBundleIsExecutableLoaded (hiToolBoxBundle)) { caller_uses_gui = 1; /* Using Carbon */ } - + if (appKitBundle && CFBundleIsExecutableLoaded (appKitBundle)) { caller_uses_gui = 1; /* Using Cocoa */ - } - + } + return caller_uses_gui; } @@ -120,33 +120,33 @@ kim_ui_environment kim_os_library_get_ui_environment (void) { #ifdef KIM_BUILTIN_UI kim_boolean has_gui_access = 0; - SessionAttributeBits sattrs = 0L; - - has_gui_access = ((SessionGetInfo (callerSecuritySession, - NULL, &sattrs) == noErr) && + SessionAttributeBits sattrs = 0L; + + has_gui_access = ((SessionGetInfo (callerSecuritySession, + NULL, &sattrs) == noErr) && (sattrs & sessionHasGraphicAccess)); - + if (has_gui_access && kim_os_library_caller_uses_gui ()) { return KIM_UI_ENVIRONMENT_GUI; } - + { int fd_stdin = fileno (stdin); int fd_stdout = fileno (stdout); char *fd_stdin_name = ttyname (fd_stdin); - + /* Session info isn't reliable for remote sessions. * Check manually for terminal access with file descriptors */ if (isatty (fd_stdin) && isatty (fd_stdout) && fd_stdin_name) { return KIM_UI_ENVIRONMENT_CLI; } } - + /* If we don't have a CLI but can talk to the GUI, use that */ if (has_gui_access) { return KIM_UI_ENVIRONMENT_GUI; } - + kim_debug_printf ("kim_os_library_get_ui_environment(): no way to talk to the user."); #endif return KIM_UI_ENVIRONMENT_NONE; @@ -167,7 +167,7 @@ kim_boolean kim_os_library_caller_is_server (void) } } } - + return FALSE; } @@ -180,7 +180,7 @@ kim_error kim_os_library_get_application_path (kim_string *out_path) kim_error err = KIM_NO_ERROR; kim_string path = NULL; CFBundleRef bundle = CFBundleGetMainBundle (); - + if (!err && !out_path) { err = check_error (KIM_NULL_PARAMETER_ERR); } /* Check if the caller is a bundle */ @@ -190,42 +190,42 @@ kim_error kim_os_library_get_application_path (kim_string *out_path) CFURLRef executable_url = CFBundleCopyExecutableURL (bundle); CFURLRef absolute_url = NULL; CFStringRef cfpath = NULL; - + if (bundle_url && resources_url && !CFEqual (bundle_url, resources_url)) { absolute_url = CFURLCopyAbsoluteURL (bundle_url); } else if (executable_url) { absolute_url = CFURLCopyAbsoluteURL (executable_url); } - + if (absolute_url) { - cfpath = CFURLCopyFileSystemPath (absolute_url, + cfpath = CFURLCopyFileSystemPath (absolute_url, kCFURLPOSIXPathStyle); if (!cfpath) { err = check_error (KIM_OUT_OF_MEMORY_ERR); } } - + if (!err && cfpath) { err = kim_os_string_create_from_cfstring (&path, cfpath); } - - if (cfpath ) { CFRelease (cfpath); } + + if (cfpath ) { CFRelease (cfpath); } if (absolute_url ) { CFRelease (absolute_url); } if (bundle_url ) { CFRelease (bundle_url); } if (resources_url ) { CFRelease (resources_url); } if (executable_url) { CFRelease (executable_url); } } - + /* Caller is not a bundle, try _NSGetExecutablePath */ /* Note: this does not work on CFM applications */ if (!err && !path) { char *buffer = NULL; uint32_t len = 0; - + /* Tiny stupid buffer to get the length of the path */ if (!err) { buffer = malloc (1); if (!buffer) { err = check_error (KIM_OUT_OF_MEMORY_ERR); } } - + /* Get the length of the path */ if (!err) { if (_NSGetExecutablePath (buffer, &len) != 0) { @@ -237,7 +237,7 @@ kim_error kim_os_library_get_application_path (kim_string *out_path) } } } - + /* Get the path */ if (!err) { if (_NSGetExecutablePath (buffer, &len) != 0) { @@ -246,18 +246,18 @@ kim_error kim_os_library_get_application_path (kim_string *out_path) err = kim_string_copy (&path, buffer); } } - + if (buffer) { free (buffer); } } - + if (!err) { *out_path = path; path = NULL; } - + kim_string_free (&path); - - return check_error (err); + + return check_error (err); } /* ------------------------------------------------------------------------ */ @@ -268,65 +268,65 @@ kim_error kim_os_library_get_caller_name (kim_string *out_application_name) kim_string name = NULL; CFBundleRef bundle = CFBundleGetMainBundle (); CFStringRef cfname = NULL; - + if (!err && !out_application_name) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err && bundle) { - cfname = CFBundleGetValueForInfoDictionaryKey (bundle, + cfname = CFBundleGetValueForInfoDictionaryKey (bundle, kCFBundleNameKey); - + if (!cfname || CFGetTypeID (cfname) != CFStringGetTypeID ()) { - cfname = CFBundleGetValueForInfoDictionaryKey (bundle, + cfname = CFBundleGetValueForInfoDictionaryKey (bundle, kCFBundleExecutableKey); } - + if (cfname) { cfname = CFStringCreateCopy (kCFAllocatorDefault, cfname); } } - + if (!err && !cfname) { kim_string path = NULL; CFURLRef cfpath = NULL; CFURLRef cfpathnoext = NULL; - + err = kim_os_library_get_application_path (&path); - + if (!err) { cfpath = CFURLCreateFromFileSystemRepresentation (kCFAllocatorDefault, (const UInt8 *) path, strlen (path), 0); - + if (cfpath) { cfpathnoext = CFURLCreateCopyDeletingPathExtension (kCFAllocatorDefault, cfpath); } - + if (cfpathnoext) { cfname = CFURLCopyLastPathComponent (cfpathnoext); } else { cfname = CFURLCopyLastPathComponent (cfpath); } } - + if (cfpathnoext) { CFRelease (cfpathnoext); } if (cfpath ) { CFRelease (cfpath); } kim_string_free (&path); } - + if (!err && cfname) { err = kim_os_string_create_from_cfstring (&name, cfname); } - + if (!err) { *out_application_name = name; name = NULL; - + } if (cfname) { CFRelease (cfname); } kim_string_free (&name); - + return check_error (err); } diff --git a/src/kim/lib/mac/kim_os_preferences.c b/src/kim/lib/mac/kim_os_preferences.c index 87700ef89f..4cbac8b61b 100644 --- a/src/kim/lib/mac/kim_os_preferences.c +++ b/src/kim/lib/mac/kim_os_preferences.c @@ -8,7 +8,7 @@ * 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 @@ -38,51 +38,51 @@ static CFStringRef kim_os_preferences_cfstring_for_key (kim_preference_key in_ke { if (in_key == kim_preference_key_options) { return CFSTR ("CredentialOptions"); - + } else if (in_key == kim_preference_key_lifetime) { return CFSTR ("CredentialLifetime"); - + } else if (in_key == kim_preference_key_renewable) { return CFSTR ("RenewableCredentials"); - + } else if (in_key == kim_preference_key_renewal_lifetime) { return CFSTR ("CredentialRenewalLifetime"); - + } else if (in_key == kim_preference_key_forwardable) { return CFSTR ("ForwardableCredentials"); - + } else if (in_key == kim_preference_key_proxiable) { return CFSTR ("ProxiableCredentials"); - + } else if (in_key == kim_preference_key_addressless) { return CFSTR ("AddresslessCredentials"); - + } else if (in_key == kim_preference_key_remember_options) { return CFSTR ("RememberCredentialAttributes"); - + } else if (in_key == kim_preference_key_client_identity) { return CFSTR ("ClientIdentity"); - + } else if (in_key == kim_preference_key_remember_client_identity) { return CFSTR ("RememberClientIdentity"); - + } else if (in_key == kim_preference_key_favorites) { return CFSTR ("FavoriteIdentities"); - + } else if (in_key == kim_preference_key_minimum_lifetime) { return CFSTR ("MinimumLifetime"); - + } else if (in_key == kim_preference_key_maximum_lifetime) { return CFSTR ("MaximumLifetime"); - + } else if (in_key == kim_preference_key_minimum_renewal_lifetime) { return CFSTR ("MinimumRenewalLifetime"); - + } else if (in_key == kim_preference_key_maximum_renewal_lifetime) { return CFSTR ("MaximumRenewalLifetime"); - + } - + return NULL; /* ignore unsupported keys */ } @@ -92,95 +92,95 @@ static CFStringRef kim_os_preferences_compat_cfstring_for_key (kim_preference_ke { if (in_key == kim_preference_key_lifetime) { return CFSTR ("KLDefaultTicketLifetime"); - + } else if (in_key == kim_preference_key_renewable) { return CFSTR ("KLGetRenewableTickets"); - + } else if (in_key == kim_preference_key_renewal_lifetime) { return CFSTR ("KLDefaultRenewableLifetime"); - + } else if (in_key == kim_preference_key_forwardable) { return CFSTR ("KLDefaultForwardableTicket"); - + } else if (in_key == kim_preference_key_proxiable) { return CFSTR ("KLGetProxiableTickets"); - + } else if (in_key == kim_preference_key_addressless) { return CFSTR ("KLGetAddresslessTickets"); - + } else if (in_key == kim_preference_key_remember_options) { return CFSTR ("KLRememberExtras"); - + } else if (in_key == kim_preference_key_client_identity) { return CFSTR ("KLName"); - + } else if (in_key == kim_preference_key_remember_client_identity) { return CFSTR ("KLRememberPrincipal"); - + } else if (in_key == kim_preference_key_favorites) { return CFSTR ("KLFavoriteIdentities"); - + } else if (in_key == kim_preference_key_minimum_lifetime) { return CFSTR ("KLMinimumTicketLifetime"); - + } else if (in_key == kim_preference_key_maximum_lifetime) { return CFSTR ("KLMaximumTicketLifetime"); - + } else if (in_key == kim_preference_key_minimum_renewal_lifetime) { return CFSTR ("KLMinimumRenewableLifetime"); - + } else if (in_key == kim_preference_key_maximum_renewal_lifetime) { return CFSTR ("KLMaximumRenewableLifetime"); - + } - + return NULL; /* ignore unsupported keys */ } /* ------------------------------------------------------------------------ */ -static kim_error kim_os_preferences_copy_value_for_file (CFStringRef in_key, - CFTypeID in_type, +static kim_error kim_os_preferences_copy_value_for_file (CFStringRef in_key, + CFTypeID in_type, CFStringRef in_file, CFPropertyListRef *out_value) { - + kim_error err = KIM_NO_ERROR; CFPropertyListRef value = NULL; CFStringRef users[] = { kCFPreferencesCurrentUser, kCFPreferencesAnyUser, NULL }; CFStringRef hosts[] = { kCFPreferencesCurrentHost, kCFPreferencesAnyHost, NULL }; - + if (!err && !in_key ) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !in_file ) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !out_value) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { kim_count u, h; - + if (!kim_library_allow_home_directory_access()) { users[0] = kCFPreferencesAnyUser; users[1] = NULL; } - + for (u = 0; !value && users[u]; u++) { for (h = 0; !value && hosts[h]; h++) { value = CFPreferencesCopyValue (in_key, in_file, users[u], hosts[h]); } - } - + } + if (value && CFGetTypeID (value) != in_type) { err = check_error (KIM_PREFERENCES_READ_ERR); } } - - + + if (!err) { *out_value = value; value = NULL; } - + if (value) { CFRelease (value); } - + return check_error (err); } @@ -188,61 +188,61 @@ static kim_error kim_os_preferences_copy_value_for_file (CFStringRef in_ /* ------------------------------------------------------------------------ */ -static kim_error kim_os_preferences_copy_value (kim_preference_key in_key, - CFTypeID in_type, +static kim_error kim_os_preferences_copy_value (kim_preference_key in_key, + CFTypeID in_type, CFPropertyListRef *out_value) { kim_error err = KIM_NO_ERROR; CFStringRef key = kim_os_preferences_cfstring_for_key (in_key); - + err = kim_os_preferences_copy_value_for_file (key, in_type, KIM_PREFERENCES_FILE, out_value); - + return check_error (err); } /* ------------------------------------------------------------------------ */ -static kim_error kim_os_preferences_copy_value_compat (kim_preference_key in_key, - CFTypeID in_type, +static kim_error kim_os_preferences_copy_value_compat (kim_preference_key in_key, + CFTypeID in_type, CFPropertyListRef *out_value) { kim_error err = KIM_NO_ERROR; CFStringRef key = kim_os_preferences_compat_cfstring_for_key (in_key); - + err = kim_os_preferences_copy_value_for_file (key, in_type, KLL_PREFERENCES_FILE, out_value); - + return check_error (err); } /* ------------------------------------------------------------------------ */ -static kim_error kim_os_preferences_set_value (kim_preference_key in_key, +static kim_error kim_os_preferences_set_value (kim_preference_key in_key, CFPropertyListRef in_value) { kim_error err = KIM_NO_ERROR; CFStringRef key = NULL; - + /* in_value may be NULL if removing the key */ - + if (!err) { key = kim_os_preferences_cfstring_for_key (in_key); } - + if (!err && key) { kim_boolean homedir_ok = kim_library_allow_home_directory_access(); CFStringRef user = homedir_ok ? kCFPreferencesCurrentUser : kCFPreferencesAnyUser; CFStringRef host = homedir_ok ? kCFPreferencesAnyHost : kCFPreferencesCurrentHost; - + CFPreferencesSetValue (key, in_value, KIM_PREFERENCES_FILE, user, host); if (!CFPreferencesSynchronize (KIM_PREFERENCES_FILE, user, host)) { err = check_error (KIM_PREFERENCES_WRITE_ERR); } } - + return check_error (err); } @@ -250,35 +250,35 @@ static kim_error kim_os_preferences_set_value (kim_preference_key in_key, /* ------------------------------------------------------------------------ */ -kim_error kim_os_preferences_get_identity_for_key (kim_preference_key in_key, +kim_error kim_os_preferences_get_identity_for_key (kim_preference_key in_key, kim_identity in_hardcoded_default, kim_identity *out_identity) { kim_error err = KIM_NO_ERROR; kim_string string = NULL; CFStringRef value = NULL; - + if (!err && !out_identity) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { - err = kim_os_preferences_copy_value (in_key, CFStringGetTypeID (), + err = kim_os_preferences_copy_value (in_key, CFStringGetTypeID (), (CFPropertyListRef *) &value); - + } - + if (!err && !value) { - err = kim_os_preferences_copy_value_compat (in_key, CFStringGetTypeID (), + err = kim_os_preferences_copy_value_compat (in_key, CFStringGetTypeID (), (CFPropertyListRef *) &value); } - + if (!err) { if (value) { err = kim_os_string_create_from_cfstring (&string, value); - + if (!err) { if (!strcmp (kim_os_preference_any_identity, string)) { *out_identity = KIM_IDENTITY_ANY; - + } else { err = kim_identity_create_from_string (out_identity, string); } @@ -287,68 +287,68 @@ kim_error kim_os_preferences_get_identity_for_key (kim_preference_key in_key, err = kim_identity_copy (out_identity, in_hardcoded_default); } } - + kim_string_free (&string); if (value) { CFRelease (value); } - + return check_error (err); } /* ------------------------------------------------------------------------ */ -kim_error kim_os_preferences_set_identity_for_key (kim_preference_key in_key, +kim_error kim_os_preferences_set_identity_for_key (kim_preference_key in_key, kim_identity in_identity) { kim_error err = KIM_NO_ERROR; CFStringRef value = NULL; kim_string string = NULL; - + /* in_identity can be KIM_IDENTITY_ANY */ - + if (!err) { if (in_identity) { err = kim_identity_get_string (in_identity, &string); - + } else { err = kim_string_copy (&string, kim_os_preference_any_identity); } } - + if (!err) { err = kim_os_string_get_cfstring (string, &value); } - + if (!err) { err = kim_os_preferences_set_value (in_key, value); } - + if (value) { CFRelease (value); } kim_string_free (&string); - + return check_error (err); } /* ------------------------------------------------------------------------ */ -kim_error kim_os_preferences_get_lifetime_for_key (kim_preference_key in_key, +kim_error kim_os_preferences_get_lifetime_for_key (kim_preference_key in_key, kim_lifetime in_hardcoded_default, kim_lifetime *out_lifetime) { kim_error err = KIM_NO_ERROR; CFNumberRef value = NULL; - + if (!err && !out_lifetime) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { - err = kim_os_preferences_copy_value (in_key, CFNumberGetTypeID (), + err = kim_os_preferences_copy_value (in_key, CFNumberGetTypeID (), (CFPropertyListRef *) &value); } - + if (!err && !value) { - err = kim_os_preferences_copy_value_compat (in_key, CFNumberGetTypeID (), + err = kim_os_preferences_copy_value_compat (in_key, CFNumberGetTypeID (), (CFPropertyListRef *) &value); } - + if (!err) { if (value) { SInt32 number; // CFNumbers are signed so we need to cast @@ -361,56 +361,56 @@ kim_error kim_os_preferences_get_lifetime_for_key (kim_preference_key in_key, *out_lifetime = in_hardcoded_default; } } - + if (value) { CFRelease (value); } - + return check_error (err); } /* ------------------------------------------------------------------------ */ -kim_error kim_os_preferences_set_lifetime_for_key (kim_preference_key in_key, +kim_error kim_os_preferences_set_lifetime_for_key (kim_preference_key in_key, kim_lifetime in_lifetime) { kim_error err = KIM_NO_ERROR; CFNumberRef value = NULL; SInt32 number = (SInt32) in_lifetime; - + if (!err) { value = CFNumberCreate (kCFAllocatorDefault, kCFNumberSInt32Type, &number); if (!value) { err = KIM_OUT_OF_MEMORY_ERR; } } - + if (!err) { err = kim_os_preferences_set_value (in_key, value); } - + if (value) { CFRelease (value); } - + return check_error (err); } /* ------------------------------------------------------------------------ */ -kim_error kim_os_preferences_get_boolean_for_key (kim_preference_key in_key, +kim_error kim_os_preferences_get_boolean_for_key (kim_preference_key in_key, kim_boolean in_hardcoded_default, kim_boolean *out_boolean) { kim_error err = KIM_NO_ERROR; CFBooleanRef value = NULL; - + if (!err && !out_boolean) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { - err = kim_os_preferences_copy_value (in_key, CFBooleanGetTypeID (), + err = kim_os_preferences_copy_value (in_key, CFBooleanGetTypeID (), (CFPropertyListRef *) &value); } - + if (!err && !value) { - err = kim_os_preferences_copy_value_compat (in_key, CFBooleanGetTypeID (), + err = kim_os_preferences_copy_value_compat (in_key, CFBooleanGetTypeID (), (CFPropertyListRef *) &value); } - + if (!err) { if (value) { *out_boolean = CFBooleanGetValue (value); @@ -418,24 +418,24 @@ kim_error kim_os_preferences_get_boolean_for_key (kim_preference_key in_key, *out_boolean = in_hardcoded_default; } } - + if (value) { CFRelease (value); } - + return check_error (err); } /* ------------------------------------------------------------------------ */ -kim_error kim_os_preferences_set_boolean_for_key (kim_preference_key in_key, +kim_error kim_os_preferences_set_boolean_for_key (kim_preference_key in_key, kim_boolean in_boolean) { kim_error err = KIM_NO_ERROR; CFBooleanRef value = in_boolean ? kCFBooleanTrue : kCFBooleanFalse; - + if (!err) { err = kim_os_preferences_set_value (in_key, value); } - + return check_error (err); } @@ -444,167 +444,167 @@ kim_error kim_os_preferences_set_boolean_for_key (kim_preference_key in_key, /* ------------------------------------------------------------------------ */ static kim_error kim_os_preferences_copy_value_for_dict_key (CFDictionaryRef in_dictionary, - kim_preference_key in_key, - CFTypeID in_type, + kim_preference_key in_key, + CFTypeID in_type, CFPropertyListRef *out_value) { kim_error err = KIM_NO_ERROR; CFPropertyListRef value = NULL; - + if (!err && !in_dictionary) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !out_value ) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { CFStringRef key = kim_os_preferences_cfstring_for_key (in_key); - + value = CFDictionaryGetValue (in_dictionary, key); if (value && CFGetTypeID (value) != in_type) { err = check_error (KIM_PREFERENCES_READ_ERR); } } - + if (!err) { *out_value = value; } - + return check_error (err); } /* ------------------------------------------------------------------------ */ static kim_error kim_os_preferences_set_value_for_dict_key (CFMutableDictionaryRef in_dictionary, - kim_preference_key in_key, + kim_preference_key in_key, CFPropertyListRef in_value) { kim_error err = KIM_NO_ERROR; - + if (!err && !in_dictionary) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !in_value ) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { CFStringRef key = kim_os_preferences_cfstring_for_key (in_key); - + CFDictionarySetValue (in_dictionary, key, in_value); } - + return check_error (err); } /* ------------------------------------------------------------------------ */ -static kim_error kim_os_preferences_dictionary_to_options (CFDictionaryRef in_dictionary, +static kim_error kim_os_preferences_dictionary_to_options (CFDictionaryRef in_dictionary, kim_options *out_options) { kim_error err = KIM_NO_ERROR; kim_options options = KIM_OPTIONS_DEFAULT; kim_boolean found_options = 0; - + if (!err && !in_dictionary) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !out_options ) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { err = kim_options_create_empty (&options); } - + if (!err) { CFBooleanRef value = NULL; - + err = kim_os_preferences_copy_value_for_dict_key (in_dictionary, - kim_preference_key_renewable, - CFBooleanGetTypeID (), + kim_preference_key_renewable, + CFBooleanGetTypeID (), (CFPropertyListRef *) &value); - + if (!err && value) { found_options = 1; err = kim_options_set_renewable (options, CFBooleanGetValue (value)); } } - + if (!err) { CFNumberRef value = NULL; SInt32 lifetime; // CFNumbers are signed so we need to cast - + err = kim_os_preferences_copy_value_for_dict_key (in_dictionary, - kim_preference_key_lifetime, - CFNumberGetTypeID (), + kim_preference_key_lifetime, + CFNumberGetTypeID (), (CFPropertyListRef *) &value); - - if (!err && value && CFNumberGetValue (value, kCFNumberSInt32Type, + + if (!err && value && CFNumberGetValue (value, kCFNumberSInt32Type, &lifetime)) { found_options = 1; err = kim_options_set_lifetime (options, lifetime); } } - + if (!err) { CFNumberRef value = NULL; SInt32 lifetime; // CFNumbers are signed so we need to cast - + err = kim_os_preferences_copy_value_for_dict_key (in_dictionary, - kim_preference_key_renewal_lifetime, - CFNumberGetTypeID (), + kim_preference_key_renewal_lifetime, + CFNumberGetTypeID (), (CFPropertyListRef *) &value); - - if (!err && value && CFNumberGetValue (value, kCFNumberSInt32Type, + + if (!err && value && CFNumberGetValue (value, kCFNumberSInt32Type, &lifetime)) { found_options = 1; err = kim_options_set_renewal_lifetime (options, lifetime); } } - + if (!err) { CFBooleanRef value = NULL; - + err = kim_os_preferences_copy_value_for_dict_key (in_dictionary, - kim_preference_key_forwardable, - CFBooleanGetTypeID (), + kim_preference_key_forwardable, + CFBooleanGetTypeID (), (CFPropertyListRef *) &value); - + if (!err && value) { found_options = 1; err = kim_options_set_forwardable (options, CFBooleanGetValue (value)); } } - + if (!err) { CFBooleanRef value = NULL; - + err = kim_os_preferences_copy_value_for_dict_key (in_dictionary, - kim_preference_key_proxiable, - CFBooleanGetTypeID (), + kim_preference_key_proxiable, + CFBooleanGetTypeID (), (CFPropertyListRef *) &value); - + if (!err && value) { found_options = 1; err = kim_options_set_proxiable (options, CFBooleanGetValue (value)); } } - + if (!err) { CFBooleanRef value = NULL; - + err = kim_os_preferences_copy_value_for_dict_key (in_dictionary, - kim_preference_key_addressless, - CFBooleanGetTypeID (), + kim_preference_key_addressless, + CFBooleanGetTypeID (), (CFPropertyListRef *) &value); - + if (!err && value) { found_options = 1; err = kim_options_set_addressless (options, CFBooleanGetValue (value)); } } - + if (!err && !found_options) { kim_options_free (&options); options = KIM_OPTIONS_DEFAULT; } - + if (!err) { *out_options = options; options = NULL; } - + kim_options_free (&options); - + return check_error (err); } @@ -614,112 +614,112 @@ static kim_error kim_os_preferences_options_to_dictionary (kim_options CFMutableDictionaryRef io_dictionary) { kim_error err = KIM_NO_ERROR; - + if (!err && !in_options ) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !io_dictionary) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { CFNumberRef value = NULL; kim_lifetime lifetime; - + err = kim_options_get_lifetime (in_options, &lifetime); - + if (!err) { SInt32 number = (SInt32) lifetime; - - value = CFNumberCreate (kCFAllocatorDefault, + + value = CFNumberCreate (kCFAllocatorDefault, kCFNumberSInt32Type, &number); if (!value) { err = KIM_OUT_OF_MEMORY_ERR; } } - + if (!err) { - err = kim_os_preferences_set_value_for_dict_key (io_dictionary, - kim_preference_key_lifetime, + err = kim_os_preferences_set_value_for_dict_key (io_dictionary, + kim_preference_key_lifetime, value); } - - if (value) { CFRelease (value); } + + if (value) { CFRelease (value); } } - + if (!err) { kim_boolean boolean; - + err = kim_options_get_renewable (in_options, &boolean); - + if (!err) { CFBooleanRef value = boolean ? kCFBooleanTrue : kCFBooleanFalse; - - err = kim_os_preferences_set_value_for_dict_key (io_dictionary, - kim_preference_key_renewable, + + err = kim_os_preferences_set_value_for_dict_key (io_dictionary, + kim_preference_key_renewable, value); } - } - + } + if (!err) { CFNumberRef value = NULL; kim_lifetime lifetime; - + err = kim_options_get_renewal_lifetime (in_options, &lifetime); - + if (!err) { SInt32 number = (SInt32) lifetime; - - value = CFNumberCreate (kCFAllocatorDefault, + + value = CFNumberCreate (kCFAllocatorDefault, kCFNumberSInt32Type, &number); if (!value) { err = KIM_OUT_OF_MEMORY_ERR; } } - + if (!err) { - err = kim_os_preferences_set_value_for_dict_key (io_dictionary, - kim_preference_key_renewal_lifetime, + err = kim_os_preferences_set_value_for_dict_key (io_dictionary, + kim_preference_key_renewal_lifetime, value); } - - if (value) { CFRelease (value); } + + if (value) { CFRelease (value); } } - + if (!err) { kim_boolean boolean; - + err = kim_options_get_forwardable (in_options, &boolean); - + if (!err) { CFBooleanRef value = boolean ? kCFBooleanTrue : kCFBooleanFalse; - - err = kim_os_preferences_set_value_for_dict_key (io_dictionary, - kim_preference_key_forwardable, + + err = kim_os_preferences_set_value_for_dict_key (io_dictionary, + kim_preference_key_forwardable, value); } - } - + } + if (!err) { kim_boolean boolean; - + err = kim_options_get_proxiable (in_options, &boolean); - + if (!err) { CFBooleanRef value = boolean ? kCFBooleanTrue : kCFBooleanFalse; - - err = kim_os_preferences_set_value_for_dict_key (io_dictionary, - kim_preference_key_proxiable, + + err = kim_os_preferences_set_value_for_dict_key (io_dictionary, + kim_preference_key_proxiable, value); } } - + if (!err) { kim_boolean boolean; - + err = kim_options_get_addressless (in_options, &boolean); - + if (!err) { CFBooleanRef value = boolean ? kCFBooleanTrue : kCFBooleanFalse; - - err = kim_os_preferences_set_value_for_dict_key (io_dictionary, - kim_preference_key_addressless, + + err = kim_os_preferences_set_value_for_dict_key (io_dictionary, + kim_preference_key_addressless, value); } - } - + } + return check_error (err); } @@ -734,164 +734,164 @@ static kim_error kim_os_preferences_get_options_compat (kim_options *out_options kim_error err = KIM_NO_ERROR; kim_options options = KIM_OPTIONS_DEFAULT; kim_boolean found_options = 0; - + if (!err && !out_options) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { err = kim_options_create_empty (&options); } - - if (!err) { + + if (!err) { CFNumberRef value = NULL; SInt32 lifetime; // CFNumbers are signed so we need to cast - - err = kim_os_preferences_copy_value_compat (kim_preference_key_lifetime, - CFNumberGetTypeID (), + + err = kim_os_preferences_copy_value_compat (kim_preference_key_lifetime, + CFNumberGetTypeID (), (CFPropertyListRef *) &value); - - if (!err && value && CFNumberGetValue (value, kCFNumberSInt32Type, + + if (!err && value && CFNumberGetValue (value, kCFNumberSInt32Type, &lifetime)) { found_options = 1; err = kim_options_set_lifetime (options, lifetime); } - + if (value) { CFRelease (value); } } - + if (!err) { CFBooleanRef value = NULL; - - err = kim_os_preferences_copy_value_compat (kim_preference_key_renewable, - CFBooleanGetTypeID (), + + err = kim_os_preferences_copy_value_compat (kim_preference_key_renewable, + CFBooleanGetTypeID (), (CFPropertyListRef *) &value); - + if (!err && value) { found_options = 1; err = kim_options_set_renewable (options, CFBooleanGetValue (value)); } - + if (value) { CFRelease (value); } } - + if (!err) { CFNumberRef value = NULL; SInt32 lifetime; // CFNumbers are signed so we need to cast - - err = kim_os_preferences_copy_value_compat (kim_preference_key_renewal_lifetime, - CFNumberGetTypeID (), + + err = kim_os_preferences_copy_value_compat (kim_preference_key_renewal_lifetime, + CFNumberGetTypeID (), (CFPropertyListRef *) &value); - - if (!err && value && CFNumberGetValue (value, kCFNumberSInt32Type, + + if (!err && value && CFNumberGetValue (value, kCFNumberSInt32Type, &lifetime)) { found_options = 1; err = kim_options_set_renewal_lifetime (options, lifetime); } - + if (value) { CFRelease (value); } } - + if (!err) { CFBooleanRef value = NULL; - - err = kim_os_preferences_copy_value_compat (kim_preference_key_forwardable, - CFBooleanGetTypeID (), + + err = kim_os_preferences_copy_value_compat (kim_preference_key_forwardable, + CFBooleanGetTypeID (), (CFPropertyListRef *) &value); - + if (!err && value) { found_options = 1; err = kim_options_set_forwardable (options, CFBooleanGetValue (value)); } - + if (value) { CFRelease (value); } } - + if (!err) { CFBooleanRef value = NULL; - - err = kim_os_preferences_copy_value_compat (kim_preference_key_proxiable, - CFBooleanGetTypeID (), + + err = kim_os_preferences_copy_value_compat (kim_preference_key_proxiable, + CFBooleanGetTypeID (), (CFPropertyListRef *) &value); - + if (!err && value) { found_options = 1; err = kim_options_set_proxiable (options, CFBooleanGetValue (value)); } - + if (value) { CFRelease (value); } } - + if (!err) { CFBooleanRef value = NULL; - - err = kim_os_preferences_copy_value_compat (kim_preference_key_addressless, - CFBooleanGetTypeID (), + + err = kim_os_preferences_copy_value_compat (kim_preference_key_addressless, + CFBooleanGetTypeID (), (CFPropertyListRef *) &value); - + if (!err && value) { found_options = 1; err = kim_options_set_addressless (options, CFBooleanGetValue (value)); } - + if (value) { CFRelease (value); } } - + if (!err && !found_options) { kim_options_free (&options); options = KIM_OPTIONS_DEFAULT; } - + if (!err) { *out_options = options; } - + return check_error (err); } /* ------------------------------------------------------------------------ */ -kim_error kim_os_preferences_get_options_for_key (kim_preference_key in_key, +kim_error kim_os_preferences_get_options_for_key (kim_preference_key in_key, kim_options *out_options) { kim_error err = KIM_NO_ERROR; CFDictionaryRef dictionary = NULL; kim_options options = KIM_OPTIONS_DEFAULT; - + if (!err && !out_options) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { - err = kim_os_preferences_copy_value (in_key, CFDictionaryGetTypeID (), + err = kim_os_preferences_copy_value (in_key, CFDictionaryGetTypeID (), (CFPropertyListRef *) &dictionary); - + if (!err && dictionary) { err = kim_os_preferences_dictionary_to_options (dictionary, &options); } } - + if (!err && !dictionary) { err = kim_os_preferences_get_options_compat (&options); } - + if (!err) { *out_options = options; } - + if (dictionary) { CFRelease (dictionary); } - + return check_error (err); } /* ------------------------------------------------------------------------ */ -kim_error kim_os_preferences_set_options_for_key (kim_preference_key in_key, +kim_error kim_os_preferences_set_options_for_key (kim_preference_key in_key, kim_options in_options) { kim_error err = KIM_NO_ERROR; CFMutableDictionaryRef dictionary = NULL; - + /* in_options may be KIM_OPTIONS_DEFAULT, in which case we empty the dict */ - + if (!err && in_options) { - dictionary = CFDictionaryCreateMutable (kCFAllocatorDefault, 0, + dictionary = CFDictionaryCreateMutable (kCFAllocatorDefault, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); if (!dictionary) { err = check_error (KIM_OUT_OF_MEMORY_ERR); } @@ -900,14 +900,14 @@ kim_error kim_os_preferences_set_options_for_key (kim_preference_key in_key, err = kim_os_preferences_options_to_dictionary (in_options, dictionary); } } - + if (!err) { /* NULL dictioray will remove any entry for this key */ err = kim_os_preferences_set_value (in_key, dictionary); } - + if (dictionary) { CFRelease (dictionary); } - + return check_error (err); } @@ -915,145 +915,145 @@ kim_error kim_os_preferences_set_options_for_key (kim_preference_key in_key, /* ------------------------------------------------------------------------ */ -kim_error kim_os_preferences_get_favorites_for_key (kim_preference_key in_key, +kim_error kim_os_preferences_get_favorites_for_key (kim_preference_key in_key, kim_favorites io_favorites) { kim_error err = KIM_NO_ERROR; CFArrayRef value = NULL; - + if (!err && !io_favorites) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { - err = kim_os_preferences_copy_value (in_key, CFArrayGetTypeID (), + err = kim_os_preferences_copy_value (in_key, CFArrayGetTypeID (), (CFPropertyListRef *) &value); } - + if (!err && value) { if (!value || CFArrayGetCount (value) < 1) { err = kim_favorites_remove_all_identities (io_favorites); - + } else { CFIndex count = CFArrayGetCount (value); CFIndex i; - + for (i = 0; !err && i < count; i++) { CFDictionaryRef dictionary = NULL; CFStringRef cfstring = NULL; - + dictionary = (CFDictionaryRef) CFArrayGetValueAtIndex (value, i); if (!dictionary || CFGetTypeID (dictionary) != CFDictionaryGetTypeID ()) { err = check_error (KIM_PREFERENCES_READ_ERR); } - + if (!err) { err = kim_os_preferences_copy_value_for_dict_key (dictionary, kim_preference_key_client_identity, CFStringGetTypeID (), - (CFPropertyListRef *) &cfstring); + (CFPropertyListRef *) &cfstring); } - + if (!err && cfstring) { kim_string string = NULL; kim_identity identity = NULL; kim_options options = KIM_OPTIONS_DEFAULT; - + err = kim_os_string_create_from_cfstring (&string, cfstring); - + if (!err) { err = kim_identity_create_from_string (&identity, string); } - + if (!err && (CFDictionaryGetCount (dictionary) > 1)) { - err = kim_os_preferences_dictionary_to_options (dictionary, + err = kim_os_preferences_dictionary_to_options (dictionary, &options); } - + if (!err) { err = kim_favorites_add_identity (io_favorites, identity, options); } - + kim_string_free (&string); kim_options_free (&options); kim_identity_free (&identity); } } - + if (err) { kim_favorites_remove_all_identities (io_favorites); } } } - + if (value) { CFRelease (value); } - + return check_error (err); } /* ------------------------------------------------------------------------ */ -kim_error kim_os_preferences_set_favorites_for_key (kim_preference_key in_key, +kim_error kim_os_preferences_set_favorites_for_key (kim_preference_key in_key, kim_favorites in_favorites) { kim_error err = KIM_NO_ERROR; kim_count count = 0; CFMutableArrayRef array = NULL; - + if (!err && !in_favorites) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { err = kim_favorites_get_number_of_identities (in_favorites, &count); } - + if (!err) { - array = CFArrayCreateMutable (kCFAllocatorDefault, count, + array = CFArrayCreateMutable (kCFAllocatorDefault, count, &kCFTypeArrayCallBacks); if (!array) { err = KIM_OUT_OF_MEMORY_ERR; } } - + if (!err) { kim_count i; - + for (i = 0; !err && i < count; i++) { kim_identity identity = NULL; kim_options options = NULL; kim_string string = NULL; CFStringRef cfstring = NULL; CFMutableDictionaryRef dictionary = NULL; - - err = kim_favorites_get_identity_at_index (in_favorites, i, + + err = kim_favorites_get_identity_at_index (in_favorites, i, &identity, &options); - + if (!err) { err = kim_identity_get_string (identity, &string); } - + if (!err) { err = kim_os_string_get_cfstring (string, &cfstring); } - + if (!err) { - dictionary = CFDictionaryCreateMutable (kCFAllocatorDefault, 0, + dictionary = CFDictionaryCreateMutable (kCFAllocatorDefault, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); if (!dictionary) { err = check_error (KIM_OUT_OF_MEMORY_ERR); } } - + if (!err) { err = kim_os_preferences_set_value_for_dict_key (dictionary, kim_preference_key_client_identity, - cfstring); + cfstring); } - + if (!err && options) { - err = kim_os_preferences_options_to_dictionary (options, + err = kim_os_preferences_options_to_dictionary (options, dictionary); } - + if (!err) { CFArrayAppendValue (array, dictionary); } - + if (dictionary) { CFRelease (dictionary); } if (cfstring ) { CFRelease (cfstring); } kim_string_free (&string); @@ -1061,13 +1061,12 @@ kim_error kim_os_preferences_set_favorites_for_key (kim_preference_key in_key, kim_identity_free (&identity); } } - + if (!err) { err = kim_os_preferences_set_value (in_key, array); } - + if (array) { CFRelease (array); } - + return check_error (err); } - diff --git a/src/kim/lib/mac/kim_os_selection_hints.c b/src/kim/lib/mac/kim_os_selection_hints.c index bc1a64868b..27a62461de 100644 --- a/src/kim/lib/mac/kim_os_selection_hints.c +++ b/src/kim/lib/mac/kim_os_selection_hints.c @@ -8,7 +8,7 @@ * 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 @@ -51,37 +51,37 @@ static kim_error kim_os_selection_hints_get_selection_hints_array (CFArrayRef *o CFPropertyListRef value = NULL; CFStringRef users[] = { kCFPreferencesCurrentUser, kCFPreferencesAnyUser, NULL }; CFStringRef hosts[] = { kCFPreferencesCurrentHost, kCFPreferencesAnyHost, NULL }; - + if (!err && !out_selection_hints_array) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { kim_count u, h; - + if (!kim_library_allow_home_directory_access()) { users[0] = kCFPreferencesAnyUser; users[1] = NULL; } - + for (u = 0; !value && users[u]; u++) { for (h = 0; !value && hosts[h]; h++) { - value = CFPreferencesCopyValue (KIM_SELECTION_HINTS_ARRAY, - KIM_SELECTION_HINTS_FILE, + value = CFPreferencesCopyValue (KIM_SELECTION_HINTS_ARRAY, + KIM_SELECTION_HINTS_FILE, users[u], hosts[h]); } - } - + } + if (value && CFGetTypeID (value) != CFArrayGetTypeID ()) { err = check_error (KIM_PREFERENCES_READ_ERR); } } - + if (!err) { *out_selection_hints_array = value; value = NULL; } - + if (value) { CFRelease (value); } - + return check_error (err); } @@ -90,21 +90,21 @@ static kim_error kim_os_selection_hints_get_selection_hints_array (CFArrayRef *o static kim_error kim_os_selection_hints_set_selection_hints_array (CFArrayRef in_selection_hints_array) { kim_error err = KIM_NO_ERROR; - + if (!err && !in_selection_hints_array) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { kim_boolean homedir_ok = kim_library_allow_home_directory_access(); CFStringRef user = homedir_ok ? kCFPreferencesCurrentUser : kCFPreferencesAnyUser; CFStringRef host = homedir_ok ? kCFPreferencesAnyHost : kCFPreferencesCurrentHost; - - CFPreferencesSetValue (KIM_SELECTION_HINTS_ARRAY, in_selection_hints_array, + + CFPreferencesSetValue (KIM_SELECTION_HINTS_ARRAY, in_selection_hints_array, KIM_SELECTION_HINTS_FILE, user, host); if (!CFPreferencesSynchronize (KIM_SELECTION_HINTS_FILE, user, host)) { err = check_error (KIM_PREFERENCES_WRITE_ERR); } } - + return check_error (err); } @@ -122,71 +122,71 @@ static kim_error kim_os_selection_hints_create_dictionary (kim_selection_hints CFStringRef keys[KIM_MAX_HINTS] = { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL }; CFStringRef values[KIM_MAX_HINTS] = { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL }; CFIndex i = 0; - + if (!err && !in_selection_hints ) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !in_identity ) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !out_hints_dictionary) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { err = kim_selection_hints_get_preference_strings (in_selection_hints, &preference_strings); } - + if (!err) { err = kim_identity_get_string (in_identity, &identity_string); } - + if (!err) { keys[i] = KIM_APPLICATION_ID_HINT; err = kim_os_string_get_cfstring (preference_strings.application_identifier, &values[i]); } - + if (!err) { keys[++i] = KIM_IDENTITY_HINT; err = kim_os_string_get_cfstring (identity_string, &values[i]); } - + if (!err && preference_strings.service_identity) { keys[++i] = KIM_SERVICE_IDENTITY_HINT; err = kim_os_string_get_cfstring (preference_strings.service_identity, &values[i]); } - + if (!err && preference_strings.user) { keys[++i] = KIM_USER_HINT; err = kim_os_string_get_cfstring (preference_strings.user, &values[i]); } - + if (!err && preference_strings.client_realm) { keys[++i] = KIM_CLIENT_REALM_HINT; err = kim_os_string_get_cfstring (preference_strings.client_realm, &values[i]); } - + if (!err && preference_strings.service) { keys[++i] = KIM_SERVICE_HINT; err = kim_os_string_get_cfstring (preference_strings.service, &values[i]); } - + if (!err && preference_strings.service_realm) { keys[++i] = KIM_SERVICE_REALM_HINT; err = kim_os_string_get_cfstring (preference_strings.service_realm, &values[i]); } - + if (!err && preference_strings.server) { keys[++i] = KIM_SERVER_HINT; err = kim_os_string_get_cfstring (preference_strings.server, &values[i]); } - + if (!err) { - *out_hints_dictionary = CFDictionaryCreate (kCFAllocatorDefault, - (const void **) keys, - (const void **) values, + *out_hints_dictionary = CFDictionaryCreate (kCFAllocatorDefault, + (const void **) keys, + (const void **) values, i+1, /* number of hints */ - &kCFTypeDictionaryKeyCallBacks, - &kCFTypeDictionaryValueCallBacks); + &kCFTypeDictionaryKeyCallBacks, + &kCFTypeDictionaryValueCallBacks); } - + for (i = 0; i < KIM_MAX_HINTS; i++) { if (values[i]) { CFRelease (values[i]); } } kim_string_free (&identity_string); - + return check_error (err); } @@ -196,17 +196,17 @@ static kim_boolean kim_os_selection_hints_compare_hint (kim_string in_string, CFStringRef in_value) { kim_boolean equal = 0; - - if (!in_string && !in_value) { - equal = 1; - + + if (!in_string && !in_value) { + equal = 1; + } else if (in_string && in_value) { if (CFGetTypeID (in_value) == CFStringGetTypeID ()) { kim_comparison comparison; - - kim_error err = kim_os_string_compare_to_cfstring (in_string, in_value, + + kim_error err = kim_os_string_compare_to_cfstring (in_string, in_value, &comparison); - + if (!err && kim_comparison_is_equal_to (comparison)) { equal = 1; } @@ -214,7 +214,7 @@ static kim_boolean kim_os_selection_hints_compare_hint (kim_string in_string, kim_debug_printf ("%s: Malformed string in hints dictionary.", __FUNCTION__); } } - + return equal; } @@ -227,61 +227,61 @@ static kim_error kim_os_selection_hints_compare_to_dictionary (kim_selection_hin kim_error err = KIM_NO_ERROR; kim_selection_hints_preference_strings preference_strings = { NULL, NULL, NULL, NULL, NULL, NULL, NULL }; kim_boolean hints_equal = 1; - + if (!err && !in_selection_hints ) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !in_hints_dictionary) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !out_hints_equal ) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { err = kim_selection_hints_get_preference_strings (in_selection_hints, &preference_strings); } - + if (!err && hints_equal) { - hints_equal = kim_os_selection_hints_compare_hint (preference_strings.application_identifier, - CFDictionaryGetValue (in_hints_dictionary, + hints_equal = kim_os_selection_hints_compare_hint (preference_strings.application_identifier, + CFDictionaryGetValue (in_hints_dictionary, KIM_APPLICATION_ID_HINT)); } - + if (!err && hints_equal) { - hints_equal = kim_os_selection_hints_compare_hint (preference_strings.service_identity, - CFDictionaryGetValue (in_hints_dictionary, + hints_equal = kim_os_selection_hints_compare_hint (preference_strings.service_identity, + CFDictionaryGetValue (in_hints_dictionary, KIM_SERVICE_IDENTITY_HINT)); } - + if (!err && hints_equal) { - hints_equal = kim_os_selection_hints_compare_hint (preference_strings.user, - CFDictionaryGetValue (in_hints_dictionary, + hints_equal = kim_os_selection_hints_compare_hint (preference_strings.user, + CFDictionaryGetValue (in_hints_dictionary, KIM_USER_HINT)); } - + if (!err && hints_equal) { - hints_equal = kim_os_selection_hints_compare_hint (preference_strings.client_realm, - CFDictionaryGetValue (in_hints_dictionary, + hints_equal = kim_os_selection_hints_compare_hint (preference_strings.client_realm, + CFDictionaryGetValue (in_hints_dictionary, KIM_CLIENT_REALM_HINT)); } - + if (!err && hints_equal) { - hints_equal = kim_os_selection_hints_compare_hint (preference_strings.service, - CFDictionaryGetValue (in_hints_dictionary, + hints_equal = kim_os_selection_hints_compare_hint (preference_strings.service, + CFDictionaryGetValue (in_hints_dictionary, KIM_SERVICE_HINT)); } - + if (!err && hints_equal) { - hints_equal = kim_os_selection_hints_compare_hint (preference_strings.service_realm, - CFDictionaryGetValue (in_hints_dictionary, + hints_equal = kim_os_selection_hints_compare_hint (preference_strings.service_realm, + CFDictionaryGetValue (in_hints_dictionary, KIM_SERVICE_REALM_HINT)); } - + if (!err && hints_equal) { - hints_equal = kim_os_selection_hints_compare_hint (preference_strings.server, - CFDictionaryGetValue (in_hints_dictionary, + hints_equal = kim_os_selection_hints_compare_hint (preference_strings.server, + CFDictionaryGetValue (in_hints_dictionary, KIM_SERVER_HINT)); } - + if (!err) { *out_hints_equal = hints_equal; } - + return check_error (err); } @@ -293,23 +293,23 @@ static kim_error kim_os_selection_hints_get_dictionary_identity (CFDictionaryRef kim_error err = KIM_NO_ERROR; CFStringRef identity_cfstr = NULL; kim_string identity_string = NULL; - + identity_cfstr = CFDictionaryGetValue (in_dictionary, KIM_IDENTITY_HINT); if (!identity_cfstr || CFGetTypeID (identity_cfstr) != CFStringGetTypeID ()) { kim_debug_printf ("%s: Malformed hints dictionary (invalid identity).", __FUNCTION__); err = check_error (KIM_PREFERENCES_READ_ERR); } - + if (!err) { err = kim_os_string_create_from_cfstring (&identity_string, identity_cfstr); } - + if (!err) { err = kim_identity_create_from_string (out_identity, identity_string); } - + kim_string_free (&identity_string); - + return check_error (err); } @@ -326,47 +326,47 @@ kim_error kim_os_selection_hints_lookup_identity (kim_selection_hints in_select CFIndex count = 0; kim_boolean found = 0; CFDictionaryRef found_dictionary = NULL; - + if (!err && !in_selection_hints) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !out_identity ) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { err = kim_os_selection_hints_get_selection_hints_array (&hints_array); } - + if (!err && hints_array) { count = CFArrayGetCount (hints_array); } - + for (i = 0; !err && !found && i < count; i++) { CFDictionaryRef dictionary = NULL; - + dictionary = CFArrayGetValueAtIndex (hints_array, i); if (!dictionary) { err = KIM_OUT_OF_MEMORY_ERR; } - + if (!err && CFGetTypeID (dictionary) != CFDictionaryGetTypeID ()) { kim_debug_printf ("%s: Malformed entry in hints array.", __FUNCTION__); continue; /* skip entries which aren't dictionaries */ } - + if (!err) { - err = kim_os_selection_hints_compare_to_dictionary (in_selection_hints, + err = kim_os_selection_hints_compare_to_dictionary (in_selection_hints, dictionary, &found); } - + if (!err && found) { found_dictionary = dictionary; } } - + if (!err && found) { err = kim_os_selection_hints_get_dictionary_identity (found_dictionary, out_identity); } - + if (hints_array) { CFRelease (hints_array); } - + return check_error (err); } @@ -382,58 +382,58 @@ kim_error kim_os_selection_hints_remember_identity (kim_selection_hints in_selec CFIndex i = 0; kim_boolean hint_already_exists = 0; kim_boolean hints_array_changed = 0; - + if (!err && !in_selection_hints) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !in_identity ) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { err = kim_os_selection_hints_get_selection_hints_array (&old_hints_array); } - + if (!err) { if (old_hints_array) { - new_hints_array = CFArrayCreateMutableCopy (kCFAllocatorDefault, 0, + new_hints_array = CFArrayCreateMutableCopy (kCFAllocatorDefault, 0, old_hints_array); } else { - new_hints_array = CFArrayCreateMutable (kCFAllocatorDefault, 0, - &kCFTypeArrayCallBacks); + new_hints_array = CFArrayCreateMutable (kCFAllocatorDefault, 0, + &kCFTypeArrayCallBacks); } if (!new_hints_array) { err = KIM_OUT_OF_MEMORY_ERR; } } - + if (!err) { count = CFArrayGetCount (new_hints_array); } - + for (i = 0; !err && i < count; i++) { CFDictionaryRef dictionary = NULL; kim_identity identity = NULL; kim_boolean hints_equal = 0; - + dictionary = CFArrayGetValueAtIndex (new_hints_array, i); if (!dictionary) { err = KIM_OUT_OF_MEMORY_ERR; } - + if (!err && CFGetTypeID (dictionary) != CFDictionaryGetTypeID ()) { kim_debug_printf ("%s: Malformed entry in hints array.", __FUNCTION__); continue; /* skip entries which aren't dictionaries */ } - + if (!err) { - err = kim_os_selection_hints_compare_to_dictionary (in_selection_hints, + err = kim_os_selection_hints_compare_to_dictionary (in_selection_hints, dictionary, &hints_equal); } - + if (!err && hints_equal) { kim_comparison comparison; - + err = kim_os_selection_hints_get_dictionary_identity (dictionary, &identity); - + if (!err) { err = kim_identity_compare (in_identity, identity, &comparison); } - + if (!err) { if (kim_comparison_is_equal_to (comparison) && !hint_already_exists) { hint_already_exists = 1; @@ -444,33 +444,33 @@ kim_error kim_os_selection_hints_remember_identity (kim_selection_hints in_selec hints_array_changed = 1; } } - + kim_identity_free (&identity); } } - + if (!err && !hint_already_exists) { CFDictionaryRef new_hint_dictionary = NULL; - - err = kim_os_selection_hints_create_dictionary (in_selection_hints, + + err = kim_os_selection_hints_create_dictionary (in_selection_hints, in_identity, &new_hint_dictionary); - + if (!err) { CFArrayInsertValueAtIndex (new_hints_array, 0, new_hint_dictionary); hints_array_changed = 1; } - + if (new_hint_dictionary) { CFRelease (new_hint_dictionary); } } - + if (!err && hints_array_changed) { err = kim_os_selection_hints_set_selection_hints_array (new_hints_array); } - + if (new_hints_array ) { CFRelease (new_hints_array); } if (old_hints_array ) { CFRelease (old_hints_array); } - + return check_error (err); } @@ -483,54 +483,53 @@ kim_error kim_os_selection_hints_forget_identity (kim_selection_hints in_selecti CFMutableArrayRef new_hints_array = NULL; CFIndex count = 0; CFIndex i = 0; - + if (!err && !in_selection_hints) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { err = kim_os_selection_hints_get_selection_hints_array (&old_hints_array); } - + if (!err) { - new_hints_array = CFArrayCreateMutableCopy (kCFAllocatorDefault, 0, + new_hints_array = CFArrayCreateMutableCopy (kCFAllocatorDefault, 0, old_hints_array); if (!new_hints_array) { err = KIM_OUT_OF_MEMORY_ERR; } } - + if (!err) { count = CFArrayGetCount (new_hints_array); } - + for (i = 0; !err && i < count; i++) { CFDictionaryRef dictionary = NULL; kim_boolean hints_equal = 0; - + dictionary = CFArrayGetValueAtIndex (new_hints_array, i); if (!dictionary) { err = KIM_OUT_OF_MEMORY_ERR; } - + if (!err && CFGetTypeID (dictionary) != CFDictionaryGetTypeID ()) { kim_debug_printf ("%s: Malformed entry in hints array.", __FUNCTION__); continue; /* skip entries which aren't dictionaries */ } - + if (!err) { - err = kim_os_selection_hints_compare_to_dictionary (in_selection_hints, + err = kim_os_selection_hints_compare_to_dictionary (in_selection_hints, dictionary, &hints_equal); } - + if (!err && hints_equal) { CFArrayRemoveValueAtIndex (new_hints_array, i); i--; /* back up one index so we don't skip */ count = CFArrayGetCount (new_hints_array); /* count changed */ } } - + if (!err) { err = kim_os_selection_hints_set_selection_hints_array (new_hints_array); } - + if (new_hints_array) { CFRelease (new_hints_array); } - + return check_error (err); } - diff --git a/src/kim/lib/mac/kim_os_string.c b/src/kim/lib/mac/kim_os_string.c index 96573eec9e..944b8c995f 100644 --- a/src/kim/lib/mac/kim_os_string.c +++ b/src/kim/lib/mac/kim_os_string.c @@ -8,7 +8,7 @@ * 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 @@ -37,14 +37,14 @@ kim_error kim_os_string_create_localized (kim_string *out_string, kim_error err = lock_err; kim_string string = NULL; CFStringRef cfkey = NULL; - + if (!err && !out_string) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !in_string ) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { err = kim_os_string_get_cfstring (in_string, &cfkey); } - + if (!err && kim_library_allow_home_directory_access ()) { CFStringRef cfstring = NULL; CFBundleRef framework = CFBundleGetBundleWithIdentifier (CFSTR ("edu.mit.Kerberos")); @@ -56,35 +56,35 @@ kim_error kim_os_string_create_localized (kim_string *out_string, framework, ""); } - + if (main_bundle && !cfstring) { cfstring = CFCopyLocalizedStringFromTableInBundle (cfkey, CFSTR ("InfoPlist"), main_bundle, ""); - } - + } + if (!err && cfstring) { err = kim_os_string_create_from_cfstring (&string, cfstring); } - + if (cfstring) { CFRelease (cfstring); } } - + if (!err && !string) { err = kim_string_copy (&string, in_string); } - + if (!err) { *out_string = string; string = NULL; } - + if (cfkey) { CFRelease (cfkey); } kim_string_free (&string); - + if (!lock_err) { kim_os_library_unlock_for_bundle_lookup (); } - + return check_error (err); } @@ -96,47 +96,47 @@ kim_error kim_os_string_create_from_cfstring (kim_string *out_string, kim_error err = KIM_NO_ERROR; kim_string string = NULL; CFIndex length = 0; - + if (!err && !out_string ) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !in_cfstring) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { char *ptr = NULL; - - /* check if in_cfstring is a C string internally so we can + + /* check if in_cfstring is a C string internally so we can * avoid using CFStringGetMaximumSizeForEncoding which is wasteful */ - ptr = (char *) CFStringGetCStringPtr(in_cfstring, + ptr = (char *) CFStringGetCStringPtr(in_cfstring, kCFStringEncodingUTF8); if (ptr) { string = strdup (ptr); if (!string) { err = check_error (KIM_OUT_OF_MEMORY_ERR); } } else { - length = CFStringGetMaximumSizeForEncoding (CFStringGetLength (in_cfstring), + length = CFStringGetMaximumSizeForEncoding (CFStringGetLength (in_cfstring), kCFStringEncodingUTF8) + 1; - + string = (char *) calloc (length, sizeof (char)); if (!string) { err = check_error (KIM_OUT_OF_MEMORY_ERR); } - + if (!err) { - if (!CFStringGetCString (in_cfstring, - (char *) string, - length, + if (!CFStringGetCString (in_cfstring, + (char *) string, + length, kCFStringEncodingUTF8)) { err = KIM_OUT_OF_MEMORY_ERR; - } - } + } + } } } - - + + if (!err) { *out_string = string; string = NULL; } - + kim_string_free (&string); - + return check_error (err); } @@ -147,24 +147,24 @@ kim_error kim_os_string_get_cfstring (kim_string in_string, { kim_error err = KIM_NO_ERROR; CFStringRef cfstring = NULL; - + if (!err && !in_string ) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !out_cfstring) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { - cfstring = CFStringCreateWithCString (kCFAllocatorDefault, - in_string, + cfstring = CFStringCreateWithCString (kCFAllocatorDefault, + in_string, kCFStringEncodingUTF8); if (!cfstring) { err = KIM_OUT_OF_MEMORY_ERR; } } - + if (!err) { *out_cfstring = cfstring; cfstring = NULL; } - + if (cfstring) { CFRelease (cfstring); } - + return check_error (err); } @@ -178,34 +178,34 @@ kim_error kim_os_string_compare (kim_string in_string, kim_error err = KIM_NO_ERROR; CFStringRef cfstring = NULL; CFStringRef compare_to_cfstring = NULL; - + if (!err && !in_string ) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !in_compare_to_string) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !out_comparison ) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { - err = kim_os_string_get_cfstring (in_string, + err = kim_os_string_get_cfstring (in_string, &cfstring); } - + if (!err) { - err = kim_os_string_get_cfstring (in_compare_to_string, + err = kim_os_string_get_cfstring (in_compare_to_string, &compare_to_cfstring); } - + if (!err) { - CFOptionFlags options = (in_case_insensitive ? + CFOptionFlags options = (in_case_insensitive ? 1 : kCFCompareCaseInsensitive); - + /* Returned CFComparisonResult is compatible with kim_comparison_t */ - *out_comparison = CFStringCompare (cfstring, - compare_to_cfstring, - options); + *out_comparison = CFStringCompare (cfstring, + compare_to_cfstring, + options); } - + if (cfstring ) { CFRelease (cfstring); } if (compare_to_cfstring) { CFRelease (compare_to_cfstring); } - + return check_error (err); } @@ -217,21 +217,21 @@ kim_error kim_os_string_compare_to_cfstring (kim_string in_string, { kim_error err = KIM_NO_ERROR; CFStringRef cfstring = NULL; - + if (!err && !in_string ) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !in_compare_to_cfstring) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !out_comparison ) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { err = kim_os_string_get_cfstring (in_string, &cfstring); } - + if (!err) { /* Returned CFComparisonResult is compatible with kim_comparison_t */ - *out_comparison = CFStringCompare (cfstring, in_compare_to_cfstring, 0); + *out_comparison = CFStringCompare (cfstring, in_compare_to_cfstring, 0); } - + if (cfstring) { CFRelease (cfstring); } - + return check_error (err); } diff --git a/src/kim/lib/mac/kim_os_ui_gui.c b/src/kim/lib/mac/kim_os_ui_gui.c index 1f9122570c..5de8ef191b 100644 --- a/src/kim/lib/mac/kim_os_ui_gui.c +++ b/src/kim/lib/mac/kim_os_ui_gui.c @@ -56,59 +56,59 @@ kim_error kim_os_ui_gui_init (kim_ui_context *io_context) kim_string path = NULL; k5_ipc_stream request = NULL; k5_ipc_stream reply = NULL; - + if (!err && !io_context) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { err = kim_library_get_application_name (&name); } - + if (!err) { err = kim_os_library_get_application_path (&path); } - + if (!err) { err = krb5int_ipc_stream_new (&request); } - + if (!err) { err = krb5int_ipc_stream_write_string (request, "init"); } - + if (!err) { err = krb5int_ipc_stream_write_int32 (request, getpid()); } - + if (!err) { err = krb5int_ipc_stream_write_string (request, name ? name : ""); } - + if (!err) { err = krb5int_ipc_stream_write_string (request, path ? path : ""); } - + if (!err) { err = kim_os_ui_gui_send_request (1 /* launch server */, request, &reply); } - + if (!err) { int32_t result = 0; err = krb5int_ipc_stream_read_int32 (reply, &result); if (!err) { err = check_error (result); } } - + if (!err) { io_context->tcontext = NULL; } - + krb5int_ipc_stream_release (request); krb5int_ipc_stream_release (reply); kim_string_free (&name); kim_string_free (&path); - + return check_error (err); } @@ -125,15 +125,15 @@ kim_error kim_os_ui_gui_enter_identity (kim_ui_context *in_context, char *identity_string = NULL; kim_identity identity = NULL; uint32_t change_password = 0; - + if (!err && !io_options ) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !out_identity ) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !out_change_password) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { err = krb5int_ipc_stream_new (&request); } - + if (!err) { err = krb5int_ipc_stream_write_string (request, "enter_identity"); } @@ -141,21 +141,21 @@ kim_error kim_os_ui_gui_enter_identity (kim_ui_context *in_context, if (!err) { err = kim_options_write_to_stream (io_options, request); } - + if (!err) { err = kim_os_ui_gui_send_request (0 /* don't launch server */, request, &reply); if (!reply) { err = check_error (KIM_NO_SERVER_ERR); } } - + if (!err) { int32_t result = 0; - + err = krb5int_ipc_stream_read_int32 (reply, &result); if (!err) { err = check_error (result); } } - + if (!err) { err = krb5int_ipc_stream_read_string (reply, &identity_string); } @@ -163,21 +163,21 @@ kim_error kim_os_ui_gui_enter_identity (kim_ui_context *in_context, if (!err) { err = krb5int_ipc_stream_read_uint32 (reply, &change_password); } - + if (!err) { err = kim_options_read_from_stream (io_options, reply); } - + if (!err) { err = kim_identity_create_from_string (&identity, identity_string); } - + if (!err) { *out_identity = identity; identity = NULL; *out_change_password = change_password; } - + kim_identity_free (&identity); krb5int_ipc_stream_free_string (identity_string); krb5int_ipc_stream_release (request); @@ -200,45 +200,45 @@ kim_error kim_os_ui_gui_select_identity (kim_ui_context *in_context, kim_options options = NULL; kim_identity identity = NULL; uint32_t change_password = 0; - + if (!err && !io_hints ) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !out_identity ) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !out_change_password) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { err = krb5int_ipc_stream_new (&request); } - + if (!err) { err = krb5int_ipc_stream_write_string (request, "select_identity"); } - + if (!err) { err = kim_selection_hints_write_to_stream (io_hints, request); } - + if (!err) { err = kim_os_ui_gui_send_request (0 /* don't launch server */, request, &reply); if (!reply) { err = check_error (KIM_NO_SERVER_ERR); } } - + if (!err) { int32_t result = 0; - + err = krb5int_ipc_stream_read_int32 (reply, &result); if (!err) { err = check_error (result); } } - + if (!err) { err = krb5int_ipc_stream_read_string (reply, &identity_string); } - + if (!err) { err = kim_identity_create_from_string (&identity, identity_string); } - + if (!err) { err = krb5int_ipc_stream_read_uint32 (reply, &change_password); } @@ -246,23 +246,23 @@ kim_error kim_os_ui_gui_select_identity (kim_ui_context *in_context, if (!err) { err = kim_options_create_from_stream (&options, reply); } - + if (!err) { err = kim_selection_hints_set_options (io_hints, options); } - + if (!err) { *out_identity = identity; identity = NULL; *out_change_password = change_password; } - - kim_identity_free (&identity); + + kim_identity_free (&identity); kim_options_free (&options); - krb5int_ipc_stream_free_string (identity_string); + krb5int_ipc_stream_free_string (identity_string); krb5int_ipc_stream_release (request); krb5int_ipc_stream_release (reply); - + return check_error (err); } @@ -271,8 +271,8 @@ kim_error kim_os_ui_gui_select_identity (kim_ui_context *in_context, kim_error kim_os_ui_gui_auth_prompt (kim_ui_context *in_context, kim_identity in_identity, kim_prompt_type in_type, - kim_boolean in_allow_save_reply, - kim_boolean in_hide_reply, + kim_boolean in_allow_save_reply, + kim_boolean in_hide_reply, kim_string in_title, kim_string in_message, kim_string in_description, @@ -283,76 +283,76 @@ kim_error kim_os_ui_gui_auth_prompt (kim_ui_context *in_context, k5_ipc_stream request = NULL; k5_ipc_stream reply = NULL; kim_string identity_string = NULL; - + if (!err && !in_identity) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !out_reply ) { err = check_error (KIM_NULL_PARAMETER_ERR); } /* in_title, in_message or in_description may be NULL */ - + if (!err) { err = kim_identity_get_string (in_identity, &identity_string); } - + if (!err) { err = krb5int_ipc_stream_new (&request); } - + if (!err) { err = krb5int_ipc_stream_write_string (request, "auth_prompt"); } - + if (!err) { err = krb5int_ipc_stream_write_string (request, identity_string); } - + if (!err) { err = krb5int_ipc_stream_write_int32 (request, in_type); } - + if (!err) { err = krb5int_ipc_stream_write_int32 (request, in_allow_save_reply); } - + if (!err) { err = krb5int_ipc_stream_write_int32 (request, in_hide_reply); } - + if (!err) { - err = krb5int_ipc_stream_write_string (request, + err = krb5int_ipc_stream_write_string (request, in_title ? in_title : ""); } - + if (!err) { - err = krb5int_ipc_stream_write_string (request, + err = krb5int_ipc_stream_write_string (request, in_message ? in_message : ""); } - + if (!err) { - err = krb5int_ipc_stream_write_string (request, + err = krb5int_ipc_stream_write_string (request, in_description ? in_description : ""); } - + if (!err) { err = kim_os_ui_gui_send_request (0 /* don't launch server */, request, &reply); if (!reply) { err = check_error (KIM_NO_SERVER_ERR); } } - + if (!err) { int32_t result = 0; - + err = krb5int_ipc_stream_read_int32 (reply, &result); if (!err) { err = check_error (result); } } - + if (!err) { err = krb5int_ipc_stream_read_string (reply, out_reply); - } - + } + if (!err) { err = krb5int_ipc_stream_read_int32 (reply, out_save_reply); - } - + } + kim_string_free (&identity_string); krb5int_ipc_stream_release (request); @@ -374,62 +374,62 @@ kim_error kim_os_ui_gui_change_password (kim_ui_context *in_context, k5_ipc_stream request = NULL; k5_ipc_stream reply = NULL; kim_string identity_string = NULL; - + char *old_password = NULL; char *new_password = NULL; char *vfy_password = NULL; - + if (!err && !in_identity ) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !out_old_password) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !out_new_password) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !out_vfy_password) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { err = kim_identity_get_string (in_identity, &identity_string); } - + if (!err) { err = krb5int_ipc_stream_new (&request); } - + if (!err) { err = krb5int_ipc_stream_write_string (request, "change_password"); } - + if (!err) { err = krb5int_ipc_stream_write_string (request, identity_string); } - + if (!err) { err = krb5int_ipc_stream_write_int32 (request, in_old_password_expired); } - + if (!err) { err = kim_os_ui_gui_send_request (0 /* don't launch server */, request, &reply); if (!reply) { err = check_error (KIM_NO_SERVER_ERR); } } - + if (!err) { int32_t result = 0; - + err = krb5int_ipc_stream_read_int32 (reply, &result); if (!err) { err = check_error (result); } } - + if (!err) { err = krb5int_ipc_stream_read_string (reply, &old_password); - } - + } + if (!err) { err = krb5int_ipc_stream_read_string (reply, &new_password); - } - + } + if (!err) { err = krb5int_ipc_stream_read_string (reply, &vfy_password); - } - + } + if (!err) { *out_old_password = (char *) old_password; old_password = NULL; @@ -438,12 +438,12 @@ kim_error kim_os_ui_gui_change_password (kim_ui_context *in_context, *out_vfy_password = (char *) vfy_password; vfy_password = NULL; } - - kim_string_free (&identity_string); - krb5int_ipc_stream_free_string (old_password); - krb5int_ipc_stream_free_string (new_password); - krb5int_ipc_stream_free_string (vfy_password); - + + kim_string_free (&identity_string); + krb5int_ipc_stream_free_string (old_password); + krb5int_ipc_stream_free_string (new_password); + krb5int_ipc_stream_free_string (vfy_password); + krb5int_ipc_stream_release (request); krb5int_ipc_stream_release (reply); @@ -462,26 +462,26 @@ kim_error kim_os_ui_gui_handle_error (kim_ui_context *in_context, k5_ipc_stream request = NULL; k5_ipc_stream reply = NULL; kim_string identity_string = NULL; - + if (!err && !in_error_message ) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !in_error_description) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { err = kim_identity_get_string (in_identity, &identity_string); } - + if (!err) { err = krb5int_ipc_stream_new (&request); } - + if (!err) { err = krb5int_ipc_stream_write_string (request, "handle_error"); } - + if (!err) { err = krb5int_ipc_stream_write_string (request, identity_string); } - + if (!err) { err = krb5int_ipc_stream_write_int32 (request, in_error); } @@ -489,26 +489,26 @@ kim_error kim_os_ui_gui_handle_error (kim_ui_context *in_context, if (!err) { err = krb5int_ipc_stream_write_string (request, in_error_message); } - + if (!err) { err = krb5int_ipc_stream_write_string (request, in_error_description); } - + if (!err) { err = kim_os_ui_gui_send_request (0 /* don't launch server */, request, &reply); if (!reply) { err = check_error (KIM_NO_SERVER_ERR); } } - + if (!err) { int32_t result = 0; - + err = krb5int_ipc_stream_read_int32 (reply, &result); if (!err) { err = check_error (result); } } - - kim_string_free (&identity_string); + + kim_string_free (&identity_string); krb5int_ipc_stream_release (request); krb5int_ipc_stream_release (reply); @@ -531,29 +531,29 @@ kim_error kim_os_ui_gui_fini (kim_ui_context *io_context) kim_error err = KIM_NO_ERROR; k5_ipc_stream request = NULL; k5_ipc_stream reply = NULL; - + if (!err) { err = krb5int_ipc_stream_new (&request); } - + if (!err) { err = krb5int_ipc_stream_write_string (request, "fini"); } - + if (!err) { err = kim_os_ui_gui_send_request (0 /* don't launch server */, request, &reply); if (!reply) { err = check_error (KIM_NO_SERVER_ERR); } } - + if (!err) { int32_t result = 0; - + err = krb5int_ipc_stream_read_int32 (reply, &result); if (!err) { err = check_error (result); } - } - + } + krb5int_ipc_stream_release (request); krb5int_ipc_stream_release (reply); diff --git a/src/kim/test/main.c b/src/kim/test/main.c index e3efbd7f6a..8eb5a42b77 100644 --- a/src/kim/test/main.c +++ b/src/kim/test/main.c @@ -28,51 +28,51 @@ #include "test_kim_preferences.h" #include "test_kim_selection_hints.h" -int main (int argc, const char * argv[]) +int main (int argc, const char * argv[]) { kim_test_state_t state = NULL; - + if (test_init (&state)) { return 1; } - + test_kim_identity_create_from_krb5_principal (state); test_kim_identity_create_from_string (state); - + test_kim_identity_create_from_components (state); - + test_kim_identity_copy (state); - + test_kim_identity_compare (state); - + test_kim_identity_get_display_string (state); - + test_kim_identity_get_realm (state); - + test_kim_identity_get_number_of_components (state); - + test_kim_identity_get_component_at_index (state); - + test_kim_identity_get_krb5_principal (state); - + test_kim_preferences_create (state); - + test_kim_preferences_copy (state); - + test_kim_preferences_set_options (state); - + test_kim_preferences_set_remember_options (state); - + test_kim_preferences_set_client_identity (state); - + test_kim_selection_hints_set_hint (state); - + test_kim_selection_hints_remember_identity (state); - + test_kim_preferences_add_favorite_identity (state); - + test_kim_preferences_remove_favorite_identity(state); - + return test_cleanup (state); } diff --git a/src/kim/test/test_kim_common.c b/src/kim/test/test_kim_common.c index 802d41564e..e62a237a4a 100644 --- a/src/kim/test/test_kim_common.c +++ b/src/kim/test/test_kim_common.c @@ -33,23 +33,23 @@ const char *k_no_test_name = "No test name set"; int test_init (kim_test_state_t *out_state) { kim_test_state_t state = NULL; - + printf ("Initializing tests... "); state = malloc (sizeof (*state)); - if (!state) { + if (!state) { printf ("out of memory.\n\n"); - return 1; + return 1; } - + state->test_name = k_no_test_name; state->global_fail_count = 0; state->test_fail_count = 0; - + *out_state = state; - + printf ("done.\n\n"); - + return 0; } @@ -58,7 +58,7 @@ int test_init (kim_test_state_t *out_state) int test_cleanup (kim_test_state_t io_state) { int global_fail_count = io_state->global_fail_count; - + printf ("Exiting. %d total failures.", global_fail_count); free (io_state); @@ -72,7 +72,7 @@ void start_test (kim_test_state_t in_state, { in_state->test_name = in_test_name; in_state->test_fail_count = 0; - + printf ("Testing %s...\n", in_state->test_name); } @@ -80,58 +80,58 @@ void start_test (kim_test_state_t in_state, void end_test (kim_test_state_t in_state) { - printf ("Finished testing %s. %d failures.\n\n", + printf ("Finished testing %s. %d failures.\n\n", in_state->test_name, in_state->test_fail_count); - + in_state->test_name = k_no_test_name; in_state->global_fail_count += in_state->test_fail_count; - in_state->test_fail_count = 0; + in_state->test_fail_count = 0; } /* ------------------------------------------------------------------------ */ -void fail_if_error (kim_test_state_t in_state, +void fail_if_error (kim_test_state_t in_state, const char *in_function, - kim_error in_err, + kim_error in_err, const char *in_format, ...) { if (in_err) { va_list args; kim_string message = NULL; - + kim_error err = kim_string_create_for_last_error (&message, in_err); - + printf ("\tFAILURE: "); printf ("%s() got %d (%s) ", in_function, in_err, !err ? message : "Unknown"); - + va_start (args, in_format); vprintf (in_format, args); va_end (args); - + printf ("\n"); - + in_state->test_fail_count++; - + kim_string_free (&message); } } /* ------------------------------------------------------------------------ */ -void log_failure (kim_test_state_t in_state, +void log_failure (kim_test_state_t in_state, const char *in_format, ...) { va_list args; - + printf ("\tFAILURE: "); - + va_start (args, in_format); vprintf (in_format, args); va_end (args); - + printf ("\n"); in_state->test_fail_count++; diff --git a/src/kim/test/test_kim_common.h b/src/kim/test/test_kim_common.h index e7ac3eb30f..8364094b59 100644 --- a/src/kim/test/test_kim_common.h +++ b/src/kim/test/test_kim_common.h @@ -47,9 +47,9 @@ void start_test (kim_test_state_t in_state, void end_test (kim_test_state_t in_state); -void fail_if_error (kim_test_state_t in_state, +void fail_if_error (kim_test_state_t in_state, const char *in_function, - kim_error in_err, + kim_error in_err, const char *in_format, ...) #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7) @@ -57,7 +57,7 @@ __attribute__ ((__format__ (__printf__, 4, 5))) #endif ; -void log_failure (kim_test_state_t in_state, +void log_failure (kim_test_state_t in_state, const char *in_format, ...) #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7) diff --git a/src/kim/test/test_kim_identity.c b/src/kim/test/test_kim_identity.c index 2f1ac089f3..81be6b11db 100644 --- a/src/kim/test/test_kim_identity.c +++ b/src/kim/test/test_kim_identity.c @@ -51,8 +51,8 @@ test_identity test_identities[] = { {"user/i1/i2@EXAMPLE.COM", "user/i1/i2@EXAMPLE.COM", 0, "EXAMPLE.COM", 3, { "user", "i1", "i2", NULL, NULL } }, {"user/i1/i2/i3/i4@EXAMPLE.COM", "user/i1/i2/i3/i4@EXAMPLE.COM", 0, "EXAMPLE.COM", 5, { "user", "i1", "i2", "i3", "i4" } }, {"an insanely long principal for testing icky hex key principals/an insanely long instance for testing icky hex key principals@AN-INSANELY-LONG-REALM-NAME-FOR-TESTING-AUTOGENERATED-REALM-NAMES", - "an insanely long principal for testing icky hex key principals/an insanely long instance for testing icky hex key principals@AN-INSANELY-LONG-REALM-NAME-FOR-TESTING-AUTOGENERATED-REALM-NAMES", - 0, "AN-INSANELY-LONG-REALM-NAME-FOR-TESTING-AUTOGENERATED-REALM-NAMES", + "an insanely long principal for testing icky hex key principals/an insanely long instance for testing icky hex key principals@AN-INSANELY-LONG-REALM-NAME-FOR-TESTING-AUTOGENERATED-REALM-NAMES", + 0, "AN-INSANELY-LONG-REALM-NAME-FOR-TESTING-AUTOGENERATED-REALM-NAMES", 2, { "an insanely long principal for testing icky hex key principals", "an insanely long instance for testing icky hex key principals", NULL, NULL, NULL } }, { NULL, NULL, 0, NULL, 0, { NULL, NULL, NULL, NULL, NULL } }, }; @@ -62,56 +62,56 @@ test_identity test_identities[] = { void test_kim_identity_create_from_krb5_principal (kim_test_state_t state) { kim_count i = 0; - + start_test (state, "kim_identity_create_from_krb5_principal"); - + for (i = 0; test_identities[i].string; i++) { kim_error err = KIM_NO_ERROR; krb5_context context = NULL; krb5_principal principal = NULL; kim_identity identity = NULL; kim_string string = NULL; - + printf ("."); - + err = krb5_init_context (&context); - fail_if_error (state, "krb5_init_context", err, + fail_if_error (state, "krb5_init_context", err, "while initializing context"); - + if (!err) { err = krb5_parse_name (context, test_identities[i].string, &principal); - fail_if_error (state, "krb5_parse_name", err, - "while creating krb5_principal for %s", + fail_if_error (state, "krb5_parse_name", err, + "while creating krb5_principal for %s", test_identities[i].string); } - + if (!err) { err = kim_identity_create_from_krb5_principal (&identity, context, principal); - fail_if_error (state, "kim_identity_create_from_string", err, - "while creating the identity for %s", + fail_if_error (state, "kim_identity_create_from_string", err, + "while creating the identity for %s", test_identities[i].string); } - + if (!err) { err = kim_identity_get_string (identity, &string); - fail_if_error (state, "kim_identity_get_string", err, - "while getting the string for %s", + fail_if_error (state, "kim_identity_get_string", err, + "while getting the string for %s", test_identities[i].string); } - + if (!err && strcmp (string, test_identities[i].string)) { - log_failure (state, "Unexpected string (got '%s', expected '%s')", + log_failure (state, "Unexpected string (got '%s', expected '%s')", string, test_identities[i].string); } - + kim_string_free (&string); kim_identity_free (&identity); if (principal) { krb5_free_principal (context, principal); } if (context ) { krb5_free_context (context); } } - + printf ("\n"); - + end_test (state); } @@ -120,41 +120,41 @@ void test_kim_identity_create_from_krb5_principal (kim_test_state_t state) void test_kim_identity_create_from_string (kim_test_state_t state) { kim_count i = 0; - + start_test (state, "kim_identity_create_from_string"); - + for (i = 0; test_identities[i].string; i++) { kim_error err = KIM_NO_ERROR; kim_identity identity = NULL; kim_string string = NULL; - + printf ("."); - + if (!err) { err = kim_identity_create_from_string (&identity, test_identities[i].string); - fail_if_error (state, "kim_identity_create_from_string", err, - "while creating the identity for %s", + fail_if_error (state, "kim_identity_create_from_string", err, + "while creating the identity for %s", test_identities[i].string); } - + if (!err) { err = kim_identity_get_string (identity, &string); - fail_if_error (state, "kim_identity_get_string", err, - "while getting the string for %s", + fail_if_error (state, "kim_identity_get_string", err, + "while getting the string for %s", test_identities[i].string); } - + if (!err && strcmp (string, test_identities[i].string)) { - log_failure (state, "Unexpected string (got '%s', expected '%s')", + log_failure (state, "Unexpected string (got '%s', expected '%s')", string, test_identities[i].string); } - + kim_string_free (&string); kim_identity_free (&identity); } - + printf ("\n"); - + end_test (state); } @@ -164,48 +164,48 @@ void test_kim_identity_create_from_string (kim_test_state_t state) void test_kim_identity_create_from_components (kim_test_state_t state) { kim_count i = 0; - + start_test (state, "kim_identity_create_from_components"); - + for (i = 0; test_identities[i].string; i++) { kim_error err = KIM_NO_ERROR; kim_identity identity = NULL; kim_string string = NULL; - + printf ("."); - + if (!err) { - err = kim_identity_create_from_components (&identity, - test_identities[i].realm, - test_identities[i].components[0], - test_identities[i].components[1], - test_identities[i].components[2], - test_identities[i].components[3], + err = kim_identity_create_from_components (&identity, + test_identities[i].realm, + test_identities[i].components[0], + test_identities[i].components[1], + test_identities[i].components[2], + test_identities[i].components[3], test_identities[i].components[4], NULL); - fail_if_error (state, "kim_identity_create_from_components", err, - "while creating the identity for %s", + fail_if_error (state, "kim_identity_create_from_components", err, + "while creating the identity for %s", test_identities[i].string); } - + if (!err) { err = kim_identity_get_string (identity, &string); - fail_if_error (state, "kim_identity_get_string", err, - "while getting the string for %s", + fail_if_error (state, "kim_identity_get_string", err, + "while getting the string for %s", test_identities[i].string); } - + if (!err && strcmp (string, test_identities[i].string)) { - log_failure (state, "Unexpected string (got '%s', expected '%s')", + log_failure (state, "Unexpected string (got '%s', expected '%s')", string, test_identities[i].string); } - + kim_string_free (&string); kim_identity_free (&identity); } - + printf ("\n"); - + end_test (state); } @@ -214,49 +214,49 @@ void test_kim_identity_create_from_components (kim_test_state_t state) void test_kim_identity_copy (kim_test_state_t state) { kim_count i = 0; - + start_test (state, "kim_identity_copy"); - + for (i = 0; test_identities[i].string; i++) { kim_error err = KIM_NO_ERROR; kim_identity identity = NULL; kim_identity identity_copy = NULL; kim_string string = NULL; - + printf ("."); - + if (!err) { err = kim_identity_create_from_string (&identity, test_identities[i].string); - fail_if_error (state, "kim_identity_create_from_string", err, - "while creating the identity for %s", + fail_if_error (state, "kim_identity_create_from_string", err, + "while creating the identity for %s", test_identities[i].string); } - + if (!err) { err = kim_identity_copy (&identity_copy, identity); - fail_if_error (state, "kim_identity_copy", err, + fail_if_error (state, "kim_identity_copy", err, "while copying %s", test_identities[i].string); } - + if (!err) { err = kim_identity_get_string (identity_copy, &string); - fail_if_error (state, "kim_identity_get_string", err, - "while getting the string for the copy of %s", + fail_if_error (state, "kim_identity_get_string", err, + "while getting the string for the copy of %s", test_identities[i].string); } - + if (!err && strcmp (string, test_identities[i].string)) { - log_failure (state, "Unexpected string (got '%s', expected '%s')", + log_failure (state, "Unexpected string (got '%s', expected '%s')", string, test_identities[i].string); } - + kim_string_free (&string); kim_identity_free (&identity_copy); kim_identity_free (&identity); } - + printf ("\n"); - + end_test (state); } @@ -265,55 +265,55 @@ void test_kim_identity_copy (kim_test_state_t state) void test_kim_identity_compare (kim_test_state_t state) { kim_count i, j = 0; - + start_test (state, "kim_identity_create_from_string"); - + for (i = 0; test_identities[i].string; i++) { kim_error err = KIM_NO_ERROR; kim_identity identity = NULL; - + printf ("."); - + err = kim_identity_create_from_string (&identity, test_identities[i].string); - fail_if_error (state, "kim_identity_create_from_string", err, - "while creating the identity for %s", + fail_if_error (state, "kim_identity_create_from_string", err, + "while creating the identity for %s", test_identities[i].string); - + for (j = 0; !err && test_identities[j].string; j++) { kim_identity compare_to_identity = NULL; kim_comparison comparison = 0; - + err = kim_identity_create_from_string (&compare_to_identity, test_identities[j].string); - fail_if_error (state, "kim_identity_create_from_string", err, - "while creating the identity for %s", + fail_if_error (state, "kim_identity_create_from_string", err, + "while creating the identity for %s", test_identities[j].string); - + if (!err) { err = kim_identity_compare (identity, compare_to_identity, &comparison); - fail_if_error (state, "kim_identity_compare", err, - "while comparing %s and %s", + fail_if_error (state, "kim_identity_compare", err, + "while comparing %s and %s", test_identities[i].string, test_identities[j].string); } - + if (!err) { if (i == j && !kim_comparison_is_equal_to (comparison)) { - log_failure (state, "Expected %s and %s to be equal but kim_identity_compare returned %d", + log_failure (state, "Expected %s and %s to be equal but kim_identity_compare returned %d", test_identities[i].string, test_identities[j].string, comparison); - + } else if (i != j && kim_comparison_is_equal_to (comparison)) { - log_failure (state, "Expected %s and %s to be NOT equal but kim_identity_compare returned %d", + log_failure (state, "Expected %s and %s to be NOT equal but kim_identity_compare returned %d", test_identities[i].string, test_identities[j].string, comparison); } } - + kim_identity_free (&compare_to_identity); } - + kim_identity_free (&identity); } - + printf ("\n"); - + end_test (state); } @@ -322,41 +322,41 @@ void test_kim_identity_compare (kim_test_state_t state) void test_kim_identity_get_display_string (kim_test_state_t state) { kim_count i = 0; - + start_test (state, "kim_identity_get_display_string"); - + for (i = 0; test_identities[i].string; i++) { kim_error err = KIM_NO_ERROR; kim_identity identity = NULL; kim_string string = NULL; - + printf ("."); - + if (!err) { err = kim_identity_create_from_string (&identity, test_identities[i].string); - fail_if_error (state, "kim_identity_create_from_string", err, - "while creating the identity for %s", + fail_if_error (state, "kim_identity_create_from_string", err, + "while creating the identity for %s", test_identities[i].string); } - + if (!err) { err = kim_identity_get_display_string (identity, &string); - fail_if_error (state, "kim_identity_get_display_string", err, - "while getting the display string for %s", + fail_if_error (state, "kim_identity_get_display_string", err, + "while getting the display string for %s", test_identities[i].string); } - + if (!err && strcmp (string, test_identities[i].display_string)) { - log_failure (state, "Unexpected display string for %s (got '%s', expected '%s')", + log_failure (state, "Unexpected display string for %s (got '%s', expected '%s')", test_identities[i].string, string, test_identities[i].display_string); } - + kim_string_free (&string); kim_identity_free (&identity); } - + printf ("\n"); - + end_test (state); } @@ -365,40 +365,40 @@ void test_kim_identity_get_display_string (kim_test_state_t state) void test_kim_identity_get_realm (kim_test_state_t state) { kim_count i = 0; - + start_test (state, "kim_identity_get_realm"); - + for (i = 0; test_identities[i].string; i++) { kim_error err = KIM_NO_ERROR; kim_identity identity = NULL; kim_string realm = NULL; - + printf ("."); - + if (!err) { err = kim_identity_create_from_string (&identity, test_identities[i].string); - fail_if_error (state, "kim_identity_create_from_string", err, - "while creating the identity for %s", + fail_if_error (state, "kim_identity_create_from_string", err, + "while creating the identity for %s", test_identities[i].string); } - + if (!err) { err = kim_identity_get_realm (identity, &realm); - fail_if_error (state, "kim_identity_get_realm", err, + fail_if_error (state, "kim_identity_get_realm", err, "while getting the realm for %s", test_identities[i].string); } - + if (!err && strcmp (realm, test_identities[i].realm)) { - log_failure (state, "Unexpected realm string (got '%s', expected '%s')", + log_failure (state, "Unexpected realm string (got '%s', expected '%s')", realm, test_identities[i].realm); } - + kim_string_free (&realm); kim_identity_free (&identity); } - + printf ("\n"); - + end_test (state); } @@ -407,40 +407,40 @@ void test_kim_identity_get_realm (kim_test_state_t state) void test_kim_identity_get_number_of_components (kim_test_state_t state) { kim_count i = 0; - + start_test (state, "kim_identity_get_number_of_components"); - + for (i = 0; test_identities[i].string; i++) { kim_error err = KIM_NO_ERROR; kim_identity identity = NULL; kim_count count = 0; - + printf ("."); - + if (!err) { err = kim_identity_create_from_string (&identity, test_identities[i].string); - fail_if_error (state, "kim_identity_create_from_string", err, - "while creating the identity for %s", + fail_if_error (state, "kim_identity_create_from_string", err, + "while creating the identity for %s", test_identities[i].string); } - + if (!err) { err = kim_identity_get_number_of_components (identity, &count); - fail_if_error (state, "kim_identity_get_number_of_components", err, - "while getting number of components of %s", + fail_if_error (state, "kim_identity_get_number_of_components", err, + "while getting number of components of %s", test_identities[i].string); } - + if (!err && (count != test_identities[i].component_count)) { - log_failure (state, "Unexpected component count of %s (got %d, expected %d)", + log_failure (state, "Unexpected component count of %s (got %d, expected %d)", test_identities[i].string, (int) count, (int) test_identities[i].component_count); } - + kim_identity_free (&identity); } - + printf ("\n"); - + end_test (state); } @@ -449,45 +449,45 @@ void test_kim_identity_get_number_of_components (kim_test_state_t state) void test_kim_identity_get_component_at_index (kim_test_state_t state) { kim_count i = 0; - + start_test (state, "kim_identity_get_component_at_index"); - + for (i = 0; test_identities[i].string; i++) { kim_error err = KIM_NO_ERROR; kim_identity identity = NULL; kim_count c = 0; - + printf ("."); - + if (!err) { err = kim_identity_create_from_string (&identity, test_identities[i].string); - fail_if_error (state, "kim_identity_create_from_string", err, - "while creating the identity for %s", + fail_if_error (state, "kim_identity_create_from_string", err, + "while creating the identity for %s", test_identities[i].string); } - + for (c = 0; !err && c < test_identities[i].component_count; c++) { kim_string component = NULL; - + err = kim_identity_get_component_at_index (identity, c, &component); - fail_if_error (state, "kim_identity_get_component_at_index", err, + fail_if_error (state, "kim_identity_get_component_at_index", err, "while getting component %d of %s", (int) c, test_identities[i].string); - + if (!err && strcmp (component, test_identities[i].components[c])) { - log_failure (state, "Unexpected component %d of %s (got '%s', expected '%s')", - (int) c, test_identities[i].string, + log_failure (state, "Unexpected component %d of %s (got '%s', expected '%s')", + (int) c, test_identities[i].string, component, test_identities[i].components[c]); } - + kim_string_free (&component); } - + kim_identity_free (&identity); } - + printf ("\n"); - + end_test (state); } @@ -496,58 +496,58 @@ void test_kim_identity_get_component_at_index (kim_test_state_t state) void test_kim_identity_get_krb5_principal (kim_test_state_t state) { kim_count i = 0; - + start_test (state, "kim_identity_get_krb5_principal"); - + for (i = 0; test_identities[i].string; i++) { kim_error err = KIM_NO_ERROR; krb5_context context = NULL; krb5_principal principal = NULL; krb5_principal identity_principal = NULL; kim_identity identity = NULL; - + printf ("."); - + err = krb5_init_context (&context); - fail_if_error (state, "krb5_init_context", err, + fail_if_error (state, "krb5_init_context", err, "while initializing context"); - + if (!err) { err = krb5_parse_name (context, test_identities[i].string, &principal); - fail_if_error (state, "krb5_parse_name", err, - "while creating krb5_principal for %s", + fail_if_error (state, "krb5_parse_name", err, + "while creating krb5_principal for %s", test_identities[i].string); } - + if (!err && !err) { err = kim_identity_create_from_string (&identity, test_identities[i].string); - fail_if_error (state, "kim_identity_create_from_string", err, - "while creating the identity for %s", + fail_if_error (state, "kim_identity_create_from_string", err, + "while creating the identity for %s", test_identities[i].string); } - + if (!err && !err) { err = kim_identity_get_krb5_principal (identity, context, &identity_principal); - fail_if_error (state, "kim_identity_get_krb5_principal", err, - "while getting the krb5_principal for %s", + fail_if_error (state, "kim_identity_get_krb5_principal", err, + "while getting the krb5_principal for %s", test_identities[i].string); } - + if (!err && !err) { if (!krb5_principal_compare (context, principal, identity_principal)) { - log_failure (state, "Principal and identity principal for %s do not match", + log_failure (state, "Principal and identity principal for %s do not match", test_identities[i].string); } } - + kim_identity_free (&identity); if (identity_principal) { krb5_free_principal (context, identity_principal); } if (principal ) { krb5_free_principal (context, principal); } if (context ) { krb5_free_context (context); } } - + printf ("\n"); - + end_test (state); } @@ -556,38 +556,38 @@ void test_kim_identity_get_krb5_principal (kim_test_state_t state) void test_kim_identity_is_tgt_service (kim_test_state_t state) { kim_count i = 0; - + start_test (state, "kim_identity_is_tgt_service"); - + for (i = 0; test_identities[i].string; i++) { kim_error err = KIM_NO_ERROR; kim_identity_t identity = NULL; kim_boolean_t is_tgt_service = 0; - + printf ("."); - + if (!err) { err = kim_identity_create_from_string (&identity, test_identities[i].string); - fail_if_error (state, "kim_identity_create_from_string", err, - "while creating the identity for %s", + fail_if_error (state, "kim_identity_create_from_string", err, + "while creating the identity for %s", test_identities[i].string); } - + if (!err) { err = kim_identity_is_tgt_service (identity, &is_tgt_service); - fail_if_error (state, "kim_identity_is_tgt_service", err, - "while determining if %s is a tgt service", + fail_if_error (state, "kim_identity_is_tgt_service", err, + "while determining if %s is a tgt service", test_identities[i].string); } - + if (!err && (is_tgt_service != test_identities[i].is_tgt_service)) { - log_failure (state, "Unexpected result from kim_identity_is_tgt_service for %s (got %d, expected %d)", + log_failure (state, "Unexpected result from kim_identity_is_tgt_service for %s (got %d, expected %d)", test_identities[i].string, is_tgt_service, test_identities[i].is_tgt_service); } - + kim_identity_free (&identity); } - + printf ("\n"); end_test (state); diff --git a/src/kim/test/test_kim_preferences.c b/src/kim/test/test_kim_preferences.c index 2766ad4d19..967cbc057b 100644 --- a/src/kim/test/test_kim_preferences.c +++ b/src/kim/test/test_kim_preferences.c @@ -39,39 +39,39 @@ void print_favorites(kim_test_state_t state) kim_preferences prefs = NULL; kim_count count, j; kim_string string; - + err = kim_preferences_create (&prefs); - fail_if_error (state, "kim_preferences_create", err, + fail_if_error (state, "kim_preferences_create", err, "while creating preferences"); - + if (!err) { err = kim_preferences_get_number_of_favorite_identities (prefs, &count); - fail_if_error (state, "kim_preferences_get_number_of_favorite_identities", err, + fail_if_error (state, "kim_preferences_get_number_of_favorite_identities", err, "while getting number of favorite identities"); printf("%qu favorites...\n", count); } - - + + for (j = 0; j < count; j++) { kim_identity compare_identity = NULL; kim_options compare_options = NULL; - err = kim_preferences_get_favorite_identity_at_index (prefs, j, - &compare_identity, + err = kim_preferences_get_favorite_identity_at_index (prefs, j, + &compare_identity, &compare_options); - fail_if_error (state, "kim_preferences_get_favorite_identity_at_index", err, + fail_if_error (state, "kim_preferences_get_favorite_identity_at_index", err, "while getting favorite identity %d", (int) j); - + if (!err) { kim_identity_get_display_string(compare_identity, &string); printf(" %2qu: %s\n", j, string); } - + kim_identity_free (&compare_identity); kim_options_free (&compare_options); } - - kim_preferences_free (&prefs); + + kim_preferences_free (&prefs); } /* ------------------------------------------------------------------------ */ @@ -82,50 +82,50 @@ kim_boolean favorites_contains_identity(kim_test_state_t state, kim_identity ide kim_preferences prefs = NULL; kim_count count, j; kim_boolean found = 0; - + err = kim_preferences_create (&prefs); - fail_if_error (state, "kim_preferences_create", err, + fail_if_error (state, "kim_preferences_create", err, "while creating preferences"); - + if (!err) { err = kim_preferences_get_number_of_favorite_identities (prefs, &count); - fail_if_error (state, "kim_preferences_get_number_of_favorite_identities", err, + fail_if_error (state, "kim_preferences_get_number_of_favorite_identities", err, "while getting number of favorite identities"); } - + for (j = 0; j < count; j++) { kim_identity compare_identity = NULL; kim_options compare_options = NULL; kim_comparison comparison = 0; - - err = kim_preferences_get_favorite_identity_at_index (prefs, j, - &compare_identity, + + err = kim_preferences_get_favorite_identity_at_index (prefs, j, + &compare_identity, &compare_options); - fail_if_error (state, "kim_preferences_get_favorite_identity_at_index", err, + fail_if_error (state, "kim_preferences_get_favorite_identity_at_index", err, "while getting favorite identity %d", (int) j); - + if (!err) { kim_string display_string = NULL; - err = kim_identity_compare (identity, compare_identity, + err = kim_identity_compare (identity, compare_identity, &comparison); if (err) { kim_identity_get_display_string(identity, &display_string); - fail_if_error (state, "kim_identity_compare", err, - "while comparing %s to favorite identity %d", + fail_if_error (state, "kim_identity_compare", err, + "while comparing %s to favorite identity %d", display_string, (int) j); } } - + if (!err && kim_comparison_is_equal_to (comparison)) { found = 1; } - + kim_identity_free (&compare_identity); kim_options_free (&compare_options); } - + kim_preferences_free (&prefs); - + return found; } @@ -133,7 +133,7 @@ kim_boolean favorites_contains_identity(kim_test_state_t state, kim_identity ide void test_kim_preferences_create (kim_test_state_t state) { - + start_test (state, "kim_preferences_create"); { @@ -141,12 +141,12 @@ void test_kim_preferences_create (kim_test_state_t state) kim_preferences prefs = NULL; err = kim_preferences_create (&prefs); - fail_if_error (state, "kim_preferences_create", err, + fail_if_error (state, "kim_preferences_create", err, "while creating preferences"); - + kim_preferences_free (&prefs); } - + end_test (state); } @@ -154,28 +154,28 @@ void test_kim_preferences_create (kim_test_state_t state) void test_kim_preferences_copy (kim_test_state_t state) { - + start_test (state, "test_kim_preferences_copy"); - + { kim_error err = KIM_NO_ERROR; kim_preferences prefs = NULL; kim_preferences prefs_copy = NULL; - + err = kim_preferences_create (&prefs); - fail_if_error (state, "kim_preferences_create", err, + fail_if_error (state, "kim_preferences_create", err, "while creating preferences"); - + if (!err) { err = kim_preferences_copy (&prefs_copy, prefs); - fail_if_error (state, "kim_preferences_copy", err, - "while copying preferences"); + fail_if_error (state, "kim_preferences_copy", err, + "while copying preferences"); } - + kim_preferences_free (&prefs_copy); kim_preferences_free (&prefs); } - + end_test (state); } @@ -184,76 +184,76 @@ void test_kim_preferences_copy (kim_test_state_t state) void test_kim_preferences_set_options (kim_test_state_t state) { kim_error err = KIM_NO_ERROR; - + start_test (state, "kim_preferences_set_options"); - + if (!err) { kim_preferences prefs = NULL; kim_options options = NULL; - + err = kim_preferences_create (&prefs); - fail_if_error (state, "kim_preferences_create", err, + fail_if_error (state, "kim_preferences_create", err, "while creating preferences"); - + if (!err) { err = kim_preferences_get_options (prefs, &options); - fail_if_error (state, "kim_preferences_get_options", err, + fail_if_error (state, "kim_preferences_get_options", err, "while getting old options"); } - + if (!err) { err = kim_options_set_lifetime (options, TEST_LIFETIME); - fail_if_error (state, "kim_options_set_lifetime", err, - "while setting the lifetime to %d", TEST_LIFETIME); + fail_if_error (state, "kim_options_set_lifetime", err, + "while setting the lifetime to %d", TEST_LIFETIME); } - + if (!err) { err = kim_preferences_set_options (prefs, options); - fail_if_error (state, "kim_preferences_set_options", err, + fail_if_error (state, "kim_preferences_set_options", err, "while setting the new options"); } - + if (!err) { err = kim_preferences_synchronize (prefs); - fail_if_error (state, "kim_preferences_synchronize", err, + fail_if_error (state, "kim_preferences_synchronize", err, "while setting the identity to KIM_IDENTITY_ANY"); } - + kim_options_free (&options); kim_preferences_free (&prefs); } - + if (!err) { kim_preferences prefs = NULL; kim_options verify_options = NULL; kim_lifetime lifetime = 0; - + err = kim_preferences_create (&prefs); - fail_if_error (state, "kim_preferences_create", err, + fail_if_error (state, "kim_preferences_create", err, "while creating preferences"); - - + + if (!err) { err = kim_preferences_get_options (prefs, &verify_options); - fail_if_error (state, "kim_preferences_get_options", err, + fail_if_error (state, "kim_preferences_get_options", err, "while getting options for verification"); } - + if (!err) { err = kim_options_get_lifetime (verify_options, &lifetime); - fail_if_error (state, "kim_options_get_data", err, - "while getting the custom data of the verify options"); + fail_if_error (state, "kim_options_get_data", err, + "while getting the custom data of the verify options"); } - + if (!err && lifetime != TEST_LIFETIME) { - log_failure (state, "Unexpected lifetime in options (got %d, expected %d)", + log_failure (state, "Unexpected lifetime in options (got %d, expected %d)", (int) lifetime, TEST_LIFETIME); } - + kim_options_free (&verify_options); kim_preferences_free (&prefs); } - + end_test (state); } @@ -261,99 +261,99 @@ void test_kim_preferences_set_options (kim_test_state_t state) void test_kim_preferences_set_remember_options (kim_test_state_t state) { - + kim_error err = KIM_NO_ERROR; - + start_test (state, "kim_preferences_set_remember_options"); - + if (!err) { kim_preferences prefs = NULL; - + err = kim_preferences_create (&prefs); - fail_if_error (state, "kim_preferences_create", err, + fail_if_error (state, "kim_preferences_create", err, "while creating preferences"); - + if (!err) { err = kim_preferences_set_remember_options (prefs, TRUE); - fail_if_error (state, "kim_preferences_set_remember_options", err, + fail_if_error (state, "kim_preferences_set_remember_options", err, "while setting the preference to remember options"); } - + if (!err) { err = kim_preferences_synchronize (prefs); - fail_if_error (state, "kim_preferences_synchronize", err, + fail_if_error (state, "kim_preferences_synchronize", err, "while setting the identity to KIM_IDENTITY_ANY"); } - + kim_preferences_free (&prefs); } - + if (!err) { kim_preferences prefs = NULL; kim_boolean remember_options = TRUE; - + err = kim_preferences_create (&prefs); - fail_if_error (state, "kim_preferences_create", err, + fail_if_error (state, "kim_preferences_create", err, "while creating preferences"); - + if (!err) { err = kim_preferences_get_remember_options (prefs, &remember_options); - fail_if_error (state, "kim_preferences_get_remember_options", err, + fail_if_error (state, "kim_preferences_get_remember_options", err, "while getting the preference to remember options"); } - + if (!err && !remember_options) { - log_failure (state, "Unexpected remember options preference (got %d, expected TRUE)", + log_failure (state, "Unexpected remember options preference (got %d, expected TRUE)", remember_options); } - + kim_preferences_free (&prefs); } - + if (!err) { kim_preferences prefs = NULL; - + err = kim_preferences_create (&prefs); - fail_if_error (state, "kim_preferences_create", err, + fail_if_error (state, "kim_preferences_create", err, "while creating preferences"); - + if (!err) { err = kim_preferences_set_remember_options (prefs, FALSE); - fail_if_error (state, "kim_preferences_set_remember_options", err, + fail_if_error (state, "kim_preferences_set_remember_options", err, "while setting the preference to remember options"); } - + if (!err) { err = kim_preferences_synchronize (prefs); - fail_if_error (state, "kim_preferences_synchronize", err, + fail_if_error (state, "kim_preferences_synchronize", err, "while setting the identity to KIM_IDENTITY_ANY"); } - + kim_preferences_free (&prefs); } - + if (!err) { kim_preferences prefs = NULL; kim_boolean remember_options = FALSE; - + err = kim_preferences_create (&prefs); - fail_if_error (state, "kim_preferences_create", err, + fail_if_error (state, "kim_preferences_create", err, "while creating preferences"); - + if (!err) { err = kim_preferences_get_remember_options (prefs, &remember_options); - fail_if_error (state, "kim_preferences_get_remember_options", err, + fail_if_error (state, "kim_preferences_get_remember_options", err, "while getting the preference to remember options"); } - + if (!err && remember_options) { - log_failure (state, "Unexpected remember options preference (got %d, expected 0)", + log_failure (state, "Unexpected remember options preference (got %d, expected 0)", remember_options); } - + kim_preferences_free (&prefs); } - + end_test (state); } @@ -361,118 +361,118 @@ void test_kim_preferences_set_remember_options (kim_test_state_t state) void test_kim_preferences_set_client_identity (kim_test_state_t state) { - + kim_error err = KIM_NO_ERROR; kim_string test_string = "user@EXAMPLE.COM"; kim_identity test_identity = KIM_IDENTITY_ANY; kim_identity identity = KIM_IDENTITY_ANY; kim_comparison comparison = 0; - + start_test (state, "kim_preferences_set_client_identity"); - - + + if (!err) { err = kim_identity_create_from_string (&test_identity, test_string); - fail_if_error (state, "kim_identity_create_from_string", err, + fail_if_error (state, "kim_identity_create_from_string", err, "while creating the identity for %s", test_string); } - + if (!err) { kim_preferences prefs = NULL; err = kim_preferences_create (&prefs); - fail_if_error (state, "kim_preferences_create", err, + fail_if_error (state, "kim_preferences_create", err, "while creating preferences"); - + if (!err) { err = kim_preferences_set_client_identity (prefs, KIM_IDENTITY_ANY); - fail_if_error (state, "kim_preferences_set_client_identity", err, + fail_if_error (state, "kim_preferences_set_client_identity", err, "while setting the identity to KIM_IDENTITY_ANY"); } - + if (!err) { err = kim_preferences_synchronize (prefs); - fail_if_error (state, "kim_preferences_synchronize", err, + fail_if_error (state, "kim_preferences_synchronize", err, "while setting the identity to KIM_IDENTITY_ANY"); } - + kim_preferences_free (&prefs); } - + if (!err) { kim_preferences prefs = NULL; err = kim_preferences_create (&prefs); - fail_if_error (state, "kim_preferences_create", err, + fail_if_error (state, "kim_preferences_create", err, "while creating preferences"); - + if (!err) { err = kim_preferences_get_client_identity (prefs, &identity); - fail_if_error (state, "kim_preferences_get_client_identity", err, + fail_if_error (state, "kim_preferences_get_client_identity", err, "while getting the client identity preference"); } - + if (!err && identity != KIM_IDENTITY_ANY) { - log_failure (state, "Unexpected client identity preference (got %p, expected %p)", + log_failure (state, "Unexpected client identity preference (got %p, expected %p)", identity, KIM_IDENTITY_ANY); kim_identity_free (&identity); } - + kim_preferences_free (&prefs); } - + if (!err) { kim_preferences prefs = NULL; err = kim_preferences_create (&prefs); - fail_if_error (state, "kim_preferences_create", err, + fail_if_error (state, "kim_preferences_create", err, "while creating preferences"); - + if (!err) { err = kim_preferences_set_client_identity (prefs, test_identity); - fail_if_error (state, "kim_preferences_set_client_identity", err, + fail_if_error (state, "kim_preferences_set_client_identity", err, "while setting the identity to %s", test_string); } - + if (!err) { err = kim_preferences_synchronize (prefs); - fail_if_error (state, "kim_preferences_synchronize", err, + fail_if_error (state, "kim_preferences_synchronize", err, "while setting the identity to KIM_IDENTITY_ANY"); } - + kim_preferences_free (&prefs); } - - + + if (!err) { kim_preferences prefs = NULL; kim_string string = NULL; err = kim_preferences_create (&prefs); - fail_if_error (state, "kim_preferences_create", err, + fail_if_error (state, "kim_preferences_create", err, "while creating preferences"); - + if (!err) { err = kim_preferences_get_client_identity (prefs, &identity); - fail_if_error (state, "kim_preferences_get_client_identity", err, + fail_if_error (state, "kim_preferences_get_client_identity", err, "while getting the client identity preference"); } - + if (!err && identity) { err = kim_identity_get_string (identity, &string); - fail_if_error (state, "kim_identity_get_string", err, + fail_if_error (state, "kim_identity_get_string", err, "while getting the string for client identity preference"); } - + if (!err) { err = kim_identity_compare (identity, test_identity, &comparison); - fail_if_error (state, "kim_identity_compare", err, - "while comparing %s to the identity preference %s", + fail_if_error (state, "kim_identity_compare", err, + "while comparing %s to the identity preference %s", test_string, string ? string : "NULL"); } - + if (!err && !kim_comparison_is_equal_to (comparison)) { - log_failure (state, "Unexpected client identity preference (got %s, expected %s)", + log_failure (state, "Unexpected client identity preference (got %s, expected %s)", string ? string : "NULL", test_string); kim_identity_free (&identity); } @@ -480,7 +480,7 @@ void test_kim_preferences_set_client_identity (kim_test_state_t state) kim_string_free (&string); kim_preferences_free (&prefs); } - + kim_identity_free (&identity); kim_identity_free (&test_identity); @@ -507,95 +507,95 @@ struct favorite_identity fids[] = { void test_kim_preferences_add_favorite_identity (kim_test_state_t state) { kim_error err = KIM_NO_ERROR; - + start_test (state, "kim_preferences_add_favorite_identity"); - + if (!err) { kim_preferences prefs = NULL; kim_options options = NULL; kim_count i; - + err = kim_preferences_create (&prefs); - fail_if_error (state, "kim_preferences_create", err, + fail_if_error (state, "kim_preferences_create", err, "while creating preferences"); - + if (!err) { err = kim_preferences_remove_all_favorite_identities (prefs); - fail_if_error (state, "kim_preferences_remove_all_favorite_identities", err, + fail_if_error (state, "kim_preferences_remove_all_favorite_identities", err, "while removing all favorite identities"); } - + if (!err) { err = kim_options_create (&options); - fail_if_error (state, "kim_options_create", err, + fail_if_error (state, "kim_options_create", err, "while creating options"); - } - + } + for (i = 0; !err && fids[i].identity; i++) { kim_identity identity = NULL; - + err = kim_identity_create_from_string (&identity, fids[i].identity); - fail_if_error (state, "kim_identity_create_from_string", err, - "while creating the identity for %s", + fail_if_error (state, "kim_identity_create_from_string", err, + "while creating the identity for %s", fids[i].identity); - + if (!err) { err = kim_options_set_lifetime (options, fids[i].lifetime); - fail_if_error (state, "kim_options_set_lifetime", err, - "while setting the lifetime to %d", - (int) fids[i].lifetime); + fail_if_error (state, "kim_options_set_lifetime", err, + "while setting the lifetime to %d", + (int) fids[i].lifetime); } - + if (!err) { err = kim_options_set_renewal_lifetime (options, fids[i].renewal_lifetime); - fail_if_error (state, "kim_options_set_renewal_lifetime", err, - "while setting the renewal lifetime to %d", - (int) fids[i].renewal_lifetime); + fail_if_error (state, "kim_options_set_renewal_lifetime", err, + "while setting the renewal lifetime to %d", + (int) fids[i].renewal_lifetime); } - + if (!err) { err = kim_preferences_add_favorite_identity (prefs, identity, options); - fail_if_error (state, "kim_preferences_add_favorite_identity", err, - "while adding %s to the favorite identities", - fids[i].identity); + fail_if_error (state, "kim_preferences_add_favorite_identity", err, + "while adding %s to the favorite identities", + fids[i].identity); } - + kim_identity_free (&identity); } - + if (!err) { err = kim_preferences_synchronize (prefs); - fail_if_error (state, "kim_preferences_synchronize", err, + fail_if_error (state, "kim_preferences_synchronize", err, "while setting the favorite identities"); } - + kim_options_free (&options); kim_preferences_free (&prefs); } - + if (!err) { kim_preferences prefs = NULL; kim_count count, i; - + err = kim_preferences_create (&prefs); - fail_if_error (state, "kim_preferences_create", err, + fail_if_error (state, "kim_preferences_create", err, "while creating preferences"); - + if (!err) { err = kim_preferences_get_number_of_favorite_identities (prefs, &count); - fail_if_error (state, "kim_preferences_get_number_of_favorite_identities", err, + fail_if_error (state, "kim_preferences_get_number_of_favorite_identities", err, "while getting number of favorite identities"); } - - + + for (i = 0; !err && fids[i].identity; i++) { kim_identity identity = NULL; kim_count j; kim_boolean found = 0; - + err = kim_identity_create_from_string (&identity, fids[i].identity); - fail_if_error (state, "kim_identity_create_from_string", err, - "while creating the identity for %s", + fail_if_error (state, "kim_identity_create_from_string", err, + "while creating the identity for %s", fids[i].identity); for (j = 0; j < count; j++) { @@ -603,73 +603,73 @@ void test_kim_preferences_add_favorite_identity (kim_test_state_t state) kim_options compare_options = NULL; kim_comparison comparison; - err = kim_preferences_get_favorite_identity_at_index (prefs, j, - &compare_identity, + err = kim_preferences_get_favorite_identity_at_index (prefs, j, + &compare_identity, &compare_options); - fail_if_error (state, "kim_preferences_get_favorite_identity_at_index", err, + fail_if_error (state, "kim_preferences_get_favorite_identity_at_index", err, "while getting favorite identity %d", (int) j); - + if (!err) { - err = kim_identity_compare (identity, compare_identity, + err = kim_identity_compare (identity, compare_identity, &comparison); - fail_if_error (state, "kim_identity_compare", err, - "while comparing %s to favorite identity %d", + fail_if_error (state, "kim_identity_compare", err, + "while comparing %s to favorite identity %d", fids[i].identity, (int) i); } - + if (!err && kim_comparison_is_equal_to (comparison)) { kim_lifetime compare_lifetime; kim_lifetime compare_renewal_lifetime; - + found = 1; - + err = kim_options_get_lifetime (compare_options, &compare_lifetime); - fail_if_error (state, "kim_options_get_lifetime", err, - "while getting the lifetime for %s", - fids[i].identity); - + fail_if_error (state, "kim_options_get_lifetime", err, + "while getting the lifetime for %s", + fids[i].identity); + if (!err && fids[i].lifetime != compare_lifetime) { - log_failure (state, "Unexpected lifetime for %s (got %d, expected %d)", + log_failure (state, "Unexpected lifetime for %s (got %d, expected %d)", fids[i].identity, (int) compare_lifetime, - (int) fids[i].lifetime); + (int) fids[i].lifetime); } - + if (!err) { - err = kim_options_get_renewal_lifetime (compare_options, + err = kim_options_get_renewal_lifetime (compare_options, &compare_renewal_lifetime); - fail_if_error (state, "kim_options_get_renewal_lifetime", err, - "while getting the lifetime for %s", - fids[i].identity); + fail_if_error (state, "kim_options_get_renewal_lifetime", err, + "while getting the lifetime for %s", + fids[i].identity); } - + if (!err && fids[i].renewal_lifetime != compare_renewal_lifetime) { - log_failure (state, "Unexpected renewal lifetime for %s (got %d, expected %d)", - fids[i].identity, + log_failure (state, "Unexpected renewal lifetime for %s (got %d, expected %d)", + fids[i].identity, (int) compare_renewal_lifetime, - (int) fids[i].renewal_lifetime); + (int) fids[i].renewal_lifetime); } } - + kim_identity_free (&compare_identity); kim_options_free (&compare_options); } - + if (!err && !found) { - log_failure (state, "Favorite identity %s not found in favorite identities list", + log_failure (state, "Favorite identity %s not found in favorite identities list", fids[i].identity); } - + kim_identity_free (&identity); } - + if (!err && i != count) { - log_failure (state, "Unexpected number of favorite identities (got %d, expected %d)", + log_failure (state, "Unexpected number of favorite identities (got %d, expected %d)", (int) count, (int) i); } - + kim_preferences_free (&prefs); } - + end_test (state); } @@ -678,7 +678,7 @@ void test_kim_preferences_add_favorite_identity (kim_test_state_t state) void test_kim_preferences_remove_favorite_identity (kim_test_state_t state) { kim_error err = KIM_NO_ERROR; - + start_test (state, "kim_preferences_remove_favorite_identity"); /* * 1. Remove all favorites to start with a clean slate @@ -686,233 +686,233 @@ void test_kim_preferences_remove_favorite_identity (kim_test_state_t state) * 3. Verify added favorites * 4. Remove those favorites one by one, checking each time to make sure they were removed */ - + // Remove old and add new if (!err) { kim_preferences prefs = NULL; kim_options options = NULL; kim_count i; - + err = kim_preferences_create (&prefs); - fail_if_error (state, "kim_preferences_create", err, + fail_if_error (state, "kim_preferences_create", err, "while creating preferences"); - + if (!err) { err = kim_preferences_remove_all_favorite_identities (prefs); - fail_if_error (state, "kim_preferences_remove_all_favorite_identities", err, + fail_if_error (state, "kim_preferences_remove_all_favorite_identities", err, "while removing all favorite identities"); } - + if (!err) { err = kim_preferences_get_number_of_favorite_identities (prefs, &i); - fail_if_error (state, "kim_preferences_get_number_of_favorite_identities", err, + fail_if_error (state, "kim_preferences_get_number_of_favorite_identities", err, "while getting number of favorite identities after clearing"); - } - + } + if (!err) { err = kim_options_create (&options); - fail_if_error (state, "kim_options_create", err, + fail_if_error (state, "kim_options_create", err, "while creating options"); - } - + } + for (i = 0; !err && fids[i].identity; i++) { kim_identity identity = NULL; - + err = kim_identity_create_from_string (&identity, fids[i].identity); - fail_if_error (state, "kim_identity_create_from_string", err, - "while creating the identity for %s", + fail_if_error (state, "kim_identity_create_from_string", err, + "while creating the identity for %s", fids[i].identity); - + if (!err) { err = kim_options_set_lifetime (options, fids[i].lifetime); - fail_if_error (state, "kim_options_set_lifetime", err, - "while setting the lifetime to %d", - (int) fids[i].lifetime); + fail_if_error (state, "kim_options_set_lifetime", err, + "while setting the lifetime to %d", + (int) fids[i].lifetime); } - + if (!err) { err = kim_options_set_renewal_lifetime (options, fids[i].renewal_lifetime); - fail_if_error (state, "kim_options_set_renewal_lifetime", err, - "while setting the renewal lifetime to %d", - (int) fids[i].renewal_lifetime); + fail_if_error (state, "kim_options_set_renewal_lifetime", err, + "while setting the renewal lifetime to %d", + (int) fids[i].renewal_lifetime); } - + if (!err) { err = kim_preferences_add_favorite_identity (prefs, identity, options); - fail_if_error (state, "kim_preferences_add_favorite_identity", err, - "while adding %s to the favorite identities", - fids[i].identity); + fail_if_error (state, "kim_preferences_add_favorite_identity", err, + "while adding %s to the favorite identities", + fids[i].identity); } - + kim_identity_free (&identity); } - + if (!err) { err = kim_preferences_synchronize (prefs); - fail_if_error (state, "kim_preferences_synchronize", err, + fail_if_error (state, "kim_preferences_synchronize", err, "while setting the favorite identities"); } - + kim_options_free (&options); kim_preferences_free (&prefs); } - + // Verify add if (!err) { kim_preferences prefs = NULL; kim_count count, i; - + err = kim_preferences_create (&prefs); - fail_if_error (state, "kim_preferences_create", err, + fail_if_error (state, "kim_preferences_create", err, "while creating preferences"); - + if (!err) { err = kim_preferences_get_number_of_favorite_identities (prefs, &count); - fail_if_error (state, "kim_preferences_get_number_of_favorite_identities", err, + fail_if_error (state, "kim_preferences_get_number_of_favorite_identities", err, "while getting number of favorite identities"); } - - + + for (i = 0; !err && fids[i].identity; i++) { kim_identity identity = NULL; kim_count j; kim_boolean found = 0; - + err = kim_identity_create_from_string (&identity, fids[i].identity); - fail_if_error (state, "kim_identity_create_from_string", err, - "while creating the identity for %s", + fail_if_error (state, "kim_identity_create_from_string", err, + "while creating the identity for %s", fids[i].identity); - + for (j = 0; j < count; j++) { kim_identity compare_identity = NULL; kim_options compare_options = NULL; kim_comparison comparison; - - err = kim_preferences_get_favorite_identity_at_index (prefs, j, - &compare_identity, + + err = kim_preferences_get_favorite_identity_at_index (prefs, j, + &compare_identity, &compare_options); - fail_if_error (state, "kim_preferences_get_favorite_identity_at_index", err, + fail_if_error (state, "kim_preferences_get_favorite_identity_at_index", err, "while getting favorite identity %d", (int) j); - + if (!err) { - err = kim_identity_compare (identity, compare_identity, + err = kim_identity_compare (identity, compare_identity, &comparison); - fail_if_error (state, "kim_identity_compare", err, - "while comparing %s to favorite identity %d", + fail_if_error (state, "kim_identity_compare", err, + "while comparing %s to favorite identity %d", fids[i].identity, (int) i); } - + if (!err && kim_comparison_is_equal_to (comparison)) { kim_lifetime compare_lifetime; kim_lifetime compare_renewal_lifetime; - + found = 1; - + err = kim_options_get_lifetime (compare_options, &compare_lifetime); - fail_if_error (state, "kim_options_get_lifetime", err, - "while getting the lifetime for %s", - fids[i].identity); - + fail_if_error (state, "kim_options_get_lifetime", err, + "while getting the lifetime for %s", + fids[i].identity); + if (!err && fids[i].lifetime != compare_lifetime) { - log_failure (state, "Unexpected lifetime for %s (got %d, expected %d)", + log_failure (state, "Unexpected lifetime for %s (got %d, expected %d)", fids[i].identity, (int) compare_lifetime, - (int) fids[i].lifetime); + (int) fids[i].lifetime); } - + if (!err) { - err = kim_options_get_renewal_lifetime (compare_options, + err = kim_options_get_renewal_lifetime (compare_options, &compare_renewal_lifetime); - fail_if_error (state, "kim_options_get_renewal_lifetime", err, - "while getting the lifetime for %s", - fids[i].identity); + fail_if_error (state, "kim_options_get_renewal_lifetime", err, + "while getting the lifetime for %s", + fids[i].identity); } - + if (!err && fids[i].renewal_lifetime != compare_renewal_lifetime) { - log_failure (state, "Unexpected renewal lifetime for %s (got %d, expected %d)", - fids[i].identity, + log_failure (state, "Unexpected renewal lifetime for %s (got %d, expected %d)", + fids[i].identity, (int) compare_renewal_lifetime, - (int) fids[i].renewal_lifetime); + (int) fids[i].renewal_lifetime); } } - + kim_identity_free (&compare_identity); kim_options_free (&compare_options); } - + if (!err && !found) { - log_failure (state, "Favorite identity %s not found in favorite identities list", + log_failure (state, "Favorite identity %s not found in favorite identities list", fids[i].identity); } - + kim_identity_free (&identity); } - + if (!err && i != count) { - log_failure (state, "Unexpected number of favorite identities (got %d, expected %d)", + log_failure (state, "Unexpected number of favorite identities (got %d, expected %d)", (int) count, (int) i); } - + kim_preferences_free (&prefs); } - + // Remove one by one if (!err) { kim_preferences prefs = NULL; kim_count count, j; - + err = kim_preferences_create (&prefs); - fail_if_error (state, "kim_preferences_create", err, + fail_if_error (state, "kim_preferences_create", err, "while creating preferences"); - + if (!err) { err = kim_preferences_get_number_of_favorite_identities (prefs, &count); - fail_if_error (state, "kim_preferences_get_number_of_favorite_identities", err, + fail_if_error (state, "kim_preferences_get_number_of_favorite_identities", err, "while getting number of favorite identities"); } - + for (j = 0; j < count; j++) { kim_identity compare_identity = NULL; kim_options compare_options = NULL; kim_string string = NULL; - - err = kim_preferences_get_favorite_identity_at_index (prefs, 0, - &compare_identity, + + err = kim_preferences_get_favorite_identity_at_index (prefs, 0, + &compare_identity, &compare_options); - fail_if_error (state, "kim_preferences_get_favorite_identity_at_index", err, + fail_if_error (state, "kim_preferences_get_favorite_identity_at_index", err, "while getting favorite identity %d", (int) j); - + if (!err) { err = kim_identity_get_display_string(compare_identity, &string); - fail_if_error (state, "kim_identity_get_display_string", err, + fail_if_error (state, "kim_identity_get_display_string", err, "while getting the display string for identity %d", (int) j); } - + if (!err) { err = kim_preferences_remove_favorite_identity(prefs, compare_identity); - fail_if_error (state, "kim_preferences_remove_favorite_identity", err, + fail_if_error (state, "kim_preferences_remove_favorite_identity", err, "while removing favorite identity %d \"%s\"", (int) j, string); } if (!err) { err = kim_preferences_synchronize (prefs); - fail_if_error (state, "kim_preferences_synchronize", err, + fail_if_error (state, "kim_preferences_synchronize", err, "while removing favorite %qu: %s", j, string); } - + if (!err && favorites_contains_identity(state, compare_identity)) { kim_string display_string = NULL; kim_identity_get_display_string(compare_identity, &display_string); - log_failure (state, "Favorite identities still contains %s after removal", + log_failure (state, "Favorite identities still contains %s after removal", display_string); } - + kim_string_free (&string); kim_identity_free (&compare_identity); kim_options_free (&compare_options); } - + kim_preferences_free (&prefs); } - + end_test (state); } diff --git a/src/kim/test/test_kim_selection_hints.c b/src/kim/test/test_kim_selection_hints.c index 2a24a610e8..655980e268 100644 --- a/src/kim/test/test_kim_selection_hints.c +++ b/src/kim/test/test_kim_selection_hints.c @@ -51,53 +51,53 @@ void test_kim_selection_hints_set_hint (kim_test_state_t state) { kim_error err = KIM_NO_ERROR; kim_count i = 0; - + start_test (state, "test_kim_selection_hints_set_hint"); for (i = 0; !err && test_hints[i].key; i++) { kim_selection_hints hints = NULL; kim_string string = NULL; kim_comparison comparison = 0; - + printf ("."); err = kim_selection_hints_create (&hints, KSH_TEST_ID); - fail_if_error (state, "kim_selection_hints_create", err, + fail_if_error (state, "kim_selection_hints_create", err, "while creating selection hints for %s", KSH_TEST_ID); - + if (!err) { err = kim_selection_hints_set_hint (hints, test_hints[i].key, test_hints[i].hint); - fail_if_error (state, "kim_selection_hints_set_hint", - err, "while setting hint %s to %s", - test_hints[i].key, test_hints[i].hint); + fail_if_error (state, "kim_selection_hints_set_hint", + err, "while setting hint %s to %s", + test_hints[i].key, test_hints[i].hint); } - + if (!err) { err = kim_selection_hints_get_hint (hints, test_hints[i].key, &string); - fail_if_error (state, "kim_selection_hints_get_hint", + fail_if_error (state, "kim_selection_hints_get_hint", err, "while getting hint %s", test_hints[i].key); } - + if (!err) { err = kim_string_compare (test_hints[i].hint, string, &comparison); - fail_if_error (state, "kim_identity_compare", err, - "while comparing %s to %s (hint %s)", - test_hints[i].hint, + fail_if_error (state, "kim_identity_compare", err, + "while comparing %s to %s (hint %s)", + test_hints[i].hint, string ? string : "NULL", test_hints[i].key); } - + if (!err && !kim_comparison_is_equal_to (comparison)) { - log_failure (state, "Unexpected hint %s (got %s, expected %s)", - test_hints[i].key, - string ? string : "NULL", + log_failure (state, "Unexpected hint %s (got %s, expected %s)", + test_hints[i].key, + string ? string : "NULL", test_hints[i].hint); } - + kim_string_free (&string); kim_selection_hints_free (&hints); } - - end_test (state); + + end_test (state); } @@ -113,66 +113,66 @@ void test_kim_selection_hints_remember_identity (kim_test_state_t state) kim_string string = NULL; kim_identity identity = KIM_IDENTITY_ANY; kim_comparison comparison = 0; - + start_test (state, "kim_selection_hints_remember_identity"); - + if (!err) { err = kim_selection_hints_create (&hints, KSH_TEST_ID); - fail_if_error (state, "kim_selection_hints_create", err, + fail_if_error (state, "kim_selection_hints_create", err, "while creating selection hints for %s", KSH_TEST_ID); } - - for (i = 0; !err && test_hints[i].key; i++) { + + for (i = 0; !err && test_hints[i].key; i++) { err = kim_selection_hints_set_hint (hints, test_hints[i].key, test_hints[i].hint); - fail_if_error (state, "kim_selection_hints_set_hint", - err, "while setting hint %s to %s", + fail_if_error (state, "kim_selection_hints_set_hint", + err, "while setting hint %s to %s", test_hints[i].key, test_hints[i].hint); } - + if (!err) { - err = kim_identity_create_from_string (&client_identity, + err = kim_identity_create_from_string (&client_identity, KSH_IDENTITY); - fail_if_error (state, "kim_identity_create_from_string", err, - "while creating an identity for %s", + fail_if_error (state, "kim_identity_create_from_string", err, + "while creating an identity for %s", KSH_IDENTITY); } - + if (!err) { err = kim_selection_hints_remember_identity (hints, client_identity); - fail_if_error (state, "kim_selection_hints_remember_identity", - err, "while remembering identity %s", + fail_if_error (state, "kim_selection_hints_remember_identity", + err, "while remembering identity %s", KSH_IDENTITY); } - + if (!err) { err = kim_selection_hints_get_identity (hints, &identity); - fail_if_error (state, "kim_selection_hints_get_identity", - err, "while checking if identity is %s", + fail_if_error (state, "kim_selection_hints_get_identity", + err, "while checking if identity is %s", KSH_IDENTITY); } - + if (!err && identity) { err = kim_identity_get_string (identity, &string); - fail_if_error (state, "kim_identity_get_string", err, + fail_if_error (state, "kim_identity_get_string", err, "while getting the string for the client identity hint"); } - + if (!err) { err = kim_identity_compare (client_identity, identity, &comparison); - fail_if_error (state, "kim_identity_compare", err, - "while comparing %s to the identity hint %s", + fail_if_error (state, "kim_identity_compare", err, + "while comparing %s to the identity hint %s", KSH_IDENTITY, string ? string : "NULL"); } - + if (!err && !kim_comparison_is_equal_to (comparison)) { - log_failure (state, "Unexpected client identity hint (got %s, expected %s)", + log_failure (state, "Unexpected client identity hint (got %s, expected %s)", string ? string : "NULL", KSH_IDENTITY); } - + kim_string_free (&string); kim_identity_free (&identity); kim_identity_free (&client_identity); kim_selection_hints_free (&hints); - + end_test (state); } diff --git a/src/kim/test/test_kll.c b/src/kim/test/test_kll.c index d1773ae30f..e0261480c0 100644 --- a/src/kim/test/test_kll.c +++ b/src/kim/test/test_kll.c @@ -21,10 +21,10 @@ int main(void) KLTime t; KLStatus err; KLPrincipal principal; - + /* force use of UI */ - fclose (stdin); - + fclose (stdin); + err = KLCreatePrincipalFromTriplet ("nobody", "", "TEST-KERBEROS-1.3.1", &principal); printf ("KLCreatePrincipalFromTriplet(nobody@TEST-KERBEROS-1.3.1) (err = %d)\n", err); if (err == klNoErr) { @@ -32,58 +32,58 @@ int main(void) printf ("KLChangePassword() (err = %d)\n", err); KLDisposePrincipal (principal); } - + err = KLLastChangedTime(&t); printf ("KLLastChangedTime returned %d (err = %d)\n", t, err); - + TestKLPrincipal (); TestLoginOptions (); TestApplicationOptions (); TestErrorHandling (); TestKerberosRealms (); TestHighLevelAPI (); - + err = KLLastChangedTime(&t); printf ("KLLastChangedTime returned %d (err = %d)\n", t, err); - - return 0; + + return 0; } void TestErrorHandling (void) { long err; char* errorString; - + err = KLGetErrorString (KRB5KRB_AP_ERR_BAD_INTEGRITY, &errorString); printf ("KLGetErrorString() returned %s (err = %ld)\n", errorString, err); if (!err) { KLDisposeString (errorString); } - + err = KLGetErrorString (klCredentialsBadAddressErr, &errorString); - printf ("KLGetErrorString() returned %s (err = %ld)\n", errorString, err); + printf ("KLGetErrorString() returned %s (err = %ld)\n", errorString, err); if (!err) { KLDisposeString (errorString); } - + err = KLGetErrorString (klCacheDoesNotExistErr, &errorString); - printf ("KLGetErrorString() returned %s (err = %ld)\n", errorString, err); + printf ("KLGetErrorString() returned %s (err = %ld)\n", errorString, err); if (!err) { KLDisposeString (errorString); } - + err = KLGetErrorString (klPasswordMismatchErr, &errorString); - printf ("KLGetErrorString() returned %s (err = %ld)\n", errorString, err); + printf ("KLGetErrorString() returned %s (err = %ld)\n", errorString, err); if (!err) { KLDisposeString (errorString); } - + err = KLGetErrorString (klInsecurePasswordErr, &errorString); - printf ("KLGetErrorString() returned %s (err = %ld)\n", errorString, err); + printf ("KLGetErrorString() returned %s (err = %ld)\n", errorString, err); if (!err) { KLDisposeString (errorString); } - + err = KLGetErrorString (klPasswordChangeFailedErr, &errorString); - printf ("KLGetErrorString() returned %s (err = %ld)\n", errorString, err); + printf ("KLGetErrorString() returned %s (err = %ld)\n", errorString, err); if (!err) { KLDisposeString (errorString); } - + err = KLGetErrorString (klCantContactServerErr, &errorString); - printf ("KLGetErrorString() returned %s (err = %ld)\n", errorString, err); + printf ("KLGetErrorString() returned %s (err = %ld)\n", errorString, err); if (!err) { KLDisposeString (errorString); } - + err = KLGetErrorString (klCantDisplayUIErr, &errorString); - printf ("KLGetErrorString() returned %s (err = %ld)\n", errorString, err); + printf ("KLGetErrorString() returned %s (err = %ld)\n", errorString, err); if (!err) { KLDisposeString (errorString); } } @@ -96,7 +96,7 @@ void TestHighLevelAPI (void) char* principalString; char timeString[256]; KLBoolean valid; - + err = KLCreatePrincipalFromTriplet ("grail", "", "TESTV5-KERBEROS-1.3.1", &inPrincipal); printf ("KLCreatePrincipalFromTriplet(grail@TESTV5-KERBEROS-1.3.1) (err = %d)\n", err); if (err == klNoErr) { @@ -109,7 +109,7 @@ void TestHighLevelAPI (void) } KLDisposePrincipal (inPrincipal); } - + err = KLCreatePrincipalFromTriplet ("nobody", "", "TEST-KERBEROS-1.3.1", &inPrincipal); printf ("KLCreatePrincipalFromTriplet(nobody@TEST-KERBEROS-1.3.1) (err = %d)\n", err); if (err == klNoErr) { @@ -122,7 +122,7 @@ void TestHighLevelAPI (void) } KLDisposePrincipal (inPrincipal); } - + err = KLAcquireNewInitialTickets (NULL, NULL, &inPrincipal, &outCredCacheName); printf ("KLAcquireNewInitialTickets() (err = %d)\n", err); if (err == klNoErr) { @@ -135,21 +135,21 @@ void TestHighLevelAPI (void) } KLDisposePrincipal (inPrincipal); } - + err = KLSetDefaultLoginOption (loginOption_LoginName, "testname", 3); printf ("KLSetDefaultLoginOption(loginOption_LoginName) to testname (err = %d)\n", err); if (err == klNoErr) { err = KLSetDefaultLoginOption (loginOption_LoginInstance, "testinstance", 6); printf ("KLSetDefaultLoginOption(loginOption_LoginInstance) to testinstance (err = %d)\n", err); } - + err = KLAcquireNewInitialTickets (NULL, NULL, &inPrincipal, &outCredCacheName); printf ("KLAcquireNewInitialTickets() (err = %d)\n", err); if (err == klNoErr) { KLDisposeString (outCredCacheName); KLDisposePrincipal (inPrincipal); } - + // Principal == NULL while (KLAcquireNewInitialTickets (NULL, NULL, &outPrincipal, &outCredCacheName) == klNoErr) { err = KLTicketExpirationTime (outPrincipal, kerberosVersion_All, &expirationTime); @@ -171,14 +171,14 @@ void TestHighLevelAPI (void) KLDisposeString (outCredCacheName); KLDisposePrincipal (outPrincipal); } - + err = KLAcquireNewInitialTickets (NULL, NULL, &outPrincipal, &outCredCacheName); if (err == klNoErr) { KLDisposeString (outCredCacheName); KLDisposePrincipal (outPrincipal); } - - + + err = KLCreatePrincipalFromTriplet ("nobody", "", "TEST-KERBEROS-1.3.1", &inPrincipal); printf ("KLCreatePrincipalFromTriplet(nobody@TEST-KERBEROS-1.3.1) (err = %d)\n", err); if (err == klNoErr) { @@ -189,10 +189,10 @@ void TestHighLevelAPI (void) KLDisposePrincipal (outPrincipal); } err = KLDestroyTickets (inPrincipal); - + KLDisposePrincipal (inPrincipal); } - + err = KLCreatePrincipalFromTriplet ("nobody", "", "TEST-KERBEROS-1.3.1", &inPrincipal); printf ("KLCreatePrincipalFromTriplet(nobody@TEST-KERBEROS-1.3.1) (err = %d)\n", err); if (err == klNoErr) { @@ -202,7 +202,7 @@ void TestHighLevelAPI (void) KLDisposeString (outCredCacheName); KLDisposePrincipal (outPrincipal); } - + err = KLAcquireNewInitialTickets (inPrincipal, NULL, &outPrincipal, &outCredCacheName); if (err == klNoErr) { err = KLGetStringFromPrincipal (outPrincipal, kerberosVersion_V5, &principalString); @@ -210,22 +210,22 @@ void TestHighLevelAPI (void) err = KLTicketExpirationTime (outPrincipal, kerberosVersion_All, &expirationTime); printf ("Tickets for principal '%s' expire on %s\n", principalString, TimeToString(timeString, expirationTime)); - + KLDisposeString (principalString); } KLDisposeString (outCredCacheName); KLDisposePrincipal (outPrincipal); } - + err = KLChangePassword (inPrincipal); printf ("KLChangePassword() (err = %d)\n", err); - + err = KLDestroyTickets (inPrincipal); printf ("KLDestroyTickets() (err = %d)\n", err); - + KLDisposePrincipal (inPrincipal); } - + } @@ -241,22 +241,22 @@ void TestKLPrincipal (void) char *user = NULL; char *instance = NULL; char *realm = NULL; - + printf ("Entering TestKLPrincipal()\n"); printf ("----------------------------------------------------------------\n"); - + err = KLCreatePrincipalFromString ("thisprincipalnameislongerthanissupportedbyKerberos4@TEST-KERBEROS-1.3.1", kerberosVersion_V5, &extraLongPrincipal); printf ("KLCreatePrincipalFromString " "('thisprincipalnameislongerthanissupportedbyKerberos4@TEST-KERBEROS-1.3.1') " "(err = %s)\n", error_message(err)); - + printf ("----------------------------------------------------------------\n"); - + err = KLCreatePrincipalFromTriplet ("nobody", "", "TEST-KERBEROS-1.3.1", &principal); printf ("KLCreatePrincipalFromTriplet ('nobody' '' 'TEST-KERBEROS-1.3.1') (err = %s)\n", error_message(err)); - + if (err == klNoErr) { err = KLGetStringFromPrincipal (principal, kerberosVersion_V5, &principalString); if (err == klNoErr) { @@ -265,7 +265,7 @@ void TestKLPrincipal (void) } else { printf ("KLGetStringFromPrincipal(nobody@TEST-KERBEROS-1.3.1, v5) returned (err = %s)\n", error_message(err)); } - + err = KLGetStringFromPrincipal (principal, kerberosVersion_V4, &principalString); if (err == klNoErr) { printf ("KLGetStringFromPrincipal (nobody@TEST-KERBEROS-1.3.1, v4) returned string '%s'\n", principalString); @@ -273,7 +273,7 @@ void TestKLPrincipal (void) } else { printf ("KLGetStringFromPrincipal(nobody@TEST-KERBEROS-1.3.1, v4) returned (err = %s)\n", error_message(err)); } - + err = KLGetTripletFromPrincipal (principal, &user, &instance, &realm); if (err == klNoErr) { printf ("KLGetTripletFromPrincipal (nobody@TEST-KERBEROS-1.3.1) returned triplet %s' '%s' '%s'\n", @@ -283,14 +283,14 @@ void TestKLPrincipal (void) KLDisposeString (realm); } else { printf ("KLGetTripletFromPrincipal(nobody@TEST-KERBEROS-1.3.1) returned (err = %s)\n", error_message(err)); - } + } } - + printf ("----------------------------------------------------------------\n"); - + err = KLCreatePrincipalFromTriplet ("nobody", "admin", "TEST-KERBEROS-1.3.1", &adminPrincipal); printf ("KLCreatePrincipalFromTriplet ('nobody' 'admin' 'TEST-KERBEROS-1.3.1') (err = %d)\n", err); - + if (err == klNoErr) { err = KLGetStringFromPrincipal (adminPrincipal, kerberosVersion_V5, &principalString); if (err == klNoErr) { @@ -299,7 +299,7 @@ void TestKLPrincipal (void) } else { printf ("KLGetStringFromPrincipal(nobody/admin@TEST-KERBEROS-1.3.1, v5) returned (err = %d)\n", err); } - + err = KLGetStringFromPrincipal (adminPrincipal, kerberosVersion_V4, &principalString); if (err == klNoErr) { printf ("KLGetStringFromPrincipal (nobody/admin@TEST-KERBEROS-1.3.1, v4) returned string '%s'\n", principalString); @@ -307,7 +307,7 @@ void TestKLPrincipal (void) } else { printf ("KLGetStringFromPrincipal(nobody/admin@TEST-KERBEROS-1.3.1, v4) returned (err = %d)\n", err); } - + err = KLGetTripletFromPrincipal (adminPrincipal, &user, &instance, &realm); if (err == klNoErr) { printf ("KLGetTripletFromPrincipal (nobody/admin@TEST-KERBEROS-1.3.1) returned triplet %s' '%s' '%s'\n", @@ -319,9 +319,9 @@ void TestKLPrincipal (void) printf ("KLGetTripletFromPrincipal(lxs/admin@TEST-KERBEROS-1.3.1) returned (err = %d)\n", err); } } - + printf ("----------------------------------------------------------------\n"); - + err = KLCreatePrincipalFromString ("nobody/root@TEST-KERBEROS-1.3.1", kerberosVersion_V5, &adminPrincipalV5); printf ("KLCreatePrincipalFromString ('nobody/root@TEST-KERBEROS-1.3.1', v5) (err = %d)\n", err); if (err == klNoErr) { @@ -332,7 +332,7 @@ void TestKLPrincipal (void) } else { printf ("KLGetStringFromPrincipal(nobody/root@TEST-KERBEROS-1.3.1, v5) returned (err = %d)\n", err); } - + err = KLGetStringFromPrincipal (adminPrincipalV5, kerberosVersion_V4, &principalString); if (err == klNoErr) { printf ("KLGetStringFromPrincipal (nobody/admin@TEST-KERBEROS-1.3.1, v4) returned string '%s'\n", principalString); @@ -340,7 +340,7 @@ void TestKLPrincipal (void) } else { printf ("KLGetStringFromPrincipal(nobody/admin@TEST-KERBEROS-1.3.1, v4) returned (err = %d)\n", err); } - + err = KLGetTripletFromPrincipal (adminPrincipalV5, &user, &instance, &realm); if (err == klNoErr) { printf ("KLGetTripletFromPrincipal (nobody/admin@TEST-KERBEROS-1.3.1) returned triplet %s' '%s' '%s'\n", @@ -352,9 +352,9 @@ void TestKLPrincipal (void) printf ("KLGetTripletFromPrincipal(nobody/admin@TEST-KERBEROS-1.3.1) returned (err = %d)\n", err); } } - + printf ("----------------------------------------------------------------\n"); - + err = KLCreatePrincipalFromString ("nobody.admin@TEST-KERBEROS-1.3.1", kerberosVersion_V4, &adminPrincipalV4); printf ("KLCreatePrincipalFromString ('nobody.admin@TEST-KERBEROS-1.3.1') (err = %d)\n", err); if (err == klNoErr) { @@ -365,7 +365,7 @@ void TestKLPrincipal (void) } else { printf ("KLGetStringFromPrincipal(nobody.admin@TEST-KERBEROS-1.3.1, v5) returned (err = %d)\n", err); } - + err = KLGetStringFromPrincipal (adminPrincipalV4, kerberosVersion_V4, &principalString); if (err == klNoErr) { printf ("KLGetStringFromPrincipal (nobody.admin@TEST-KERBEROS-1.3.1, v4) returned string '%s'\n", principalString); @@ -373,7 +373,7 @@ void TestKLPrincipal (void) } else { printf ("KLGetStringFromPrincipal(nobody.admin@TEST-KERBEROS-1.3.1, v4) returned (err = %d)\n", err); } - + err = KLGetTripletFromPrincipal (adminPrincipalV4, &user, &instance, &realm); if (err == klNoErr) { printf ("KLGetTripletFromPrincipal (nobody.admin@TEST-KERBEROS-1.3.1) returned triplet %s' '%s' '%s'\n", @@ -385,12 +385,12 @@ void TestKLPrincipal (void) printf ("KLGetTripletFromPrincipal(nobody.admin@TEST-KERBEROS-1.3.1) returned (err = %d)\n", err); } } - + printf ("----------------------------------------------------------------\n"); - + if (adminPrincipalV4 != NULL && adminPrincipalV5 != NULL) { KLBoolean equivalent; - + err = KLComparePrincipal (adminPrincipalV5, adminPrincipalV4, &equivalent); if (err == klNoErr) { printf ("KLComparePrincipal %s comparing nobody/admin@TEST-KERBEROS-1.3.1 and nobody.admin@TEST-KERBEROS-1.3.1\n", @@ -399,10 +399,10 @@ void TestKLPrincipal (void) printf ("KLComparePrincipal returned (err = %d)\n", err); } } - + if (principal != NULL && adminPrincipalV5 != NULL) { KLBoolean equivalent; - + err = KLComparePrincipal (principal, adminPrincipalV4, &equivalent); if (err == klNoErr) { printf ("KLComparePrincipal %s comparing nobody@TEST-KERBEROS-1.3.1 and nobody.admin@TEST-KERBEROS-1.3.1\n", @@ -411,10 +411,10 @@ void TestKLPrincipal (void) printf ("KLComparePrincipal returned (err = %d)\n", err); } } - + if (principal != NULL && adminPrincipalV5 != NULL) { KLBoolean equivalent; - + err = KLComparePrincipal (principal, adminPrincipalV5, &equivalent); if (err == klNoErr) { printf ("KLComparePrincipal %s comparing nobody@TEST-KERBEROS-1.3.1 and nobody/admin@TEST-KERBEROS-1.3.1\n", @@ -423,10 +423,10 @@ void TestKLPrincipal (void) printf ("KLComparePrincipal returned (err = %d)\n", err); } } - + if (adminPrincipal != NULL && adminPrincipalV5 != NULL) { KLBoolean equivalent; - + err = KLComparePrincipal (adminPrincipalV5, principal, &equivalent); if (err == klNoErr) { printf ("KLComparePrincipal %s comparing nobody/admin@TEST-KERBEROS-1.3.1 and nobody@TEST-KERBEROS-1.3.1\n", @@ -435,9 +435,9 @@ void TestKLPrincipal (void) printf ("KLComparePrincipal returned (err = %d)\n", err); } } - + printf ("----------------------------------------------------------------\n\n"); - + if (extraLongPrincipal != NULL) KLDisposePrincipal (extraLongPrincipal); if (adminPrincipalV5 != NULL) KLDisposePrincipal (adminPrincipalV5); if (adminPrincipalV4 != NULL) KLDisposePrincipal (adminPrincipalV4); @@ -456,24 +456,24 @@ void TestKerberosRealms (void) printf ("About to test Kerberos realms\n"); KLRemoveAllKerberosRealms (); KLAcquireNewInitialTickets (NULL, NULL, NULL, NULL); - + KLInsertKerberosRealm (realmList_End, "FOO"); KLInsertKerberosRealm (realmList_End, "BAR"); KLInsertKerberosRealm (realmList_End, "BAZ"); KLAcquireNewInitialTickets (NULL, NULL, NULL, NULL); - + KLInsertKerberosRealm (realmList_End, "FOO"); KLAcquireNewInitialTickets (NULL, NULL, NULL, NULL); - + KLSetKerberosRealm (0, "QUUX"); KLAcquireNewInitialTickets (NULL, NULL, NULL, NULL); - + KLRemoveKerberosRealm (0); KLAcquireNewInitialTickets (NULL, NULL, NULL, NULL); - + KLSetKerberosRealm (2, "TEST-KERBEROS-1.3.1"); KLAcquireNewInitialTickets (NULL, NULL, NULL, NULL); - + KLRemoveAllKerberosRealms (); KLInsertKerberosRealm (realmList_End, "TEST-KERBEROS-1.3.1"); KLInsertKerberosRealm (realmList_End, "TEST-KERBEROS-1.0.6"); @@ -485,7 +485,7 @@ void TestKerberosRealms (void) KLInsertKerberosRealm (realmList_End, "TEST-HEIMDAL-0.3D"); KLInsertKerberosRealm (realmList_End, "TESTV5-HEIMDAL-0.3D"); KLInsertKerberosRealm (realmList_End, "TEST-KTH-KRB-1.1"); -} +} void TestLoginOptions (void) @@ -493,25 +493,25 @@ void TestLoginOptions (void) KLBoolean optionSetting; KLStatus err = klNoErr; KLLifetime lifetime; - + lifetime = 10*60; KLSetDefaultLoginOption(loginOption_MinimalTicketLifetime, &lifetime, sizeof(KLLifetime)); - + lifetime = 8*60*60; KLSetDefaultLoginOption(loginOption_MaximalTicketLifetime, &lifetime, sizeof(KLLifetime)); - + lifetime = 8*60*60; KLSetDefaultLoginOption(loginOption_DefaultTicketLifetime, &lifetime, sizeof(KLLifetime)); - + optionSetting = FALSE; KLSetDefaultLoginOption(loginOption_DefaultForwardableTicket, &optionSetting, sizeof(optionSetting)); - + optionSetting = TRUE; KLSetDefaultLoginOption(loginOption_RememberPrincipal, &optionSetting, sizeof(optionSetting)); - + optionSetting = TRUE; err = KLSetDefaultLoginOption(loginOption_RememberExtras, &optionSetting, sizeof(optionSetting)); - + if (err == klNoErr) { KLAcquireNewInitialTickets (NULL, NULL, NULL, NULL); optionSetting = TRUE; @@ -532,9 +532,9 @@ char* TimeToString (char* timeString, long t) /* we come in in 1970 time */ time_t timer = (time_t) t; struct tm tm; - + tm = *localtime (&timer); - + sprintf(timeString, "%.3s %.3s%3d %.2d:%.2d:%.2d %d", day_name[tm.tm_wday], month_name[tm.tm_mon], @@ -543,7 +543,7 @@ char* TimeToString (char* timeString, long t) tm.tm_min, tm.tm_sec, tm.tm_year + 1900); - + return timeString; } @@ -553,4 +553,3 @@ void MyKerberosLoginIdleCallback (KLRefCon inAppData) syslog (LOG_ALERT, "App got callback while waiting for Mach IPC (appData == %d)\n", inAppData); // KLCancelAllDialogs (); } - diff --git a/src/kim/test/test_kll_terminal.c b/src/kim/test/test_kll_terminal.c index 9c22625bf6..20a5e7898c 100644 --- a/src/kim/test/test_kll_terminal.c +++ b/src/kim/test/test_kll_terminal.c @@ -2,13 +2,13 @@ -int main (void) +int main (void) { KLStatus err; KLPrincipal principal; char *principalName; char *cacheName; - + printf ("Testing KLAcquireNewTickets (nil)...\n"); err = KLAcquireNewTickets (nil, &principal, &cacheName); @@ -18,22 +18,22 @@ int main (void) printf ("Got tickets for '%s' in cache '%s'\n", principalName, cacheName); KLDisposeString (principalName); } else { - printf ("KLGetStringFromPrincipal() returned (err = %ld)\n", err); + printf ("KLGetStringFromPrincipal() returned (err = %ld)\n", err); } KLDisposeString (cacheName); - + printf ("Testing KLChangePassword (principal)...\n"); - + err = KLChangePassword (principal); if (err != klNoErr) { printf ("KLChangePassword() returned (err = %ld)\n", err); } - + KLDisposePrincipal (principal); } else { printf ("KLAcquireNewTickets() returned (err = %ld)\n", err); } - - printf ("All done testing!\n"); - return 0; -}
\ No newline at end of file + + printf ("All done testing!\n"); + return 0; +} diff --git a/src/kim/test/test_ui_plugin.c b/src/kim/test/test_ui_plugin.c index 9a6e3761d9..a37fa7f839 100644 --- a/src/kim/test/test_ui_plugin.c +++ b/src/kim/test/test_ui_plugin.c @@ -43,18 +43,18 @@ const char *magic = "test_ui_context_magic"; /* ------------------------------------------------------------------------ */ static void test_ui_vlog (test_ui_context in_context, - const char *in_format, + const char *in_format, va_list in_args) { if (!in_context) { asl_log (NULL, NULL, ASL_LEVEL_ERR, "NULL context!"); - + } else if (strcmp (in_context->magic, magic)) { - asl_log (NULL, NULL, ASL_LEVEL_ERR, + asl_log (NULL, NULL, ASL_LEVEL_ERR, "Magic mismatch. Context corrupted!"); - + } else { - asl_vlog (in_context->asl_context, NULL, ASL_LEVEL_NOTICE, + asl_vlog (in_context->asl_context, NULL, ASL_LEVEL_NOTICE, in_format, in_args); } } @@ -62,19 +62,19 @@ static void test_ui_vlog (test_ui_context in_context, /* ------------------------------------------------------------------------ */ static void test_ui_log_ (void *in_context, - const char *in_function, + const char *in_function, const char *in_format, ...) { test_ui_context context = in_context; char *format = NULL; va_list args; - + asprintf (&format, "%s: %s", in_function, in_format); - - va_start (args, in_format); + + va_start (args, in_format); test_ui_vlog (context, format, args); va_end (args); - + free (format); } @@ -88,38 +88,38 @@ static kim_error test_ui_init (void **out_context) { kim_error err = KIM_NO_ERROR; test_ui_context context = NULL; - + if (!err) { context = malloc (sizeof (*context)); if (!context) { err = KIM_OUT_OF_MEMORY_ERR; } - } - + } + if (!err) { context->got_error = 0; context->magic = magic; - context->asl_context = asl_open (NULL, - "com.apple.console", + context->asl_context = asl_open (NULL, + "com.apple.console", ASL_OPT_NO_DELAY | ASL_OPT_STDERR); if (!context->asl_context) { err = KIM_OUT_OF_MEMORY_ERR; } } - + if (!err) { test_ui_log (context, "returning with no error."); } else { kim_string estring = NULL; - + kim_string_create_for_last_error (&estring, err); test_ui_log (NULL, "returning %d: %s", err, estring); kim_string_free (&estring); } - - if (!err) { + + if (!err) { *out_context = context; context = NULL; } - + free (context); - + return err; } @@ -132,9 +132,9 @@ static kim_error test_ui_enter_identity (void *in_context, { kim_error err = KIM_NO_ERROR; kim_identity identity = NULL; - + test_ui_log (in_context, "entering..."); - + if (!err) { test_ui_context context = in_context; if (context->got_error > 1) { @@ -143,39 +143,39 @@ static kim_error test_ui_enter_identity (void *in_context, err = KIM_USER_CANCELED_ERR; } } - + if (!err) { err = kim_options_set_lifetime (io_options, 1800); } - + if (!err) { err = kim_options_set_renewal_lifetime (io_options, 3600); } - + if (!err) { err = kim_identity_create_from_string (&identity, "nobody@TEST-KERBEROS-1.5"); } - + if (!err) { *out_identity = identity; identity = NULL; *out_change_password = 0; } - + kim_identity_free (&identity); - + if (!err) { test_ui_log (in_context, "returning with no error."); } else { kim_string estring = NULL; - + kim_string_create_for_last_error (&estring, err); test_ui_log (in_context, "returning %d: %s", err, estring); kim_string_free (&estring); } - - return err; + + return err; } /* ------------------------------------------------------------------------ */ @@ -188,9 +188,9 @@ static kim_error test_ui_select_identity (void *in_context, kim_error err = KIM_NO_ERROR; kim_identity identity = NULL; kim_options options = NULL; - + test_ui_log (in_context, "entering..."); - + if (!err) { test_ui_context context = in_context; if (context->got_error > 1) { @@ -199,61 +199,61 @@ static kim_error test_ui_select_identity (void *in_context, err = KIM_USER_CANCELED_ERR; } } - + if (!err) { err = kim_selection_hints_get_options (io_hints, &options); } - + if (!err && !options) { err = kim_options_create (&options); } - + if (!err) { err = kim_options_set_lifetime (options, 1800); } - + if (!err) { err = kim_options_set_renewal_lifetime (options, 3600); } - + if (!err) { err = kim_selection_hints_set_options (io_hints, options); } - + if (!err) { err = kim_identity_create_from_string (&identity, "nobody@TEST-KERBEROS-1.5"); } - + if (!err) { *out_identity = identity; identity = NULL; *out_change_password = 0; } - + kim_options_free (&options); kim_identity_free (&identity); - + if (!err) { test_ui_log (in_context, "returning with no error."); } else { kim_string estring = NULL; - + kim_string_create_for_last_error (&estring, err); test_ui_log (in_context, "returning %d: %s", err, estring); kim_string_free (&estring); } - - return err; -} + + return err; +} /* ------------------------------------------------------------------------ */ static kim_error test_ui_auth_prompt (void *in_context, kim_identity in_identity, kim_prompt_type in_type, - kim_boolean in_allow_save_reply, - kim_boolean in_hide_reply, + kim_boolean in_allow_save_reply, + kim_boolean in_hide_reply, kim_string in_title, kim_string in_message, kim_string in_description, @@ -263,13 +263,13 @@ static kim_error test_ui_auth_prompt (void *in_context, kim_error err = KIM_NO_ERROR; kim_string string = NULL; char *reply = NULL; - + test_ui_log (in_context, "entering..."); - + if (!err) { err = kim_identity_get_display_string (in_identity, &string); } - + if (!err) { test_ui_log (in_context, "\tidentity = %s", string); test_ui_log (in_context, "\ttype = %d", in_type); @@ -278,11 +278,11 @@ static kim_error test_ui_auth_prompt (void *in_context, test_ui_log (in_context, "\ttitle = %s", in_title); test_ui_log (in_context, "\tmessage = %s", in_message); test_ui_log (in_context, "\tdescription = %s", in_description); - + reply = strdup ("ydobon"); if (!reply) { err = KIM_OUT_OF_MEMORY_ERR; } } - + if (!err) { test_ui_context context = in_context; if (context->got_error > 1) { @@ -291,26 +291,26 @@ static kim_error test_ui_auth_prompt (void *in_context, err = KIM_USER_CANCELED_ERR; } } - + if (!err) { *out_reply = reply; reply = NULL; *out_save_reply = 0; } - + free (reply); kim_string_free (&string); - + if (!err) { test_ui_log (in_context, "returning with no error."); } else { kim_string estring = NULL; - + kim_string_create_for_last_error (&estring, err); test_ui_log (in_context, "returning %d: %s", err, estring); kim_string_free (&estring); } - + return err; } @@ -328,26 +328,26 @@ static kim_error test_ui_change_password (void *in_context, char *old_password = NULL; char *new_password = NULL; char *vfy_password = NULL; - + test_ui_log (in_context, "entering..."); - + if (!err) { err = kim_identity_get_display_string (in_identity, &string); } - + if (!err) { test_ui_log (in_context, "\tidentity = %s", string); - test_ui_log (in_context, "\told_password_expired = %d", + test_ui_log (in_context, "\told_password_expired = %d", in_old_password_expired); old_password = strdup ("ydobon"); new_password = strdup ("foo"); vfy_password = strdup ("foo"); - if (!old_password || !new_password || !vfy_password) { - err = KIM_OUT_OF_MEMORY_ERR; + if (!old_password || !new_password || !vfy_password) { + err = KIM_OUT_OF_MEMORY_ERR; } } - + if (!err) { test_ui_context context = in_context; if (context->got_error > 1) { @@ -365,22 +365,22 @@ static kim_error test_ui_change_password (void *in_context, *out_verify_password = vfy_password; vfy_password = NULL; } - + free (old_password); free (new_password); free (vfy_password); kim_string_free (&string); - + if (!err) { test_ui_log (in_context, "returning with no error."); } else { kim_string estring = NULL; - + kim_string_create_for_last_error (&estring, err); test_ui_log (in_context, "returning %d: %s", err, estring); kim_string_free (&estring); } - + return err; } @@ -394,13 +394,13 @@ static kim_error test_ui_handle_error (void *in_context, { kim_error err = KIM_NO_ERROR; kim_string string = NULL; - + test_ui_log (in_context, "entering..."); - + if (!err) { err = kim_identity_get_display_string (in_identity, &string); } - + if (!err) { test_ui_context context = in_context; @@ -408,22 +408,22 @@ static kim_error test_ui_handle_error (void *in_context, test_ui_log (in_context, "\terror = %d", in_error); test_ui_log (in_context, "\tmessage = %s", in_error_message); test_ui_log (in_context, "\tdescription = %s", in_error_description); - + context->got_error++; } - + kim_string_free (&string); - + if (!err) { test_ui_log (in_context, "returning with no error."); } else { kim_string estring = NULL; - + kim_string_create_for_last_error (&estring, err); test_ui_log (in_context, "returning %d: %s", err, estring); kim_string_free (&estring); } - + return err; } @@ -446,14 +446,14 @@ static kim_error test_ui_fini (void *io_context) kim_error err = KIM_NO_ERROR; test_ui_log (io_context, "deallocating..."); - + if (io_context) { test_ui_context context = io_context; - + asl_close (context->asl_context); free (context); } - + return err; } |