--- run-passwd.c.ori 2016-04-01 16:41:39.545611926 +0200 +++ run-passwd.c 2016-04-01 16:36:34.561617153 +0200 @@ -292,6 +292,10 @@ passwd_handler->backend_stdout_watch_id = 0; } + /* Remove element of stdin_queue */ + if ( ! passwd_handler->backend_stdin_queue == NULL ) + g_queue_clear( passwd_handler->backend_stdin_queue); + /* Close PID */ if (passwd_handler->backend_pid != -1) { @@ -404,15 +408,25 @@ if (is_string_complete (str->str, "assword: ", "failure", "wrong", "error", NULL)) { if (g_strrstr (str->str, "assword: ") != NULL) { - /* Authentication successful */ - passwd_handler->backend_state = PASSWD_STATE_NEW; + /* Retype is asked directly */ + if ( g_strrstr (str->str, "etype") != NULL) { + printf("etype"); + passwd_handler->backend_state = PASSWD_STATE_RETYPE; + io_queue_pop (passwd_handler->backend_stdin_queue, passwd_handler->backend_stdin); - /* Trigger callback to update authentication status */ - if (passwd_handler->auth_cb) - passwd_handler->auth_cb (passwd_handler, - NULL, - passwd_handler->auth_cb_data); + } + else { + /* Authentication successful */ + + passwd_handler->backend_state = PASSWD_STATE_NEW; + + /* Trigger callback to update authentication status */ + if (passwd_handler->auth_cb) + passwd_handler->auth_cb (passwd_handler, + NULL, + passwd_handler->auth_cb_data); + } } else { /* Authentication failed */ @@ -563,10 +577,13 @@ passwd_handler->backend_state = PASSWD_STATE_NEW; - /* since passwd didn't ask for our old password - * in this case, simply remove it from the queue */ - pw = g_queue_pop_head (passwd_handler->backend_stdin_queue); - g_free (pw); + if (! is_string_complete (str->str, "current", "CURRENT", NULL)) { + + /* since passwd didn't ask for our old password + * in this case, simply remove it from the queue */ + pw = g_queue_pop_head (passwd_handler->backend_stdin_queue); + g_free (pw); + } /* Pop the IO queue, i.e. send new password */ io_queue_pop (passwd_handler->backend_stdin_queue, passwd_handler->backend_stdin);