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 0A90861D8A for ; Thu, 10 Feb 2022 15:52:42 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id EEACB1EC95 for ; Thu, 10 Feb 2022 15:52:11 +0100 (CET) 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)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id 595081EC8B for ; Thu, 10 Feb 2022 15:52:11 +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 2E12846DCD for ; Thu, 10 Feb 2022 15:52:11 +0100 (CET) From: Dominik Csapak To: pve-devel@lists.proxmox.com Date: Thu, 10 Feb 2022 15:52:10 +0100 Message-Id: <20220210145210.1254509-1-d.csapak@proxmox.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.159 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% 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. [agent.pm] Subject: [pve-devel] [PATCH qemu-server] fix #3683: agent file-write: enable user to encode the content themselves X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 10 Feb 2022 14:52:42 -0000 by adding an optional parameter 'encode' (enabled by default). When it is disabled, the content must be base64 encoded already. This way, users can send a binary file to the vm by base64 encoding it themselves Signed-off-by: Dominik Csapak --- PVE/API2/Qemu/Agent.pm | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/PVE/API2/Qemu/Agent.pm b/PVE/API2/Qemu/Agent.pm index a1aa740..9a06191 100644 --- a/PVE/API2/Qemu/Agent.pm +++ b/PVE/API2/Qemu/Agent.pm @@ -473,7 +473,15 @@ __PACKAGE__->register_method({ type => 'string', maxLength => 60*1024, # 60k, smaller than our 64k POST limit description => "The content to write into the file." - } + }, + encode => { + type => 'boolean', + description => "If set the content will be encoded as base64" + ." (required by QEMU). Otherwise the content needs to be encoded" + ." beforehand. (Default is true)", + optional => 1, + default => 1, + }, }, }, returns => { type => 'null' }, @@ -481,7 +489,15 @@ __PACKAGE__->register_method({ my ($param) = @_; my $vmid = $param->{vmid}; - my $buf = encode_base64($param->{content}); + my $encode = $param->{encode} // 1; + my $buf; + if ($encode) { + $buf = encode_base64($param->{content}); + } else { + die "content is not base64 encoded\n" + if $param->{content} !~ m@^(?:[A-Z0-9+/]{4})*(?:[A-Z0-9+/]{2}==|[A-Z0-9+/]{3}=)?$@mi; + $buf = $param->{content}; + } my $qgafh = agent_cmd($vmid, "file-open", { path => $param->{file}, mode => 'wb' }, "can't open file"); my $write = agent_cmd($vmid, "file-write", { handle => $qgafh, 'buf-b64' => $buf }, "can't write to file"); -- 2.30.2