From 0cf6654fd95b94da7135ef257b75bbd381bb815d Mon Sep 17 00:00:00 2001 From: Ilia Ross Date: Sat, 20 Jun 2026 15:33:22 +0200 Subject: [PATCH] Fix Postfix localhost destination after hostname domain change - When the system hostname domain changes, update `localhost.` in Postfix `mydestination` to `localhost.`. - This sits alongside the existing hostname/FQDN updates for Postfix destinations. Previous behavior: `save_dns.cgi` only updated Postfix `mydestination` entries that exactly matched: - the old short hostname, like `host` - the old FQDN, like `host.old-domain.test` It did **not** update: - `localhost.old-domain.test` So if you changed: ```text host.old-domain.test ``` to: ```text host.new-domain.test ``` Postfix could become: ```text mydestination = host.new-domain.test, host, localhost.old-domain.test ``` After this hunk, it also updates that localhost domain entry: ```text localhost.old-domain.test ``` to: ```text localhost.new-domain.test ``` --- net/save_dns.cgi | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/net/save_dns.cgi b/net/save_dns.cgi index 876bb50be..29207db54 100755 --- a/net/save_dns.cgi +++ b/net/save_dns.cgi @@ -124,6 +124,19 @@ 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");