[pve-devel] [PATCH common 4/4] CLIHandler: add a default read_password implementation

Wolfgang Bumiller w.bumiller at proxmox.com
Fri Nov 24 11:24:25 CET 2017


Moved here from pvesh, pveum and pct. They all need the same
functionality currently. 'pvesh' wants to pass the
Term::ReadLine instance which we currently don't use here
as we don't want to actually use readline.

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

diff --git a/src/PVE/CLIHandler.pm b/src/PVE/CLIHandler.pm
index efc8a1a..3d10ecb 100644
--- a/src/PVE/CLIHandler.pm
+++ b/src/PVE/CLIHandler.pm
@@ -7,6 +7,7 @@ use PVE::SafeSyslog;
 use PVE::Exception qw(raise raise_param_exc);
 use PVE::RESTHandler;
 use PVE::INotify;
+use PVE::PTY;
 
 use base qw(PVE::RESTHandler);
 
@@ -47,6 +48,18 @@ my $complete_command_names = sub {
     return $res;
 };
 
+sub read_password {
+    my ($term, $noverify) = @_;
+
+    my $passwd = PVE::PTY::read_password('Password: ');
+    if (!$noverify) {
+	my $passwd2 = PVE::PTY::read_password('Retype password: ');
+	die "Passwords do not match.\n" if $passwd ne $passwd2;
+    }
+
+    return $passwd;
+}
+
 __PACKAGE__->register_method ({
     name => 'help',
     path => 'help',
-- 
2.11.0





More information about the pve-devel mailing list