[pve-devel] [PATCH common] read_password improvements

Wolfgang Bumiller w.bumiller at proxmox.com
Wed Dec 13 11:56:20 CET 2017


* Cancel on Ctrl+C (die())
* Finish on Ctrl+D (eof/eot) without appending a newline
* Also finish on \n to be sure.

Signed-off-by: Wolfgang Bumiller <w.bumiller at proxmox.com>
---
 src/PVE/PTY.pm | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/src/PVE/PTY.pm b/src/PVE/PTY.pm
index 1178ea7..fa78196 100644
--- a/src/PVE/PTY.pm
+++ b/src/PVE/PTY.pm
@@ -194,10 +194,13 @@ sub read_password(;$$) {
 	syswrite($outfd, $query, length($query));
 	while (($got = sysread($infd, $ch, 1))) {
 	    my ($ord) = unpack('C', $ch);
-	    if ($ord == 0xD) {
+	    last if $ord == 4; # ^D / EOF
+	    if ($ord == 0xA || $ord == 0xD) {
 		# newline, we're done
 		syswrite($outfd, "\r\n", 2);
 		last;
+	    } elsif ($ord == 3) { # ^C
+		die "password input aborted\n";
 	    } elsif ($ord == 0x7f) {
 		# backspace - if it's the first key disable
 		# asterisks
-- 
2.11.0





More information about the pve-devel mailing list