[pve-devel] [PATCH][pve-manager] Changes set_userpasswd method

Игорь Шестаков shine at selectel.ru
Mon Oct 28 10:31:46 CET 2013


Done.

diff --git a/PVE/OpenVZ.pm b/PVE/OpenVZ.pm
index a16d4fc..7788f66 100644
--- a/PVE/OpenVZ.pm
+++ b/PVE/OpenVZ.pm
@@ -1244,13 +1244,13 @@ sub replacepw {
 }

 sub set_rootpasswd {
-    my ($privatedir, $opt_rootpasswd) = @_;
+    my ($opt_rootpasswd, $rootdir) = @_;

-    my $pwfile = "$privatedir/etc/passwd";
+    my $pwfile = "$rootdir/etc/passwd";

     return if ! -f $pwfile;

-    my $shadow = "$privatedir/etc/shadow";
+    my $shadow = "$rootdir/etc/shadow";

     if ($opt_rootpasswd !~ m/^\$/) {
  my $time = substr (Digest::SHA::sha1_base64 (time), 0, 8);



diff --git a/PVE/API2/OpenVZ.pm b/PVE/API2/OpenVZ.pm
index 06fe60b..60ef124 100644
--- a/PVE/API2/OpenVZ.pm
+++ b/PVE/API2/OpenVZ.pm
@@ -406,15 +406,23 @@ __PACKAGE__->register_method({
  }

     } else {
- PVE::Tools::file_set_contents($basecfg_fn, $rawconf);
- my $cmd = ['vzctl', '--skiplock', 'create', $vmid,
-   '--ostemplate', $archive, '--private', $private];
- run_command($cmd);
-
- # hack: vzctl '--userpasswd' starts the CT, but we want
- # to avoid that for create
- PVE::OpenVZ::set_rootpasswd($private, $password)
-    if defined($password);
+        PVE::Tools::file_set_contents($basecfg_fn, $rawconf);
+        my $cmd = ['vzctl', '--skiplock', 'create', $vmid,
+                   '--ostemplate', $ostmp, '--private', $private];
+        run_command($cmd);
+        my $rootdir = PVE::OpenVZ::get_rootdir($conf, $vmid);
+
+        $cmd = ['/usr/sbin/vzctl', '--skiplock', 'mount', $vmid];
+        run_command($cmd);
+        die "Cannot mount $vmid" if !PVE::OpenVZ::check_mounted($conf,
$vmid);
+
+        # hack: vzctl '--userpasswd' starts the CT, but we want
+        # to avoid that for create
+        PVE::OpenVZ::set_rootpasswd($password, $rootdir)
+            if defined($password);
+
+        $cmd = ['/usr/sbin/vzctl', '--skiplock', 'umount', $vmid];
+        run_command($cmd);
     }

     PVE::AccessControl::add_vm_to_pool($vmid, $pool) if $pool;



On Mon, Oct 28, 2013 at 12:20 PM, Dietmar Maurer <dietmar at proxmox.com>wrote:

> > Of course, we can use "vzctl mount", but then function set_rootpasswd
> must be
> > rewrited to use "vzctl mount" for simfs too.
>
> I guess that is the correct way to implement it.
>
>
>


-- 
С уважением, Шестаков Игорь
Сеть дата-центров "Селектел"
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.proxmox.com/pipermail/pve-devel/attachments/20131028/5cf390d5/attachment.htm>


More information about the pve-devel mailing list