From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [IPv6:2a0f:8001:1:32::40]) by lore.proxmox.com (Postfix) with ESMTPS id F109A1FF0E2 for ; Thu, 30 Jul 2026 16:18:47 +0200 (CEST) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id AD84821472; Thu, 30 Jul 2026 16:18:47 +0200 (CEST) From: Jonas Theisen To: pmg-devel@lists.proxmox.com Subject: [PATCH pmg-api] postfix: config: use postalias and update aliases.db only if changed Date: Wed, 29 Jul 2026 18:06:08 +0200 Message-ID: <20260729160639.431458-1-j.theisen@proxmox.com> X-Mailer: git-send-email 2.47.3 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1785341207239 X-SPAM-LEVEL: Spam detection results: 0 DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment (newer systems) RCVD_IN_DNSWL_LOW -0.7 Sender listed at https://www.dnswl.org/, low trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record X-MailFrom: j.theisen@proxmox.com X-Mailman-Rule-Hits: nonmember-moderation X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation Message-ID-Hash: BCT4SZ5B2QKA7T6UVBXCLVFTJIUEZ5QN X-Message-ID-Hash: BCT4SZ5B2QKA7T6UVBXCLVFTJIUEZ5QN X-Mailman-Approved-At: Thu, 30 Jul 2026 16:18:30 +0200 X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox Mail Gateway development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Replace sendmail-interface command newaliases with postfix native postalias Added update logic for postalias to only run if changes are present since the overwrite every two minutes would trigger a log message next time an email was received on a cluster node. This is analogus to the already added run_postmap for other postfix files, see 78982d93 ("run_postmap: only run postmap if file was modified") run_postmap could not be reused since it does not handle alias files Reported by a forum user in https://forum.proxmox.com/threads/185048/ To test change /etc/aliases and run 'pmgcm sync' on cluster node. aliases.db should be updated. If unchanged aliases.db on cluster node should also stay unchanged in contrast to the previous overwrite every two minutes. Signed-off-by: Jonas Theisen --- src/PMG/Config.pm | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/src/PMG/Config.pm b/src/PMG/Config.pm index 5f95857..a03e79e 100644 --- a/src/PMG/Config.pm +++ b/src/PMG/Config.pm @@ -1923,6 +1923,30 @@ sub rewrite_postfix_welcomelist { return $changes; } +my sub run_postalias { + my ($filename) = @_; + + # make sure the file exists (else postalias fails) + IO::File->new($filename, 'a', 0644); + + my $mtime_src = (CORE::stat($filename))[9] // die "unable to read mtime of $filename\n"; + + my $mtime_dst = (CORE::stat("$filename.db"))[9] // 0; + + # if not changed, do nothing + return if $mtime_src <= $mtime_dst; + + eval { + PVE::Tools::run_command( + ['/usr/sbin/postalias', $filename], + errmsg => "unable to update postfix aliases $filename", + ); + }; + my $err = $@; + + warn $err if $err; +} + # rewrite /etc/postfix/* sub rewrite_config_postfix { my ($self, $rulecache) = @_; @@ -1950,8 +1974,8 @@ sub rewrite_config_postfix { $changes = 1 if $rulecache && rewrite_postfix_welcomelist($rulecache); - # make sure aliases.db is up to date - system('/usr/bin/newaliases'); + # update aliases.db if necessary + run_postalias('/etc/aliases'); return $changes; } -- 2.47.3