From 429bc9d0a2b0cd234e78dee6607916c29d904ef7 Mon Sep 17 00:00:00 2001 From: Thomas Lamprecht Date: Sun, 10 Apr 2022 17:47:20 +0200 Subject: [PATCH] restore daemon: rust fmt Signed-off-by: Thomas Lamprecht --- proxmox-restore-daemon/src/main.rs | 6 ++- .../src/proxmox_restore_daemon/api.rs | 23 +++++----- .../src/proxmox_restore_daemon/auth.rs | 30 +++++++------ .../src/proxmox_restore_daemon/disk.rs | 42 +++++++------------ 4 files changed, 50 insertions(+), 51 deletions(-) diff --git a/proxmox-restore-daemon/src/main.rs b/proxmox-restore-daemon/src/main.rs index 47790a7d..8f479de9 100644 --- a/proxmox-restore-daemon/src/main.rs +++ b/proxmox-restore-daemon/src/main.rs @@ -80,7 +80,10 @@ fn setup_system_env() -> Result<(), Error> { std::fs::create_dir_all("/etc")?; let mut passwd = File::create("/etc/passwd")?; writeln!(passwd, "root:x:0:0:root:/root:/bin/sh")?; - writeln!(passwd, "backup:x:34:34:backup:/var/backups:/usr/sbin/nologin")?; + writeln!( + passwd, + "backup:x:34:34:backup:/var/backups:/usr/sbin/nologin" + )?; let mut group = File::create("/etc/group")?; writeln!(group, "root:x:0:")?; @@ -89,7 +92,6 @@ fn setup_system_env() -> Result<(), Error> { Ok(()) } - async fn run() -> Result<(), Error> { watchdog_init(); diff --git a/proxmox-restore-daemon/src/proxmox_restore_daemon/api.rs b/proxmox-restore-daemon/src/proxmox_restore_daemon/api.rs index 1333590d..ef9d53b7 100644 --- a/proxmox-restore-daemon/src/proxmox_restore_daemon/api.rs +++ b/proxmox-restore-daemon/src/proxmox_restore_daemon/api.rs @@ -13,12 +13,12 @@ use serde_json::Value; use tokio::sync::Semaphore; use pathpatterns::{MatchEntry, MatchPattern, MatchType, Pattern}; +use proxmox_compression::zip::zip_directory; use proxmox_router::{ - list_subdirs_api_method, - ApiHandler, ApiMethod, ApiResponseFuture, Permission, Router, RpcEnvironment, SubdirMap, + list_subdirs_api_method, ApiHandler, ApiMethod, ApiResponseFuture, Permission, Router, + RpcEnvironment, SubdirMap, }; use proxmox_schema::*; -use proxmox_compression::zip::zip_directory; use proxmox_sys::fs::read_subdir; use proxmox_sys::sortable; @@ -29,7 +29,7 @@ use pbs_tools::json::required_string_param; use pxar::encoder::aio::TokioWriter; -use super::{disk::ResolveResult, watchdog_remaining, watchdog_inhibit, watchdog_ping}; +use super::{disk::ResolveResult, watchdog_inhibit, watchdog_ping, watchdog_remaining}; // NOTE: All API endpoints must have Permission::Superuser, as the configs for authentication do // not exist within the restore VM. Safety is guaranteed by checking a ticket via a custom ApiAuth. @@ -73,7 +73,10 @@ fn read_uptime() -> Result { } )] /// General status information -fn status(rpcenv: &mut dyn RpcEnvironment, keep_timeout: bool) -> Result { +fn status( + rpcenv: &mut dyn RpcEnvironment, + keep_timeout: bool, +) -> Result { if !keep_timeout && rpcenv.get_auth_id().is_some() { watchdog_ping(); } @@ -164,8 +167,9 @@ fn list( if path.components().count() == 1 { // ignore '.' and '..' match path.components().next().unwrap() { - std::path::Component::CurDir - | std::path::Component::ParentDir => continue, + std::path::Component::CurDir | std::path::Component::ParentDir => { + continue + } _ => {} } } @@ -192,10 +196,7 @@ fn list( let mut t_path = path.clone(); t_path.push(b'/'); t_path.extend(t.as_bytes()); - res.push(ArchiveEntry::new( - &t_path[..], - None, - )); + res.push(ArchiveEntry::new(&t_path[..], None)); } } ResolveResult::BucketComponents(comps) => { diff --git a/proxmox-restore-daemon/src/proxmox_restore_daemon/auth.rs b/proxmox-restore-daemon/src/proxmox_restore_daemon/auth.rs index 1f5dc4a9..1d6e2a8f 100644 --- a/proxmox-restore-daemon/src/proxmox_restore_daemon/auth.rs +++ b/proxmox-restore-daemon/src/proxmox_restore_daemon/auth.rs @@ -1,17 +1,17 @@ //! Authentication via a static ticket file use std::fs::File; -use std::io::prelude::*; use std::future::Future; +use std::io::prelude::*; use std::pin::Pin; use anyhow::{bail, format_err, Error}; -use hyper::{Body, Response, Method, StatusCode}; use http::request::Parts; use http::HeaderMap; +use hyper::{Body, Method, Response, StatusCode}; use proxmox_router::UserInformation; -use proxmox_rest_server::{ServerAdapter, AuthError, RestEnvironment}; +use proxmox_rest_server::{AuthError, RestEnvironment, ServerAdapter}; const TICKET_FILE: &str = "/ticket"; @@ -21,8 +21,12 @@ impl UserInformation for SimpleUserInformation { fn is_superuser(&self, userid: &str) -> bool { userid == "root@pam" } - fn is_group_member(&self, _userid: &str, _group: &str) -> bool { false } - fn lookup_privs(&self, _userid: &str, _path: &[&str]) -> u64 { 0 } + fn is_group_member(&self, _userid: &str, _group: &str) -> bool { + false + } + fn lookup_privs(&self, _userid: &str, _path: &[&str]) -> u64 { + 0 + } } pub struct StaticAuthAdapter { @@ -30,7 +34,6 @@ pub struct StaticAuthAdapter { } impl StaticAuthAdapter { - pub fn new() -> Result { let mut ticket_file = File::open(TICKET_FILE)?; let mut ticket = String::new(); @@ -42,19 +45,23 @@ impl StaticAuthAdapter { } } - impl ServerAdapter for StaticAuthAdapter { - fn check_auth<'a>( &'a self, headers: &'a HeaderMap, _method: &'a Method, - ) -> Pin), AuthError>> + Send + 'a>> { + ) -> Pin< + Box< + dyn Future), AuthError>> + + Send + + 'a, + >, + > { Box::pin(async move { - match headers.get(hyper::header::AUTHORIZATION) { Some(header) if header.to_str().unwrap_or("") == &self.ticket => { - let user_info: Box = Box::new(SimpleUserInformation {}); + let user_info: Box = + Box::new(SimpleUserInformation {}); Ok((String::from("root@pam"), user_info)) } _ => { @@ -72,7 +79,6 @@ impl ServerAdapter for StaticAuthAdapter { _parts: Parts, ) -> Pin> + Send>> { Box::pin(async move { - let index = "

Proxmox Backup Restore Daemon/h1>

"; Response::builder() diff --git a/proxmox-restore-daemon/src/proxmox_restore_daemon/disk.rs b/proxmox-restore-daemon/src/proxmox_restore_daemon/disk.rs index 3eb8d8b6..f397ecbe 100644 --- a/proxmox-restore-daemon/src/proxmox_restore_daemon/disk.rs +++ b/proxmox-restore-daemon/src/proxmox_restore_daemon/disk.rs @@ -9,9 +9,9 @@ use anyhow::{bail, format_err, Error}; use lazy_static::lazy_static; use log::{info, warn}; -use proxmox_sys::fs; -use proxmox_sys::command::run_command; use proxmox_schema::const_regex; +use proxmox_sys::command::run_command; +use proxmox_sys::fs; use pbs_api_types::BLOCKDEVICE_NAME_REGEX; @@ -371,12 +371,9 @@ impl DiskState { // create mapping for virtio drives and .fidx files (via serial description) // note: disks::DiskManager relies on udev, which we don't have - for entry in proxmox_sys::fs::scan_subdir( - libc::AT_FDCWD, - "/sys/block", - &BLOCKDEVICE_NAME_REGEX, - )? - .filter_map(Result::ok) + for entry in + proxmox_sys::fs::scan_subdir(libc::AT_FDCWD, "/sys/block", &BLOCKDEVICE_NAME_REGEX)? + .filter_map(Result::ok) { let name = unsafe { entry.file_name_utf8_unchecked() }; if !name.starts_with("vd") { @@ -416,12 +413,8 @@ impl DiskState { } let mut parts = Vec::new(); - for entry in proxmox_sys::fs::scan_subdir( - libc::AT_FDCWD, - sys_path, - &VIRTIO_PART_REGEX, - )? - .filter_map(Result::ok) + for entry in proxmox_sys::fs::scan_subdir(libc::AT_FDCWD, sys_path, &VIRTIO_PART_REGEX)? + .filter_map(Result::ok) { let part_name = unsafe { entry.file_name_utf8_unchecked() }; let dev_node = format!("/dev/{}", part_name); @@ -730,18 +723,15 @@ impl DiskState { }; // bucket found, check mount - let mountpoint = self - .filesystems - .ensure_mounted(bucket) - .map_err(|err| { - format_err!( - "mounting '{}/{}/{}' failed: {}", - req_fidx, - bucket_type, - components.join("/"), - err - ) - })?; + let mountpoint = self.filesystems.ensure_mounted(bucket).map_err(|err| { + format_err!( + "mounting '{}/{}/{}' failed: {}", + req_fidx, + bucket_type, + components.join("/"), + err + ) + })?; let mut local_path = PathBuf::new(); local_path.push(mountpoint);