From 9238cdf50d5febb16f45207d5efd9522cf61b2ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20Gr=C3=BCnbichler?= Date: Mon, 10 Aug 2020 13:25:05 +0200 Subject: [PATCH] datastore api: only decode unencrypted indices MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit these checks were already in place for regular downloading of backed up files, also do them when attempting to decode a catalog, or when downloading decoded files referenced by a pxar index. Signed-off-by: Fabian Grünbichler --- src/api2/admin/datastore.rs | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/src/api2/admin/datastore.rs b/src/api2/admin/datastore.rs index a0a14a2f..d535b4d2 100644 --- a/src/api2/admin/datastore.rs +++ b/src/api2/admin/datastore.rs @@ -1133,9 +1133,18 @@ fn catalog( let allowed = (user_privs & PRIV_DATASTORE_READ) != 0; if !allowed { check_backup_owner(&datastore, backup_dir.group(), &userid)?; } + let file_name = CATALOG_NAME; + + let (_manifest, files) = read_backup_index(&datastore, &backup_dir)?; + for file in files { + if file.filename == file_name && file.crypt_mode == Some(CryptMode::Encrypt) { + bail!("cannot decode '{}' - is encrypted", file_name); + } + } + let mut path = datastore.base_path(); path.push(backup_dir.relative_path()); - path.push(CATALOG_NAME); + path.push(file_name); let index = DynamicIndexReader::open(&path) .map_err(|err| format_err!("unable to read dynamic index '{:?}' - {}", &path, err))?; @@ -1238,19 +1247,24 @@ fn pxar_file_download( let allowed = (user_privs & PRIV_DATASTORE_READ) != 0; if !allowed { check_backup_owner(&datastore, backup_dir.group(), &userid)?; } - let mut path = datastore.base_path(); - path.push(backup_dir.relative_path()); - let mut components = base64::decode(&filepath)?; if components.len() > 0 && components[0] == '/' as u8 { components.remove(0); } let mut split = components.splitn(2, |c| *c == '/' as u8); - let pxar_name = split.next().unwrap(); + let pxar_name = std::str::from_utf8(split.next().unwrap())?; let file_path = split.next().ok_or(format_err!("filepath looks strange '{}'", filepath))?; + let (_manifest, files) = read_backup_index(&datastore, &backup_dir)?; + for file in files { + if file.filename == pxar_name && file.crypt_mode == Some(CryptMode::Encrypt) { + bail!("cannot decode '{}' - is encrypted", pxar_name); + } + } - path.push(OsStr::from_bytes(&pxar_name)); + let mut path = datastore.base_path(); + path.push(backup_dir.relative_path()); + path.push(pxar_name); let index = DynamicIndexReader::open(&path) .map_err(|err| format_err!("unable to read dynamic index '{:?}' - {}", &path, err))?;