mirror of
https://github.com/systemd/systemd-stable.git
synced 2025-08-31 09:50:11 +03:00
tty-ask-pwd-agent: give the possiblity to skip a password prompt
If multiple passwords are waiting the agent will prompt for each of them. Give the possiblity to the user to skip some of them by pressing 'C-d'.
This commit is contained in:
@ -371,6 +371,13 @@ int ask_password_tty(
|
|||||||
if (n == 0 || c == '\n' || c == 0)
|
if (n == 0 || c == '\n' || c == 0)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
if (c == 4) { /* C-d also known as EOT */
|
||||||
|
if (ttyfd >= 0)
|
||||||
|
(void) loop_write(ttyfd, "(skipped)", 9, false);
|
||||||
|
|
||||||
|
goto skipped;
|
||||||
|
}
|
||||||
|
|
||||||
if (c == 21) { /* C-u */
|
if (c == 21) { /* C-u */
|
||||||
|
|
||||||
if (!(flags & ASK_PASSWORD_SILENT))
|
if (!(flags & ASK_PASSWORD_SILENT))
|
||||||
@ -467,6 +474,7 @@ int ask_password_tty(
|
|||||||
if (r < 0)
|
if (r < 0)
|
||||||
goto finish;
|
goto finish;
|
||||||
|
|
||||||
|
skipped:
|
||||||
if (keyname)
|
if (keyname)
|
||||||
(void) add_to_keyring_and_log(keyname, flags, l);
|
(void) add_to_keyring_and_log(keyname, flags, l);
|
||||||
|
|
||||||
|
@ -417,6 +417,9 @@ static int process_one_password_file(const char *filename) {
|
|||||||
if (r < 0)
|
if (r < 0)
|
||||||
return log_error_errno(r, "Failed to query password: %m");
|
return log_error_errno(r, "Failed to query password: %m");
|
||||||
|
|
||||||
|
if (strv_isempty(passwords))
|
||||||
|
return -ECANCELED;
|
||||||
|
|
||||||
r = send_passwords(socket_name, passwords);
|
r = send_passwords(socket_name, passwords);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return log_error_errno(r, "Failed to send: %m");
|
return log_error_errno(r, "Failed to send: %m");
|
||||||
@ -525,11 +528,20 @@ static int process_and_watch_password_files(void) {
|
|||||||
pollfd[FD_SIGNAL].events = POLLIN;
|
pollfd[FD_SIGNAL].events = POLLIN;
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
r = process_password_files();
|
int timeout = -1;
|
||||||
if (r < 0)
|
|
||||||
log_error_errno(r, "Failed to process password: %m");
|
|
||||||
|
|
||||||
if (poll(pollfd, _FD_MAX, -1) < 0) {
|
r = process_password_files();
|
||||||
|
if (r < 0) {
|
||||||
|
if (r == -ECANCELED)
|
||||||
|
/* Disable poll() timeout since at least one password has
|
||||||
|
* been skipped and therefore one file remains and is
|
||||||
|
* unlikely to trigger any events. */
|
||||||
|
timeout = 0;
|
||||||
|
else
|
||||||
|
log_error_errno(r, "Failed to process password: %m");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (poll(pollfd, _FD_MAX, timeout) < 0) {
|
||||||
if (errno == EINTR)
|
if (errno == EINTR)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user