kim_error kim_os_preferences_set_identity_for_key (kim_preference_key in_key, kim_identity in_identity) { kim_error err = KIM_NO_ERROR; CFStringRef value = NULL; kim_string string = NULL; /* in_identity can be KIM_IDENTITY_ANY */ if (!err) { if (in_identity) { err = kim_identity_get_string (in_identity, &string); } else { err = kim_string_copy (&string, kim_os_preference_any_identity); } } if (!err) { err = kim_os_string_get_cfstring (string, &value); } if (!err) { err = kim_os_preferences_set_value (in_key, value); } if (value) { CFRelease (value); } kim_string_free (&string); return check_error (err); }
kim_error kim_identity_compare (kim_identity in_identity, kim_identity in_compare_to_identity, kim_comparison *out_comparison) { kim_error err = KIM_NO_ERROR; if (!err && !in_identity ) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !in_compare_to_identity) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !out_comparison ) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err) { if (krb5_principal_compare (in_identity->context, in_identity->principal, in_compare_to_identity->principal)) { *out_comparison = 0; } else { kim_string string = NULL; kim_string compare_to_string = NULL; err = kim_identity_get_string (in_identity, &string); if (!err) { err = kim_identity_get_string (in_compare_to_identity, &compare_to_string); } if (!err) { err = kim_string_compare (string, compare_to_string, out_comparison); } kim_string_free (&string); kim_string_free (&compare_to_string); } } return check_error (err); }
kim_error kim_identity_get_display_string (kim_identity in_identity, kim_string *out_display_string) { kim_error err = KIM_NO_ERROR; kim_string string = NULL; if (!err && !in_identity ) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !out_display_string) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err) { err = kim_identity_get_string (in_identity, &string); } if (!err) { kim_count i, j; kim_count length = strlen (string) + 1; /* Copy the '\0' */ char *display_string = (char *) string; /* so we can modify it */ /* In place copy, skipping escaped separators. * Note that we do not want to remove other escaped characters * (tab, break, newline, NULL) because they are less readable * when unescaped (and NULL isn't a valid string character). */ for (i = 0, j = 0; i < length; i++) { if (string[i] == '\\') { switch (string[i + 1]) { case '/': /* component separator */ case '@': /* realm separator */ continue; /* skip the '\' */ } } display_string[j++] = string[i]; /* Copy this char */ } *out_display_string = string; string = NULL; } if (string) { kim_string_free (&string); } return check_error (err); }
static kim_error kim_os_selection_hints_create_dictionary (kim_selection_hints in_selection_hints, kim_identity in_identity, CFDictionaryRef *out_hints_dictionary) { kim_error err = KIM_NO_ERROR; kim_selection_hints_preference_strings preference_strings = { NULL, NULL, NULL, NULL, NULL, NULL, NULL }; kim_string identity_string = NULL; CFStringRef keys[KIM_MAX_HINTS] = { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL }; CFStringRef values[KIM_MAX_HINTS] = { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL }; CFIndex i = 0; if (!err && !in_selection_hints ) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !in_identity ) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !out_hints_dictionary) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err) { err = kim_selection_hints_get_preference_strings (in_selection_hints, &preference_strings); } if (!err) { err = kim_identity_get_string (in_identity, &identity_string); } if (!err) { keys[i] = KIM_APPLICATION_ID_HINT; err = kim_os_string_get_cfstring (preference_strings.application_identifier, &values[i]); } if (!err) { keys[++i] = KIM_IDENTITY_HINT; err = kim_os_string_get_cfstring (identity_string, &values[i]); } if (!err && preference_strings.service_identity) { keys[++i] = KIM_SERVICE_IDENTITY_HINT; err = kim_os_string_get_cfstring (preference_strings.service_identity, &values[i]); } if (!err && preference_strings.user) { keys[++i] = KIM_USER_HINT; err = kim_os_string_get_cfstring (preference_strings.user, &values[i]); } if (!err && preference_strings.client_realm) { keys[++i] = KIM_CLIENT_REALM_HINT; err = kim_os_string_get_cfstring (preference_strings.client_realm, &values[i]); } if (!err && preference_strings.service) { keys[++i] = KIM_SERVICE_HINT; err = kim_os_string_get_cfstring (preference_strings.service, &values[i]); } if (!err && preference_strings.service_realm) { keys[++i] = KIM_SERVICE_REALM_HINT; err = kim_os_string_get_cfstring (preference_strings.service_realm, &values[i]); } if (!err && preference_strings.server) { keys[++i] = KIM_SERVER_HINT; err = kim_os_string_get_cfstring (preference_strings.server, &values[i]); } if (!err) { *out_hints_dictionary = CFDictionaryCreate (kCFAllocatorDefault, (const void **) keys, (const void **) values, i+1, /* number of hints */ &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); } for (i = 0; i < KIM_MAX_HINTS; i++) { if (values[i]) { CFRelease (values[i]); } } kim_string_free (&identity_string); return check_error (err); }
/* ------------------------------------------------------------------------ */ kim_error kim_os_preferences_set_favorites_for_key (kim_preference_key in_key, kim_favorites in_favorites) { kim_error err = KIM_NO_ERROR; kim_count count = 0; CFMutableArrayRef array = NULL; if (!err && !in_favorites) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err) { err = kim_favorites_get_number_of_identities (in_favorites, &count); } if (!err) { array = CFArrayCreateMutable (kCFAllocatorDefault, count, &kCFTypeArrayCallBacks); if (!array) { err = KIM_OUT_OF_MEMORY_ERR; } } if (!err) { kim_count i; for (i = 0; !err && i < count; i++) { kim_identity identity = NULL; kim_options options = NULL; kim_string string = NULL; CFStringRef cfstring = NULL; CFMutableDictionaryRef dictionary = NULL; err = kim_favorites_get_identity_at_index (in_favorites, i, &identity, &options); if (!err) { err = kim_identity_get_string (identity, &string); } if (!err) { err = kim_os_string_get_cfstring (string, &cfstring); } if (!err) { dictionary = CFDictionaryCreateMutable (kCFAllocatorDefault, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); if (!dictionary) { err = check_error (KIM_OUT_OF_MEMORY_ERR); } } if (!err) { err = kim_os_preferences_set_value_for_dict_key (dictionary, kim_preference_key_client_identity, cfstring); } if (!err && options) { err = kim_os_preferences_options_to_dictionary (options, dictionary); } if (!err) { CFArrayAppendValue (array, dictionary); } if (dictionary) { CFRelease (dictionary); } if (cfstring ) { CFRelease (cfstring); } kim_string_free (&string); kim_options_free (&options); kim_identity_free (&identity); } } if (!err) { err = kim_os_preferences_set_value (in_key, array); } if (array) { CFRelease (array); } return check_error (err); }