diff options
Diffstat (limited to 'src/kim/lib/kim_selection_hints.c')
-rw-r--r-- | src/kim/lib/kim_selection_hints.c | 369 |
1 files changed, 184 insertions, 185 deletions
diff --git a/src/kim/lib/kim_selection_hints.c b/src/kim/lib/kim_selection_hints.c index 3704d87e9..6aba4420d 100644 --- a/src/kim/lib/kim_selection_hints.c +++ b/src/kim/lib/kim_selection_hints.c @@ -6,7 +6,7 @@ * require a specific license from the United States Government. * It is the responsibility of any person or organization contemplating * export to obtain such a license before exporting. - * + * * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and * distribute this software and its documentation for any purpose and * without fee is hereby granted, provided that the above copyright @@ -40,7 +40,7 @@ struct kim_selection_hints_opaque { kim_string server; }; -struct kim_selection_hints_opaque kim_selection_hints_initializer = { +struct kim_selection_hints_opaque kim_selection_hints_initializer = { NULL, kim_empty_string, KIM_OPTIONS_DEFAULT, @@ -60,23 +60,23 @@ static inline kim_error kim_selection_hints_allocate (kim_selection_hints *out_s { kim_error err = kim_library_init (); kim_selection_hints selection_hints = NULL; - + if (!err && !out_selection_hints) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { selection_hints = malloc (sizeof (*selection_hints)); if (!selection_hints) { err = KIM_OUT_OF_MEMORY_ERR; } } - + if (!err) { *selection_hints = kim_selection_hints_initializer; *out_selection_hints = selection_hints; selection_hints = NULL; } - + kim_selection_hints_free (&selection_hints); - - return check_error (err); + + return check_error (err); } /* ------------------------------------------------------------------------ */ @@ -86,27 +86,27 @@ kim_error kim_selection_hints_create (kim_selection_hints *out_selection_hints, { kim_error err = KIM_NO_ERROR; kim_selection_hints selection_hints = NULL; - + if (!err && !out_selection_hints ) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !in_application_identifier) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { err = kim_selection_hints_allocate (&selection_hints); } - + if (!err) { - err = kim_string_copy (&selection_hints->application_identifier, + err = kim_string_copy (&selection_hints->application_identifier, in_application_identifier); } - + if (!err) { *out_selection_hints = selection_hints; selection_hints = NULL; } - + kim_selection_hints_free (&selection_hints); - - return check_error (err); + + return check_error (err); } /* ------------------------------------------------------------------------ */ @@ -116,70 +116,70 @@ kim_error kim_selection_hints_copy (kim_selection_hints *out_selection_hints, { kim_error err = KIM_NO_ERROR; kim_selection_hints selection_hints = NULL; - + if (!err && !out_selection_hints) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !in_selection_hints ) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { err = kim_selection_hints_allocate (&selection_hints); } - + if (!err) { - err = kim_string_copy (&selection_hints->application_identifier, + err = kim_string_copy (&selection_hints->application_identifier, in_selection_hints->application_identifier); } - + if (!err && in_selection_hints->explanation) { - err = kim_string_copy (&selection_hints->explanation, + err = kim_string_copy (&selection_hints->explanation, in_selection_hints->explanation); } - + if (!err && in_selection_hints->options) { - err = kim_options_copy (&selection_hints->options, + err = kim_options_copy (&selection_hints->options, in_selection_hints->options); } - + if (!err && in_selection_hints->service_identity) { - err = kim_string_copy (&selection_hints->service_identity, + err = kim_string_copy (&selection_hints->service_identity, in_selection_hints->service_identity); } - + if (!err && in_selection_hints->client_realm) { - err = kim_string_copy (&selection_hints->client_realm, + err = kim_string_copy (&selection_hints->client_realm, in_selection_hints->client_realm); } - + if (!err && in_selection_hints->user) { - err = kim_string_copy (&selection_hints->user, + err = kim_string_copy (&selection_hints->user, in_selection_hints->user); } - + if (!err && in_selection_hints->service_realm) { - err = kim_string_copy (&selection_hints->service_realm, + err = kim_string_copy (&selection_hints->service_realm, in_selection_hints->service_realm); } - + if (!err && in_selection_hints->service) { - err = kim_string_copy (&selection_hints->service, + err = kim_string_copy (&selection_hints->service, in_selection_hints->service); } - + if (!err && in_selection_hints->server) { - err = kim_string_copy (&selection_hints->server, + err = kim_string_copy (&selection_hints->server, in_selection_hints->server); } - + if (!err) { selection_hints->allow_user_interaction = in_selection_hints->allow_user_interaction; selection_hints->use_cached_results = in_selection_hints->use_cached_results; - + *out_selection_hints = selection_hints; selection_hints = NULL; } - + kim_selection_hints_free (&selection_hints); - - return check_error (err); + + return check_error (err); } /* ------------------------------------------------------------------------ */ @@ -189,48 +189,48 @@ kim_error kim_selection_hints_set_hint (kim_selection_hints io_selection_hints, kim_string in_hint_string) { kim_error err = KIM_NO_ERROR; - + if (!err && !io_selection_hints) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !in_hint_key ) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !in_hint_string ) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { if (!strcmp (in_hint_key, kim_hint_key_client_realm)) { kim_string_free (&io_selection_hints->client_realm); - err = kim_string_copy (&io_selection_hints->client_realm, + err = kim_string_copy (&io_selection_hints->client_realm, in_hint_string); - + } else if (!strcmp (in_hint_key, kim_hint_key_user)) { kim_string_free (&io_selection_hints->user); - err = kim_string_copy (&io_selection_hints->user, + err = kim_string_copy (&io_selection_hints->user, in_hint_string); - + } else if (!strcmp (in_hint_key, kim_hint_key_service_realm)) { kim_string_free (&io_selection_hints->service_realm); - err = kim_string_copy (&io_selection_hints->service_realm, + err = kim_string_copy (&io_selection_hints->service_realm, in_hint_string); - + } else if (!strcmp (in_hint_key, kim_hint_key_service)) { kim_string_free (&io_selection_hints->service); - err = kim_string_copy (&io_selection_hints->service, + err = kim_string_copy (&io_selection_hints->service, in_hint_string); - + } else if (!strcmp (in_hint_key, kim_hint_key_server)) { kim_string_free (&io_selection_hints->server); - err = kim_string_copy (&io_selection_hints->server, + err = kim_string_copy (&io_selection_hints->server, in_hint_string); - + } else if (!strcmp (in_hint_key, kim_hint_key_service_identity)) { kim_string_free (&io_selection_hints->service_identity); - err = kim_string_copy (&io_selection_hints->service_identity, + err = kim_string_copy (&io_selection_hints->service_identity, in_hint_string); - + } else { err = kim_error_set_message_for_code (KIM_UNSUPPORTED_HINT_ERR, in_hint_key); } } - + return check_error (err); } @@ -242,36 +242,36 @@ kim_error kim_selection_hints_get_hint (kim_selection_hints in_selection_hints, { kim_error err = KIM_NO_ERROR; kim_string hint = NULL; - + if (!err && !in_selection_hints) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !in_hint_key ) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !out_hint_string ) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { if (!strcmp (in_hint_key, kim_hint_key_client_realm)) { hint = in_selection_hints->client_realm; - + } else if (!strcmp (in_hint_key, kim_hint_key_user)) { hint = in_selection_hints->user; - + } else if (!strcmp (in_hint_key, kim_hint_key_service_realm)) { hint = in_selection_hints->service_realm; - + } else if (!strcmp (in_hint_key, kim_hint_key_service)) { hint = in_selection_hints->service; - + } else if (!strcmp (in_hint_key, kim_hint_key_server)) { hint = in_selection_hints->server; - + } else if (!strcmp (in_hint_key, kim_hint_key_service_identity)) { hint = in_selection_hints->service_identity; - + } else { err = kim_error_set_message_for_code (KIM_UNSUPPORTED_HINT_ERR, in_hint_key); } } - + if (!err) { if (hint && hint != kim_empty_string) { err = kim_string_copy (out_hint_string, hint); @@ -279,7 +279,7 @@ kim_error kim_selection_hints_get_hint (kim_selection_hints in_selection_hints, *out_hint_string = NULL; } } - + return check_error (err); } @@ -289,14 +289,14 @@ kim_error kim_selection_hints_set_explanation (kim_selection_hints io_selection_ kim_string in_explanation) { kim_error err = KIM_NO_ERROR; - + if (!err && !io_selection_hints) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !in_explanation ) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { err = kim_string_copy (&io_selection_hints->explanation, in_explanation); } - + return check_error (err); } @@ -306,19 +306,19 @@ kim_error kim_selection_hints_get_explanation (kim_selection_hints in_selection kim_string *out_explanation) { kim_error err = KIM_NO_ERROR; - + if (!err && !in_selection_hints) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !out_explanation ) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { - if (in_selection_hints->explanation && + if (in_selection_hints->explanation && in_selection_hints->explanation != kim_empty_string) { err = kim_string_copy (out_explanation, in_selection_hints->explanation); } else { *out_explanation = NULL; } } - + return check_error (err); } @@ -328,19 +328,19 @@ kim_error kim_selection_hints_get_application_id (kim_selection_hints in_select kim_string *out_application_id) { kim_error err = KIM_NO_ERROR; - + if (!err && !in_selection_hints) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !out_application_id) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { if (in_selection_hints->application_identifier) { - err = kim_string_copy (out_application_id, + err = kim_string_copy (out_application_id, in_selection_hints->application_identifier); } else { *out_application_id = NULL; } } - + return check_error (err); } @@ -350,14 +350,14 @@ kim_error kim_selection_hints_set_options (kim_selection_hints io_selection_hint kim_options in_options) { kim_error err = KIM_NO_ERROR; - + if (!err && !io_selection_hints) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !in_options ) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { err = kim_options_copy (&io_selection_hints->options, in_options); } - + return check_error (err); } @@ -367,14 +367,14 @@ kim_error kim_selection_hints_get_options (kim_selection_hints in_selection_hin kim_options *out_options) { kim_error err = KIM_NO_ERROR; - + if (!err && !in_selection_hints) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !out_options ) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { err = kim_options_copy (out_options, in_selection_hints->options); } - + return check_error (err); } @@ -384,13 +384,13 @@ kim_error kim_selection_hints_set_allow_user_interaction (kim_selection_hints io kim_boolean in_allow_user_interaction) { kim_error err = KIM_NO_ERROR; - + if (!err && !io_selection_hints ) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { io_selection_hints->allow_user_interaction = in_allow_user_interaction; } - + return check_error (err); } @@ -400,14 +400,14 @@ kim_error kim_selection_hints_get_allow_user_interaction (kim_selection_hints i kim_boolean *out_allow_user_interaction) { kim_error err = KIM_NO_ERROR; - + if (!err && !in_selection_hints ) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !out_allow_user_interaction) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { *out_allow_user_interaction = in_selection_hints->allow_user_interaction; } - + return check_error (err); } @@ -417,13 +417,13 @@ kim_error kim_selection_hints_set_remember_identity (kim_selection_hints io_sele kim_boolean in_use_cached_results) { kim_error err = KIM_NO_ERROR; - + if (!err && !io_selection_hints ) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { io_selection_hints->use_cached_results = in_use_cached_results; } - + return check_error (err); } @@ -433,14 +433,14 @@ kim_error kim_selection_hints_get_remember_identity (kim_selection_hints in_sel kim_boolean *out_use_cached_results) { kim_error err = KIM_NO_ERROR; - + if (!err && !in_selection_hints ) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !out_use_cached_results) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { *out_use_cached_results = in_selection_hints->use_cached_results; } - + return check_error (err); } @@ -452,56 +452,56 @@ kim_error kim_selection_hints_get_identity (kim_selection_hints in_selection_hi kim_error err = KIM_NO_ERROR; kim_identity identity = NULL; kim_ccache ccache = NULL; - + if (!err && !in_selection_hints) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !out_identity ) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err && in_selection_hints->use_cached_results) { err = kim_os_selection_hints_lookup_identity (in_selection_hints, &identity); } - + if (!err && !identity && in_selection_hints->allow_user_interaction) { kim_ui_context context; - + err = kim_ui_init (&context); - + while (!err && !identity) { kim_boolean user_wants_change_password = 0; - err = kim_ui_select_identity (&context, - in_selection_hints, + err = kim_ui_select_identity (&context, + in_selection_hints, &identity, &user_wants_change_password); - + if (!err && user_wants_change_password) { - err = kim_identity_change_password_common (identity, 0, - &context, + err = kim_identity_change_password_common (identity, 0, + &context, NULL); - + /* reenter select_identity so just forget this identity * even if we got an error */ - if (err == KIM_USER_CANCELED_ERR || + if (err == KIM_USER_CANCELED_ERR || err == KIM_DUPLICATE_UI_REQUEST_ERR) { err = KIM_NO_ERROR; } kim_identity_free (&identity); } - + } - + if (context.initialized) { kim_error terr = KIM_NO_ERROR; terr = kim_ui_fini (&context); err = (terr != KIM_NO_ERROR) ? terr : err; } } - + if (!err) { *out_identity = identity; identity = NULL; } - + kim_identity_free (&identity); kim_ccache_free (&ccache); - + return check_error (err); } @@ -511,15 +511,15 @@ kim_error kim_selection_hints_remember_identity (kim_selection_hints in_selectio kim_identity in_identity) { kim_error err = KIM_NO_ERROR; - + if (!err && !in_selection_hints) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !in_identity ) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { - err = kim_os_selection_hints_remember_identity (in_selection_hints, + err = kim_os_selection_hints_remember_identity (in_selection_hints, in_identity); } - + return check_error (err); } @@ -528,13 +528,13 @@ kim_error kim_selection_hints_remember_identity (kim_selection_hints in_selectio kim_error kim_selection_hints_forget_identity (kim_selection_hints in_selection_hints) { kim_error err = KIM_NO_ERROR; - + if (!err && !in_selection_hints) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { err = kim_os_selection_hints_forget_identity (in_selection_hints); } - + return check_error (err); } @@ -544,10 +544,10 @@ kim_error kim_selection_hints_get_preference_strings (kim_selection_hints kim_selection_hints_preference_strings *io_preference_strings) { kim_error err = KIM_NO_ERROR; - + if (!err && !in_selection_hints ) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !io_preference_strings) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { io_preference_strings->application_identifier = in_selection_hints->application_identifier; io_preference_strings->service_identity = in_selection_hints->service_identity; @@ -557,7 +557,7 @@ kim_error kim_selection_hints_get_preference_strings (kim_selection_hints io_preference_strings->service = in_selection_hints->service; io_preference_strings->server = in_selection_hints->server; } - + return check_error (err); } @@ -588,56 +588,56 @@ kim_error kim_selection_hints_write_to_stream (kim_selection_hints in_selection_ k5_ipc_stream io_stream) { kim_error err = KIM_NO_ERROR; - + if (!err && !in_selection_hints) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !io_stream ) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err) { - err = krb5int_ipc_stream_write_string (io_stream, + err = krb5int_ipc_stream_write_string (io_stream, in_selection_hints->application_identifier); } - + if (!err) { - err = krb5int_ipc_stream_write_string (io_stream, + err = krb5int_ipc_stream_write_string (io_stream, in_selection_hints->explanation); } - + if (!err) { - err = kim_options_write_to_stream (in_selection_hints->options, + err = kim_options_write_to_stream (in_selection_hints->options, io_stream); } - + if (!err) { - err = krb5int_ipc_stream_write_string (io_stream, + err = krb5int_ipc_stream_write_string (io_stream, in_selection_hints->service_identity); } - + if (!err) { - err = krb5int_ipc_stream_write_string (io_stream, + err = krb5int_ipc_stream_write_string (io_stream, in_selection_hints->client_realm); } - + if (!err) { - err = krb5int_ipc_stream_write_string (io_stream, + err = krb5int_ipc_stream_write_string (io_stream, in_selection_hints->user); } - + if (!err) { - err = krb5int_ipc_stream_write_string (io_stream, + err = krb5int_ipc_stream_write_string (io_stream, in_selection_hints->service_realm); } - + if (!err) { - err = krb5int_ipc_stream_write_string (io_stream, + err = krb5int_ipc_stream_write_string (io_stream, in_selection_hints->service); } - + if (!err) { - err = krb5int_ipc_stream_write_string (io_stream, + err = krb5int_ipc_stream_write_string (io_stream, in_selection_hints->server); } - - return check_error (err); + + return check_error (err); } /* ------------------------------------------------------------------------ */ @@ -646,114 +646,114 @@ kim_error kim_selection_hints_read_from_stream (kim_selection_hints io_selection k5_ipc_stream io_stream) { kim_error err = KIM_NO_ERROR; - + if (!err && !io_selection_hints) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !io_stream ) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { char *application_identifier = NULL; err = krb5int_ipc_stream_read_string (io_stream, &application_identifier); - + if (!err) { - err = kim_string_copy (&io_selection_hints->application_identifier, + err = kim_string_copy (&io_selection_hints->application_identifier, application_identifier); } - + krb5int_ipc_stream_free_string (application_identifier); } - + if (!err) { char *explanation = NULL; err = krb5int_ipc_stream_read_string (io_stream, &explanation); - + if (!err) { - err = kim_string_copy (&io_selection_hints->explanation, + err = kim_string_copy (&io_selection_hints->explanation, explanation); } - + krb5int_ipc_stream_free_string (explanation); } - + if (!err) { if (io_selection_hints->options) { - err = kim_options_read_from_stream (io_selection_hints->options, + err = kim_options_read_from_stream (io_selection_hints->options, io_stream); } else { - err = kim_options_create_from_stream (&io_selection_hints->options, + err = kim_options_create_from_stream (&io_selection_hints->options, io_stream); } } - + if (!err) { char *service_identity = NULL; err = krb5int_ipc_stream_read_string (io_stream, &service_identity); - + if (!err) { - err = kim_string_copy (&io_selection_hints->service_identity, + err = kim_string_copy (&io_selection_hints->service_identity, service_identity); } - + krb5int_ipc_stream_free_string (service_identity); } - + if (!err) { char *client_realm = NULL; err = krb5int_ipc_stream_read_string (io_stream, &client_realm); - + if (!err) { - err = kim_string_copy (&io_selection_hints->client_realm, + err = kim_string_copy (&io_selection_hints->client_realm, client_realm); } - + krb5int_ipc_stream_free_string (client_realm); } - + if (!err) { char *user = NULL; err = krb5int_ipc_stream_read_string (io_stream, &user); - + if (!err) { err = kim_string_copy (&io_selection_hints->user, user); } - + krb5int_ipc_stream_free_string (user); } - + if (!err) { char *service_realm = NULL; err = krb5int_ipc_stream_read_string (io_stream, &service_realm); - + if (!err) { - err = kim_string_copy (&io_selection_hints->service_realm, + err = kim_string_copy (&io_selection_hints->service_realm, service_realm); } - + krb5int_ipc_stream_free_string (service_realm); } - + if (!err) { char *service = NULL; err = krb5int_ipc_stream_read_string (io_stream, &service); - + if (!err) { err = kim_string_copy (&io_selection_hints->service, service); } - + krb5int_ipc_stream_free_string (service); } - + if (!err) { char *server = NULL; err = krb5int_ipc_stream_read_string (io_stream, &server); - + if (!err) { err = kim_string_copy (&io_selection_hints->server, server); } - + krb5int_ipc_stream_free_string (server); } - - return check_error (err); + + return check_error (err); } /* ------------------------------------------------------------------------ */ @@ -763,25 +763,24 @@ kim_error kim_selection_hints_create_from_stream (kim_selection_hints *out_selec { kim_error err = KIM_NO_ERROR; kim_selection_hints selection_hints = NULL; - + if (!err && !out_selection_hints) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err && !io_stream ) { err = check_error (KIM_NULL_PARAMETER_ERR); } - + if (!err) { err = kim_selection_hints_allocate (&selection_hints); } - + if (!err) { err = kim_selection_hints_read_from_stream (selection_hints, io_stream); } - + if (!err) { *out_selection_hints = selection_hints; selection_hints = NULL; } - + kim_selection_hints_free (&selection_hints); - - return check_error (err); -} + return check_error (err); +} |