From: Alexandra Ellwood Date: Mon, 8 Sep 2008 21:21:51 +0000 (+0000) Subject: Use krb5 threading functions. X-Git-Tag: krb5-1.7-alpha1~442 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=fc0dacfba57436f48776458190990d49f489ca23;p=krb5.git Use krb5 threading functions. Remove use of ECODE since errors are no longer objects. Fixed bug where bundle error strings were not returned when homedir access was off. Switched to using UTF8 unconditionally. ticket: 6055 git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@20709 dc483132-0cff-0310-8789-dd5450dbe970 --- diff --git a/src/include/k5-thread.h b/src/include/k5-thread.h index ad1ad8b73..c2d4f4bf2 100644 --- a/src/include/k5-thread.h +++ b/src/include/k5-thread.h @@ -414,6 +414,7 @@ typedef enum { K5_KEY_CCAPI_REQUEST_PORT, K5_KEY_CCAPI_REPLY_STREAM, K5_KEY_CCAPI_SERVER_DIED, + K5_KEY_COM_ERR_REENTER, #endif K5_KEY_MAX } k5_key_t; diff --git a/src/include/kim/kim_library.h b/src/include/kim/kim_library.h new file mode 100644 index 000000000..104c1b391 --- /dev/null +++ b/src/include/kim/kim_library.h @@ -0,0 +1,40 @@ +/* + * Copyright 2005-2008 Massachusetts Institute of Technology. + * All Rights Reserved. + * + * Export of this software from the United States of America may + * require a specific license from the United States Government. + * It is the responsibility of any person or organization contemplating + * export to obtain such a license before exporting. + * + * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and + * distribute this software and its documentation for any purpose and + * without fee is hereby granted, provided that the above copyright + * notice appear in all copies and that both that copyright notice and + * this permission notice appear in supporting documentation, and that + * the name of M.I.T. not be used in advertising or publicity pertaining + * to distribution of the software without specific, written prior + * permission. Furthermore if you modify this software you must label + * your software as modified software and not distribute it in such a + * fashion that it might be confused with the original M.I.T. software. + * M.I.T. makes no representations about the suitability of + * this software for any purpose. It is provided "as is" without express + * or implied warranty. + */ + + +#ifndef KIM_LIBRARY_H +#define KIM_LIBRARY_H + +#include + + +kim_error kim_library_set_allow_home_directory_access (kim_boolean in_allow_access); + +kim_boolean kim_library_allow_home_directory_access (void); + +kim_error kim_library_set_allow_automatic_prompting (kim_boolean in_allow_automatic_prompting); + +kim_boolean kim_library_allow_automatic_prompting (void); + +#endif /* KIM_LIBRARY_H */ diff --git a/src/kim/agent/mac/Identities.m b/src/kim/agent/mac/Identities.m index a3c070731..f950bc13e 100644 --- a/src/kim/agent/mac/Identities.m +++ b/src/kim/agent/mac/Identities.m @@ -275,7 +275,7 @@ } } - if (err == KIM_NO_CREDENTIALS_ECODE) { + if (err == KIM_NO_CREDENTIALS_ERR) { /* ccache is empty, just ignore it */ err = KIM_NO_ERROR; } diff --git a/src/kim/lib/kim_ccache.c b/src/kim/lib/kim_ccache.c index f2b6d16d3..5831a66ad 100644 --- a/src/kim/lib/kim_ccache.c +++ b/src/kim/lib/kim_ccache.c @@ -40,14 +40,14 @@ kim_error kim_ccache_iterator_create (kim_ccache_iterator *out_ccache_iterator) kim_error err = KIM_NO_ERROR; kim_ccache_iterator ccache_iterator = NULL; - if (!err && !out_ccache_iterator) { err = param_error (1, "out_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) { *ccache_iterator = kim_ccache_iterator_initializer; } else { - err = os_error (errno); + err = KIM_OUT_OF_MEMORY_ERR; } } @@ -79,8 +79,8 @@ 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 = param_error (1, "in_ccache_iterator", "NULL"); } - if (!err && !out_ccache ) { err = param_error (2, "out_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) { krb5_error_code terr = krb5_cccol_cursor_next (in_ccache_iterator->context, @@ -140,9 +140,9 @@ static kim_error kim_ccache_create_resolve_name (kim_string *out_resolve_name, { kim_error err = KIM_NO_ERROR; - if (!err && !out_resolve_name) { err = param_error (1, "out_resolve_name", "NULL"); } - if (!err && !in_name ) { err = param_error (2, "in_name", "NULL"); } - if (!err && !in_type ) { err = param_error (2, "in_type", "NULL"); } + 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", @@ -185,11 +185,11 @@ static inline kim_error kim_ccache_allocate (kim_ccache *out_ccache) kim_error err = KIM_NO_ERROR; kim_ccache ccache = NULL; - if (!err && !out_ccache) { err = param_error (1, "out_ccache", "NULL"); } + if (!err && !out_ccache) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err) { ccache = malloc (sizeof (*ccache)); - if (!ccache) { err = os_error (errno); } + if (!ccache) { err = KIM_OUT_OF_MEMORY_ERR; } } if (!err) { @@ -213,7 +213,7 @@ kim_error kim_ccache_create_new (kim_ccache *out_ccache, kim_credential credential = NULL; kim_identity client_identity = NULL; - if (!err && !out_ccache) { err = param_error (1, "out_ccache", "NULL"); } + if (!err && !out_ccache) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err) { err = kim_credential_create_new (&credential, in_client_identity, in_options); @@ -241,8 +241,8 @@ kim_error kim_ccache_create_new_if_needed (kim_ccache *out_ccache, { kim_error err = KIM_NO_ERROR; - if (!err && !out_ccache ) { err = param_error (1, "out_ccache", "NULL"); } - if (!err && !in_client_identity) { err = param_error (2, "in_client_identity", "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) { err = kim_ccache_create_from_client_identity (out_ccache, in_client_identity); @@ -265,8 +265,8 @@ kim_error kim_ccache_create_from_client_identity (kim_ccache *out_ccache, kim_ccache_iterator iterator = NULL; kim_boolean found = FALSE; - if (!err && !out_ccache ) { err = param_error (1, "out_ccache", "NULL"); } - if (!err && !in_client_identity) { err = param_error (2, "in_client_identity", "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) { err = kim_ccache_iterator_create (&iterator); @@ -284,7 +284,7 @@ kim_error kim_ccache_create_from_client_identity (kim_ccache *out_ccache, err = kim_identity_get_display_string (in_client_identity, &string); if (!err) { - err = kim_error_set_message_for_code (KIM_NO_SUCH_PRINCIPAL_ECODE, + err = kim_error_set_message_for_code (KIM_NO_SUCH_PRINCIPAL_ERR, string); } @@ -326,7 +326,7 @@ kim_error kim_ccache_create_from_keytab (kim_ccache *out_ccache, kim_credential credential = NULL; kim_identity client_identity = NULL; - if (!err && !out_ccache) { err = param_error (1, "out_ccache", "NULL"); } + if (!err && !out_ccache) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err) { err = kim_credential_create_from_keytab (&credential, in_identity, @@ -356,7 +356,7 @@ 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 = param_error (1, "out_ccache", "NULL"); } + if (!err && !out_ccache) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err) { err = kim_ccache_allocate (&ccache); @@ -389,8 +389,8 @@ 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 = param_error (1, "out_ccache", "NULL"); } - if (!err && !in_display_name) { err = param_error (2, "in_display_name", "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); @@ -425,9 +425,9 @@ 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 = param_error (1, "out_ccache", "NULL"); } - if (!err && !in_name ) { err = param_error (2, "in_name", "NULL"); } - if (!err && !in_type ) { err = param_error (2, "in_type", "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); @@ -450,9 +450,9 @@ kim_error kim_ccache_create_from_krb5_ccache (kim_ccache *out_ccache, { kim_error err = KIM_NO_ERROR; - if (!err && !out_ccache ) { err = param_error (1, "out_ccache", "NULL"); } - if (!err && !in_krb5_ccache ) { err = param_error (2, "in_krb5_ccache", "NULL"); } - if (!err && !in_krb5_context) { err = param_error (3, "in_krb5_context", "NULL"); } + 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); @@ -473,8 +473,8 @@ kim_error kim_ccache_copy (kim_ccache *out_ccache, kim_string name = NULL; kim_string type = NULL; - if (!err && !out_ccache) { err = param_error (1, "out_ccache", "NULL"); } - if (!err && !in_ccache ) { err = param_error (2, "in_ccache", "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); @@ -504,9 +504,9 @@ kim_error kim_ccache_compare (kim_ccache in_ccache, { kim_error err = KIM_NO_ERROR; - if (!err && !in_ccache ) { err = param_error (1, "in_ccache", "NULL"); } - if (!err && !in_compare_to_ccache) { err = param_error (2, "in_compare_to_ccache", "NULL"); } - if (!err && !out_equal ) { err = param_error (3, "out_equal", "NULL"); } + 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_equal ) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err) { *out_equal = kim_ccache_k5ccaches_are_equal (in_ccache->context, @@ -527,9 +527,9 @@ 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 = param_error (1, "in_ccache", "NULL"); } - if (!err && !in_krb5_context) { err = param_error (2, "in_krb5_context", "NULL"); } - if (!err && !out_krb5_ccache) { err = param_error (2, "out_krb5_ccache", "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); @@ -553,8 +553,8 @@ kim_error kim_ccache_get_type (kim_ccache in_ccache, { kim_error err = KIM_NO_ERROR; - if (!err && !in_ccache) { err = param_error (1, "in_ccache", "NULL"); } - if (!err && !out_type ) { err = param_error (2, "out_type", "NULL"); } + 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, @@ -571,8 +571,8 @@ kim_error kim_ccache_get_name (kim_ccache in_ccache, { kim_error err = KIM_NO_ERROR; - if (!err && !in_ccache) { err = param_error (1, "in_ccache", "NULL"); } - if (!err && !out_name ) { err = param_error (2, "out_name", "NULL"); } + 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, @@ -589,8 +589,8 @@ kim_error kim_ccache_get_display_name (kim_ccache in_ccache, { kim_error err = KIM_NO_ERROR; - if (!err && !in_ccache ) { err = param_error (1, "in_ccache", "NULL"); } - if (!err && !out_display_name) { err = param_error (2, "out_display_name", "NULL"); } + 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, @@ -612,8 +612,8 @@ 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 = param_error (1, "in_ccache", "NULL"); } - if (!err && !out_client_identity) { err = param_error (2, "out_client_identity", "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, @@ -648,7 +648,7 @@ static kim_error kim_ccache_get_dominant_credential (kim_ccache in_cc kim_credential_state dominant_state = kim_credentials_state_valid; kim_credential dominant_credential = NULL; - if (!err && !in_ccache) { err = param_error (1, "in_ccache", "NULL"); } + if (!err && !in_ccache) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err) { err = kim_credential_iterator_create (&iterator, in_ccache); @@ -725,7 +725,7 @@ static kim_error kim_ccache_get_dominant_credential (kim_ccache in_cc } if (!err) { - err = kim_error_set_message_for_code (KIM_NO_CREDENTIALS_ECODE, + err = kim_error_set_message_for_code (KIM_NO_CREDENTIALS_ERR, identity_string); } @@ -764,8 +764,8 @@ kim_error kim_ccache_get_valid_credential (kim_ccache in_ccache, kim_credential_state state = kim_credentials_state_valid; kim_credential credential = NULL; - if (!err && !in_ccache ) { err = param_error (1, "in_ccache", "NULL"); } - if (!err && !out_credential) { err = param_error (2, "out_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, @@ -785,20 +785,20 @@ kim_error kim_ccache_get_valid_credential (kim_ccache in_ccache, if (!err) { if (state == kim_credentials_state_expired) { - err = kim_error_set_message_for_code (KIM_CREDENTIALS_EXPIRED_ECODE, + 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_ECODE, + 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_ECODE, + 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_ECODE, + err = kim_error_set_message_for_code (KIM_NEEDS_VALIDATION_ERR, identity_string); } } @@ -824,8 +824,8 @@ kim_error kim_ccache_get_state (kim_ccache in_ccache, { kim_error err = KIM_NO_ERROR; - if (!err && !in_ccache) { err = param_error (1, "in_ccache", "NULL"); } - if (!err && !out_state) { err = param_error (2, "out_state", "NULL"); } + 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, @@ -843,8 +843,8 @@ 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 = param_error (1, "in_ccache", "NULL"); } - if (!err && !out_start_time) { err = param_error (2, "out_start_time", "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, @@ -868,8 +868,8 @@ 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 = param_error (1, "in_ccache", "NULL"); } - if (!err && !out_expiration_time) { err = param_error (2, "out_expiration_time", "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, @@ -894,8 +894,8 @@ 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 = param_error (1, "in_ccache", "NULL"); } - if (!err && !out_renewal_expiration_time) { err = param_error (2, "out_renewal_expiration_time", "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, @@ -920,7 +920,7 @@ kim_error kim_ccache_set_default (kim_ccache io_ccache) { kim_error err = KIM_NO_ERROR; - if (!err && !io_ccache) { err = param_error (1, "io_ccache", "NULL"); } + if (!err && !io_ccache) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err) { char *environment_ccache_name = getenv ("KRB5CCNAME"); @@ -987,7 +987,7 @@ kim_error kim_ccache_set_default (kim_ccache io_ccache) err = kim_ccache_get_display_name (io_ccache, &display_name); if (!err) { - err = kim_error_set_message_for_code (KIM_CANT_BECOME_DEFAULT_ECODE, + err = kim_error_set_message_for_code (KIM_CANT_BECOME_DEFAULT_ERR, display_name); } @@ -1001,17 +1001,15 @@ kim_error kim_ccache_set_default (kim_ccache io_ccache) /* get a CCAPI ccache for this cache */ if (!err) { - err = ccapi_error (cc_initialize (&cc_context, ccapi_version_4, - NULL, NULL)); + err = cc_initialize (&cc_context, ccapi_version_4, NULL, NULL); } if (!err) { - err = ccapi_error (cc_context_open_ccache (cc_context, name, - &cc_ccache)); + err = cc_context_open_ccache (cc_context, name, &cc_ccache); } if (!err) { - err = ccapi_error (cc_ccache_set_default (cc_ccache)); + err = cc_ccache_set_default (cc_ccache); } if (cc_context) { cc_context_release (cc_context); } @@ -1037,7 +1035,7 @@ kim_error kim_ccache_verify (kim_ccache in_ccache, kim_error err = KIM_NO_ERROR; kim_credential credential = NULL; - if (!err && !in_ccache) { err = param_error (1, "in_ccache", "NULL"); } + if (!err && !in_ccache) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err) { err = kim_ccache_get_valid_credential (in_ccache, &credential); @@ -1064,7 +1062,7 @@ kim_error kim_ccache_renew (kim_ccache in_ccache, kim_credential credential = NULL; kim_identity client_identity = NULL; - if (!err && !in_ccache) { err = param_error (1, "in_ccache", "NULL"); } + if (!err && !in_ccache) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err) { err = kim_ccache_get_valid_credential (in_ccache, &credential); @@ -1097,7 +1095,7 @@ kim_error kim_ccache_validate (kim_ccache in_ccache, kim_credential credential = NULL; kim_identity client_identity = NULL; - if (!err && !in_ccache) { err = param_error (1, "in_ccache", "NULL"); } + if (!err && !in_ccache) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err) { err = kim_ccache_get_valid_credential (in_ccache, &credential); diff --git a/src/kim/lib/kim_credential.c b/src/kim/lib/kim_credential.c index 5467c497b..9952a9c72 100644 --- a/src/kim/lib/kim_credential.c +++ b/src/kim/lib/kim_credential.c @@ -43,15 +43,15 @@ kim_error kim_credential_iterator_create (kim_credential_iterator *out_credentia kim_error err = KIM_NO_ERROR; kim_credential_iterator credential_iterator = NULL; - if (!err && !out_credential_iterator) { err = param_error (1, "out_credential_iterator", "NULL"); } - if (!err && !in_ccache ) { err = param_error (2, "in_ccache", "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) { *credential_iterator = kim_credential_iterator_initializer; } else { - err = os_error (errno); + err = KIM_OUT_OF_MEMORY_ERR; } } @@ -89,8 +89,8 @@ kim_error kim_credential_iterator_next (kim_credential_iterator in_credential_i { kim_error err = KIM_NO_ERROR; - if (!err && !in_credential_iterator) { err = param_error (1, "in_credential_iterator", "NULL"); } - if (!err && !out_credential ) { err = param_error (2, "out_credential", "NULL"); } + 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; @@ -158,11 +158,11 @@ static inline kim_error kim_credential_allocate (kim_credential *out_credential) kim_error err = KIM_NO_ERROR; kim_credential credential = NULL; - if (!err && !out_credential) { err = param_error (1, "out_credential", "NULL"); } + if (!err && !out_credential) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err) { credential = malloc (sizeof (*credential)); - if (!credential) { err = os_error (errno); } + if (!credential) { err = KIM_OUT_OF_MEMORY_ERR; } } if (!err) { @@ -185,7 +185,7 @@ kim_error kim_credential_create_new (kim_credential *out_credential, kim_error err = KIM_NO_ERROR; kim_credential credential = NULL; - if (!err && !out_credential) { err = param_error (1, "out_credential", "NULL"); } + if (!err && !out_credential) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err) { err = kim_credential_allocate (&credential); @@ -228,7 +228,7 @@ kim_error kim_credential_create_from_keytab (kim_credential *out_credential, kim_string service_name = NULL; krb5_get_init_creds_opt *init_cred_options = NULL; - if (!err && !out_credential) { err = param_error (1, "out_credential", "NULL"); } + if (!err && !out_credential) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err) { err = kim_credential_allocate (&credential); @@ -353,9 +353,9 @@ 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 = param_error (1, "out_credential", "NULL"); } - if (!err && !in_krb5_creds ) { err = param_error (2, "in_krb5_creds", "NULL"); } - if (!err && !in_krb5_context) { err = param_error (3, "in_krb5_context", "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); @@ -388,8 +388,8 @@ kim_error kim_credential_copy (kim_credential *out_credential, kim_error err = KIM_NO_ERROR; kim_credential credential = NULL; - if (!err && !out_credential) { err = param_error (1, "out_credential", "NULL"); } - if (!err && !in_credential ) { err = param_error (2, "in_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); @@ -422,9 +422,9 @@ kim_error kim_credential_get_krb5_creds (kim_credential in_credential, { kim_error err = KIM_NO_ERROR; - if (!err && !in_credential ) { err = param_error (1, "in_credential", "NULL"); } - if (!err && !in_krb5_context) { err = param_error (2, "in_krb5_context", "NULL"); } - if (!err && !out_krb5_creds ) { err = param_error (3, "out_krb5_creds", "NULL"); } + 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, @@ -443,8 +443,8 @@ kim_error kim_credential_get_client_identity (kim_credential in_credential, { kim_error err = KIM_NO_ERROR; - if (!err && !in_credential ) { err = param_error (1, "in_credential", "NULL"); } - if (!err && !out_client_identity) { err = param_error (2, "out_client_identity", "NULL"); } + 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, @@ -462,8 +462,8 @@ kim_error kim_credential_get_service_identity (kim_credential in_credential, { kim_error err = KIM_NO_ERROR; - if (!err && !in_credential ) { err = param_error (1, "in_credential", "NULL"); } - if (!err && !out_service_identity) { err = param_error (2, "out_service_identity", "NULL"); } + 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, @@ -482,8 +482,8 @@ 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 = param_error (1, "in_credential", "NULL"); } - if (!err && !out_is_tgt ) { err = param_error (2, "out_is_tgt", "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); @@ -508,8 +508,8 @@ kim_error kim_credential_get_state (kim_credential in_credential, kim_time start_time = 0; krb5_timestamp now = 0; - if (!err && !in_credential) { err = param_error (1, "in_credential", "NULL"); } - if (!err && !out_state ) { err = param_error (2, "out_state", "NULL"); } + 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); @@ -581,7 +581,7 @@ kim_error kim_credential_get_start_time (kim_credential in_credential, { kim_error err = KIM_NO_ERROR; - if (!err && !in_credential) { err = param_error (1, "in_credential", "NULL"); } + if (!err && !in_credential) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err) { *out_start_time = (in_credential->creds->times.starttime ? @@ -599,7 +599,7 @@ kim_error kim_credential_get_expiration_time (kim_credential in_credential, { kim_error err = KIM_NO_ERROR; - if (!err && !in_credential) { err = param_error (1, "in_credential", "NULL"); } + if (!err && !in_credential) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err) { *out_expiration_time = in_credential->creds->times.endtime; @@ -615,7 +615,7 @@ kim_error kim_credential_get_renewal_expiration_time (kim_credential in_credent { kim_error err = KIM_NO_ERROR; - if (!err && !in_credential) { err = param_error (1, "in_credential", "NULL"); } + if (!err && !in_credential) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err) { *out_renewal_expiration_time = in_credential->creds->times.renew_till; @@ -637,8 +637,8 @@ kim_error kim_credential_store (kim_credential in_credential, krb5_principal client_principal = NULL; kim_boolean destroy_ccache_on_error = FALSE; - if (!err && !in_credential ) { err = param_error (1, "in_credential", "NULL"); } - if (!err && !in_client_identity) { err = param_error (2, "in_client_identity", "NULL"); } + if (!err && !in_credential ) { err = check_error (KIM_NULL_PARAMETER_ERR); } + if (!err && !in_client_identity) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err) { err = krb5_error (NULL, krb5_init_context (&context)); @@ -666,7 +666,7 @@ kim_error kim_credential_store (kim_credential in_credential, if (!err) { err = kim_ccache_get_krb5_ccache (ccache, context, &k5ccache); - } else if (err == KIM_NO_SUCH_PRINCIPAL_ECODE) { + } else if (err == KIM_NO_SUCH_PRINCIPAL_ERR) { /* Nothing to replace, create a new ccache */ err = krb5_error (context, krb5_cc_new_unique (context, "API", NULL, @@ -724,7 +724,7 @@ kim_error kim_credential_verify (kim_credential in_credential, krb5_principal service_principal = NULL; krb5_keytab keytab = NULL; - if (!err && !in_credential) { err = param_error (1, "in_credential", "NULL"); } + if (!err && !in_credential) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err) { err = krb5_error (NULL, krb5_init_secure_context (&scontext)); @@ -819,7 +819,7 @@ kim_error kim_credential_renew (kim_credential *io_credential, kim_string service_name = NULL; krb5_ccache ccache = NULL; - if (!err && !io_credential) { err = param_error (1, "io_credential", "NULL"); } + if (!err && !io_credential) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err) { kim_options options = in_options; @@ -895,7 +895,7 @@ kim_error kim_credential_validate (kim_credential *io_credential, kim_string service_name = NULL; krb5_ccache ccache = NULL; - if (!err && !io_credential) { err = param_error (1, "io_credential", "NULL"); } + if (!err && !io_credential) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err) { kim_options options = in_options; diff --git a/src/kim/lib/kim_debug.c b/src/kim/lib/kim_debug.c index ee10c3f4d..645a51f43 100644 --- a/src/kim/lib/kim_debug.c +++ b/src/kim/lib/kim_debug.c @@ -52,8 +52,8 @@ void __kim_debug_printf (kim_string in_function, kim_string format = NULL; kim_string string = NULL; - if (!err && !in_function) { err = param_error (1, "in_function", "NULL"); } - if (!err && !in_format ) { err = param_error (2, "in_format", "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", diff --git a/src/kim/lib/kim_error.c b/src/kim/lib/kim_error.c index 24d78963a..c481e2fb2 100644 --- a/src/kim/lib/kim_error.c +++ b/src/kim/lib/kim_error.c @@ -58,7 +58,7 @@ static kim_error kim_error_set_message (kim_error in_error, if (!last_error) { last_error = malloc (sizeof (*last_error)); if (!last_error) { - err = KIM_OUT_OF_MEMORY_ECODE; + err = KIM_OUT_OF_MEMORY_ERR; } else { last_error->code = KIM_NO_ERROR; err = k5_setspecific (K5_KEY_KIM_ERROR_MESSAGE, last_error); @@ -118,25 +118,7 @@ kim_string kim_error_message (kim_error in_error) static kim_boolean kim_error_is_builtin (kim_error in_error) { return (in_error == KIM_NO_ERROR || - in_error == KIM_OUT_OF_MEMORY_ECODE); -} - -#pragma mark -- Helper Functions -- - -/* These helper functions exist so we get type checking on common errors */ - -/* ------------------------------------------------------------------------ */ - -kim_error _kim_error_set_message_for_param (kim_string in_function, - unsigned int in_argument_position, - kim_string in_argument_name, - kim_string in_invalid_value) -{ - return kim_error_set_message_for_code (KIM_PARAMETER_ECODE, - in_function, - in_argument_position, - in_argument_name, - in_invalid_value); + in_error == KIM_OUT_OF_MEMORY_ERR); } #pragma mark -- Generic Functions -- diff --git a/src/kim/lib/kim_error_code.et b/src/kim/lib/kim_error_code.et index 673d05708..381f6d28c 100644 --- a/src/kim/lib/kim_error_code.et +++ b/src/kim/lib/kim_error_code.et @@ -23,51 +23,51 @@ error_table_manager "Kerberos Identity Management" error_table KIM # Configuration and System Errors -error_code KIM_OUT_OF_MEMORY_ECODE, "Out of memory" -error_code KIM_PARAMETER_ECODE, "%s(): argument %d (%s) may not be %s. Please consult the KIM API documentation" -error_code KIM_KRB5_INIT_FAILED_ECODE, "Unable to initialize Kerberos v5" -error_code KIM_NO_REALMS_ECODE, "There are no Kerberos realms configured" -error_code KIM_NO_SUCH_REALM_ECODE, "The realm '%s' is not in your configuration file or does not exist" -error_code KIM_UNSUPPORTED_HINT_ECODE, "The hint '%s' is not supported by this version of KIM" +error_code KIM_OUT_OF_MEMORY_ERR, "Out of memory" +error_code KIM_NULL_PARAMETER_ERR, "Parameter may not be NULL. Please consult the KIM API documentation" +error_code KIM_KRB5_INIT_FAILED_ERR, "Unable to initialize Kerberos v5" +error_code KIM_NO_REALMS_ERR, "There are no Kerberos realms configured" +error_code KIM_NO_SUCH_REALM_ERR, "The realm '%s' is not in your configuration file or does not exist" +error_code KIM_UNSUPPORTED_HINT_ERR, "The hint '%s' is not supported by this version of KIM" index 25 # Principal Errors -error_code KIM_BAD_PRINCIPAL_STRING_ECODE, "'%s' is not a valid Kerberos principal" -error_code KIM_BAD_COMPONENT_INDEX_ECODE, "Principal does not have a component at index %d" -error_code KIM_PASSWORD_MISMATCH_ECODE, "New and verify passwords do not match" -error_code KIM_INSECURE_PASSWORD_ECODE, "Your new password for '%s' is insecure; please pick another one" -error_code KIM_PASSWORD_CHANGE_FAILED_ECODE, "Unable to change password for %s" +error_code KIM_BAD_PRINCIPAL_STRING_ERR, "'%s' is not a valid Kerberos principal" +error_code KIM_BAD_COMPONENT_INDEX_ERR, "Principal does not have a component at index %d" +error_code KIM_PASSWORD_MISMATCH_ERR, "New and verify passwords do not match" +error_code KIM_INSECURE_PASSWORD_ERR, "Your new password for '%s' is insecure; please pick another one" +error_code KIM_PASSWORD_CHANGE_FAILED_ERR, "Unable to change password for %s" index 50 # Options Errors -error_code KIM_BAD_OPTIONS_ECODE, "Invalid options" -error_code KIM_BAD_OPTIONS_VALUE_ECODE, "Invalid value for Kerberos default login option" +error_code KIM_BAD_OPTIONS_ERR, "Invalid options" +error_code KIM_BAD_OPTIONS_VALUE_ERR, "Invalid value for Kerberos default login option" index 75 # User Interface Errors -error_code KIM_CAPS_LOCK_ECODE, "Password Incorrect (check your Caps Lock)" -error_code KIM_USER_CANCELED_ECODE, "The user cancelled the operation" -error_code KIM_NO_SERVER_ECODE, "Unable to launch or contact %s" -error_code KIM_NO_GUI_ECODE, "Unable to display a graphical user interface from this environment" -error_code KIM_NO_CLI_ECODE, "Unable to display a command line user interface from this environment" +error_code KIM_CAPS_LOCK_ERR, "Password Incorrect (check your Caps Lock)" +error_code KIM_USER_CANCELED_ERR, "The user cancelled the operation" +error_code KIM_NO_SERVER_ERR, "KerberosAgent is not responding" +error_code KIM_NO_GUI_ERR, "Unable to display a graphical user interface from this environment" +error_code KIM_NO_CLI_ERR, "Unable to display a command line user interface from this environment" index 100 # Preferences Errors -error_code KIM_PREFERENCES_READ_ECODE, "Unable to read user preferences. The file may be missing, inaccessible or corrupted" -error_code KIM_PREFERENCES_WRITE_ECODE, "Unable to write user preferences. The file may be inaccessible" -error_code KIM_IDENTITY_NOT_IN_IDENTITIES_LIST, "Identity %s is not in the favorite identities list" -error_code KIM_IDENTITY_ALREADY_IN_IDENTITIES_LIST, "Identity %s is already in the favorite identities list" -error_code KIM_BAD_IDENTITY_INDEX_ECODE, "No identity at index %d in the favorite identities list" +error_code KIM_PREFERENCES_READ_ERR, "Unable to read user preferences. The file may be missing, inaccessible or corrupted" +error_code KIM_PREFERENCES_WRITE_ERR, "Unable to write user preferences. The file may be inaccessible" +error_code KIM_IDENTITY_NOT_IN_LIST_ERR, "Identity %s is not in the favorite identities list" +error_code KIM_IDENTITY_ALREADY_IN_LIST_ERR, "Identity %s is already in the favorite identities list" +error_code KIM_BAD_IDENTITY_INDEX_ERR, "No identity at index %d in the favorite identities list" index 125 # Cache Collection Errors -error_code KIM_NO_SUCH_PRINCIPAL_ECODE, "Principal '%s' does not exist in the cache collection" -error_code KIM_CANT_BECOME_DEFAULT_ECODE, "The credentials cache '%s' cannot become the system default cache" -error_code KIM_CREDENTIALS_EXPIRED_ECODE, "The Kerberos credentials for '%s' have expired" -error_code KIM_NO_CREDENTIALS_ECODE, "No Kerberos credentials for '%s' available" -error_code KIM_BAD_IP_ADDRESS_ECODE, "The IP addresses in the Kerberos credentials for '%s' do not match any of your computer's IP addresses" -error_code KIM_NO_SUCH_CCACHE_ECODE, "The credentials cache '%s' does not exist" -error_code KIM_BAD_HOST_CONFIGURATION_ECODE, "Unable to get local hostname or address information" -error_code KIM_NEEDS_VALIDATION_ECODE, "The Kerberos credentials for '%s' need to be validated" +error_code KIM_NO_SUCH_PRINCIPAL_ERR, "Principal '%s' does not exist in the cache collection" +error_code KIM_CANT_BECOME_DEFAULT_ERR, "The credentials cache '%s' cannot become the system default cache" +error_code KIM_CREDENTIALS_EXPIRED_ERR, "The Kerberos credentials for '%s' have expired" +error_code KIM_NO_CREDENTIALS_ERR, "No Kerberos credentials for '%s' available" +error_code KIM_BAD_IP_ADDRESS_ERR, "The IP addresses in the Kerberos credentials for '%s' do not match any of your computer's IP addresses" +error_code KIM_NO_SUCH_CCACHE_ERR, "The credentials cache '%s' does not exist" +error_code KIM_BAD_HOST_CONFIGURATION_ERR, "Unable to get local hostname or address information" +error_code KIM_NEEDS_VALIDATION_ERR, "The Kerberos credentials for '%s' need to be validated" end diff --git a/src/kim/lib/kim_error_private.h b/src/kim/lib/kim_error_private.h index 6a3bcff91..72e409954 100644 --- a/src/kim/lib/kim_error_private.h +++ b/src/kim/lib/kim_error_private.h @@ -29,14 +29,6 @@ #include -kim_error _kim_error_set_message_for_param (kim_string in_function, - unsigned int in_argument_position, - kim_string in_argument_name, - kim_string in_invalid_value); -#define param_error(pos, name, value) _kim_error_set_message_for_param(__FUNCTION__,\ - pos, name, \ - value) - 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, @@ -45,8 +37,6 @@ 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) -#define ccapi_error(code) kim_error_set_message_for_code(code) -#define os_error(code) kim_error_set_message_for_code(code) kim_string kim_error_message (kim_error in_error); diff --git a/src/kim/lib/kim_identity.c b/src/kim/lib/kim_identity.c index d2115561c..db4279020 100644 --- a/src/kim/lib/kim_identity.c +++ b/src/kim/lib/kim_identity.c @@ -44,11 +44,11 @@ static inline kim_error kim_identity_allocate (kim_identity *out_identity) kim_error err = KIM_NO_ERROR; kim_identity identity = NULL; - if (!err && !out_identity) { err = param_error (1, "out_identity", "NULL"); } + if (!err && !out_identity) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err) { identity = malloc (sizeof (*identity)); - if (!identity) { err = os_error (errno); } + if (!identity) { err = KIM_OUT_OF_MEMORY_ERR; } } if (!err) { @@ -70,8 +70,8 @@ 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 = param_error (1, "out_identity", "NULL"); } - if (!err && !in_string ) { err = param_error (2, "in_string", "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); @@ -84,7 +84,7 @@ kim_error kim_identity_create_from_string (kim_identity *out_identity, 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_ECODE, + err = kim_error_set_message_for_code (KIM_BAD_PRINCIPAL_STRING_ERR, in_string); } else if (code) { err = krb5_error (identity->context, code); @@ -116,9 +116,9 @@ kim_error kim_identity_create_from_components (kim_identity *out_identity, kim_identity identity = NULL; krb5_principal_data principal_data; /* allocated by KIM so can't be returned */ - if (!err && !out_identity ) { err = param_error (1, "out_identity", "NULL"); } - if (!err && !in_realm ) { err = param_error (2, "in_realm", "NULL"); } - if (!err && !in_1st_component) { err = param_error (3, "in_1st_component", "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); @@ -138,7 +138,7 @@ kim_error kim_identity_create_from_components (kim_identity *out_identity, principal_data.length = component_count; principal_data.data = (krb5_data *) malloc (component_count * sizeof (krb5_data)); - if (!principal_data.data) { err = os_error (errno); } + if (!principal_data.data) { err = KIM_OUT_OF_MEMORY_ERR; } } if (!err) { @@ -206,9 +206,9 @@ 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 = param_error (1, "out_identity", "NULL"); } - if (!err && !in_krb5_principal) { err = param_error (2, "in_krb5_principal", "NULL"); } - if (!err && !in_krb5_context ) { err = param_error (3, "in_krb5_context", "NULL"); } + if (!err && !out_identity ) { err = check_error (KIM_NULL_PARAMETER_ERR); } + if (!err && !in_krb5_principal) { err = check_error (KIM_NULL_PARAMETER_ERR); } + if (!err && !in_krb5_context ) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err) { err = kim_identity_allocate (&identity); @@ -247,7 +247,7 @@ 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 = param_error (1, "out_identity", "NULL"); } + if (!err && !out_identity) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && in_identity != KIM_IDENTITY_ANY) { err = kim_identity_allocate (&identity); @@ -282,9 +282,9 @@ kim_error kim_identity_compare (kim_identity in_identity, { kim_error err = KIM_NO_ERROR; - if (!err && !in_identity ) { err = param_error (1, "in_identity", "NULL"); } - if (!err && !in_compare_to_identity) { err = param_error (2, "in_compare_to_identity", "NULL"); } - if (!err && !out_comparison ) { err = param_error (3, "out_comparison", "NULL"); } + 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, @@ -321,8 +321,8 @@ 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 = param_error (1, "in_identity", "NULL"); } - if (!err && !out_string ) { err = param_error (2, "out_string", "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, @@ -348,8 +348,8 @@ 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 = param_error (1, "in_identity", "NULL"); } - if (!err && !out_display_string) { err = param_error (2, "out_display_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); @@ -392,8 +392,8 @@ kim_error kim_identity_get_realm (kim_identity in_identity, { kim_error err = KIM_NO_ERROR; - if (!err && !in_identity ) { err = param_error (1, "in_identity", "NULL"); } - if (!err && !out_realm_string) { err = param_error (2, "out_realm_string", "NULL"); } + 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); @@ -411,8 +411,8 @@ kim_error kim_identity_get_number_of_components (kim_identity in_identity, { kim_error err = KIM_NO_ERROR; - if (!err && !in_identity ) { err = param_error (1, "in_identity", "NULL"); } - if (!err && !out_number_of_components) { err = param_error (2, "out_number_of_components", "NULL"); } + 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); @@ -430,14 +430,14 @@ 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 = param_error (1, "in_identity", "NULL"); } - if (!err && !out_component_string) { err = param_error (3, "out_component_string", "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_ECODE, i); + err = kim_error_set_message_for_code (KIM_BAD_COMPONENT_INDEX_ERR, i); } } @@ -456,9 +456,9 @@ kim_error kim_identity_get_krb5_principal (kim_identity in_identity, { kim_error err = KIM_NO_ERROR; - if (!err && !in_identity ) { err = param_error (1, "in_identity", "NULL"); } - if (!err && !in_krb5_context ) { err = param_error (2, "in_krb5_context", "NULL"); } - if (!err && !out_krb5_principal) { err = param_error (3, "out_krb5_principal", "NULL"); } + 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_identity->context, @@ -477,8 +477,8 @@ kim_error kim_identity_get_gss_name (kim_identity in_identity, { kim_error err = KIM_NO_ERROR; - if (!err && !in_identity ) { err = param_error (1, "in_identity", "NULL"); } - if (!err && !out_gss_name) { err = param_error (2, "out_gss_name", "NULL"); } + if (!err && !in_identity ) { err = check_error (KIM_NULL_PARAMETER_ERR); } + if (!err && !out_gss_name) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err) { #warning kim_identity_get_gss_name not implemented @@ -494,8 +494,8 @@ kim_error kim_identity_is_tgt_service (kim_identity in_identity, { kim_error err = KIM_NO_ERROR; - if (!err && !in_identity ) { err = param_error (1, "in_identity", "NULL"); } - if (!err && !out_is_tgt_service) { err = param_error (2, "out_is_tgt_service", "NULL"); } + 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); @@ -517,7 +517,7 @@ kim_error kim_identity_change_password (kim_identity in_identity, { kim_error err = KIM_NO_ERROR; - if (!err && !in_identity) { err = param_error (1, "in_identity", "NULL"); } + if (!err && !in_identity) { err = check_error (KIM_NULL_PARAMETER_ERR); } return check_error (err); } @@ -530,8 +530,8 @@ kim_error kim_identity_change_password_to_password (kim_identity in_identity, { kim_error err = KIM_NO_ERROR; - if (!err && !in_identity ) { err = param_error (1, "in_identity", "NULL"); } - if (!err && !in_new_password) { err = param_error (3, "in_new_password", "NULL"); } + if (!err && !in_identity ) { err = check_error (KIM_NULL_PARAMETER_ERR); } + if (!err && !in_new_password) { err = check_error (KIM_NULL_PARAMETER_ERR); } return check_error (err); } diff --git a/src/kim/lib/kim_library.c b/src/kim/lib/kim_library.c index 911db91c8..215e6edf7 100644 --- a/src/kim/lib/kim_library.c +++ b/src/kim/lib/kim_library.c @@ -26,56 +26,93 @@ #define KRB5_PRIVATE 1 -#include -#include -#include +#include "k5-int.h" +#include "k5-thread.h" #include #include #include "kim_private.h" #include "kim_os_private.h" -#pragma mark -- Allow Home Directory Access -- +static k5_mutex_t g_allow_home_directory_access_mutex = K5_MUTEX_PARTIAL_INITIALIZER; +static k5_mutex_t g_allow_automatic_prompting_mutex = K5_MUTEX_PARTIAL_INITIALIZER; -static pthread_mutex_t g_allow_home_directory_access_mutex = PTHREAD_MUTEX_INITIALIZER; kim_boolean g_allow_home_directory_access = TRUE; +kim_boolean g_allow_automatic_prompting = TRUE; + +MAKE_INIT_FUNCTION(kim_thread_init); +MAKE_FINI_FUNCTION(kim_thread_fini); /* ------------------------------------------------------------------------ */ -kim_error kim_library_set_allow_home_directory_access (kim_boolean in_allow_access) +static int kim_thread_init (void) { kim_error err = KIM_NO_ERROR; - int mutex_err = pthread_mutex_lock (&g_allow_home_directory_access_mutex); - if (mutex_err) { err = os_error (mutex_err); } + 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); + } + + return err; +} + +/* ------------------------------------------------------------------------ */ + +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); +} + +#pragma mark -- Allow Home Directory Access -- + +/* ------------------------------------------------------------------------ */ + +kim_error kim_library_set_allow_home_directory_access (kim_boolean in_allow_access) +{ + 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) { pthread_mutex_unlock (&g_allow_home_directory_access_mutex); } + if (!mutex_err) { k5_mutex_unlock (&g_allow_home_directory_access_mutex); } return check_error (err); } /* ------------------------------------------------------------------------ */ -kim_error kim_library_get_allow_home_directory_access (kim_boolean *out_allow_access) +static kim_error kim_library_get_allow_home_directory_access (kim_boolean *out_allow_access) { - kim_error err = KIM_NO_ERROR; - int mutex_err = 0; + kim_error err = CALL_INIT_FUNCTION (kim_thread_init); + kim_error mutex_err = KIM_NO_ERROR; - if (!err && !out_allow_access) { err = param_error (3, "out_allow_access", "NULL"); } + if (!err && !out_allow_access) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err) { - mutex_err = pthread_mutex_lock (&g_allow_home_directory_access_mutex);; - if (mutex_err) { err = os_error (mutex_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) { pthread_mutex_unlock (&g_allow_home_directory_access_mutex); } + if (!mutex_err) { k5_mutex_unlock (&g_allow_home_directory_access_mutex); } return check_error (err); } @@ -92,45 +129,46 @@ kim_boolean kim_library_allow_home_directory_access (void) #pragma mark -- Allow Automatic Prompting -- -static pthread_mutex_t g_allow_automatic_prompting_mutex = PTHREAD_MUTEX_INITIALIZER; -kim_boolean g_allow_automatic_prompting = TRUE; /* ------------------------------------------------------------------------ */ kim_error kim_library_set_allow_automatic_prompting (kim_boolean in_allow_automatic_prompting) { - kim_error err = KIM_NO_ERROR; + kim_error err = CALL_INIT_FUNCTION (kim_thread_init); + kim_error mutex_err = KIM_NO_ERROR; - int mutex_err = pthread_mutex_lock (&g_allow_automatic_prompting_mutex); - if (mutex_err) { err = os_error (mutex_err); } + 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) { pthread_mutex_unlock (&g_allow_automatic_prompting_mutex); } + if (!mutex_err) { k5_mutex_unlock (&g_allow_automatic_prompting_mutex); } return check_error (err); } /* ------------------------------------------------------------------------ */ -kim_error kim_library_get_allow_automatic_prompting (kim_boolean *out_allow_automatic_prompting) +static kim_error kim_library_get_allow_automatic_prompting (kim_boolean *out_allow_automatic_prompting) { - kim_error err = KIM_NO_ERROR; - int mutex_err = 0; + kim_error err = CALL_INIT_FUNCTION (kim_thread_init); + kim_error mutex_err = KIM_NO_ERROR; - if (!err && !out_allow_automatic_prompting) { err = param_error (3, "out_allow_automatic_prompting", "NULL"); } + if (!err && !out_allow_automatic_prompting) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err) { - mutex_err = pthread_mutex_lock (&g_allow_automatic_prompting_mutex);; - if (mutex_err) { err = os_error (mutex_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) { pthread_mutex_unlock (&g_allow_automatic_prompting_mutex); } + if (!mutex_err) { k5_mutex_unlock (&g_allow_automatic_prompting_mutex); } return check_error (err); } diff --git a/src/kim/lib/kim_library_private.h b/src/kim/lib/kim_library_private.h index 2f51ab767..8c94ead07 100644 --- a/src/kim/lib/kim_library_private.h +++ b/src/kim/lib/kim_library_private.h @@ -1,7 +1,7 @@ /* * $Header$ * - * Copyright 2006 Massachusetts Institute of Technology. + * Copyright 2006-2008 Massachusetts Institute of Technology. * All Rights Reserved. * * Export of this software from the United States of America may @@ -29,21 +29,6 @@ #include - -kim_error kim_library_set_allow_home_directory_access (kim_boolean in_allow_access); - -kim_error kim_library_get_allow_home_directory_access (kim_boolean *out_allow_access); - -kim_boolean kim_library_allow_home_directory_access (void); - -kim_error kim_library_set_allow_automatic_prompting (kim_boolean in_allow_automatic_prompting); - -kim_error kim_library_get_allow_automatic_prompting (kim_boolean *out_allow_automatic_prompting); - -kim_boolean kim_library_allow_automatic_prompting (void); - -void kim_os_library_debug_print (kim_string in_string); - kim_boolean kim_os_library_caller_is_server (void); #endif /* KIM_LIBRARY_PRIVATE_H */ diff --git a/src/kim/lib/kim_options.c b/src/kim/lib/kim_options.c index 4b3d1147f..d5bba9a84 100644 --- a/src/kim/lib/kim_options.c +++ b/src/kim/lib/kim_options.c @@ -60,11 +60,11 @@ static inline kim_error kim_options_allocate (kim_options *out_options) kim_error err = KIM_NO_ERROR; kim_options options = NULL; - if (!err && !out_options) { err = param_error (1, "out_options", "NULL"); } + if (!err && !out_options) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err) { options = malloc (sizeof (*options)); - if (!options) { err = os_error (errno); } + if (!options) { err = KIM_OUT_OF_MEMORY_ERR; } } if (!err) { @@ -85,7 +85,7 @@ kim_error kim_options_create_from_defaults (kim_options *out_options) kim_error err = KIM_NO_ERROR; kim_options options = NULL; - if (!err && !out_options) { err = param_error (1, "out_options", "NULL"); } + if (!err && !out_options) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err) { err = kim_options_allocate (&options); @@ -108,7 +108,7 @@ kim_error kim_options_create (kim_options *out_options) kim_error err = KIM_NO_ERROR; kim_preferences preferences = NULL; - if (!err && !out_options) { err = param_error (1, "out_options", "NULL"); } + if (!err && !out_options) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err) { err = kim_preferences_create (&preferences); @@ -131,8 +131,8 @@ kim_error kim_options_copy (kim_options *out_options, kim_error err = KIM_NO_ERROR; kim_options options = NULL; - if (!err && !out_options) { err = param_error (1, "out_options", "NULL"); } - if (!err && !in_options ) { err = param_error (2, "in_options", "NULL"); } + if (!err && !out_options) { err = check_error (KIM_NULL_PARAMETER_ERR); } + if (!err && !in_options ) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err) { err = kim_options_allocate (&options); @@ -175,7 +175,7 @@ kim_error kim_options_set_prompt_callback (kim_options io_options, { kim_error err = KIM_NO_ERROR; - if (!err && !io_options) { err = param_error (1, "io_options", "NULL"); } + if (!err && !io_options) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err) { io_options->prompt_callback = in_prompt_callback; @@ -191,8 +191,8 @@ kim_error kim_options_get_prompt_callback (kim_options in_options, { kim_error err = KIM_NO_ERROR; - if (!err && !in_options ) { err = param_error (1, "in_options", "NULL"); } - if (!err && !out_prompt_callback) { err = param_error (2, "out_prompt_callback", "NULL"); } + if (!err && !in_options ) { err = check_error (KIM_NULL_PARAMETER_ERR); } + if (!err && !out_prompt_callback) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err) { *out_prompt_callback = in_options->prompt_callback; @@ -209,7 +209,7 @@ kim_error kim_options_set_data (kim_options io_options, { kim_error err = KIM_NO_ERROR; - if (!err && !io_options) { err = param_error (1, "io_options", "NULL"); } + if (!err && !io_options) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err) { io_options->prompt_callback_data = in_data; @@ -225,8 +225,8 @@ kim_error kim_options_get_data (kim_options in_options, { kim_error err = KIM_NO_ERROR; - if (!err && !in_options) { err = param_error (1, "in_options", "NULL"); } - if (!err && !out_data ) { err = param_error (2, "out_data", "NULL"); } + if (!err && !in_options) { err = check_error (KIM_NULL_PARAMETER_ERR); } + if (!err && !out_data ) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err) { *out_data = in_options->prompt_callback_data; @@ -243,8 +243,8 @@ kim_error kim_options_set_prompt_response (kim_options io_options, { kim_error err = KIM_NO_ERROR; - if (!err && !io_options ) { err = param_error (1, "io_options", "NULL"); } - if (!err && !in_response) { err = param_error (2, "in_response", "NULL"); } + if (!err && !io_options ) { err = check_error (KIM_NULL_PARAMETER_ERR); } + if (!err && !in_response) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err) { #warning kim_options_set_prompt_response unimplemented @@ -261,8 +261,8 @@ kim_error kim_options_get_prompt_response (kim_options in_options, { kim_error err = KIM_NO_ERROR; - if (!err && !in_options ) { err = param_error (1, "in_options", "NULL"); } - if (!err && !out_response) { err = param_error (2, "out_response", "NULL"); } + if (!err && !in_options ) { err = check_error (KIM_NULL_PARAMETER_ERR); } + if (!err && !out_response) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err) { #warning kim_options_get_prompt_response unimplemented @@ -278,7 +278,7 @@ kim_error kim_options_set_start_time (kim_options io_options, { kim_error err = KIM_NO_ERROR; - if (!err && !io_options) { err = param_error (1, "io_options", "NULL"); } + if (!err && !io_options) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err) { io_options->start_time = in_start_time; @@ -294,8 +294,8 @@ kim_error kim_options_get_start_time (kim_options in_options, { kim_error err = KIM_NO_ERROR; - if (!err && !in_options ) { err = param_error (1, "in_options", "NULL"); } - if (!err && !out_start_time) { err = param_error (2, "out_start_time", "NULL"); } + 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; @@ -311,7 +311,7 @@ kim_error kim_options_set_lifetime (kim_options io_options, { kim_error err = KIM_NO_ERROR; - if (!err && !io_options) { err = param_error (1, "io_options", "NULL"); } + if (!err && !io_options) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err) { io_options->lifetime = in_lifetime; @@ -327,8 +327,8 @@ kim_error kim_options_get_lifetime (kim_options in_options, { kim_error err = KIM_NO_ERROR; - if (!err && !in_options ) { err = param_error (1, "in_options", "NULL"); } - if (!err && !out_lifetime) { err = param_error (2, "out_lifetime", "NULL"); } + 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; @@ -344,7 +344,7 @@ kim_error kim_options_set_renewable (kim_options io_options, { kim_error err = KIM_NO_ERROR; - if (!err && !io_options) { err = param_error (1, "io_options", "NULL"); } + if (!err && !io_options) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err) { io_options->renewable = in_renewable; @@ -360,8 +360,8 @@ kim_error kim_options_get_renewable (kim_options in_options, { kim_error err = KIM_NO_ERROR; - if (!err && !in_options ) { err = param_error (1, "in_options", "NULL"); } - if (!err && !out_renewable) { err = param_error (2, "out_renewable", "NULL"); } + 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; @@ -377,7 +377,7 @@ kim_error kim_options_set_renewal_lifetime (kim_options io_options, { kim_error err = KIM_NO_ERROR; - if (!err && !io_options) { err = param_error (1, "io_options", "NULL"); } + if (!err && !io_options) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err) { io_options->renewal_lifetime = in_renewal_lifetime; @@ -393,8 +393,8 @@ kim_error kim_options_get_renewal_lifetime (kim_options in_options, { kim_error err = KIM_NO_ERROR; - if (!err && !in_options ) { err = param_error (1, "in_options", "NULL"); } - if (!err && !out_renewal_lifetime) { err = param_error (2, "out_renewal_lifetime", "NULL"); } + 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; @@ -410,7 +410,7 @@ kim_error kim_options_set_forwardable (kim_options io_options, { kim_error err = KIM_NO_ERROR; - if (!err && !io_options) { err = param_error (1, "io_options", "NULL"); } + if (!err && !io_options) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err) { io_options->forwardable = in_forwardable; @@ -426,8 +426,8 @@ kim_error kim_options_get_forwardable (kim_options in_options, { kim_error err = KIM_NO_ERROR; - if (!err && !in_options ) { err = param_error (1, "in_options", "NULL"); } - if (!err && !out_forwardable) { err = param_error (2, "out_forwardable", "NULL"); } + 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; @@ -443,7 +443,7 @@ kim_error kim_options_set_proxiable (kim_options io_options, { kim_error err = KIM_NO_ERROR; - if (!err && !io_options) { err = param_error (1, "io_options", "NULL"); } + if (!err && !io_options) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err) { io_options->proxiable = in_proxiable; @@ -459,8 +459,8 @@ kim_error kim_options_get_proxiable (kim_options in_options, { kim_error err = KIM_NO_ERROR; - if (!err && !in_options ) { err = param_error (1, "in_options", "NULL"); } - if (!err && !out_proxiable) { err = param_error (2, "out_proxiable", "NULL"); } + 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; @@ -476,7 +476,7 @@ kim_error kim_options_set_addressless (kim_options io_options, { kim_error err = KIM_NO_ERROR; - if (!err && !io_options) { err = param_error (1, "io_options", "NULL"); } + if (!err && !io_options) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err) { io_options->addressless = in_addressless; @@ -492,8 +492,8 @@ kim_error kim_options_get_addressless (kim_options in_options, { kim_error err = KIM_NO_ERROR; - if (!err && !in_options ) { err = param_error (1, "in_options", "NULL"); } - if (!err && !out_addressless) { err = param_error (2, "out_addressless", "NULL"); } + 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; @@ -510,8 +510,8 @@ kim_error kim_options_set_service_name (kim_options io_options, kim_error err = KIM_NO_ERROR; kim_string service_name = NULL; - if (!err && !io_options ) { err = param_error (1, "io_options", "NULL"); } - if (!err && !in_service_name) { err = param_error (2, "in_service_name", "NULL"); } + if (!err && !io_options ) { err = check_error (KIM_NULL_PARAMETER_ERR); } + if (!err && !in_service_name) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err) { err = kim_string_copy (&service_name, in_service_name); @@ -532,8 +532,8 @@ kim_error kim_options_get_service_name (kim_options in_options, { kim_error err = KIM_NO_ERROR; - if (!err && !in_options ) { err = param_error (1, "in_options", "NULL"); } - if (!err && !out_service_name) { err = param_error (2, "out_service_name", "NULL"); } + 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) { err = kim_string_copy (out_service_name, in_options->service_name); @@ -552,9 +552,9 @@ kim_error kim_options_get_init_cred_options (kim_options in_option krb5_get_init_creds_opt *init_cred_options; krb5_address **addresses = NULL; - if (!err && !in_options ) { err = param_error (1, "in_options", "NULL"); } - if (!err && !in_context ) { err = param_error (2, "in_context", "NULL"); } - if (!err && !out_init_cred_options) { err = param_error (3, "out_init_cred_options", "NULL"); } + if (!err && !in_options ) { err = check_error (KIM_NULL_PARAMETER_ERR); } + if (!err && !in_context ) { err = check_error (KIM_NULL_PARAMETER_ERR); } + if (!err && !out_init_cred_options) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !in_options->addressless) { err = krb5_error (in_context, @@ -587,7 +587,7 @@ kim_error kim_options_free_init_cred_options (krb5_context in_conte { kim_error err = KIM_NO_ERROR; - if (!err && !in_context) { err = param_error (1, "in_context", "NULL"); } + if (!err && !in_context) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && io_init_cred_options && *io_init_cred_options) { if ((*io_init_cred_options)->address_list) { @@ -624,8 +624,8 @@ kim_error kim_prompt_callback_default (kim_options *io_options, { kim_error err = KIM_NO_ERROR; - if (!err && !io_options) { err = param_error (1, "io_options", "NULL"); } - if (!err && !out_reply ) { err = param_error (6, "out_reply", "NULL"); } + if (!err && !io_options) { err = check_error (KIM_NULL_PARAMETER_ERR); } + if (!err && !out_reply ) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err) { } @@ -644,8 +644,8 @@ kim_error kim_prompt_callback_gui (kim_options *io_options, { kim_error err = KIM_NO_ERROR; - if (!err && !io_options) { err = param_error (1, "io_options", "NULL"); } - if (!err && !out_reply ) { err = param_error (6, "out_reply", "NULL"); } + if (!err && !io_options) { err = check_error (KIM_NULL_PARAMETER_ERR); } + if (!err && !out_reply ) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err) { } @@ -664,8 +664,8 @@ kim_error kim_prompt_callback_cli (kim_options *io_options, { kim_error err = KIM_NO_ERROR; - if (!err && !io_options) { err = param_error (1, "io_options", "NULL"); } - if (!err && !out_reply ) { err = param_error (6, "out_reply", "NULL"); } + if (!err && !io_options) { err = check_error (KIM_NULL_PARAMETER_ERR); } + if (!err && !out_reply ) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err) { } @@ -682,5 +682,5 @@ kim_error kim_prompt_callback_none (kim_options *io_options, kim_string in_description, void **out_reply) { - return KIM_USER_CANCELED_ECODE; + return KIM_USER_CANCELED_ERR; } diff --git a/src/kim/lib/kim_preferences.c b/src/kim/lib/kim_preferences.c index d8c2dee1a..f64ae5c15 100644 --- a/src/kim/lib/kim_preferences.c +++ b/src/kim/lib/kim_preferences.c @@ -45,11 +45,11 @@ static inline kim_error kim_favorite_identities_allocate (kim_favorite_identitie kim_error err = KIM_NO_ERROR; kim_favorite_identities favorite_identities = NULL; - if (!err && !out_favorite_identities) { err = param_error (1, "out_favorite_identities", "NULL"); } + if (!err && !out_favorite_identities) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err) { favorite_identities = malloc (sizeof (*favorite_identities)); - if (!favorite_identities) { err = os_error (errno); } + if (!favorite_identities) { err = KIM_OUT_OF_MEMORY_ERR; } } if (!err) { @@ -70,7 +70,7 @@ static inline kim_error kim_favorite_identities_resize (kim_favorite_identities { kim_error err = KIM_NO_ERROR; - if (!err && !io_favorite_identities) { err = param_error (1, "io_favorite_identities", "NULL"); } + if (!err && !io_favorite_identities) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && io_favorite_identities->count != in_new_count) { kim_identity *identities = NULL; @@ -86,7 +86,7 @@ static inline kim_error kim_favorite_identities_resize (kim_favorite_identities identities = realloc (io_favorite_identities->identities, sizeof (*identities) * in_new_count); } - if (!identities) { err = os_error (errno); } + if (!identities) { err = KIM_OUT_OF_MEMORY_ERR; } } if (!err) { @@ -108,7 +108,7 @@ kim_error kim_favorite_identities_create (kim_favorite_identities *out_favorite_ kim_error err = KIM_NO_ERROR; kim_favorite_identities favorite_identities = NULL; - if (!err && !out_favorite_identities) { err = param_error (1, "out_favorite_identities", "NULL"); } + if (!err && !out_favorite_identities) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err) { err = kim_favorite_identities_allocate (&favorite_identities); @@ -132,8 +132,8 @@ kim_error kim_favorite_identities_copy (kim_favorite_identities *out_favorite_id kim_error err = KIM_NO_ERROR; kim_favorite_identities favorite_identities = NULL; - if (!err && !out_favorite_identities) { err = param_error (1, "out_favorite_identities", "NULL"); } - if (!err && !in_favorite_identities ) { err = param_error (2, "in_favorite_identities", "NULL"); } + if (!err && !out_favorite_identities) { err = check_error (KIM_NULL_PARAMETER_ERR); } + if (!err && !in_favorite_identities ) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err) { err = kim_favorite_identities_allocate (&favorite_identities); @@ -169,8 +169,8 @@ kim_error kim_favorite_identities_get_number_of_identities (kim_favorite_identit { kim_error err = KIM_NO_ERROR; - if (!err && !in_favorite_identities ) { err = param_error (1, "in_favorite_identities", "NULL"); } - if (!err && !out_number_of_identities) { err = param_error (2, "out_number_of_identities", "NULL"); } + if (!err && !in_favorite_identities ) { 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_favorite_identities->count; @@ -187,12 +187,12 @@ kim_error kim_favorite_identities_get_identity_at_index (kim_favorite_identities { kim_error err = KIM_NO_ERROR; - if (!err && !in_favorite_identities) { err = param_error (1, "in_favorite_identities", "NULL"); } - if (!err && !out_identity ) { err = param_error (3, "out_identity", "NULL"); } + if (!err && !in_favorite_identities) { err = check_error (KIM_NULL_PARAMETER_ERR); } + if (!err && !out_identity ) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err) { if (in_index >= in_favorite_identities->count) { - err = kim_error_set_message_for_code (KIM_BAD_IDENTITY_INDEX_ECODE, + err = kim_error_set_message_for_code (KIM_BAD_IDENTITY_INDEX_ERR, in_index); } } @@ -213,8 +213,8 @@ kim_error kim_favorite_identities_add_identity (kim_favorite_identities io_favor kim_identity identity = NULL; kim_count insert_at = 0; - if (!err && !io_favorite_identities) { err = param_error (1, "io_favorite_identities", "NULL"); } - if (!err && !in_identity ) { err = param_error (2, "in_identity", "NULL"); } + if (!err && !io_favorite_identities) { err = check_error (KIM_NULL_PARAMETER_ERR); } + if (!err && !in_identity ) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err) { err = kim_identity_copy (&identity, in_identity); @@ -239,7 +239,7 @@ kim_error kim_favorite_identities_add_identity (kim_favorite_identities io_favor err = kim_identity_get_display_string (in_identity, &display_string); if (!err) { - err = kim_error_set_message_for_code (KIM_IDENTITY_ALREADY_IN_IDENTITIES_LIST, + err = kim_error_set_message_for_code (KIM_IDENTITY_ALREADY_IN_LIST_ERR, display_string); } @@ -279,8 +279,8 @@ kim_error kim_favorite_identities_remove_identity (kim_favorite_identities io_fa kim_boolean found = FALSE; kim_count i; - if (!err && !io_favorite_identities) { err = param_error (1, "io_favorite_identities", "NULL"); } - if (!err && !in_identity ) { err = param_error (2, "in_identity", "NULL"); } + if (!err && !io_favorite_identities) { 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_favorite_identities->count; i++) { @@ -312,7 +312,7 @@ kim_error kim_favorite_identities_remove_identity (kim_favorite_identities io_fa err = kim_identity_get_display_string (in_identity, &display_string); if (!err) { - err = kim_error_set_message_for_code (KIM_IDENTITY_NOT_IN_IDENTITIES_LIST, + err = kim_error_set_message_for_code (KIM_IDENTITY_NOT_IN_LIST_ERR, display_string); } @@ -328,7 +328,7 @@ kim_error kim_favorite_identities_remove_all_identities (kim_favorite_identities { kim_error err = KIM_NO_ERROR; - if (!err && !io_favorite_identities) { err = param_error (1, "io_favorite_identities", "NULL"); } + if (!err && !io_favorite_identities) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err) { kim_count i; @@ -407,7 +407,7 @@ static kim_error kim_preferences_read (kim_preferences in_preferences) { kim_error err = KIM_NO_ERROR; - if (!err && !in_preferences) { err = param_error (1, "in_preferences", "NULL"); } + if (!err && !in_preferences) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err) { kim_lifetime lifetime = kim_default_lifetime; @@ -546,7 +546,7 @@ static kim_error kim_preferences_write (kim_preferences in_preferences) { kim_error err = KIM_NO_ERROR; - if (!err && !in_preferences) { err = param_error (1, "in_preferences", "NULL"); } + if (!err && !in_preferences) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && in_preferences->remember_options && in_preferences->options_changed) { kim_lifetime lifetime = kim_default_lifetime; @@ -672,11 +672,11 @@ static inline kim_error kim_preferences_allocate (kim_preferences *out_preferenc kim_error err = KIM_NO_ERROR; kim_preferences preferences = NULL; - if (!err && !out_preferences) { err = param_error (1, "out_preferences", "NULL"); } + if (!err && !out_preferences) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err) { preferences = malloc (sizeof (*preferences)); - if (!preferences) { err = os_error (errno); } + if (!preferences) { err = KIM_OUT_OF_MEMORY_ERR; } } if (!err) { @@ -697,7 +697,7 @@ kim_error kim_preferences_create (kim_preferences *out_preferences) kim_error err = KIM_NO_ERROR; kim_preferences preferences = NULL; - if (!err && !out_preferences) { err = param_error (1, "out_preferences", "NULL"); } + if (!err && !out_preferences) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err) { err = kim_preferences_allocate (&preferences); @@ -730,8 +730,8 @@ kim_error kim_preferences_copy (kim_preferences *out_preferences, kim_error err = KIM_NO_ERROR; kim_preferences preferences = NULL; - if (!err && !out_preferences) { err = param_error (1, "out_preferences", "NULL"); } - if (!err && !in_preferences ) { err = param_error (2, "in_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); @@ -770,8 +770,8 @@ 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 = param_error (1, "io_preferences", "NULL"); } - if (!err && !in_options ) { err = param_error (2, "in_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); @@ -793,8 +793,8 @@ kim_error kim_preferences_get_options (kim_preferences in_preferences, { kim_error err = KIM_NO_ERROR; - if (!err && !in_preferences) { err = param_error (1, "in_preferences", "NULL"); } - if (!err && !out_options ) { err = param_error (2, "out_options", "NULL"); } + 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); @@ -810,7 +810,7 @@ kim_error kim_preferences_set_remember_options (kim_preferences io_preferences, { kim_error err = KIM_NO_ERROR; - if (!err && !io_preferences) { err = param_error (1, "io_preferences", "NULL"); } + if (!err && !io_preferences) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err) { io_preferences->remember_options = in_remember_options; @@ -827,8 +827,8 @@ kim_error kim_preferences_get_remember_options (kim_preferences in_preferences, { kim_error err = KIM_NO_ERROR; - if (!err && !in_preferences ) { err = param_error (1, "in_preferences", "NULL"); } - if (!err && !out_remember_options) { err = param_error (2, "out_remember_options", "NULL"); } + 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; @@ -845,7 +845,7 @@ 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 = param_error (1, "io_preferences", "NULL"); } + if (!err && !io_preferences ) { err = check_error (KIM_NULL_PARAMETER_ERR); } /* in_client_identity may be KIM_IDENTITY_ANY */ if (!err && in_client_identity) { @@ -868,8 +868,8 @@ kim_error kim_preferences_get_client_identity (kim_preferences in_preferences, { kim_error err = KIM_NO_ERROR; - if (!err && !in_preferences ) { err = param_error (1, "in_preferences", "NULL"); } - if (!err && !out_client_identity) { err = param_error (2, "out_client_identity", "NULL"); } + 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); @@ -885,7 +885,7 @@ kim_error kim_preferences_set_remember_client_identity (kim_preferences io_prefe { kim_error err = KIM_NO_ERROR; - if (!err && !io_preferences) { err = param_error (1, "io_preferences", "NULL"); } + if (!err && !io_preferences) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err) { io_preferences->remember_client_identity = in_remember_client_identity; @@ -902,8 +902,8 @@ kim_error kim_preferences_get_remember_client_identity (kim_preferences in_pref { kim_error err = KIM_NO_ERROR; - if (!err && !in_preferences ) { err = param_error (1, "in_preferences", "NULL"); } - if (!err && !out_remember_client_identity) { err = param_error (2, "out_remember_client_identity", "NULL"); } + 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; @@ -919,7 +919,7 @@ kim_error kim_preferences_set_minimum_lifetime (kim_preferences io_preferences, { kim_error err = KIM_NO_ERROR; - if (!err && !io_preferences) { err = param_error (1, "io_preferences", "NULL"); } + if (!err && !io_preferences) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err) { io_preferences->minimum_lifetime = in_minimum_lifetime; @@ -936,8 +936,8 @@ kim_error kim_preferences_get_minimum_lifetime (kim_preferences in_preferences, { kim_error err = KIM_NO_ERROR; - if (!err && !in_preferences ) { err = param_error (1, "in_preferences", "NULL"); } - if (!err && !out_minimum_lifetime) { err = param_error (2, "out_minimum_lifetime", "NULL"); } + 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; @@ -953,7 +953,7 @@ kim_error kim_preferences_set_maximum_lifetime (kim_preferences io_preferences, { kim_error err = KIM_NO_ERROR; - if (!err && !io_preferences) { err = param_error (1, "io_preferences", "NULL"); } + if (!err && !io_preferences) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err) { io_preferences->maximum_lifetime = in_maximum_lifetime; @@ -970,8 +970,8 @@ kim_error kim_preferences_get_maximum_lifetime (kim_preferences in_preferences, { kim_error err = KIM_NO_ERROR; - if (!err && !in_preferences ) { err = param_error (1, "in_preferences", "NULL"); } - if (!err && !out_maximum_lifetime) { err = param_error (2, "out_maximum_lifetime", "NULL"); } + 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; @@ -987,7 +987,7 @@ kim_error kim_preferences_set_minimum_renewal_lifetime (kim_preferences io_prefe { kim_error err = KIM_NO_ERROR; - if (!err && !io_preferences) { err = param_error (1, "io_preferences", "NULL"); } + if (!err && !io_preferences) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err) { io_preferences->minimum_renewal_lifetime = in_minimum_renewal_lifetime; @@ -1004,8 +1004,8 @@ kim_error kim_preferences_get_minimum_renewal_lifetime (kim_preferences in_pref { kim_error err = KIM_NO_ERROR; - if (!err && !in_preferences ) { err = param_error (1, "in_preferences", "NULL"); } - if (!err && !out_minimum_renewal_lifetime) { err = param_error (2, "out_minimum_renewal_lifetime", "NULL"); } + 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; @@ -1021,7 +1021,7 @@ kim_error kim_preferences_set_maximum_renewal_lifetime (kim_preferences io_prefe { kim_error err = KIM_NO_ERROR; - if (!err && !io_preferences) { err = param_error (1, "io_preferences", "NULL"); } + if (!err && !io_preferences) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err) { io_preferences->maximum_renewal_lifetime = in_maximum_renewal_lifetime; @@ -1038,8 +1038,8 @@ kim_error kim_preferences_get_maximum_renewal_lifetime (kim_preferences in_pref { kim_error err = KIM_NO_ERROR; - if (!err && !in_preferences ) { err = param_error (1, "in_preferences", "NULL"); } - if (!err && !out_maximum_renewal_lifetime) { err = param_error (2, "out_maximum_renewal_lifetime", "NULL"); } + 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; @@ -1056,8 +1056,8 @@ kim_error kim_preferences_set_favorite_identities (kim_preferences io_pr kim_error err = KIM_NO_ERROR; kim_favorite_identities favorite_identities = NULL; - if (!err && !io_preferences ) { err = param_error (1, "io_preferences", "NULL"); } - if (!err && !in_favorite_identities) { err = param_error (2, "in_favorite_identities", "NULL"); } + if (!err && !io_preferences ) { err = check_error (KIM_NULL_PARAMETER_ERR); } + if (!err && !in_favorite_identities) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err) { err = kim_favorite_identities_copy (&favorite_identities, in_favorite_identities); @@ -1079,8 +1079,8 @@ kim_error kim_preferences_get_favorite_identities (kim_preferences in_p { kim_error err = KIM_NO_ERROR; - if (!err && !in_preferences ) { err = param_error (1, "in_preferences", "NULL"); } - if (!err && !out_favorite_identities) { err = param_error (2, "out_favorite_identities", "NULL"); } + if (!err && !in_preferences ) { err = check_error (KIM_NULL_PARAMETER_ERR); } + if (!err && !out_favorite_identities) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err) { err = kim_favorite_identities_copy (out_favorite_identities, in_preferences->favorite_identities); @@ -1095,7 +1095,7 @@ kim_error kim_preferences_synchronize (kim_preferences in_preferences) { kim_error err = KIM_NO_ERROR; - if (!err && !in_preferences) { err = param_error (1, "in_preferences", "NULL"); } + if (!err && !in_preferences) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err) { err = kim_preferences_write (in_preferences); diff --git a/src/kim/lib/kim_private.h b/src/kim/lib/kim_private.h index 16452a33d..428cf2b20 100644 --- a/src/kim/lib/kim_private.h +++ b/src/kim/lib/kim_private.h @@ -32,6 +32,7 @@ #include #include +#include #include "kim_library_private.h" #include "kim_debug_private.h" diff --git a/src/kim/lib/kim_selection_hints.c b/src/kim/lib/kim_selection_hints.c index 07ea4e99b..78a4c03e8 100644 --- a/src/kim/lib/kim_selection_hints.c +++ b/src/kim/lib/kim_selection_hints.c @@ -42,18 +42,18 @@ struct kim_selection_hints_opaque { }; struct kim_selection_hints_opaque kim_selection_hints_initializer = { -NULL, -NULL, -NULL, -KIM_OPTIONS_DEFAULT, -TRUE, -TRUE, -NULL, -NULL, -NULL, -NULL, -NULL, -NULL + NULL, + NULL, + NULL, + KIM_OPTIONS_DEFAULT, + TRUE, + TRUE, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL }; /* ------------------------------------------------------------------------ */ @@ -63,11 +63,11 @@ static inline kim_error kim_selection_hints_allocate (kim_selection_hints *out_s kim_error err = KIM_NO_ERROR; kim_selection_hints selection_hints = NULL; - if (!err && !out_selection_hints) { err = param_error (1, "out_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 = os_error (errno); } + if (!selection_hints) { err = KIM_OUT_OF_MEMORY_ERR; } } if (!err) { @@ -89,8 +89,8 @@ 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 = param_error (1, "out_selection_hints", "NULL"); } - if (!err && !in_application_identifier) { err = param_error (1, "in_application_identifier", "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); @@ -119,8 +119,8 @@ 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 = param_error (1, "out_selection_hints", "NULL"); } - if (!err && !in_selection_hints ) { err = param_error (1, "in_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); @@ -197,9 +197,9 @@ kim_error kim_selection_hints_set_hint (kim_selection_hints io_selection_hints, { kim_error err = KIM_NO_ERROR; - if (!err && !io_selection_hints) { err = param_error (1, "io_selection_hints", "NULL"); } - if (!err && !in_hint_key ) { err = param_error (2, "in_hint_key", "NULL"); } - if (!err && !in_hint_string ) { err = param_error (3, "in_hint_string", "NULL"); } + 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)) { @@ -227,7 +227,7 @@ kim_error kim_selection_hints_set_hint (kim_selection_hints io_selection_hints, in_hint_string); } else { - err = kim_error_set_message_for_code (KIM_UNSUPPORTED_HINT_ECODE, + err = kim_error_set_message_for_code (KIM_UNSUPPORTED_HINT_ERR, in_hint_key); } } @@ -243,9 +243,9 @@ kim_error kim_selection_hints_get_hint (kim_selection_hints in_selection_hints, { kim_error err = KIM_NO_ERROR; - if (!err && !in_selection_hints) { err = param_error (1, "in_selection_hints", "NULL"); } - if (!err && !in_hint_key ) { err = param_error (2, "in_hint_key", "NULL"); } - if (!err && !out_hint_string ) { err = param_error (3, "out_hint_string", "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)) { @@ -273,7 +273,7 @@ kim_error kim_selection_hints_get_hint (kim_selection_hints in_selection_hints, in_selection_hints->service_identity); } else { - err = kim_error_set_message_for_code (KIM_UNSUPPORTED_HINT_ECODE, + err = kim_error_set_message_for_code (KIM_UNSUPPORTED_HINT_ERR, in_hint_key); } } @@ -288,8 +288,8 @@ kim_error kim_selection_hints_set_application_name (kim_selection_hints io_selec { kim_error err = KIM_NO_ERROR; - if (!err && !io_selection_hints ) { err = param_error (1, "io_selection_hints", "NULL"); } - if (!err && !in_application_name) { err = param_error (2, "in_application_name", "NULL"); } + if (!err && !io_selection_hints ) { err = check_error (KIM_NULL_PARAMETER_ERR); } + if (!err && !in_application_name) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err) { err = kim_string_copy (&io_selection_hints->application_name, in_application_name); @@ -305,8 +305,8 @@ kim_error kim_selection_hints_get_application_name (kim_selection_hints in_sele { kim_error err = KIM_NO_ERROR; - if (!err && !in_selection_hints ) { err = param_error (1, "in_selection_hints", "NULL"); } - if (!err && !out_application_name) { err = param_error (2, "out_application_name", "NULL"); } + if (!err && !in_selection_hints ) { err = check_error (KIM_NULL_PARAMETER_ERR); } + if (!err && !out_application_name) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err) { if (in_selection_hints->application_name) { @@ -326,8 +326,8 @@ kim_error kim_selection_hints_set_explanation (kim_selection_hints io_selection_ { kim_error err = KIM_NO_ERROR; - if (!err && !io_selection_hints) { err = param_error (1, "io_selection_hints", "NULL"); } - if (!err && !in_explanation ) { err = param_error (2, "in_explanation", "NULL"); } + 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); @@ -343,8 +343,8 @@ kim_error kim_selection_hints_get_explanation (kim_selection_hints in_selection { kim_error err = KIM_NO_ERROR; - if (!err && !in_selection_hints) { err = param_error (1, "in_selection_hints", "NULL"); } - if (!err && !out_explanation ) { err = param_error (2, "out_explanation", "NULL"); } + 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) { @@ -364,8 +364,8 @@ kim_error kim_selection_hints_set_options (kim_selection_hints io_selection_hint { kim_error err = KIM_NO_ERROR; - if (!err && !io_selection_hints) { err = param_error (1, "io_selection_hints", "NULL"); } - if (!err && !in_options ) { err = param_error (2, "in_options", "NULL"); } + 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); @@ -381,8 +381,8 @@ kim_error kim_selection_hints_get_options (kim_selection_hints in_selection_hin { kim_error err = KIM_NO_ERROR; - if (!err && !in_selection_hints) { err = param_error (1, "in_selection_hints", "NULL"); } - if (!err && !out_options ) { err = param_error (2, "out_options", "NULL"); } + 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) { if (in_selection_hints->options) { @@ -402,7 +402,7 @@ kim_error kim_selection_hints_set_allow_user_interaction (kim_selection_hints io { kim_error err = KIM_NO_ERROR; - if (!err && !io_selection_hints ) { err = param_error (1, "io_selection_hints", "NULL"); } + if (!err && !io_selection_hints ) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err) { io_selection_hints->allow_user_interaction = in_allow_user_interaction; @@ -418,8 +418,8 @@ kim_error kim_selection_hints_get_allow_user_interaction (kim_selection_hints i { kim_error err = KIM_NO_ERROR; - if (!err && !in_selection_hints ) { err = param_error (1, "in_selection_hints", "NULL"); } - if (!err && !out_allow_user_interaction) { err = param_error (2, "out_allow_user_interaction", "NULL"); } + 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; @@ -435,7 +435,7 @@ kim_error kim_selection_hints_set_remember_identity (kim_selection_hints io_sele { kim_error err = KIM_NO_ERROR; - if (!err && !io_selection_hints ) { err = param_error (1, "io_selection_hints", "NULL"); } + if (!err && !io_selection_hints ) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err) { io_selection_hints->use_cached_results = in_use_cached_results; @@ -451,8 +451,8 @@ kim_error kim_selection_hints_get_remember_identity (kim_selection_hints in_sel { kim_error err = KIM_NO_ERROR; - if (!err && !in_selection_hints ) { err = param_error (1, "in_selection_hints", "NULL"); } - if (!err && !out_use_cached_results) { err = param_error (2, "out_use_cached_results", "NULL"); } + 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; @@ -470,8 +470,8 @@ kim_error kim_selection_hints_get_identity (kim_selection_hints in_selection_hi kim_identity identity = NULL; kim_ccache ccache = NULL; - if (!err && !in_selection_hints) { err = param_error (1, "in_selection_hints", "NULL"); } - if (!err && !out_identity ) { err = param_error (2, "out_identity", "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); @@ -499,8 +499,8 @@ kim_error kim_selection_hints_remember_identity (kim_selection_hints in_selectio { kim_error err = KIM_NO_ERROR; - if (!err && !in_selection_hints) { err = param_error (1, "in_selection_hints", "NULL"); } - if (!err && !in_identity ) { err = param_error (2, "in_identity", "NULL"); } + 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, @@ -516,7 +516,7 @@ kim_error kim_selection_hints_forget_identity (kim_selection_hints in_selection_ { kim_error err = KIM_NO_ERROR; - if (!err && !in_selection_hints) { err = param_error (1, "in_selection_hints", "NULL"); } + if (!err && !in_selection_hints) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err) { err = kim_os_selection_hints_forget_identity (in_selection_hints); @@ -532,8 +532,8 @@ kim_error kim_selection_hints_get_preference_strings (kim_selection_hints { kim_error err = KIM_NO_ERROR; - if (!err && !in_selection_hints ) { err = param_error (1, "in_selection_hints", "NULL"); } - if (!err && !io_preference_strings) { err = param_error (2, "io_preference_strings", "NULL"); } + 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; diff --git a/src/kim/lib/kim_string.c b/src/kim/lib/kim_string.c index 76e700001..4e7356515 100644 --- a/src/kim/lib/kim_string.c +++ b/src/kim/lib/kim_string.c @@ -52,7 +52,7 @@ kim_error kim_string_create_from_format_va_retcode (kim_string *out_string, kim_error err = KIM_NO_ERROR; int count = vasprintf ((char **) out_string, in_format, in_args); - if (count < 0) { err = os_error (ENOMEM); } + if (count < 0) { err = check_error (KIM_OUT_OF_MEMORY_ERR); } return err; } @@ -66,8 +66,8 @@ kim_error kim_string_create_from_format_va (kim_string *out_string, kim_error err = KIM_NO_ERROR; kim_string string = NULL; - if (!err && !out_string) { err = param_error (1, "out_string", "NULL"); } - if (!err && !in_format ) { err = param_error (2, "in_format", "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, @@ -94,12 +94,12 @@ kim_error kim_string_create_from_buffer (kim_string *out_string, kim_error err = KIM_NO_ERROR; kim_string string = NULL; - if (!err && !out_string) { err = param_error (1, "out_string", "NULL"); } - if (!err && !in_buffer ) { err = param_error (2, "in_buffer", "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 = os_error (ENOMEM); } + if (!string) { err = check_error (KIM_OUT_OF_MEMORY_ERR); } } if (!err) { @@ -121,12 +121,12 @@ kim_error kim_string_copy (kim_string *out_string, kim_error err = KIM_NO_ERROR; kim_string string = NULL; - if (!err && !out_string) { err = param_error (1, "out_string", "NULL"); } - if (!err && !in_string ) { err = param_error (2, "in_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) { string = calloc (strlen (in_string) + 1, sizeof (char *)); - if (!string) { err = os_error (ENOMEM); } + if (!string) { err = check_error (KIM_OUT_OF_MEMORY_ERR); } } if (!err) { diff --git a/src/kim/lib/mac/kim_os_identity.c b/src/kim/lib/mac/kim_os_identity.c index 8088be183..18e217660 100644 --- a/src/kim/lib/mac/kim_os_identity.c +++ b/src/kim/lib/mac/kim_os_identity.c @@ -35,7 +35,7 @@ kim_error kim_os_identity_create_for_username (kim_identity *out_identity) { kim_error err = KIM_NO_ERROR; - if (!err && !out_identity) { err = param_error (1, "out_identity", "NULL"); } + if (!err && !out_identity) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err) { struct passwd *pw = getpwuid (getuid ()); diff --git a/src/kim/lib/mac/kim_os_library.c b/src/kim/lib/mac/kim_os_library.c index 350515bca..c9f563454 100644 --- a/src/kim/lib/mac/kim_os_library.c +++ b/src/kim/lib/mac/kim_os_library.c @@ -24,11 +24,72 @@ * or implied warranty. */ -#include -#include +#include +#include "k5-int.h" +#include "k5-thread.h" +#include #include "kim_os_private.h" + +static k5_mutex_t g_bundle_lookup_mutex = K5_MUTEX_PARTIAL_INITIALIZER; + +MAKE_INIT_FUNCTION(kim_os_library_thread_init); +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; +} + +/* ------------------------------------------------------------------------ */ + +static void kim_os_library_thread_fini (void) +{ + if (!INITIALIZER_RAN (kim_os_library_thread_init) || PROGRAM_EXITING ()) { + return; + } + k5_mutex_destroy (&g_bundle_lookup_mutex); +} + +#pragma mark - + +/* ------------------------------------------------------------------------ */ + +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; +} + +/* ------------------------------------------------------------------------ */ + +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; +} + +#pragma mark - + /* ------------------------------------------------------------------------ */ kim_boolean kim_os_library_caller_is_server (void) diff --git a/src/kim/lib/mac/kim_os_preferences.c b/src/kim/lib/mac/kim_os_preferences.c index 3d8e2b4e5..3606f1a85 100644 --- a/src/kim/lib/mac/kim_os_preferences.c +++ b/src/kim/lib/mac/kim_os_preferences.c @@ -35,14 +35,14 @@ /* ------------------------------------------------------------------------ */ -static kim_error kim_os_preferences_cfstring_for_key (kim_preference_key in_key, - CFStringRef *out_kim_string_key, - CFStringRef *out_kll_string_key) +static kim_error kim_os_preferences_cfstring_for_key (kim_preference_key in_key, + CFStringRef *out_kim_string_key, + CFStringRef *out_kll_string_key) { kim_error err = KIM_NO_ERROR; - if (!err && !out_kim_string_key) { err = param_error (2, "out_kim_string_key", "NULL"); } - if (!err && !out_kll_string_key) { err = param_error (3, "out_kll_string_key", "NULL"); } + if (!err && !out_kim_string_key) { err = check_error (KIM_NULL_PARAMETER_ERR); } + if (!err && !out_kll_string_key) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err) { if (in_key == kim_preference_key_lifetime) { @@ -102,7 +102,10 @@ static kim_error kim_os_preferences_cfstring_for_key (kim_preference_key in_key, *out_kll_string_key = CFSTR ("KLMaximumRenewableLifetime"); } else { - err = param_error (1, "in_key", "not in kim_preference_key_enum"); + /* ignore unsupported keys */ + kim_debug_printf ("Unsupported preference key %d", in_key); + *out_kim_string_key = NULL; + *out_kll_string_key = NULL; } } @@ -112,8 +115,8 @@ static kim_error kim_os_preferences_cfstring_for_key (kim_preference_key in_key, /* ------------------------------------------------------------------------ */ static kim_error kim_os_preferences_get_value (kim_preference_key in_key, - CFTypeID in_type, - CFPropertyListRef *out_value) + CFTypeID in_type, + CFPropertyListRef *out_value) { kim_error err = KIM_NO_ERROR; @@ -123,7 +126,7 @@ static kim_error kim_os_preferences_get_value (kim_preference_key in_key, CFStringRef hosts[] = { kCFPreferencesCurrentHost, kCFPreferencesAnyHost, NULL }; CFStringRef keys[] = { NULL, NULL, NULL }; - if (!err && !out_value) { err = param_error (3, "out_value", "NULL"); } + if (!err && !out_value) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err) { /* Index must correspond to the appropriate file */ @@ -139,7 +142,7 @@ static kim_error kim_os_preferences_get_value (kim_preference_key in_key, } for (u = 0; !value && users[u]; u++) { - for (f = 0; !value && files[f]; f++) { + for (f = 0; !value && files[f] && keys[f]; f++) { for (h = 0; !value && hosts[h]; h++) { value = CFPreferencesCopyValue (keys[f], files[f], users[u], hosts[h]); } @@ -147,7 +150,7 @@ static kim_error kim_os_preferences_get_value (kim_preference_key in_key, } if (value && CFGetTypeID (value) != in_type) { - err = check_error (KIM_PREFERENCES_READ_ECODE); + err = check_error (KIM_PREFERENCES_READ_ERR); } } @@ -171,20 +174,20 @@ static kim_error kim_os_preferences_set_value (kim_preference_key in_key, CFStringRef kim_key = NULL; CFStringRef kll_key = NULL; - if (!err && !in_value) { err = param_error (2, "in_value", "NULL"); } + if (!err && !in_value) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err) { err = kim_os_preferences_cfstring_for_key (in_key, &kim_key, &kll_key); } - if (!err) { + if (!err && kim_key) { kim_boolean homedir_ok = kim_library_allow_home_directory_access(); CFStringRef user = homedir_ok ? kCFPreferencesCurrentUser : kCFPreferencesAnyUser; CFStringRef host = homedir_ok ? kCFPreferencesAnyHost : kCFPreferencesCurrentHost; CFPreferencesSetValue (kim_key, in_value, KIM_PREFERENCES_FILE, user, host); if (!CFPreferencesSynchronize (KIM_PREFERENCES_FILE, user, host)) { - err = check_error (KIM_PREFERENCES_WRITE_ECODE); + err = check_error (KIM_PREFERENCES_WRITE_ERR); } } @@ -203,7 +206,7 @@ kim_error kim_os_preferences_get_identity_for_key (kim_preference_key in_key, kim_string string = NULL; CFStringRef value = NULL; - if (!err && !out_identity) { err = param_error (2, "out_identity", "NULL"); } + if (!err && !out_identity) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err) { err = kim_os_preferences_get_value (in_key, CFStringGetTypeID (), @@ -276,7 +279,7 @@ kim_error kim_os_preferences_get_favorite_identities_for_key (kim_preference_key kim_error err = KIM_NO_ERROR; CFArrayRef value = NULL; - if (!err && !out_favorite_identities) { err = param_error (2, "out_favorite_identities", "NULL"); } + if (!err && !out_favorite_identities) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err) { err = kim_os_preferences_get_value (in_key, CFArrayGetTypeID (), @@ -301,7 +304,7 @@ kim_error kim_os_preferences_get_favorite_identities_for_key (kim_preference_key cfstring = (CFStringRef) CFArrayGetValueAtIndex (value, i); if (!cfstring || CFGetTypeID (cfstring) != CFStringGetTypeID ()) { - err = check_error (KIM_PREFERENCES_READ_ECODE); + err = check_error (KIM_PREFERENCES_READ_ERR); } if (!err) { @@ -343,7 +346,7 @@ kim_error kim_os_preferences_set_favorite_identities_for_key (kim_preference_key kim_count count = 0; CFMutableArrayRef value = NULL; - if (!err && !in_favorite_identities) { err = param_error (2, "in_favorite_identities", "NULL"); } + if (!err && !in_favorite_identities) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err) { err = kim_favorite_identities_get_number_of_identities (in_favorite_identities, &count); @@ -351,7 +354,7 @@ kim_error kim_os_preferences_set_favorite_identities_for_key (kim_preference_key if (!err) { value = CFArrayCreateMutable (kCFAllocatorDefault, count, &kCFTypeArrayCallBacks); - if (!value) { err = os_error (ENOMEM); } + if (!value) { err = KIM_OUT_OF_MEMORY_ERR; } } if (!err) { @@ -400,7 +403,7 @@ kim_error kim_os_preferences_get_time_for_key (kim_preference_key in_key, kim_error err = KIM_NO_ERROR; CFNumberRef value = NULL; - if (!err && !out_time) { err = param_error (2, "out_time", "NULL"); } + if (!err && !out_time) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err) { err = kim_os_preferences_get_value (in_key, CFNumberGetTypeID (), @@ -411,7 +414,7 @@ kim_error kim_os_preferences_get_time_for_key (kim_preference_key in_key, if (value) { SInt32 number; // CFNumbers are signed so we need to cast if (CFNumberGetValue (value, kCFNumberSInt32Type, &number) != TRUE) { - err = os_error (ENOMEM); + err = KIM_OUT_OF_MEMORY_ERR; } else { *out_time = number; } @@ -436,7 +439,7 @@ kim_error kim_os_preferences_set_time_for_key (kim_preference_key in_key, if (!err) { value = CFNumberCreate (kCFAllocatorDefault, kCFNumberSInt32Type, &number); - if (!value) { err = os_error (ENOMEM); } + if (!value) { err = KIM_OUT_OF_MEMORY_ERR; } } if (!err) { @@ -457,7 +460,7 @@ kim_error kim_os_preferences_get_lifetime_for_key (kim_preference_key in_key, kim_error err = KIM_NO_ERROR; CFNumberRef value = NULL; - if (!err && !out_lifetime) { err = param_error (2, "out_lifetime", "NULL"); } + if (!err && !out_lifetime) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err) { err = kim_os_preferences_get_value (in_key, CFNumberGetTypeID (), @@ -468,7 +471,7 @@ kim_error kim_os_preferences_get_lifetime_for_key (kim_preference_key in_key, if (value) { SInt32 number; // CFNumbers are signed so we need to cast if (CFNumberGetValue (value, kCFNumberSInt32Type, &number) != TRUE) { - err = os_error (ENOMEM); + err = KIM_OUT_OF_MEMORY_ERR; } else { *out_lifetime = number; } @@ -493,7 +496,7 @@ kim_error kim_os_preferences_set_lifetime_for_key (kim_preference_key in_key, if (!err) { value = CFNumberCreate (kCFAllocatorDefault, kCFNumberSInt32Type, &number); - if (!value) { err = os_error (ENOMEM); } + if (!value) { err = KIM_OUT_OF_MEMORY_ERR; } } if (!err) { @@ -514,7 +517,7 @@ kim_error kim_os_preferences_get_boolean_for_key (kim_preference_key in_key, kim_error err = KIM_NO_ERROR; CFBooleanRef value = NULL; - if (!err && !out_boolean) { err = param_error (2, "out_boolean", "NULL"); } + if (!err && !out_boolean) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err) { err = kim_os_preferences_get_value (in_key, CFBooleanGetTypeID (), diff --git a/src/kim/lib/mac/kim_os_private.h b/src/kim/lib/mac/kim_os_private.h index 6fb5b8515..57176fe5e 100644 --- a/src/kim/lib/mac/kim_os_private.h +++ b/src/kim/lib/mac/kim_os_private.h @@ -30,20 +30,16 @@ #include #include "kim_private.h" +kim_error kim_os_library_lock_for_bundle_lookup (void); +kim_error kim_os_library_unlock_for_bundle_lookup (void); -CFStringEncoding kim_os_string_get_encoding (void); -CFStringRef kim_os_string_get_cfstring_for_key_and_dictionary (CFStringRef in_key, - CFBundleRef in_bundle); - -CFStringRef kim_os_string_get_cfstring_for_key (kim_string in_key_string); +kim_error kim_os_string_create_for_key (kim_string *out_string, + kim_string in_key_string); kim_error kim_os_string_create_from_cfstring (kim_string *out_string, CFStringRef in_cfstring); -kim_error kim_os_string_create_for_key (kim_string *out_string, - kim_string in_key_string); - kim_error kim_os_string_get_cfstring (kim_string in_string, CFStringRef *out_cfstring); diff --git a/src/kim/lib/mac/kim_os_selection_hints.c b/src/kim/lib/mac/kim_os_selection_hints.c index 42b56d08e..97d70db69 100644 --- a/src/kim/lib/mac/kim_os_selection_hints.c +++ b/src/kim/lib/mac/kim_os_selection_hints.c @@ -52,7 +52,7 @@ static kim_error kim_os_selection_hints_get_selection_hints_array (CFArrayRef *o CFStringRef users[] = { kCFPreferencesCurrentUser, kCFPreferencesAnyUser, NULL }; CFStringRef hosts[] = { kCFPreferencesCurrentHost, kCFPreferencesAnyHost, NULL }; - if (!err && !out_selection_hints_array) { err = param_error (1, "out_selection_hints_array", "NULL"); } + if (!err && !out_selection_hints_array) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err) { kim_count u, h; @@ -71,7 +71,7 @@ static kim_error kim_os_selection_hints_get_selection_hints_array (CFArrayRef *o } if (value && CFGetTypeID (value) != CFArrayGetTypeID ()) { - err = check_error (KIM_PREFERENCES_READ_ECODE); + err = check_error (KIM_PREFERENCES_READ_ERR); } } @@ -91,7 +91,7 @@ static kim_error kim_os_selection_hints_set_selection_hints_array (CFArrayRef in { kim_error err = KIM_NO_ERROR; - if (!err && !in_selection_hints_array) { err = param_error (1, "in_selection_hints_array", "NULL"); } + 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(); @@ -101,7 +101,7 @@ static kim_error kim_os_selection_hints_set_selection_hints_array (CFArrayRef in 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_ECODE); + err = check_error (KIM_PREFERENCES_WRITE_ERR); } } @@ -123,9 +123,9 @@ static kim_error kim_os_selection_hints_create_dictionary (kim_selection_hints CFStringRef values[KIM_MAX_HINTS] = { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL }; CFIndex i = 0; - if (!err && !in_selection_hints ) { err = param_error (1, "in_selection_hints", "NULL"); } - if (!err && !in_identity ) { err = param_error (2, "in_selection_hints", "NULL"); } - if (!err && !out_hints_dictionary) { err = param_error (3, "out_hints_dictionary", "NULL"); } + 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); @@ -228,9 +228,9 @@ static kim_error kim_os_selection_hints_compare_to_dictionary (kim_selection_hin 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 = param_error (1, "in_selection_hints", "NULL"); } - if (!err && !in_hints_dictionary) { err = param_error (2, "in_hints_dictionary", "NULL"); } - if (!err && !out_hints_equal ) { err = param_error (3, "out_hints_equal", "NULL"); } + 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); @@ -297,7 +297,7 @@ static kim_error kim_os_selection_hints_get_dictionary_identity (CFDictionaryRef 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_ECODE); + err = check_error (KIM_PREFERENCES_READ_ERR); } if (!err) { @@ -327,8 +327,8 @@ kim_error kim_os_selection_hints_lookup_identity (kim_selection_hints in_select kim_boolean found = 0; CFDictionaryRef found_dictionary = NULL; - if (!err && !in_selection_hints) { err = param_error (1, "in_selection_hints", "NULL"); } - if (!err && !out_identity ) { err = param_error (2, "out_identity", "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); @@ -342,7 +342,7 @@ kim_error kim_os_selection_hints_lookup_identity (kim_selection_hints in_select CFDictionaryRef dictionary = NULL; dictionary = CFArrayGetValueAtIndex (hints_array, i); - if (!dictionary) { err = os_error (ENOMEM); } + if (!dictionary) { err = KIM_OUT_OF_MEMORY_ERR; } if (!err && CFGetTypeID (dictionary) != CFDictionaryGetTypeID ()) { kim_debug_printf ("%s: Malformed entry in hints array.", __FUNCTION__); @@ -383,8 +383,8 @@ kim_error kim_os_selection_hints_remember_identity (kim_selection_hints in_selec kim_boolean hint_already_exists = 0; kim_boolean hints_array_changed = 0; - if (!err && !in_selection_hints) { err = param_error (1, "in_selection_hints", "NULL"); } - if (!err && !in_identity ) { err = param_error (2, "in_identity", "NULL"); } + 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); @@ -398,7 +398,7 @@ kim_error kim_os_selection_hints_remember_identity (kim_selection_hints in_selec new_hints_array = CFArrayCreateMutable (kCFAllocatorDefault, 0, &kCFTypeArrayCallBacks); } - if (!new_hints_array) { err = os_error (ENOMEM); } + if (!new_hints_array) { err = KIM_OUT_OF_MEMORY_ERR; } } if (!err) { @@ -411,7 +411,7 @@ kim_error kim_os_selection_hints_remember_identity (kim_selection_hints in_selec kim_boolean hints_equal = 0; dictionary = CFArrayGetValueAtIndex (new_hints_array, i); - if (!dictionary) { err = os_error (ENOMEM); } + if (!dictionary) { err = KIM_OUT_OF_MEMORY_ERR; } if (!err && CFGetTypeID (dictionary) != CFDictionaryGetTypeID ()) { kim_debug_printf ("%s: Malformed entry in hints array.", __FUNCTION__); @@ -484,7 +484,7 @@ kim_error kim_os_selection_hints_forget_identity (kim_selection_hints in_selecti CFIndex count = 0; CFIndex i = 0; - if (!err && !in_selection_hints) { err = param_error (1, "in_selection_hints", "NULL"); } + 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); @@ -493,7 +493,7 @@ kim_error kim_os_selection_hints_forget_identity (kim_selection_hints in_selecti if (!err) { new_hints_array = CFArrayCreateMutableCopy (kCFAllocatorDefault, 0, old_hints_array); - if (!new_hints_array) { err = os_error (ENOMEM); } + if (!new_hints_array) { err = KIM_OUT_OF_MEMORY_ERR; } } if (!err) { @@ -505,7 +505,7 @@ kim_error kim_os_selection_hints_forget_identity (kim_selection_hints in_selecti kim_boolean hints_equal = 0; dictionary = CFArrayGetValueAtIndex (new_hints_array, i); - if (!dictionary) { err = os_error (ENOMEM); } + if (!dictionary) { err = KIM_OUT_OF_MEMORY_ERR; } if (!err && CFGetTypeID (dictionary) != CFDictionaryGetTypeID ()) { kim_debug_printf ("%s: Malformed entry in hints array.", __FUNCTION__); diff --git a/src/kim/lib/mac/kim_os_string.c b/src/kim/lib/mac/kim_os_string.c index e070bed46..9cd8e0559 100644 --- a/src/kim/lib/mac/kim_os_string.c +++ b/src/kim/lib/mac/kim_os_string.c @@ -24,102 +24,133 @@ * or implied warranty. */ -#include +#include #include "kim_os_private.h" /* ------------------------------------------------------------------------ */ -/* WARNING: DO NOT CALL check_error() -- it is called by error_message()!! */ - -CFStringEncoding kim_os_string_get_encoding (void) +static kim_error kim_os_string_for_key_in_bundle (CFBundleRef in_bundle, + CFStringRef in_key, + kim_string *out_string) { - typedef TextEncoding (*GetApplicationTextEncodingProcPtr) (void); - GetApplicationTextEncodingProcPtr GetApplicationTextEncodingPtr = NULL; - CFBundleRef carbonBundle = NULL; + kim_error lock_err = kim_os_library_lock_for_bundle_lookup (); + kim_error err = lock_err; + kim_string string = NULL; - if (kim_os_library_caller_is_server ()) { - return kCFStringEncodingUTF8; /* server only does UTF8 */ - } + if (!err && !in_bundle ) { err = check_error (KIM_NULL_PARAMETER_ERR); } + if (!err && !in_key ) { err = check_error (KIM_NULL_PARAMETER_ERR); } + if (!err && !out_string) { err = check_error (KIM_NULL_PARAMETER_ERR); } - carbonBundle = CFBundleGetBundleWithIdentifier (CFSTR ("com.apple.Carbon")); - if (carbonBundle != NULL && CFBundleIsExecutableLoaded (carbonBundle)) { - GetApplicationTextEncodingPtr = (GetApplicationTextEncodingProcPtr) CFBundleGetFunctionPointerForName (carbonBundle, - CFSTR ("GetApplicationTextEncoding")); + if (!err) { + CFDictionaryRef dictionary = NULL; + int release_dictionary = 0; + CFStringRef cfstring = NULL; + +#if !KERBEROS_LITE + if (kim_library_allow_home_directory_access ()) { +#endif + /* Accesses user's homedir to get localization information */ + dictionary = CFBundleGetLocalInfoDictionary (in_bundle); + +#if !KERBEROS_LITE + } else { + CFURLRef url = NULL; + CFDataRef data = NULL; + CFAllocatorRef allocator = CFGetAllocator (in_bundle); + SInt32 code = 0; + + url = CFBundleCopyResourceURLForLocalization (in_bundle, + CFSTR("InfoPlist"), + CFSTR("strings"), + NULL, + CFSTR("English")); + + if (url && CFURLCreateDataAndPropertiesFromResource (allocator, + url, &data, + NULL, NULL, + &code)) { + + dictionary = CFPropertyListCreateFromXMLData (allocator, + data, + kCFPropertyListImmutable, + NULL); + release_dictionary = 1; + } + + if (data) { CFRelease (data); } + if (url ) { CFRelease (url); } + } +#endif + + if (dictionary && (CFGetTypeID(dictionary) == CFDictionaryGetTypeID())) { + cfstring = (CFStringRef) CFDictionaryGetValue (dictionary, in_key); + } + + if (cfstring && (CFGetTypeID (cfstring) == CFStringGetTypeID ())) { + err = kim_os_string_create_from_cfstring (&string, cfstring); + } + + if (dictionary && release_dictionary) { CFRelease (dictionary); } } - if (GetApplicationTextEncodingPtr) { - return (CFStringEncoding) (*GetApplicationTextEncodingPtr) (); + if (!err) { + /* set to NULL if no string found */ + *out_string = string; + string = NULL; } - return CFStringGetSystemEncoding (); + kim_string_free (&string); + + if (!lock_err) { kim_os_library_unlock_for_bundle_lookup (); } + + return check_error (err); } +#pragma mark - + /* ------------------------------------------------------------------------ */ -/* WARNING: DO NOT CALL check_error() -- it is called by error_message()!! */ -CFStringRef kim_os_string_get_cfstring_for_key_and_dictionary (CFStringRef in_key, - CFBundleRef in_bundle) +kim_error kim_os_string_create_for_key (kim_string *out_string, + kim_string in_key_string) { - CFDictionaryRef dictionary = NULL; - CFStringRef value = NULL; - - if (kim_library_allow_home_directory_access ()) { - // Accesses user's homedir to get localization information - dictionary = CFBundleGetLocalInfoDictionary (in_bundle); - } else { - dictionary = CFBundleGetInfoDictionary (in_bundle); - } + kim_error err = KIM_NO_ERROR; + CFStringRef key = NULL; + kim_string string = NULL; - if (dictionary) { - value = (CFTypeRef) CFDictionaryGetValue (dictionary, in_key); - } + if (!err && !out_string ) { err = check_error (KIM_NULL_PARAMETER_ERR); } + if (!err && !in_key_string) { err = check_error (KIM_NULL_PARAMETER_ERR); } - if (value && (CFGetTypeID (value) != CFStringGetTypeID ())) { - value = NULL; // Only return CFStrings + if (!err) { + err = kim_os_string_get_cfstring (in_key_string, &key); } - return value; -} - -/* ------------------------------------------------------------------------ */ -/* WARNING: DO NOT CALL check_error() -- it is called by error_message()!! */ - -CFStringRef kim_os_string_get_cfstring_for_key (kim_string in_key_string) -{ - CFStringRef key = NULL; - CFStringRef value = NULL; + if (!err) { + /* Try to find the key, first searching in the framework */ + CFBundleRef framework = CFBundleGetBundleWithIdentifier (CFSTR ("edu.mit.Kerberos")); + if (framework) { + err = kim_os_string_for_key_in_bundle (framework, key, &string); + } + } - if (in_key_string) { - key = CFStringCreateWithCString (kCFAllocatorDefault, in_key_string, kCFStringEncodingASCII); - - if (key) { - // Try to find the key, first searching in the framework, then in the main bundle - CFBundleRef frameworkBundle = CFBundleGetBundleWithIdentifier (CFSTR ("edu.mit.Kerberos")); - if (frameworkBundle) { - value = kim_os_string_get_cfstring_for_key_and_dictionary (key, frameworkBundle); - } - - if (!value) { - CFBundleRef mainBundle = CFBundleGetMainBundle (); - - if (mainBundle) { - value = kim_os_string_get_cfstring_for_key_and_dictionary (key, mainBundle); - } - } - - if (value && (CFGetTypeID (value) != CFStringGetTypeID ())) { - value = NULL; // Only return CFStrings - } - - CFRelease (key); + if (!err && !string) { + /* If we didn't find it in the framwork, try in the main bundle */ + CFBundleRef main_bundle = CFBundleGetMainBundle (); + if (main_bundle) { + err = kim_os_string_for_key_in_bundle (main_bundle, key, &string); } } - return value; + if (!err) { + *out_string = string; + string = NULL; + } + + kim_string_free (&string); + if (key) { CFRelease (key); } + + return check_error (err); } -#pragma mark - - /* ------------------------------------------------------------------------ */ kim_error kim_os_string_create_from_cfstring (kim_string *out_string, @@ -127,22 +158,25 @@ kim_error kim_os_string_create_from_cfstring (kim_string *out_string, { kim_error err = KIM_NO_ERROR; kim_string string = NULL; - CFStringEncoding encoding = kim_os_string_get_encoding (); CFIndex length = 0; - if (!err && !out_string ) { err = param_error (1, "out_string", "NULL"); } - if (!err && !in_cfstring) { err = param_error (2, "in_cfstring", "NULL"); } + if (!err && !out_string ) { err = check_error (KIM_NULL_PARAMETER_ERR); } + if (!err && !in_cfstring) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err) { - length = CFStringGetMaximumSizeForEncoding (CFStringGetLength (in_cfstring), encoding) + 1; + length = CFStringGetMaximumSizeForEncoding (CFStringGetLength (in_cfstring), + kCFStringEncodingUTF8) + 1; string = (char *) calloc (length, sizeof (char)); - if (!string) { err = os_error (errno); } + if (!string) { err = KIM_OUT_OF_MEMORY_ERR; } } if (!err) { - if (!CFStringGetCString (in_cfstring, (char *) string, length, encoding)) { - err = os_error (ENOMEM); + if (!CFStringGetCString (in_cfstring, + (char *) string, + length, + kCFStringEncodingUTF8)) { + err = KIM_OUT_OF_MEMORY_ERR; } } @@ -158,44 +192,20 @@ kim_error kim_os_string_create_from_cfstring (kim_string *out_string, /* ------------------------------------------------------------------------ */ -kim_error kim_os_string_create_for_key (kim_string *out_string, - kim_string in_key_string) -{ - kim_error err = KIM_NO_ERROR; - CFStringRef value = NULL; - - if (!err && !out_string ) { err = param_error (1, "out_string", "NULL"); } - if (!err && !in_key_string) { err = param_error (2, "in_key_string", "NULL"); } - - if (!err) { - value = kim_os_string_get_cfstring_for_key (in_key_string); - if (value) { - err = kim_os_string_create_from_cfstring (out_string, value); - } else { - // We failed to look it up. Use the key so we return something. - err = kim_string_copy (out_string, in_key_string); - } - } - - return check_error (err); -} - -/* ------------------------------------------------------------------------ */ - kim_error kim_os_string_get_cfstring (kim_string in_string, CFStringRef *out_cfstring) { kim_error err = KIM_NO_ERROR; CFStringRef cfstring = NULL; - if (!err && !in_string ) { err = param_error (1, "in_string", "NULL"); } - if (!err && !out_cfstring) { err = param_error (2, "out_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, kCFStringEncodingUTF8); - if (!cfstring) { err = os_error (ENOMEM); } + if (!cfstring) { err = KIM_OUT_OF_MEMORY_ERR; } } if (!err) { @@ -218,16 +228,18 @@ kim_error kim_os_string_compare (kim_string in_string, CFStringRef cfstring = NULL; CFStringRef compare_to_cfstring = NULL; - if (!err && !in_string ) { err = param_error (1, "in_string", "NULL"); } - if (!err && !in_compare_to_string) { err = param_error (2, "in_compare_to_string", "NULL"); } - if (!err && !out_comparison ) { err = param_error (3, "out_comparison", "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, &cfstring); + err = kim_os_string_get_cfstring (in_string, + &cfstring); } if (!err) { - err = kim_os_string_get_cfstring (in_compare_to_string, &compare_to_cfstring); + err = kim_os_string_get_cfstring (in_compare_to_string, + &compare_to_cfstring); } if (!err) { @@ -238,7 +250,7 @@ kim_error kim_os_string_compare (kim_string in_string, if (cfstring ) { CFRelease (cfstring); } if (compare_to_cfstring) { CFRelease (compare_to_cfstring); } - return check_error (err); + return check_error (err); } /* ------------------------------------------------------------------------ */ @@ -250,9 +262,9 @@ 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 = param_error (1, "in_string", "NULL"); } - if (!err && !in_compare_to_cfstring) { err = param_error (2, "in_compare_to_cfstring", "NULL"); } - if (!err && !out_comparison ) { err = param_error (3, "out_comparison", "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); @@ -265,5 +277,5 @@ kim_error kim_os_string_compare_to_cfstring (kim_string in_string, if (cfstring) { CFRelease (cfstring); } - return check_error (err); + return check_error (err); }