From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <mira@nena.proxmox.com>
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) server-digest SHA256)
 (No client certificate requested)
 by lists.proxmox.com (Postfix) with ESMTPS id 8A107EA3F
 for <pmg-devel@lists.proxmox.com>; Wed, 19 Jul 2023 17:13:57 +0200 (CEST)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
 by firstgate.proxmox.com (Proxmox) with ESMTP id 732BF9FB3
 for <pmg-devel@lists.proxmox.com>; Wed, 19 Jul 2023 17:13:57 +0200 (CEST)
Received: from nena.proxmox.com (unknown [94.136.29.99])
 by firstgate.proxmox.com (Proxmox) with ESMTP
 for <pmg-devel@lists.proxmox.com>; Wed, 19 Jul 2023 17:13:53 +0200 (CEST)
Received: by nena.proxmox.com (Postfix, from userid 1000)
 id 885972F0DF1; Wed, 19 Jul 2023 17:13:53 +0200 (CEST)
From: Mira Limbeck <m.limbeck@proxmox.com>
To: pmg-devel@lists.proxmox.com
Date: Wed, 19 Jul 2023 17:13:51 +0200
Message-Id: <20230719151352.1438974-1-m.limbeck@proxmox.com>
X-Mailer: git-send-email 2.39.2
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-SPAM-LEVEL: Spam detection results:  0
 AWL -0.636 Adjusted score from AWL reputation of From: address
 BAYES_00                 -1.9 Bayes spam probability is 0 to 1%
 DMARC_MISSING             0.1 Missing DMARC policy
 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
 RDNS_NONE 0.793 Delivered to internal network by a host with no rDNS
 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
 T_SCC_BODY_TEXT_LINE    -0.01 -
 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]
Subject: [pmg-devel] [PATCH log-tracker 1/2] add clamd signature found
 messages to log output
X-BeenThere: pmg-devel@lists.proxmox.com
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Proxmox Mail Gateway development discussion
 <pmg-devel.lists.proxmox.com>
List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pmg-devel>, 
 <mailto:pmg-devel-request@lists.proxmox.com?subject=unsubscribe>
List-Archive: <http://lists.proxmox.com/pipermail/pmg-devel/>
List-Post: <mailto:pmg-devel@lists.proxmox.com>
List-Help: <mailto:pmg-devel-request@lists.proxmox.com?subject=help>
List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pmg-devel>, 
 <mailto:pmg-devel-request@lists.proxmox.com?subject=subscribe>
X-List-Received-Date: Wed, 19 Jul 2023 15:13:57 -0000

clamd reports found signatures in the log which can be matched by the
same Queue ID pmg-smtp-filter uses. This QID makes it possible to add
those messages to the log output.

Signed-off-by: Mira Limbeck <m.limbeck@proxmox.com>
---
 src/main.rs | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/src/main.rs b/src/main.rs
index e55f17b..dbcd7bc 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -777,6 +777,20 @@ fn handle_cleanup_message(msg: &[u8], parser: &mut Parser, complete_line: &[u8])
     }
 }
 
+fn handle_clamd_message(msg: &[u8], parser: &mut Parser, complete_line: &[u8]) {
+    let data = match msg.strip_prefix(b"/var/spool/pmg/active/") {
+        Some(data) => data,
+        None => return,
+    };
+    let (qid, _data) = match parse_qid(data, 25) {
+        Some(t) => t,
+        None => return,
+    };
+
+    let fe = get_or_create_fentry(&mut parser.fentries, qid);
+    fe.borrow_mut().log.push((complete_line.into(), parser.lines));
+}
+
 #[derive(Default, Debug)]
 struct NoqueueEntry {
     from: Box<[u8]>,
@@ -1904,6 +1918,8 @@ impl Parser {
                 handle_smtpd_message(line, self, complete_line);
             } else if service == b"postfix/cleanup" {
                 handle_cleanup_message(line, self, complete_line);
+            } else if service == b"clamd" {
+                handle_clamd_message(line, self, complete_line)
             }
         }
         Ok(())
-- 
2.39.2