]> git.proxmox.com Git - pve-container.git/blobdiff - src/PVE/LXC/Setup/Base.pm
use better regex for detecting pre crypt()'d passwords
[pve-container.git] / src / PVE / LXC / Setup / Base.pm
index 7bf66ca81d62de49c0b0dd06723dfc3a2ba7479b..9b1cf124ecac80c09b5e835e10e8162e5bf6a82b 100644 (file)
@@ -17,9 +17,9 @@ use PVE::Tools;
 use PVE::Network;
 
 sub new {
-    my ($class, $conf, $rootdir) = @_;
+    my ($class, $conf, $rootdir, $os_release) = @_;
 
-    return bless { conf => $conf, rootdir => $rootdir }, $class;
+    return bless { conf => $conf, rootdir => $rootdir, os_release => $os_release }, $class;
 }
 
 sub lookup_dns_conf {
@@ -28,27 +28,24 @@ sub lookup_dns_conf {
     my $nameserver = $conf->{nameserver};
     my $searchdomains = $conf->{searchdomain};
 
-    if (!($nameserver && $searchdomains)) {
-
-       if ($conf->{'testmode'}) {
-           
-           $nameserver = "8.8.8.8 8.8.8.9";
-           $searchdomains = "proxmox.com";
-       
-       } else {
-
-           my $host_resolv_conf = $self->{host_resolv_conf};
+    if ($conf->{'testmode'}) {
+       return ('proxmox.com', '8.8.8.8 8.8.8.9');
+    }
 
-           $searchdomains = $host_resolv_conf->{search};
+    my $host_resolv_conf = $self->{host_resolv_conf};
 
-           my @list = ();
-           foreach my $k ("dns1", "dns2", "dns3") {
-               if (my $ns = $host_resolv_conf->{$k}) {
-                   push @list, $ns;
-               }
+    if (!defined($nameserver)) {
+       my @list = ();
+       foreach my $k ("dns1", "dns2", "dns3") {
+           if (my $ns = $host_resolv_conf->{$k}) {
+               push @list, $ns;
            }
-           $nameserver = join(' ', @list);
        }
+       $nameserver = join(' ', @list);
+    }
+
+    if (!defined($searchdomains)) {
+       $searchdomains = $host_resolv_conf->{search};
     }
 
     return ($searchdomains, $nameserver);
@@ -57,7 +54,8 @@ sub lookup_dns_conf {
 sub update_etc_hosts {
     my ($self, $hostip, $oldname, $newname, $searchdomains) = @_;
 
-    my $done = 0;
+    my $hosts_fn = '/etc/hosts';
+    return if $self->ct_is_file_ignored($hosts_fn);
 
     my $namepart = ($newname =~ s/\..*$//r);
 
@@ -75,7 +73,6 @@ sub update_etc_hosts {
 
     # Prepare section:
     my $section = '';
-    my $hosts_fn = '/etc/hosts';
 
     my $lo4 = "127.0.0.1 localhost.localnet localhost\n";
     my $lo6 = "::1 localhost.localnet localhost\n";
@@ -327,10 +324,6 @@ my $replacepw  = sub {
 
        my $last_change = int(time()/(60*60*24));
 
-       if ($epw =~ m/^\$TEST\$/) { # for regression tests
-           $last_change = 12345;
-       }
-       
        while (defined (my $line = <$src>)) {
            if ($shadow) {
                $line =~ s/^${user}:[^:]*:[^:]*:/${user}:${epw}:${last_change}:/;
@@ -361,7 +354,7 @@ sub set_user_password {
     my $shadow = "/etc/shadow";
     
     if (defined($opt_password)) {
-       if ($opt_password !~ m/^\$/) {
+       if ($opt_password !~ m/^\$(?:1|2[axy]?|5|6)\$[a-zA-Z0-9.\/]{1,16}\$[a-zA-Z0-9.\/]+$/) {
            my $time = substr (Digest::SHA::sha1_base64 (time), 0, 8);
            $opt_password = crypt(encode("utf8", $opt_password), "\$1\$$time\$");
        };