[pve-devel] [PATCH qemu-server 4/8] add 'set-user-password' to qm

Thomas Lamprecht t.lamprecht at proxmox.com
Mon Jun 11 11:23:48 CEST 2018


On 6/7/18 1:16 PM, Dominik Csapak wrote:
> and implement read_password for qm.pm
> 
> Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
> ---
>  PVE/CLI/qm.pm | 10 ++++++++++
>  1 file changed, 10 insertions(+)
> 
> diff --git a/PVE/CLI/qm.pm b/PVE/CLI/qm.pm
> index c017a59..ee52c4b 100755
> --- a/PVE/CLI/qm.pm
> +++ b/PVE/CLI/qm.pm
> @@ -665,6 +665,14 @@ my $print_agent_result = sub {
>      print to_json($result, { pretty => 1, canonical => 1});
>  };
>  
> +sub read_password {
> +    # return $ENV{PVE_PW_TICKET} if defined($ENV{PVE_PW_TICKET});

is above line left over?

> +    my $pw = PVE::PTY::read_password('New VM user password: ');
> +    my $pw2 = PVE::PTY::read_password('Repeat password: ');


See: [1]: https://pve.proxmox.com/pipermail/pve-devel/2018-June/032228.html

Maybe we could try to align more with passwd, as I'd like to have
the enter/retype dialog the same on the CLI as much as possible.
Maybe we could add a helper (to PTY?) which gets a confirmed
passwords, so we do not have to duplicate this code everywhere, but simply
add do:

sub read_password {
    return PVE::PTY::get_confirmed_password(); # or however you'd like to call it
}

everywhere we need it.

oh an, passwd uses 'Retype' so maybe we should stick to that as it was
earlier in [1], sample output could then look like:

# qm qga passwd 200 tom
Changing password for user 'tom' in VM 200.
Enter new password: ****
Retype new password: ****
Password changed / OK / Sorry, passwords do not match

(yes, I wrote much more than this maybe seen worth it, sorry, but IMO details
are somewhat important and it's faster if we get it already in a good shape
in than having to fix 10 inconsistencies which have grown hidden over time)

> +    die "passwords do not match\n" if $pw ne $pw2;
> +    return $pw;
> +}
> +
>  sub param_mapping {
>      my ($name) = @_;
>  
> @@ -815,6 +823,8 @@ our $cmddef = {
>      agent  => [ "PVE::API2::Qemu::Agent", 'agent', ['vmid', 'command'],
>  		{ node => $nodename }, $print_agent_result ],
>  
> +    'set-user-password' => [ "PVE::API2::Qemu::Agent", 'set-user-password', [ 'vmid', 'username' ], { node => $nodename }],
> +
>      mtunnel => [ __PACKAGE__, 'mtunnel', []],
>  
>      nbdstop => [ __PACKAGE__, 'nbdstop', ['vmid']],
> 





More information about the pve-devel mailing list