restore daemon: rust fmt
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
This commit is contained in:
parent
a22d338831
commit
429bc9d0a2
@ -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();
|
||||
|
||||
|
@ -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<f32, Error> {
|
||||
}
|
||||
)]
|
||||
/// General status information
|
||||
fn status(rpcenv: &mut dyn RpcEnvironment, keep_timeout: bool) -> Result<RestoreDaemonStatus, Error> {
|
||||
fn status(
|
||||
rpcenv: &mut dyn RpcEnvironment,
|
||||
keep_timeout: bool,
|
||||
) -> Result<RestoreDaemonStatus, Error> {
|
||||
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) => {
|
||||
|
@ -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<Self, Error> {
|
||||
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<Box<dyn Future<Output = Result<(String, Box<dyn UserInformation + Sync + Send>), AuthError>> + Send + 'a>> {
|
||||
) -> Pin<
|
||||
Box<
|
||||
dyn Future<Output = Result<(String, Box<dyn UserInformation + Sync + Send>), 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<dyn UserInformation + Send + Sync> = Box::new(SimpleUserInformation {});
|
||||
let user_info: Box<dyn UserInformation + Send + Sync> =
|
||||
Box::new(SimpleUserInformation {});
|
||||
Ok((String::from("root@pam"), user_info))
|
||||
}
|
||||
_ => {
|
||||
@ -72,7 +79,6 @@ impl ServerAdapter for StaticAuthAdapter {
|
||||
_parts: Parts,
|
||||
) -> Pin<Box<dyn Future<Output = http::Response<Body>> + Send>> {
|
||||
Box::pin(async move {
|
||||
|
||||
let index = "<center><h1>Proxmox Backup Restore Daemon/h1></center>";
|
||||
|
||||
Response::builder()
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user