From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [45.144.208.40]) by lore.proxmox.com (Postfix) with ESMTPS id 70A261FF0AA for ; Tue, 17 Nov 2026 21:42:30 +0100 (CET) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id E6C6921872; Tue, 17 Nov 2026 21:40:54 +0100 (CET) From: "Max R. Carrara" To: pve-devel@lists.proxmox.com Subject: [PATCH pve-storage v3 16/51] api: status: move content type assert for up-/downloads into helper Date: Tue, 17 Nov 2026 21:38:48 +0100 Message-ID: <20261117203953.913035-17-m.carrara@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261117203953.913035-1-m.carrara@proxmox.com> References: <20261117203953.913035-1-m.carrara@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1794948027073 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.263 Adjusted score from AWL reputation of From: address DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment (newer systems) 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 Message-ID-Hash: MB6OHZKZV2CPIVGU7AHXFRL42F62D6JD X-Message-ID-Hash: MB6OHZKZV2CPIVGU7AHXFRL42F62D6JD X-MailFrom: m.carrara@proxmox.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Wolfgang Bumiller X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox VE development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Signed-off-by: Max R. Carrara --- src/PVE/API2/Storage/Status.pm | 41 +++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 15 deletions(-) diff --git a/src/PVE/API2/Storage/Status.pm b/src/PVE/API2/Storage/Status.pm index 57ab92be..a9f902f9 100644 --- a/src/PVE/API2/Storage/Status.pm +++ b/src/PVE/API2/Storage/Status.pm @@ -42,10 +42,33 @@ __PACKAGE__->register_method({ __PACKAGE__->register_method({ subclass => "PVE::API2::Storage::FileRestore", path => '{storage}/file-restore', }); +# Content types that may currently be up- or downloaded via the API +my @ALLOWED_FILE_TRANSFER_CONTENT_TYPES = ('iso', 'vztmpl', 'import'); + +my sub assert_can_transfer_files : prototype($$$) { + my ($scfg, $storeid, $vtype) = @_; + + if (!defined($scfg->{path})) { + die "unable to transfer files from / to storage type '$scfg->{type}'" + . " - not a file-based storage\n"; + } + + if (!$scfg->{content}->{$vtype}) { + die "storage '$storeid' is not configured for content type '$vtype'\n"; + } + + my $is_allowed_vtype = grep { $_ eq $vtype } @ALLOWED_FILE_TRANSFER_CONTENT_TYPES; + if (!$is_allowed_vtype) { + raise_param_exc({ content => "content type '$vtype' not allowed for upload / download" }); + } + + return; +} + my sub assert_ova_contents { my ($file) = @_; # test if it's really a tar file with an ovf file inside my $hasOvf = 0; @@ -575,15 +598,14 @@ __PACKAGE__->register_method({ my $cfg = PVE::Storage::config(); my ($node, $storage) = $param->@{qw(node storage)}; my $scfg = PVE::Storage::storage_check_enabled($cfg, $storage, $node); - die "can't upload to storage type '$scfg->{type}'\n" - if !defined($scfg->{path}); - my $content = $param->{content}; + assert_can_transfer_files($scfg, $storage, $content); + my $tmpfilename = $param->{tmpfilename}; die "missing temporary file name\n" if !$tmpfilename; my $size = -s $tmpfilename; die "temporary file '$tmpfilename' does not exist\n" if !defined($size); @@ -617,17 +639,12 @@ __PACKAGE__->register_method({ } else { $image_format = $format; } $path = PVE::Storage::get_import_dir($cfg, $storage); - } else { - raise_param_exc({ content => "upload content type '$content' not allowed" }); } - die "storage '$storage' does not support '$content' content\n" - if !$scfg->{content}->{$content}; - my $dest = "$path/$filename"; my $dirname = dirname($dest); # best effort to match apl_download behaviour chmod 0644, $tmpfilename; @@ -815,17 +832,13 @@ __PACKAGE__->register_method({ my $cfg = PVE::Storage::config(); my ($node, $storage, $compression) = $param->@{qw(node storage compression)}; my $scfg = PVE::Storage::storage_check_enabled($cfg, $storage, $node); - die "can't upload to storage type '$scfg->{type}', not a file based storage!\n" - if !defined($scfg->{path}); - my ($content, $url) = $param->@{ 'content', 'url' }; - die "storage '$storage' is not configured for content-type '$content'\n" - if !$scfg->{content}->{$content}; + assert_can_transfer_files($scfg, $storage, $content); my $filename = PVE::Storage::normalize_content_filename($param->{filename}); my $path; my $is_ova = 0; @@ -854,12 +867,10 @@ __PACKAGE__->register_method({ } else { $image_format = $format; } $path = PVE::Storage::get_import_dir($cfg, $storage); - } else { - raise_param_exc({ content => "upload content-type '$content' is not allowed" }); } PVE::Storage::activate_storage($cfg, $storage); File::Path::make_path($path); -- 2.47.3