From 4c4a018caba30a58c3549924b8521074bbe5adad Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 26 Aug 2020 23:02:13 +0200 Subject: [PATCH 1/3] tty-ask-pw-agent: make sure "--list" works correctly Fixes: #16836 --- src/tty-ask-password-agent/tty-ask-password-agent.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/tty-ask-password-agent/tty-ask-password-agent.c b/src/tty-ask-password-agent/tty-ask-password-agent.c index 4371da4785..49b30e14e0 100644 --- a/src/tty-ask-password-agent/tty-ask-password-agent.c +++ b/src/tty-ask-password-agent/tty-ask-password-agent.c @@ -47,7 +47,7 @@ static enum { ACTION_LIST, ACTION_QUERY, ACTION_WATCH, - ACTION_WALL + ACTION_WALL, } arg_action = ACTION_QUERY; static bool arg_plymouth = false; @@ -713,7 +713,7 @@ static int run(int argc, char *argv[]) { (void) release_terminal(); } - return process_and_watch_password_files(arg_action != ACTION_QUERY); + return process_and_watch_password_files(!IN_SET(arg_action, ACTION_QUERY, ACTION_LIST)); } DEFINE_MAIN_FUNCTION(run); From 66bff73b4f91f8d2fdd385f9f1e2b6339055c9e4 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 26 Aug 2020 23:05:46 +0200 Subject: [PATCH 2/3] tty-ask-pw-agent: the message string might not be set --- src/shared/ask-password-api.c | 3 +++ src/tty-ask-password-agent/tty-ask-password-agent.c | 10 ++++------ 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/shared/ask-password-api.c b/src/shared/ask-password-api.c index 3d0b939106..a727b98e7c 100644 --- a/src/shared/ask-password-api.c +++ b/src/shared/ask-password-api.c @@ -237,6 +237,9 @@ int ask_password_plymouth( assert(ret); + if (!message) + message = "Password:"; + if (flag_file) { notify = inotify_init1(IN_CLOEXEC|IN_NONBLOCK); if (notify < 0) diff --git a/src/tty-ask-password-agent/tty-ask-password-agent.c b/src/tty-ask-password-agent/tty-ask-password-agent.c index 49b30e14e0..096b90c2aa 100644 --- a/src/tty-ask-password-agent/tty-ask-password-agent.c +++ b/src/tty-ask-password-agent/tty-ask-password-agent.c @@ -210,7 +210,7 @@ static int process_one_password_file(const char *filename) { switch (arg_action) { case ACTION_LIST: - printf("'%s' (PID %u)\n", message, pid); + printf("'%s' (PID %u)\n", strna(message), pid); return 0; case ACTION_WALL: { @@ -219,7 +219,7 @@ static int process_one_password_file(const char *filename) { if (asprintf(&wall, "Password entry required for \'%s\' (PID %u).\r\n" "Please enter password with the systemd-tty-ask-password-agent tool.", - message, + strna(message), pid) < 0) return log_oom(); @@ -233,7 +233,7 @@ static int process_one_password_file(const char *filename) { if (access(socket_name, W_OK) < 0) { if (arg_action == ACTION_QUERY) - log_info("Not querying '%s' (PID %u), lacking privileges.", message, pid); + log_info("Not querying '%s' (PID %u), lacking privileges.", strna(message), pid); return 0; } @@ -246,7 +246,6 @@ static int process_one_password_file(const char *filename) { r = ask_password_plymouth(message, not_after, flags, filename, &passwords); else r = agent_ask_password_tty(message, not_after, flags, filename, &passwords); - if (r < 0) { /* If the query went away, that's OK */ if (IN_SET(r, -ETIME, -ENOENT)) @@ -262,8 +261,7 @@ static int process_one_password_file(const char *filename) { if (r < 0) return log_error_errno(r, "Failed to send: %m"); break; - } - } + }} return 0; } From a4fd6cd3f575eb7e1452a74c2e35548739e3b252 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 26 Aug 2020 23:10:50 +0200 Subject: [PATCH 3/3] tty-ask-pw-agent: properly propagate error --- src/tty-ask-password-agent/tty-ask-password-agent.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/tty-ask-password-agent/tty-ask-password-agent.c b/src/tty-ask-password-agent/tty-ask-password-agent.c index 096b90c2aa..87779a4dd6 100644 --- a/src/tty-ask-password-agent/tty-ask-password-agent.c +++ b/src/tty-ask-password-agent/tty-ask-password-agent.c @@ -143,8 +143,7 @@ static int agent_ask_password_tty( const char *flag_file, char ***ret) { - int tty_fd = -1; - int r; + int tty_fd = -1, r; if (arg_console) { const char *con = arg_device ?: "/dev/console"; @@ -166,7 +165,7 @@ static int agent_ask_password_tty( release_terminal(); } - return 0; + return r; } static int process_one_password_file(const char *filename) {