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) server-digest SHA256) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 2FA42A9C4 for ; Tue, 27 Jun 2023 21:47:39 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 16FD51A696 for ; Tue, 27 Jun 2023 21:47:09 +0200 (CEST) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (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 firstgate.proxmox.com (Proxmox) with ESMTPS for ; Tue, 27 Jun 2023 21:47:08 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 9D58640922 for ; Tue, 27 Jun 2023 21:47:07 +0200 (CEST) From: Stoiko Ivanov To: pmg-devel@lists.proxmox.com Date: Tue, 27 Jun 2023 21:46:49 +0200 Message-Id: <20230627194650.34027-2-s.ivanov@proxmox.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230627194650.34027-1-s.ivanov@proxmox.com> References: <20230627194650.34027-1-s.ivanov@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.096 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 SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches 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] [RFC pmg-log-tracker 1/2] rfc3339 timestamps: counter-offset timezone 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: Tue, 27 Jun 2023 19:47:39 -0000 the old time-format had no timezone-information so the API treats the result as 'timezoned-epoch' and subtracts the timezone-offset In order to support both formats add the timezone-offset to the already offset time - so that the subtraction in the API is canceled out. This can luckily be dropped once we drop support for traditional syslog format. inspired by parse_rfc3339_do in proxmox-time Signed-off-by: Stoiko Ivanov --- src/main.rs | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/src/main.rs b/src/main.rs index e7bffd8..6c4a555 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2263,12 +2263,31 @@ fn parse_time_with_year(data: &'_ [u8]) -> Option<(time_t, &'_ [u8])> { timestamp_buffer[0..year_time_len].copy_from_slice(year_time); timestamp_buffer[year_time_len..timestamp_len].copy_from_slice(timezone); - match proxmox_time::parse_rfc3339(unsafe { + let epoch = match proxmox_time::parse_rfc3339(unsafe { std::str::from_utf8_unchecked(×tamp_buffer[0..timestamp_len]) }) { - Ok(ltime) => Some((ltime, data)), - Err(_err) => None, - } + Ok(ltime) => ltime, + Err(_err) => return None, + }; + + // FIXME: the traditional syslog format does not have timezone information, so the api-backend + // shifts the time by the offset (i.e. parse_time_no_year returns timestamps in local time) + // readd the TZ-offset here to match the broken format + // drop after legacy parsing is dropped. + let tz = timezone[0]; + if tz == b'Z' { + return Some((epoch, data)); + } + + let hours = (timezone[1] as i32 - 48) * 10 + (timezone[2] as i32 - 48); + let mins = (timezone[4] as i32 - 48) * 10 + (timezone[5] as i32 - 48); + let offset = hours * 3600 + mins * 60; + let epoch = match tz { + b'+' => epoch + offset as i64, + b'-' => epoch - offset as i64, + _ => unreachable!(), // already checked in parse_rfc3339 + }; + Some((epoch, data)) } fn parse_time_no_year(data: &'_ [u8], cur_year: i64, cur_month: i64) -> Option<(time_t, &'_ [u8])> { -- 2.39.2