From: Ray Strode Date: Wed, 20 Aug 2008 19:47:39 +0000 (-0400) Subject: Before asking for passwords try old passwords first X-Git-Tag: 0.6.0~188 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=808b18f767eaabe5f4ecdcf939fd3d49d11ef75a;p=thirdparty%2Fplymouth.git Before asking for passwords try old passwords first Frequently, the user will choose the same password for multiple encrypted block devices. Rather than asking them for the same information multiple times, we try to use old passwords first. --- diff --git a/src/client/plymouth.c b/src/client/plymouth.c index 33deb243..dd2ba716 100644 --- a/src/client/plymouth.c +++ b/src/client/plymouth.c @@ -190,6 +190,44 @@ on_answer (answer_state_t *answer_state, ply_event_loop_exit (answer_state->state->loop, WEXITSTATUS (exit_status)); } +static void +on_multiple_answers (answer_state_t *answer_state, + const char * const *answers) +{ + bool need_to_ask_user; + int i; + int exit_status; + + assert (answer_state->command != NULL); + + need_to_ask_user = true; + for (i = 0; answers[i] != NULL; i++) + { + bool command_started; + exit_status = 127; + command_started = answer_via_command (answer_state, answers[i], + &exit_status); + if (command_started && WIFEXITED (exit_status) && + WEXITSTATUS (exit_status) == 0) + { + need_to_ask_user = false; + break; + } + } + + if (need_to_ask_user) + { + ply_boot_client_ask_daemon_for_password (answer_state->state->client, + (ply_boot_client_answer_handler_t) + on_answer, + (ply_boot_client_response_handler_t) + on_answer_failure, answer_state); + return; + } + + ply_event_loop_exit (answer_state->state->loop, 0); +} + static void on_failure (state_t *state) { @@ -238,15 +276,25 @@ on_password_request (state_t *state, answer_state = calloc (1, sizeof (answer_state_t)); answer_state->state = state; - answer_state->command = program != NULL? strdup (program): NULL; + answer_state->command = program; - ply_boot_client_ask_daemon_for_password (state->client, - (ply_boot_client_answer_handler_t) - on_answer, - (ply_boot_client_response_handler_t) - on_answer_failure, answer_state); + if (answer_state->command != NULL) + { + ply_boot_client_ask_daemon_for_cached_passwords (state->client, + (ply_boot_client_multiple_answers_handler_t) + on_multiple_answers, + (ply_boot_client_response_handler_t) + on_answer_failure, answer_state); - free (program); + } + else + { + ply_boot_client_ask_daemon_for_password (state->client, + (ply_boot_client_answer_handler_t) + on_answer, + (ply_boot_client_response_handler_t) + on_answer_failure, answer_state); + } } int