commit 37e6f6f08be3aa1b903fa33443970cce7ec4dbba
parent fea262c2aaaaf2b81d3b9a49be5837573d85be27
Author: Tim Kourt <tim.a.kourt@linux.intel.com>
Date: Mon, 28 Oct 2019 10:21:59 -0700
client: Cancel agent prompt with CTRL+D
Previously, CTRL+D used to cause termination of the client. Now, the
command will cancel the agent’s prompts in agent mod. In regular mode
the behavior is unchanged.
Diffstat:
2 files changed, 23 insertions(+), 13 deletions(-)
diff --git a/client/agent.c b/client/agent.c
@@ -366,14 +366,17 @@ static void process_input_username_password(const char *prompt)
struct l_dbus_message *reply;
char *username;
- if (l_queue_isempty(pending_op.saved_input)) {
- /* received username */
- if (!strlen(prompt)) {
- reply = agent_reply_canceled(pending_message,
+ if (!prompt || !strlen(prompt)) {
+ reply = agent_reply_canceled(pending_message,
"Canceled by user");
- goto send_reply;
- }
+ l_queue_clear(pending_op.saved_input, l_free);
+
+ goto send_reply;
+ }
+
+ if (l_queue_isempty(pending_op.saved_input)) {
+ /* received username */
l_queue_push_tail(pending_op.saved_input, l_strdup(prompt));
display_agent_prompt(PROMPT_PASSWORD, true);
@@ -397,7 +400,7 @@ static void process_input_passphrase(const char *prompt)
{
struct l_dbus_message *reply;
- if (!strlen(prompt)) {
+ if (!prompt || !strlen(prompt)) {
reply = agent_reply_canceled(pending_message,
"Canceled by user");
goto send_reply;
@@ -412,11 +415,18 @@ send_reply:
static void process_input_password(const char *prompt)
{
- struct l_dbus_message *reply =
- l_dbus_message_new_method_return(pending_message);
+ struct l_dbus_message *reply;
+
+ if (!prompt || !strlen(prompt)) {
+ reply = agent_reply_canceled(pending_message,
+ "Canceled by user");
+ goto send_reply;
+ }
+ reply = l_dbus_message_new_method_return(pending_message);
l_dbus_message_set_arguments(reply, "s", prompt);
+send_reply:
agent_send_reply(reply);
}
diff --git a/client/display.c b/client/display.c
@@ -465,6 +465,10 @@ static void readline_callback(char *prompt)
HIST_ENTRY *previous_prompt;
+ if (agent_prompt(masked_input.use_mask ?
+ masked_input.passphrase : prompt))
+ goto done;
+
if (!prompt) {
display_quit();
@@ -473,10 +477,6 @@ static void readline_callback(char *prompt)
return;
}
- if (agent_prompt(masked_input.use_mask ?
- masked_input.passphrase : prompt))
- goto done;
-
if (!strlen(prompt))
goto done;