From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 9ED756B959 for ; Fri, 19 Feb 2021 11:31:53 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 9D22317A2A for ; Fri, 19 Feb 2021 11:31:53 +0100 (CET) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [212.186.127.180]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id B9EC917A22 for ; Fri, 19 Feb 2021 11:31:52 +0100 (CET) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 81B414627A for ; Fri, 19 Feb 2021 11:31:52 +0100 (CET) From: Mira Limbeck To: pmg-devel@lists.proxmox.com Date: Fri, 19 Feb 2021 11:31:46 +0100 Message-Id: <20210219103147.28013-2-m.limbeck@proxmox.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210219103147.28013-1-m.limbeck@proxmox.com> References: <20210219103147.28013-1-m.limbeck@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL -0.237 Adjusted score from AWL reputation of From: address KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment KAM_LAZY_DOMAIN_SECURITY 1 Sending domain does not have any anti-forgery methods NO_DNS_FOR_FROM 0.379 Envelope sender has no MX or A DNS records RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_NONE 0.001 SPF: sender does not publish an SPF Record URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [main.rs, ietf.org, proxmox.com] Subject: [pmg-devel] [PATCH log-tracker 2/3] after-queue: fix wrong DStatus if relay is 'removed' before 'lmtp' line X-BeenThere: pmg-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Mail Gateway development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 19 Feb 2021 10:31:53 -0000 We only match a QEntry with the relay Qentry in the after-queue case when we get to the 'lmtp' line. This is because it contains a reference from the first QEntry to the filter, and the filter contains a reference to the relay QEntry. If the relay log entries are finished before the 'lmtp' line, there's no way to match the relay to the first QEntry and we still assume it is before-queue filtered. To fix this we try to match the QEntries via message-id and add weak references to each other. Then we wait with finalizing either until the other is also 'removed' (finished). The message-id matching might break if the same message-id is used for different entries, so this is rather a 'hack' than a nice solution, but there's no other info in the logs we could use to match both QEntries. Signed-off-by: Mira Limbeck --- This was reported in the forum: https://forum.proxmox.com/threads/difference-between-status-accepted-accepted-and-accepted-delivered.82827/ src/main.rs | 51 ++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 40 insertions(+), 11 deletions(-) diff --git a/src/main.rs b/src/main.rs index 5069252..78d6def 100644 --- a/src/main.rs +++ b/src/main.rs @@ -427,18 +427,8 @@ fn handle_lmtp_message(msg: &[u8], parser: &mut Parser, complete_line: &[u8]) { None => return, }; - let mut dstatus = DStatus::Dsn(dsn); + let dstatus = DStatus::Dsn(dsn); - // the dsn (enhanced status code can only have a class of 2, 4 or 5 - // see https://tools.ietf.org/html/rfc3463 - if qe.borrow_mut().bq_filtered { - dstatus = match dsn { - 2 => DStatus::BqPass, - 4 => DStatus::BqDefer, - 5 => DStatus::BqReject, - _ => return, - } - } qe.borrow_mut() .add_to_entry(to, relay, dstatus, parser.current_record_state.timestamp); @@ -751,6 +741,18 @@ fn handle_cleanup_message(msg: &[u8], parser: &mut Parser, complete_line: &[u8]) qe.borrow_mut().msgid = msgid.into(); } qe.borrow_mut().cleanup = true; + + + // does not work correctly if there's a duplicate message id in the logfiles + if let Some(q) = parser.msgid_lookup.remove(msgid) { + qe.borrow_mut().aq_qentry = Some(Weak::clone(&q)); + if let Some(q) = q.upgrade() { + q.borrow_mut().aq_qentry = Some(Rc::downgrade(&qe)); + } + } + else { + parser.msgid_lookup.insert(msgid.into(), Rc::downgrade(&qe)); + } } } @@ -1205,6 +1207,7 @@ struct QEntry { bq_filtered: bool, // will differ from smtpd bq_sentry: Option>>, + aq_qentry: Option>>, } impl QEntry { @@ -1234,6 +1237,16 @@ impl QEntry { } } + if let Some(qe) = &self.aq_qentry { + if let Some(qe) = qe.upgrade() { + if !qe.borrow().removed { + return; + } + qe.borrow_mut().aq_qentry = None; + qe.borrow_mut().finalize(parser); + } + } + if let Some(fe) = self.filter.clone() { // verify that the attached FEntry is finished if it is not // before queue filtered @@ -1472,12 +1485,26 @@ impl QEntry { self.print_qentry_boilerplate(parser, is_se_bq_sentry, se); } + if self.bq_filtered { + for to in self.to_entries.iter_mut() { + to.dstatus = match to.dstatus { + // the dsn (enhanced status code can only have a class of 2, 4 or 5 + // see https://tools.ietf.org/html/rfc3463 + DStatus::Dsn(2) => DStatus::BqPass, + DStatus::Dsn(4) => DStatus::BqDefer, + DStatus::Dsn(5) => DStatus::BqReject, + _ => to.dstatus, + }; + } + } + // rev() to match the C code iteration direction (linked list vs Vec) for to in self.to_entries.iter().rev() { if !to.to.is_empty() { let final_rc; let final_borrow; let mut final_to: &ToEntry = to; + // if status == success and there's a filter attached that has // a matching 'to' in one of the ToEntries, set the ToEntry to // the one in the filter @@ -1667,6 +1694,7 @@ struct Parser { sentries: HashMap>>, fentries: HashMap, Rc>>, qentries: HashMap, Rc>>, + msgid_lookup: HashMap, Weak>>, current_record_state: RecordState, rel_line_nr: u64, @@ -1705,6 +1733,7 @@ impl Parser { sentries: HashMap::new(), fentries: HashMap::new(), qentries: HashMap::new(), + msgid_lookup: HashMap::new(), current_record_state: Default::default(), rel_line_nr: 0, current_year: years, -- 2.20.1