]> git.proxmox.com Git - proxmox-backup.git/blobdiff - src/bin/proxmox_backup_client/mount.rs
cleanup: remove unnecessary 'mut' and '.clone()'
[proxmox-backup.git] / src / bin / proxmox_backup_client / mount.rs
index 6283961effc3b9eef9e90fe475317faa51837307..f8410709df844167dcf055bd9864b176d4397a2e 100644 (file)
@@ -1,22 +1,21 @@
-use std::path::PathBuf;
-use std::sync::Arc;
-use std::os::unix::io::RawFd;
-use std::path::Path;
-use std::ffi::OsStr;
 use std::collections::HashMap;
+use std::ffi::OsStr;
 use std::hash::BuildHasher;
+use std::os::unix::io::AsRawFd;
+use std::path::{Path, PathBuf};
+use std::sync::Arc;
 
 use anyhow::{bail, format_err, Error};
-use serde_json::Value;
-use tokio::signal::unix::{signal, SignalKind};
-use nix::unistd::{fork, ForkResult, pipe};
-use futures::select;
 use futures::future::FutureExt;
+use futures::select;
 use futures::stream::{StreamExt, TryStreamExt};
+use nix::unistd::{fork, ForkResult};
+use serde_json::Value;
+use tokio::signal::unix::{signal, SignalKind};
 
 use proxmox::{sortable, identity};
 use proxmox::api::{ApiHandler, ApiMethod, RpcEnvironment, schema::*, cli::*};
-
+use proxmox::tools::fd::Fd;
 
 use proxmox_backup::tools;
 use proxmox_backup::backup::{
@@ -143,24 +142,24 @@ fn mount(
 
     // Process should be deamonized.
     // Make sure to fork before the async runtime is instantiated to avoid troubles.
-    let pipe = pipe()?;
+    let (pr, pw) = proxmox_backup::tools::pipe()?;
     match unsafe { fork() } {
         Ok(ForkResult::Parent { .. }) => {
-            nix::unistd::close(pipe.1).unwrap();
+            drop(pw);
             // Blocks the parent process until we are ready to go in the child
-            let _res = nix::unistd::read(pipe.0, &mut [0]).unwrap();
+            let _res = nix::unistd::read(pr.as_raw_fd(), &mut [0]).unwrap();
             Ok(Value::Null)
         }
         Ok(ForkResult::Child) => {
-            nix::unistd::close(pipe.0).unwrap();
+            drop(pr);
             nix::unistd::setsid().unwrap();
-            proxmox_backup::tools::runtime::main(mount_do(param, Some(pipe.1)))
+            proxmox_backup::tools::runtime::main(mount_do(param, Some(pw)))
         }
         Err(_) => bail!("failed to daemonize process"),
     }
 }
 
-async fn mount_do(param: Value, pipe: Option<RawFd>) -> Result<Value, Error> {
+async fn mount_do(param: Value, pipe: Option<Fd>) -> Result<Value, Error> {
     let repo = extract_repository_from_value(&param)?;
     let archive_name = tools::required_string_param(&param, "archive-name")?;
     let client = connect(&repo)?;
@@ -182,7 +181,9 @@ async fn mount_do(param: Value, pipe: Option<RawFd>) -> Result<Value, Error> {
     let crypt_config = match keyfile {
         None => None,
         Some(path) => {
-            let (key, _, _) = load_and_decrypt_key(&path, &crate::key::get_encryption_key_password)?;
+            println!("Encryption key file: '{:?}'", path);
+            let (key, _, fingerprint) = load_and_decrypt_key(&path, &crate::key::get_encryption_key_password)?;
+            println!("Encryption key fingerprint: '{}'", fingerprint);
             Some(Arc::new(CryptConfig::new(key)?))
         }
     };
@@ -212,6 +213,7 @@ async fn mount_do(param: Value, pipe: Option<RawFd>) -> Result<Value, Error> {
     ).await?;
 
     let (manifest, _) = client.download_manifest().await?;
+    manifest.check_fingerprint(crypt_config.as_ref().map(Arc::as_ref))?;
 
     let file_info = manifest.lookup_file_info(&server_archive_name)?;
 
@@ -232,8 +234,8 @@ async fn mount_do(param: Value, pipe: Option<RawFd>) -> Result<Value, Error> {
             }
             // Signal the parent process that we are done with the setup and it can
             // terminate.
-            nix::unistd::write(pipe, &[0u8])?;
-            nix::unistd::close(pipe).unwrap();
+            nix::unistd::write(pipe.as_raw_fd(), &[0u8])?;
+            let _: Fd = pipe;
         }
 
         Ok(())
@@ -244,7 +246,8 @@ async fn mount_do(param: Value, pipe: Option<RawFd>) -> Result<Value, Error> {
     // handle SIGINT and SIGTERM
     let mut interrupt_int = signal(SignalKind::interrupt())?;
     let mut interrupt_term = signal(SignalKind::terminate())?;
-    let mut interrupt = futures::future::select(interrupt_int.next(), interrupt_term.next());
+
+    let mut interrupt = futures::future::select(interrupt_int.recv().boxed(), interrupt_term.recv().boxed());
 
     if server_archive_name.ends_with(".didx") {
         let index = client.download_dynamic_index(&manifest, &server_archive_name).await?;
@@ -291,7 +294,7 @@ async fn mount_do(param: Value, pipe: Option<RawFd>) -> Result<Value, Error> {
 
         // poll until loop file is mapped (or errors)
         select! {
-            res = session_fut => {
+            _res = session_fut => {
                 bail!("FUSE session unexpectedly ended before loop file mapping");
             },
             res = st_recv.try_next() => {