From 4e93f8c1643791b58b36b3ce3fef78d64d09def3 Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Wed, 15 May 2019 07:14:08 +0200 Subject: [PATCH] src/api2/types.rs: add schema/format for file names --- src/api2/admin/datastore/backup.rs | 4 ++-- src/api2/types.rs | 16 +++++++++++++++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/api2/admin/datastore/backup.rs b/src/api2/admin/datastore/backup.rs index 499af695..10ef4774 100644 --- a/src/api2/admin/datastore/backup.rs +++ b/src/api2/admin/datastore/backup.rs @@ -159,7 +159,7 @@ Download the dynamic chunk index from the previous backup. Simply returns an empty list if this is the first backup. "### ) - .required("archive-name", StringSchema::new("Backup archive name.")) + .required("archive-name", crate::api2::types::BACKUP_ARCHIVE_NAME_SCHEMA.clone()) ) } @@ -167,7 +167,7 @@ pub fn api_method_create_dynamic_index() -> ApiMethod { ApiMethod::new( create_dynamic_index, ObjectSchema::new("Create dynamic chunk index file.") - .required("archive-name", StringSchema::new("Backup archive name.")) + .required("archive-name", crate::api2::types::BACKUP_ARCHIVE_NAME_SCHEMA.clone()) ) } diff --git a/src/api2/types.rs b/src/api2/types.rs index 984d7989..b5f8738d 100644 --- a/src/api2/types.rs +++ b/src/api2/types.rs @@ -7,6 +7,17 @@ use crate::tools::{self, common_regex}; lazy_static!{ + // File names: may not contain slashes, may not start with "." + pub static ref FILENAME_FORMAT: Arc = Arc::new(ApiStringFormat::VerifyFn(|name| { + if name.starts_with('.') { + bail!("file names may not start with '.'"); + } + if name.contains('/') { + bail!("file names may not contain slashes"); + } + Ok(()) + })).into(); + pub static ref IP_FORMAT: Arc = ApiStringFormat::Pattern(&common_regex::IP_REGEX).into(); pub static ref PVE_CONFIG_DIGEST_FORMAT: Arc = @@ -23,7 +34,7 @@ lazy_static!{ if node == "localhost" || node == tools::nodename() { Ok(()) } else { - Err(format_err!("no such node '{}'", node)) + bail!("no such node '{}'", node); } })) ) @@ -45,5 +56,8 @@ lazy_static!{ StringSchema::new("Third name server IP address.") .format(IP_FORMAT.clone()).into(); + pub static ref BACKUP_ARCHIVE_NAME_SCHEMA: Arc = + StringSchema::new("Backup archive name.") + .format(FILENAME_FORMAT.clone()).into(); }