mirror of
https://github.com/webmin/webmin.git
synced 2026-06-28 15:00:25 +01:00
Fix to remove unrelated network formatting cleanups
This commit is contained in:
@@ -948,8 +948,7 @@ close(SWITCH);
|
||||
&open_tempfile(SWITCH, ">/etc/nsswitch.conf");
|
||||
foreach (@switch) {
|
||||
if (/^\s*hosts:\s+/) {
|
||||
&print_tempfile(SWITCH,
|
||||
&linux_nsswitch_hosts_line($_, $conf->{'order'}));
|
||||
&print_tempfile(SWITCH, "hosts:\t$conf->{'order'}\n");
|
||||
}
|
||||
else {
|
||||
&print_tempfile(SWITCH, $_);
|
||||
@@ -1014,20 +1013,4 @@ else {
|
||||
}
|
||||
}
|
||||
|
||||
# linux_nsswitch_hosts_line(line, order)
|
||||
# Returns an updated nsswitch hosts line preserving existing spacing
|
||||
sub linux_nsswitch_hosts_line
|
||||
{
|
||||
my ($line, $order) = @_;
|
||||
$line =~ s/\r?\n$//;
|
||||
my $comment = "";
|
||||
if ($line =~ s/(\s+#.*)$//) {
|
||||
# Keep inline comments while replacing only the lookup order.
|
||||
$comment = $1;
|
||||
}
|
||||
return $1.$2.$order.$comment."\n"
|
||||
if ($line =~ /^(\s*hosts:)(\s+)\S/);
|
||||
return "hosts:\t$order$comment\n";
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
@@ -57,34 +57,18 @@ local $line="";
|
||||
&open_readfile(HOSTS, $config{'hosts_file'});
|
||||
while($line=<HOSTS>) {
|
||||
local $comment = 0;
|
||||
local $comment_prefix = "";
|
||||
local $leading = "";
|
||||
local $inline_comment = "";
|
||||
$line =~ s/\r|\n//g;
|
||||
if ($line =~ s/^(\s*#+\s*)//) {
|
||||
if ($line =~ s/^\s*#+\s*//) {
|
||||
$comment = 1;
|
||||
$comment_prefix = $1;
|
||||
}
|
||||
elsif ($line =~ s/^(\s+)//) {
|
||||
# Preserve indentation if this file uses it for host rows.
|
||||
$leading = $1;
|
||||
}
|
||||
if ($line =~ s/(\s+#.*)$//) {
|
||||
# Keep inline comments attached to edited host rows.
|
||||
$inline_comment = $1;
|
||||
}
|
||||
$line =~ s/#.*$//g;
|
||||
$line =~ s/\s+$//g;
|
||||
local @seps = &host_line_separators($line);
|
||||
local @f = split(/\s+/, $line);
|
||||
local $ipaddr = shift(@f);
|
||||
if (check_ipaddress_any($ipaddr)) {
|
||||
push(@rv, { 'address' => $ipaddr,
|
||||
'hosts' => [ @f ],
|
||||
'active' => !$comment,
|
||||
'comment_prefix' => $comment_prefix,
|
||||
'leading' => $leading,
|
||||
'comment' => $inline_comment,
|
||||
'seps' => \@seps,
|
||||
'line', $lnum,
|
||||
'index', scalar(@rv) });
|
||||
}
|
||||
@@ -94,35 +78,13 @@ close(HOSTS);
|
||||
return @rv;
|
||||
}
|
||||
|
||||
# host_line_separators(line)
|
||||
# Returns the field separators from a parsed /etc/hosts line
|
||||
sub host_line_separators
|
||||
{
|
||||
local ($line) = @_;
|
||||
local @seps;
|
||||
while($line =~ /\S+(\s+)/g) {
|
||||
push(@seps, $1);
|
||||
}
|
||||
return @seps;
|
||||
}
|
||||
|
||||
# make_host_line(&host)
|
||||
# Internal function to return a line for the hosts file
|
||||
sub make_host_line
|
||||
{
|
||||
local ($host) = @_;
|
||||
local $prefix = $host->{'active'} ? $host->{'leading'} || "" :
|
||||
$host->{'comment_prefix'} || "# ";
|
||||
local @seps = @{$host->{'seps'} || [ ]};
|
||||
local @hosts = @{$host->{'hosts'} || [ ]};
|
||||
local $line = $prefix.$host->{'address'};
|
||||
for(local $i=0; $i<@hosts; $i++) {
|
||||
# Reuse original spacing by field position, then fall back to defaults.
|
||||
local $sep = $seps[$i] || ($i == 0 ? "\t" : " ");
|
||||
$line .= $sep.$hosts[$i];
|
||||
}
|
||||
$line .= $host->{'comment'} if ($host->{'comment'});
|
||||
return $line."\n";
|
||||
return ($host->{'active'} ? "" : "# ").
|
||||
$host->{'address'}."\t".join(" ",@{$host->{'hosts'}})."\n";
|
||||
}
|
||||
|
||||
# create_host(&host)
|
||||
@@ -528,3 +490,4 @@ return $a->{'virtual'} eq '' ? -1 :
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
|
||||
@@ -124,19 +124,6 @@ if (&foreign_installed("postfix") && $in{'hostname'} ne $old_hostname) {
|
||||
&postfix::set_current_value("mydestination",
|
||||
join(", ", @mydests));
|
||||
}
|
||||
$old_domain = $old_hostname =~ /^[^\.]+\.(.*)$/ ? $1 :
|
||||
$old_fqdn =~ /^[^\.]+\.(.*)$/ ? $1 : undef;
|
||||
$new_domain = $in{'hostname'} =~ /^[^\.]+\.(.*)$/ ? $1 :
|
||||
$new_fqdn =~ /^[^\.]+\.(.*)$/ ? $1 : undef;
|
||||
if ($old_domain && $new_domain &&
|
||||
lc($old_domain) ne lc($new_domain)) {
|
||||
$idx = &indexoflc("localhost.$old_domain", @mydests);
|
||||
if ($idx >= 0) {
|
||||
$mydests[$idx] = "localhost.$new_domain";
|
||||
&postfix::set_current_value("mydestination",
|
||||
join(", ", @mydests));
|
||||
}
|
||||
}
|
||||
|
||||
# Update postfix myorigin
|
||||
$myorigin = &postfix::get_current_value("myorigin");
|
||||
@@ -160,3 +147,4 @@ if (&foreign_installed("postfix") && $in{'hostname'} ne $old_hostname) {
|
||||
|
||||
&webmin_log("dns", undef, undef, \%in);
|
||||
&redirect("");
|
||||
|
||||
|
||||
@@ -149,15 +149,6 @@ do "$root/net/netplan-lib.pl" || die "netplan-lib.pl: $@ $!";
|
||||
$main::netplan_dir = $tmp;
|
||||
}
|
||||
|
||||
is(main::linux_nsswitch_hosts_line("hosts: files dns\n",
|
||||
"files dns"),
|
||||
"hosts: files dns\n",
|
||||
"Linux DNS save preserves nsswitch hosts spacing");
|
||||
is(main::linux_nsswitch_hosts_line("hosts:\tfiles dns # local policy\n",
|
||||
"files mdns4 dns"),
|
||||
"hosts:\tfiles mdns4 dns # local policy\n",
|
||||
"Linux DNS save preserves nsswitch hosts comments");
|
||||
|
||||
my $netplan = "$tmp/50-cloud-init.yaml";
|
||||
write_text($netplan, <<'YAML');
|
||||
network:
|
||||
|
||||
Reference in New Issue
Block a user