diff cli-auth.c @ 268:475a818dd6e7

Cancel a dbclient password prompt if the user presses ctrl-c. Enter still has to be pressed since glibc blocks ctrl-c in getpass()
author Matt Johnston <matt@ucc.asn.au>
date Sun, 15 Jan 2006 06:43:24 +0000
parents efbaf6b03837
children 64abb124763d baea1d43e7eb
line wrap: on
line diff
--- a/cli-auth.c	Sun Jan 15 06:39:48 2006 +0000
+++ b/cli-auth.c	Sun Jan 15 06:43:24 2006 +0000
@@ -278,3 +278,18 @@
 
 	TRACE(("leave cli_auth_try"))
 }
+
+/* A helper for getpass() that exits if the user cancels. The returned
+ * password is statically allocated by getpass() */
+char* getpass_or_cancel()
+{
+	char* password = NULL;
+
+	password = getpass("Password: ");
+
+	/* 0x03 is a ctrl-c character in the buffer. */
+	if (password == NULL || strchr(password, '\3') != NULL) {
+		dropbear_close("Interrupted.");
+	}
+	return password;
+}