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);
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);
# 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";
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}:/;
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\$");
};