[pve-devel] [PATCH common] read_password improvements

Thomas Lamprecht t.lamprecht at proxmox.com
Wed Dec 13 12:23:51 CET 2017


On 12/13/2017 11:56 AM, Wolfgang Bumiller wrote:
> * 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
> 

Reviewed-by: Thomas Lamprecht <t.lamprecht at proxmox.com>
Tested-by: Thomas Lamprecht <t.lamprecht at proxmox.com>




More information about the pve-devel mailing list