diff options
author | Alexandra Ellwood <lxs@mit.edu> | 2008-09-30 20:05:17 +0000 |
---|---|---|
committer | Alexandra Ellwood <lxs@mit.edu> | 2008-09-30 20:05:17 +0000 |
commit | 6b6d24e1ae0aadffb9062ac94ae8e600e09dbef0 (patch) | |
tree | 2bddd1c4440a027ef8f1ee702bc53c0872de3703 /src/kim | |
parent | 7dea4900af23686834aa9c899206438a8d27076a (diff) | |
download | krb5-6b6d24e1ae0aadffb9062ac94ae8e600e09dbef0.tar.gz krb5-6b6d24e1ae0aadffb9062ac94ae8e600e09dbef0.tar.xz krb5-6b6d24e1ae0aadffb9062ac94ae8e600e09dbef0.zip |
krb5 library-side changes for com_err based error strings
ticket: 6138
git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@20786 dc483132-0cff-0310-8789-dd5450dbe970
Diffstat (limited to 'src/kim')
-rw-r--r-- | src/kim/agent/mac/ServerDemux.m | 2 | ||||
-rw-r--r-- | src/kim/lib/kim_ccache.c | 4 | ||||
-rw-r--r-- | src/kim/lib/kim_credential.c | 4 | ||||
-rw-r--r-- | src/kim/lib/kim_identity.c | 2 | ||||
-rw-r--r-- | src/kim/lib/kim_library.c | 32 | ||||
-rw-r--r-- | src/kim/lib/kim_library_private.h | 2 | ||||
-rw-r--r-- | src/kim/lib/kim_options.c | 2 | ||||
-rw-r--r-- | src/kim/lib/kim_preferences.c | 8 | ||||
-rw-r--r-- | src/kim/lib/kim_selection_hints.c | 2 | ||||
-rw-r--r-- | src/kim/lib/kim_string.c | 18 | ||||
-rw-r--r-- | src/kim/lib/mac/kim_os_private.h | 4 | ||||
-rw-r--r-- | src/kim/lib/mac/kim_os_string.c | 144 |
12 files changed, 80 insertions, 144 deletions
diff --git a/src/kim/agent/mac/ServerDemux.m b/src/kim/agent/mac/ServerDemux.m index c09d7ec85..ed4e73d1d 100644 --- a/src/kim/agent/mac/ServerDemux.m +++ b/src/kim/agent/mac/ServerDemux.m @@ -303,7 +303,7 @@ static int32_t kim_handle_request_auth_prompt (mach_port_t in_client_port, if (!err) { NSLog (@"Got auth prompt with identity '%s', type '%d', allow_save_reply '%d', hide '%d', title '%s', message '%s', description '%s'", - identity_string, type, hide_reply, title, message, description); + identity_string, type, allow_save_reply, hide_reply, title, message, description); err = kim_handle_reply_auth_prompt (in_reply_port, "ydobon", 0, 0); #warning Send auth prompt message to main thread with 2 ports and arguments } diff --git a/src/kim/lib/kim_ccache.c b/src/kim/lib/kim_ccache.c index 152095d54..b30351c4a 100644 --- a/src/kim/lib/kim_ccache.c +++ b/src/kim/lib/kim_ccache.c @@ -38,7 +38,7 @@ struct kim_ccache_iterator_opaque kim_ccache_iterator_initializer = { NULL, NULL kim_error kim_ccache_iterator_create (kim_ccache_iterator *out_ccache_iterator) { - kim_error err = KIM_NO_ERROR; + kim_error err = kim_library_init (); kim_ccache_iterator ccache_iterator = NULL; if (!err && !out_ccache_iterator) { err = check_error (KIM_NULL_PARAMETER_ERR); } @@ -181,7 +181,7 @@ static kim_error kim_ccache_create_resolve_name (kim_string *out_resolve_name, static inline kim_error kim_ccache_allocate (kim_ccache *out_ccache) { - kim_error err = KIM_NO_ERROR; + kim_error err = kim_library_init (); kim_ccache ccache = NULL; if (!err && !out_ccache) { err = check_error (KIM_NULL_PARAMETER_ERR); } diff --git a/src/kim/lib/kim_credential.c b/src/kim/lib/kim_credential.c index 64561896d..8465aa59d 100644 --- a/src/kim/lib/kim_credential.c +++ b/src/kim/lib/kim_credential.c @@ -41,7 +41,7 @@ struct kim_credential_iterator_opaque kim_credential_iterator_initializer = { NU kim_error kim_credential_iterator_create (kim_credential_iterator *out_credential_iterator, kim_ccache in_ccache) { - kim_error err = KIM_NO_ERROR; + kim_error err = kim_library_init (); kim_credential_iterator credential_iterator = NULL; if (!err && !out_credential_iterator) { err = check_error (KIM_NULL_PARAMETER_ERR); } @@ -178,7 +178,7 @@ struct kim_credential_opaque kim_credential_initializer = { NULL, NULL }; static inline kim_error kim_credential_allocate (kim_credential *out_credential) { - kim_error err = KIM_NO_ERROR; + kim_error err = kim_library_init (); kim_credential credential = NULL; if (!err && !out_credential) { err = check_error (KIM_NULL_PARAMETER_ERR); } diff --git a/src/kim/lib/kim_identity.c b/src/kim/lib/kim_identity.c index 10604e6d0..33877746e 100644 --- a/src/kim/lib/kim_identity.c +++ b/src/kim/lib/kim_identity.c @@ -41,7 +41,7 @@ struct kim_identity_opaque kim_identity_initializer = { NULL, NULL }; static inline kim_error kim_identity_allocate (kim_identity *out_identity) { - kim_error err = KIM_NO_ERROR; + kim_error err = kim_library_init (); kim_identity identity = NULL; if (!err && !out_identity) { err = check_error (KIM_NULL_PARAMETER_ERR); } diff --git a/src/kim/lib/kim_library.c b/src/kim/lib/kim_library.c index c235fbda7..8096ec6b1 100644 --- a/src/kim/lib/kim_library.c +++ b/src/kim/lib/kim_library.c @@ -34,6 +34,38 @@ #include "kim_private.h" #include "kim_os_private.h" + +MAKE_INIT_FUNCTION(kim_error_init); +MAKE_FINI_FUNCTION(kim_error_fini); + +/* ------------------------------------------------------------------------ */ + +static int kim_error_init (void) +{ + add_error_table (&et_KIM_error_table); + return 0; +} + +/* ------------------------------------------------------------------------ */ + +static void kim_error_fini (void) +{ + if (!INITIALIZER_RAN (kim_error_init) || PROGRAM_EXITING ()) { + return; + } + + remove_error_table (&et_KIM_error_table); +} + +/* ------------------------------------------------------------------------ */ + +kim_error kim_library_init (void) +{ + return CALL_INIT_FUNCTION (kim_error_init); +} + +#pragma mark - + 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 k5_mutex_t g_ui_environment_mutex = K5_MUTEX_PARTIAL_INITIALIZER; diff --git a/src/kim/lib/kim_library_private.h b/src/kim/lib/kim_library_private.h index b44cb6513..83c06d791 100644 --- a/src/kim/lib/kim_library_private.h +++ b/src/kim/lib/kim_library_private.h @@ -29,6 +29,8 @@ #include <kim/kim.h> +kim_error kim_library_init (void); + kim_ui_environment kim_os_library_get_ui_environment (void); kim_ui_environment kim_library_ui_environment (void); diff --git a/src/kim/lib/kim_options.c b/src/kim/lib/kim_options.c index d97b34699..91ec406bb 100644 --- a/src/kim/lib/kim_options.c +++ b/src/kim/lib/kim_options.c @@ -57,7 +57,7 @@ NULL }; static inline kim_error kim_options_allocate (kim_options *out_options) { - kim_error err = KIM_NO_ERROR; + kim_error err = kim_library_init (); kim_options options = NULL; if (!err && !out_options) { err = check_error (KIM_NULL_PARAMETER_ERR); } diff --git a/src/kim/lib/kim_preferences.c b/src/kim/lib/kim_preferences.c index b2e740d9e..29f37cd9a 100644 --- a/src/kim/lib/kim_preferences.c +++ b/src/kim/lib/kim_preferences.c @@ -136,7 +136,7 @@ static kim_error kim_favorites_copy (kim_favorites in_favorites, kim_error err = KIM_NO_ERROR; if (!err && !in_favorites) { err = check_error (KIM_NULL_PARAMETER_ERR); } - if (!err && !io_favorites ) { err = check_error (KIM_NULL_PARAMETER_ERR); } + if (!err && !io_favorites) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err) { err = kim_favorites_resize (io_favorites, in_favorites->count); @@ -491,10 +491,6 @@ static kim_error kim_preferences_read (kim_preferences in_preferences) &in_preferences->maximum_renewal_lifetime); } - if (!err) { - - } - return check_error (err); } @@ -576,7 +572,7 @@ static kim_error kim_preferences_write (kim_preferences in_preferences) static inline kim_error kim_preferences_allocate (kim_preferences *out_preferences) { - kim_error err = KIM_NO_ERROR; + kim_error err = kim_library_init (); kim_preferences preferences = NULL; if (!err && !out_preferences) { err = check_error (KIM_NULL_PARAMETER_ERR); } diff --git a/src/kim/lib/kim_selection_hints.c b/src/kim/lib/kim_selection_hints.c index 8cb98f683..6bfa3f182 100644 --- a/src/kim/lib/kim_selection_hints.c +++ b/src/kim/lib/kim_selection_hints.c @@ -58,7 +58,7 @@ struct kim_selection_hints_opaque kim_selection_hints_initializer = { static inline kim_error kim_selection_hints_allocate (kim_selection_hints *out_selection_hints) { - kim_error err = KIM_NO_ERROR; + kim_error err = kim_library_init (); kim_selection_hints selection_hints = NULL; if (!err && !out_selection_hints) { err = check_error (KIM_NULL_PARAMETER_ERR); } diff --git a/src/kim/lib/kim_string.c b/src/kim/lib/kim_string.c index 2dc284c93..b84a12c8e 100644 --- a/src/kim/lib/kim_string.c +++ b/src/kim/lib/kim_string.c @@ -32,7 +32,7 @@ kim_error kim_string_create_from_format (kim_string *out_string, kim_string in_format, ...) { - kim_error err = KIM_NO_ERROR; + kim_error err = kim_library_init (); va_list args; va_start (args, in_format); @@ -48,7 +48,7 @@ kim_error kim_string_create_from_format_va_retcode (kim_string *out_string, kim_string in_format, va_list in_args) { - kim_error err = KIM_NO_ERROR; + kim_error err = kim_library_init (); int count = vasprintf ((char **) out_string, in_format, in_args); if (count < 0) { err = check_error (KIM_OUT_OF_MEMORY_ERR); } @@ -62,7 +62,7 @@ kim_error kim_string_create_from_format_va (kim_string *out_string, kim_string in_format, va_list in_args) { - kim_error err = KIM_NO_ERROR; + kim_error err = kim_library_init (); kim_string string = NULL; if (!err && !out_string) { err = check_error (KIM_NULL_PARAMETER_ERR); } @@ -90,7 +90,7 @@ kim_error kim_string_create_from_buffer (kim_string *out_string, const char *in_buffer, kim_count in_length) { - kim_error err = KIM_NO_ERROR; + kim_error err = kim_library_init (); kim_string string = NULL; if (!err && !out_string) { err = check_error (KIM_NULL_PARAMETER_ERR); } @@ -117,7 +117,11 @@ kim_error kim_string_create_from_buffer (kim_string *out_string, kim_error kim_string_create_for_last_error (kim_string *out_string, kim_error in_error) { - return kim_string_copy (out_string, kim_error_message (in_error)); + kim_error err = kim_library_init (); + + err = kim_string_copy (out_string, kim_error_message (in_error)); + + return check_error (err); } /* ------------------------------------------------------------------------ */ @@ -125,7 +129,7 @@ kim_error kim_string_create_for_last_error (kim_string *out_string, kim_error kim_string_copy (kim_string *out_string, kim_string in_string) { - kim_error err = KIM_NO_ERROR; + kim_error err = kim_library_init (); kim_string string = NULL; if (!err && !out_string) { err = check_error (KIM_NULL_PARAMETER_ERR); } @@ -137,7 +141,7 @@ kim_error kim_string_copy (kim_string *out_string, } if (!err) { - strcpy ((char *) string, in_string); + strncpy ((char *) string, in_string, strlen (in_string) + 1); *out_string = string; string = NULL; } diff --git a/src/kim/lib/mac/kim_os_private.h b/src/kim/lib/mac/kim_os_private.h index 039502a7e..f14440df4 100644 --- a/src/kim/lib/mac/kim_os_private.h +++ b/src/kim/lib/mac/kim_os_private.h @@ -41,10 +41,6 @@ kim_error kim_os_library_unlock_for_bundle_lookup (void); kim_error kim_os_library_get_application_path (kim_string *out_path); - -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); diff --git a/src/kim/lib/mac/kim_os_string.c b/src/kim/lib/mac/kim_os_string.c index d51bc48b2..0529f3920 100644 --- a/src/kim/lib/mac/kim_os_string.c +++ b/src/kim/lib/mac/kim_os_string.c @@ -29,142 +29,48 @@ #include "kim_os_private.h" /* ------------------------------------------------------------------------ */ -static kim_error kim_os_string_for_key_in_bundle (CFBundleRef in_bundle, - CFStringRef in_key, - kim_string *out_string) -{ - kim_error err = KIM_NO_ERROR; - kim_string string = NULL; - - 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); } - - 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 (!err) { - /* set to NULL if no string found */ - *out_string = string; - string = NULL; - } - - kim_string_free (&string); - - return check_error (err); -} - -#pragma mark - - -/* ------------------------------------------------------------------------ */ kim_error kim_os_string_create_localized (kim_string *out_string, kim_string in_string) { - kim_error err = KIM_NO_ERROR; + kim_error lock_err = kim_os_library_lock_for_bundle_lookup (); + kim_error err = lock_err; kim_string string = NULL; + CFStringRef cfkey = NULL; if (!err && !out_string) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !in_string ) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err) { - err = kim_os_string_create_for_key (&string, in_string); - } - - if (!err && !string) { - err = kim_string_copy (&string, in_string); - } - - if (!err) { - *out_string = string; - string = NULL; + err = kim_os_string_get_cfstring (in_string, &cfkey); } - kim_string_free (&string); - - return check_error (err); -} - -/* ------------------------------------------------------------------------ */ - -kim_error kim_os_string_create_for_key (kim_string *out_string, - kim_string in_key_string) -{ - kim_error lock_err = kim_os_library_lock_for_bundle_lookup (); - kim_error err = lock_err; - CFStringRef key = NULL; - kim_string string = NULL; - - if (!err && !out_string ) { err = check_error (KIM_NULL_PARAMETER_ERR); } - if (!err && !in_key_string) { err = check_error (KIM_NULL_PARAMETER_ERR); } - - if (!err) { - err = kim_os_string_get_cfstring (in_key_string, &key); - } - - if (!err) { - /* Try to find the key, first searching in the framework */ + if (!err && kim_library_allow_home_directory_access ()) { + CFStringRef cfstring = NULL; CFBundleRef framework = CFBundleGetBundleWithIdentifier (CFSTR ("edu.mit.Kerberos")); + CFBundleRef main_bundle = CFBundleGetMainBundle (); + if (framework) { - err = kim_os_string_for_key_in_bundle (framework, key, &string); + cfstring = CFCopyLocalizedStringFromTableInBundle (cfkey, + CFSTR ("InfoPlist"), + framework, + ""); + } + + if (main_bundle && !cfstring) { + cfstring = CFCopyLocalizedStringFromTableInBundle (cfkey, + CFSTR ("InfoPlist"), + main_bundle, + ""); + } + + if (!err && cfstring) { + err = kim_os_string_create_from_cfstring (&string, cfstring); } } if (!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); - } + err = kim_string_copy (&string, in_string); } if (!err) { @@ -172,8 +78,8 @@ kim_error kim_os_string_create_for_key (kim_string *out_string, string = NULL; } + if (cfkey) { CFRelease (cfkey); } kim_string_free (&string); - if (key) { CFRelease (key); } if (!lock_err) { kim_os_library_unlock_for_bundle_lookup (); } |