Skip to contentSkip to conversation

client: Cancel agent prompt with CTRL+D

PATCH Applied Tim Kourt 2 participants 2 messages Oct 28, 2019

lore
Share & tools
lore

Tim Kourt

author
#0 lore raw

PATCH 1/1 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.

---
 client/agent.c   | 28 +++++++++++++++++++---------
 client/display.c |  8 ++++----
 2 files changed, 23 insertions(+), 13 deletions(-)
client/agent.c +19 -9
index 78499419..16bc3c4f 100644
@@ -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);
 }
 
client/display.c +4 -4
index c08183da..cd17ad84 100644
@@ -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;
 
Signature · 1 line
2.13.6
#1 lore raw

Hi Tim,

Quoted 8 lines · Tim Kourt

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.

---
  client/agent.c   | 28 +++++++++++++++++++---------
  client/display.c |  8 ++++----
  2 files changed, 23 insertions(+), 13 deletions(-)

Applied, thanks.

Regards,
-Denis