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 AC72760F79 for ; Thu, 19 Nov 2020 10:02:56 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 9C91322CD3 for ; Thu, 19 Nov 2020 10:02:56 +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 6D12C22CC7 for ; Thu, 19 Nov 2020 10:02:55 +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 31EAB42AB0 for ; Thu, 19 Nov 2020 10:02:55 +0100 (CET) From: Dominik Csapak To: pbs-devel@lists.proxmox.com Date: Thu, 19 Nov 2020 10:02:52 +0100 Message-Id: <20201119090252.31587-1-d.csapak@proxmox.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.340 Adjusted score from AWL reputation of From: address KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment 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_PASS -0.001 SPF: sender matches 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. [tools.rs, task.rs, proxmox-backup-manager.rs] Subject: [pbs-devel] [PATCH proxmox-backup] fix systemd-encoded upid strings in http client X-BeenThere: pbs-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Backup Server development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 19 Nov 2020 09:02:56 -0000 since we systemd-encode parts of the upid string, and those can contain characters that are invalid in urls (e.g. '\'), we have to percent encode those add a 'percent_encode_component' helper, so that we can maybe change the AsciiSet for all uses at the same time Signed-off-by: Dominik Csapak --- we can also change the http client interface to take a &[&str] instead a &str for the path, and always percent encode all components, but for now this should be enough src/bin/proxmox-backup-manager.rs | 2 +- src/bin/proxmox_backup_client/task.rs | 2 +- src/client/task_log.rs | 3 ++- src/tools.rs | 7 ++++++- 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/bin/proxmox-backup-manager.rs b/src/bin/proxmox-backup-manager.rs index 219476fc..a763d6d6 100644 --- a/src/bin/proxmox-backup-manager.rs +++ b/src/bin/proxmox-backup-manager.rs @@ -245,7 +245,7 @@ async fn task_stop(param: Value) -> Result { let mut client = connect()?; - let path = format!("api2/json/nodes/localhost/tasks/{}", upid_str); + let path = format!("api2/json/nodes/localhost/tasks/{}", tools::percent_encode_component(upid_str)); let _ = client.delete(&path, None).await?; Ok(Value::Null) diff --git a/src/bin/proxmox_backup_client/task.rs b/src/bin/proxmox_backup_client/task.rs index 29b2cc00..6f567f22 100644 --- a/src/bin/proxmox_backup_client/task.rs +++ b/src/bin/proxmox_backup_client/task.rs @@ -124,7 +124,7 @@ async fn task_stop(param: Value) -> Result { let mut client = connect(&repo)?; - let path = format!("api2/json/nodes/localhost/tasks/{}", upid_str); + let path = format!("api2/json/nodes/localhost/tasks/{}", tools::percent_encode_component(upid_str)); let _ = client.delete(&path, None).await?; Ok(Value::Null) diff --git a/src/client/task_log.rs b/src/client/task_log.rs index 7f16d84d..2e2e4d74 100644 --- a/src/client/task_log.rs +++ b/src/client/task_log.rs @@ -2,6 +2,7 @@ use anyhow::{bail, Error}; use serde_json::json; use super::HttpClient; +use crate::tools; pub async fn display_task_log( client: HttpClient, @@ -9,7 +10,7 @@ pub async fn display_task_log( strip_date: bool, ) -> Result<(), Error> { - let path = format!("api2/json/nodes/localhost/tasks/{}/log", upid_str); + let path = format!("api2/json/nodes/localhost/tasks/{}/log", tools::percent_encode_component(upid_str)); let mut start = 1; let limit = 500; diff --git a/src/tools.rs b/src/tools.rs index a9b3378d..08f9d22f 100644 --- a/src/tools.rs +++ b/src/tools.rs @@ -12,7 +12,7 @@ use std::path::Path; use anyhow::{bail, format_err, Error}; use serde_json::Value; use openssl::hash::{hash, DigestBytes, MessageDigest}; -use percent_encoding::AsciiSet; +use percent_encoding::{utf8_percent_encode, AsciiSet}; pub use proxmox::tools::fd::Fd; @@ -289,6 +289,11 @@ pub fn extract_cookie(cookie: &str, cookie_name: &str) -> Option { None } +/// percent encode a url component +pub fn percent_encode_component(comp: &str) -> String { + utf8_percent_encode(comp, percent_encoding::NON_ALPHANUMERIC).to_string() +} + pub fn join(data: &Vec, sep: char) -> String { let mut list = String::new(); -- 2.20.1