]> git.proxmox.com Git - pve-common.git/commitdiff
read_password improvements
authorWolfgang Bumiller <w.bumiller@proxmox.com>
Wed, 13 Dec 2017 10:47:23 +0000 (11:47 +0100)
committerWolfgang Bumiller <w.bumiller@proxmox.com>
Wed, 13 Dec 2017 13:49:14 +0000 (14:49 +0100)
* 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@proxmox.com>
Reviewed-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
Tested-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
src/PVE/PTY.pm

index 1178ea7a2da01eb29e6b2373a50445197cdaa1ec..fa781962bd5cce8d596fc09c69b530b81b331543 100644 (file)
@@ -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