return kim_prompt_type_preauth;
}
-
#pragma mark -
/* ------------------------------------------------------------------------ */
-kim_error kim_ui_init (kim_ui_context *io_context)
+static kim_error kim_ui_init_lazy (kim_ui_context *io_context)
{
kim_error err = KIM_NO_ERROR;
if (!err && !io_context) { err = check_error (KIM_NULL_PARAMETER_ERR); }
- if (!err) {
+ if (!err && !io_context->initialized) {
#ifndef LEAN_CLIENT
kim_ui_environment environment = kim_library_ui_environment ();
err = check_error (KIM_NO_UI_ERR);
}
#endif /* LEAN_CLIENT */
+
+ if (!err) {
+ io_context->initialized = 1;
+ }
}
+ return check_error (err);
+}
+
+#pragma mark -
+
+/* ------------------------------------------------------------------------ */
+
+kim_error kim_ui_init (kim_ui_context *io_context)
+{
+ kim_error err = KIM_NO_ERROR;
+
+ if (!err && !io_context) { err = check_error (KIM_NULL_PARAMETER_ERR); }
+
if (!err) {
+ /* Lazy initialization so we only actually initialize if a prompt
+ * gets called. This is important because krb5_get_init_creds_*
+ * can't tell us if a prompt is going to get called in advance */
+ io_context->initialized = 0;
io_context->identity = NULL;
io_context->prompt_count = 0;
}
if (!err && !in_context ) { err = check_error (KIM_NULL_PARAMETER_ERR); }
if (!err && !out_identity) { err = check_error (KIM_NULL_PARAMETER_ERR); }
+ if (!err) {
+ err = kim_ui_init_lazy (in_context);
+ }
+
if (!err) {
if (in_context->type == kim_ui_type_gui_plugin) {
err = kim_ui_plugin_enter_identity (in_context,
if (!err && !in_hints ) { err = check_error (KIM_NULL_PARAMETER_ERR); }
if (!err && !out_identity) { err = check_error (KIM_NULL_PARAMETER_ERR); }
+ if (!err) {
+ err = kim_ui_init_lazy (in_context);
+ }
+
if (!err) {
if (in_context->type == kim_ui_type_gui_plugin) {
err = kim_ui_plugin_select_identity (in_context,
if (!got_saved_password) {
context->prompt_count++;
-
- if (context->type == kim_ui_type_gui_plugin) {
- err = kim_ui_plugin_auth_prompt (context,
- context->identity,
- type,
- in_prompts[i].hidden,
- in_name,
- in_banner,
- in_prompts[i].prompt,
- &reply);
-
+
+ err = kim_ui_init_lazy (in_context);
+
+ if (!err) {
+ if (context->type == kim_ui_type_gui_plugin) {
+ err = kim_ui_plugin_auth_prompt (context,
+ context->identity,
+ type,
+ in_prompts[i].hidden,
+ in_name,
+ in_banner,
+ in_prompts[i].prompt,
+ &reply);
+
#ifndef LEAN_CLIENT
- } else if (context->type == kim_ui_type_gui_builtin) {
- err = kim_os_ui_gui_auth_prompt (context,
- context->identity,
- type,
- in_prompts[i].hidden,
- in_name,
- in_banner,
- in_prompts[i].prompt,
- &reply);
-
- } else if (context->type == kim_ui_type_cli) {
- err = kim_ui_cli_auth_prompt (context,
- context->identity,
- type,
- in_prompts[i].hidden,
- in_name,
- in_banner,
- in_prompts[i].prompt,
- &reply);
+ } else if (context->type == kim_ui_type_gui_builtin) {
+ err = kim_os_ui_gui_auth_prompt (context,
+ context->identity,
+ type,
+ in_prompts[i].hidden,
+ in_name,
+ in_banner,
+ in_prompts[i].prompt,
+ &reply);
+
+ } else if (context->type == kim_ui_type_cli) {
+ err = kim_ui_cli_auth_prompt (context,
+ context->identity,
+ type,
+ in_prompts[i].hidden,
+ in_name,
+ in_banner,
+ in_prompts[i].prompt,
+ &reply);
#endif /* LEAN_CLIENT */
-
- } else {
- err = check_error (KIM_NO_UI_ERR);
+
+ } else {
+ err = check_error (KIM_NO_UI_ERR);
+ }
}
}
-
+
if (!err) {
uint32_t reply_len = strlen (reply);
if (!err && !out_new_password ) { err = check_error (KIM_NULL_PARAMETER_ERR); }
if (!err && !out_verify_password) { err = check_error (KIM_NULL_PARAMETER_ERR); }
+ if (!err) {
+ err = kim_ui_init_lazy (in_context);
+ }
+
if (!err) {
if (in_context->type == kim_ui_type_gui_plugin) {
err = kim_ui_plugin_change_password (in_context,
return check_error (err);
}
-/* ------------------------------------------------------------------------ */
-/* Helper function */
-
-kim_error kim_ui_handle_kim_error (kim_ui_context *in_context,
- kim_identity in_identity,
- enum kim_ui_error_type in_type,
- kim_error in_error)
-{
- kim_error err = KIM_NO_ERROR;
- kim_string message = NULL;
- kim_string description = NULL;
-
- if (!err) {
- /* Do this first so last error doesn't get overwritten */
- err = kim_string_create_for_last_error (&description, in_error);
- }
-
- if (!err && !in_context) { err = check_error (KIM_NULL_PARAMETER_ERR); }
-
- if (!err) {
- kim_string key = NULL;
-
- switch (in_type) {
- case kim_ui_error_type_authentication:
- key = "Kerberos Login Failed:";
- break;
-
- case kim_ui_error_type_change_password:
- key = "Kerberos Change Password Failed:";
- break;
-
- case kim_ui_error_type_selection:
- case kim_ui_error_type_generic:
- default:
- key = "Kerberos Operation Failed:";
- break;
- }
-
- err = kim_os_string_create_localized (&message, key);
- }
-
- if (!err) {
- err = kim_ui_handle_error (in_context, in_identity,
- in_error, message, description);
- }
-
- kim_string_free (&description);
- kim_string_free (&message);
-
- return check_error (err);
-}
-
/* ------------------------------------------------------------------------ */
kim_error kim_ui_handle_error (kim_ui_context *in_context,
if (!err && !in_error_message ) { err = check_error (KIM_NULL_PARAMETER_ERR); }
if (!err && !in_error_description) { err = check_error (KIM_NULL_PARAMETER_ERR); }
+ if (!err) {
+ err = kim_ui_init_lazy (in_context);
+ }
+
if (!err) {
if (in_context->type == kim_ui_type_gui_plugin) {
err = kim_ui_plugin_handle_error (in_context,
void kim_ui_free_string (kim_ui_context *in_context,
char **io_string)
{
- if (in_context && io_string && *io_string) {
+ kim_error err = kim_ui_init_lazy (in_context);
+
+ if (!err && in_context && io_string && *io_string) {
if (in_context->type == kim_ui_type_gui_plugin) {
kim_ui_plugin_free_string (in_context,
io_string);
kim_ui_cli_free_string (in_context,
io_string);
#endif /* LEAN_CLIENT */
-
}
}
}
if (!err && !io_context) { err = check_error (KIM_NULL_PARAMETER_ERR); }
- if (!err) {
+ if (!err && io_context->initialized) {
if (io_context->type == kim_ui_type_gui_plugin) {
err = kim_ui_plugin_fini (io_context);
return check_error (err);
}
+
+#pragma mark -
+
+/* ------------------------------------------------------------------------ */
+/* Helper function */
+
+kim_error kim_ui_handle_kim_error (kim_ui_context *in_context,
+ kim_identity in_identity,
+ enum kim_ui_error_type in_type,
+ kim_error in_error)
+{
+ kim_error err = KIM_NO_ERROR;
+ kim_string message = NULL;
+ kim_string description = NULL;
+
+ if (!err) {
+ /* Do this first so last error doesn't get overwritten */
+ err = kim_string_create_for_last_error (&description, in_error);
+ }
+
+ if (!err && !in_context) { err = check_error (KIM_NULL_PARAMETER_ERR); }
+
+ if (!err) {
+ kim_string key = NULL;
+
+ switch (in_type) {
+ case kim_ui_error_type_authentication:
+ key = "Kerberos Login Failed:";
+ break;
+
+ case kim_ui_error_type_change_password:
+ key = "Kerberos Change Password Failed:";
+ break;
+
+ case kim_ui_error_type_selection:
+ case kim_ui_error_type_generic:
+ default:
+ key = "Kerberos Operation Failed:";
+ break;
+ }
+
+ err = kim_os_string_create_localized (&message, key);
+ }
+
+ if (!err) {
+ err = kim_ui_handle_error (in_context, in_identity,
+ in_error, message, description);
+ }
+
+ kim_string_free (&description);
+ kim_string_free (&message);
+
+ return check_error (err);
+}