[pve-devel] [PATCH container] Add read_password sub for 'pct create'

Fabian Grünbichler f.gruenbichler at proxmox.com
Wed Mar 30 13:51:52 CEST 2016


Read the container root password from stdin when creating a
container with 'pct create ... -password', instead of
providing it as command line argument. This is consistent
with 'pveum adduser' and pvesh, as described in #737 and #777.
---
Note that this is a backwards-incompatible change, since
'password' as parameter name is hardcoded in JSONSchema.pm
there is no good way to transition this.

 src/PVE/CLI/pct.pm | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/src/PVE/CLI/pct.pm b/src/PVE/CLI/pct.pm
index 963015b..c3cea6a 100755
--- a/src/PVE/CLI/pct.pm
+++ b/src/PVE/CLI/pct.pm
@@ -6,6 +6,7 @@ use warnings;
 use POSIX;
 use Fcntl;
 use File::Copy 'copy';
+use Term::ReadLine;
 
 use PVE::SafeSyslog;
 use PVE::Tools qw(extract_param);
@@ -31,6 +32,16 @@ my $upid_exit = sub {
     exit($status eq 'OK' ? 0 : -1);
 };
 
+sub read_password {
+    my $term = new Term::ReadLine ('pct');
+    my $attribs = $term->Attribs;
+    $attribs->{redisplay_function} = $attribs->{shadow_redisplay};
+    my $input = $term->readline('Enter password: ');
+    my $conf = $term->readline('Retype password: ');
+    die "Passwords do not match.\n" if ($input ne $conf);
+    return $input;
+}
+
 __PACKAGE__->register_method ({
     name => 'unlock',
     path => 'unlock',
-- 
2.1.4





More information about the pve-devel mailing list