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")?;
|
std::fs::create_dir_all("/etc")?;
|
||||||
let mut passwd = File::create("/etc/passwd")?;
|
let mut passwd = File::create("/etc/passwd")?;
|
||||||
writeln!(passwd, "root:x:0:0:root:/root:/bin/sh")?;
|
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")?;
|
let mut group = File::create("/etc/group")?;
|
||||||
writeln!(group, "root:x:0:")?;
|
writeln!(group, "root:x:0:")?;
|
||||||
|
@ -89,7 +92,6 @@ fn setup_system_env() -> Result<(), Error> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
async fn run() -> Result<(), Error> {
|
async fn run() -> Result<(), Error> {
|
||||||
watchdog_init();
|
watchdog_init();
|
||||||
|
|
||||||
|
|
|
@ -13,12 +13,12 @@ use serde_json::Value;
|
||||||
use tokio::sync::Semaphore;
|
use tokio::sync::Semaphore;
|
||||||
|
|
||||||
use pathpatterns::{MatchEntry, MatchPattern, MatchType, Pattern};
|
use pathpatterns::{MatchEntry, MatchPattern, MatchType, Pattern};
|
||||||
|
use proxmox_compression::zip::zip_directory;
|
||||||
use proxmox_router::{
|
use proxmox_router::{
|
||||||
list_subdirs_api_method,
|
list_subdirs_api_method, ApiHandler, ApiMethod, ApiResponseFuture, Permission, Router,
|
||||||
ApiHandler, ApiMethod, ApiResponseFuture, Permission, Router, RpcEnvironment, SubdirMap,
|
RpcEnvironment, SubdirMap,
|
||||||
};
|
};
|
||||||
use proxmox_schema::*;
|
use proxmox_schema::*;
|
||||||
use proxmox_compression::zip::zip_directory;
|
|
||||||
use proxmox_sys::fs::read_subdir;
|
use proxmox_sys::fs::read_subdir;
|
||||||
use proxmox_sys::sortable;
|
use proxmox_sys::sortable;
|
||||||
|
|
||||||
|
@ -29,7 +29,7 @@ use pbs_tools::json::required_string_param;
|
||||||
|
|
||||||
use pxar::encoder::aio::TokioWriter;
|
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
|
// 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.
|
// 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
|
/// 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() {
|
if !keep_timeout && rpcenv.get_auth_id().is_some() {
|
||||||
watchdog_ping();
|
watchdog_ping();
|
||||||
}
|
}
|
||||||
|
@ -164,8 +167,9 @@ fn list(
|
||||||
if path.components().count() == 1 {
|
if path.components().count() == 1 {
|
||||||
// ignore '.' and '..'
|
// ignore '.' and '..'
|
||||||
match path.components().next().unwrap() {
|
match path.components().next().unwrap() {
|
||||||
std::path::Component::CurDir
|
std::path::Component::CurDir | std::path::Component::ParentDir => {
|
||||||
| std::path::Component::ParentDir => continue,
|
continue
|
||||||
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -192,10 +196,7 @@ fn list(
|
||||||
let mut t_path = path.clone();
|
let mut t_path = path.clone();
|
||||||
t_path.push(b'/');
|
t_path.push(b'/');
|
||||||
t_path.extend(t.as_bytes());
|
t_path.extend(t.as_bytes());
|
||||||
res.push(ArchiveEntry::new(
|
res.push(ArchiveEntry::new(&t_path[..], None));
|
||||||
&t_path[..],
|
|
||||||
None,
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ResolveResult::BucketComponents(comps) => {
|
ResolveResult::BucketComponents(comps) => {
|
||||||
|
|
|
@ -1,17 +1,17 @@
|
||||||
//! Authentication via a static ticket file
|
//! Authentication via a static ticket file
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::prelude::*;
|
|
||||||
use std::future::Future;
|
use std::future::Future;
|
||||||
|
use std::io::prelude::*;
|
||||||
use std::pin::Pin;
|
use std::pin::Pin;
|
||||||
|
|
||||||
use anyhow::{bail, format_err, Error};
|
use anyhow::{bail, format_err, Error};
|
||||||
use hyper::{Body, Response, Method, StatusCode};
|
|
||||||
use http::request::Parts;
|
use http::request::Parts;
|
||||||
use http::HeaderMap;
|
use http::HeaderMap;
|
||||||
|
use hyper::{Body, Method, Response, StatusCode};
|
||||||
|
|
||||||
use proxmox_router::UserInformation;
|
use proxmox_router::UserInformation;
|
||||||
|
|
||||||
use proxmox_rest_server::{ServerAdapter, AuthError, RestEnvironment};
|
use proxmox_rest_server::{AuthError, RestEnvironment, ServerAdapter};
|
||||||
|
|
||||||
const TICKET_FILE: &str = "/ticket";
|
const TICKET_FILE: &str = "/ticket";
|
||||||
|
|
||||||
|
@ -21,8 +21,12 @@ impl UserInformation for SimpleUserInformation {
|
||||||
fn is_superuser(&self, userid: &str) -> bool {
|
fn is_superuser(&self, userid: &str) -> bool {
|
||||||
userid == "root@pam"
|
userid == "root@pam"
|
||||||
}
|
}
|
||||||
fn is_group_member(&self, _userid: &str, _group: &str) -> bool { false }
|
fn is_group_member(&self, _userid: &str, _group: &str) -> bool {
|
||||||
fn lookup_privs(&self, _userid: &str, _path: &[&str]) -> u64 { 0 }
|
false
|
||||||
|
}
|
||||||
|
fn lookup_privs(&self, _userid: &str, _path: &[&str]) -> u64 {
|
||||||
|
0
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct StaticAuthAdapter {
|
pub struct StaticAuthAdapter {
|
||||||
|
@ -30,7 +34,6 @@ pub struct StaticAuthAdapter {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl StaticAuthAdapter {
|
impl StaticAuthAdapter {
|
||||||
|
|
||||||
pub fn new() -> Result<Self, Error> {
|
pub fn new() -> Result<Self, Error> {
|
||||||
let mut ticket_file = File::open(TICKET_FILE)?;
|
let mut ticket_file = File::open(TICKET_FILE)?;
|
||||||
let mut ticket = String::new();
|
let mut ticket = String::new();
|
||||||
|
@ -42,19 +45,23 @@ impl StaticAuthAdapter {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
impl ServerAdapter for StaticAuthAdapter {
|
impl ServerAdapter for StaticAuthAdapter {
|
||||||
|
|
||||||
fn check_auth<'a>(
|
fn check_auth<'a>(
|
||||||
&'a self,
|
&'a self,
|
||||||
headers: &'a HeaderMap,
|
headers: &'a HeaderMap,
|
||||||
_method: &'a Method,
|
_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 {
|
Box::pin(async move {
|
||||||
|
|
||||||
match headers.get(hyper::header::AUTHORIZATION) {
|
match headers.get(hyper::header::AUTHORIZATION) {
|
||||||
Some(header) if header.to_str().unwrap_or("") == &self.ticket => {
|
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))
|
Ok((String::from("root@pam"), user_info))
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
|
@ -72,7 +79,6 @@ impl ServerAdapter for StaticAuthAdapter {
|
||||||
_parts: Parts,
|
_parts: Parts,
|
||||||
) -> Pin<Box<dyn Future<Output = http::Response<Body>> + Send>> {
|
) -> Pin<Box<dyn Future<Output = http::Response<Body>> + Send>> {
|
||||||
Box::pin(async move {
|
Box::pin(async move {
|
||||||
|
|
||||||
let index = "<center><h1>Proxmox Backup Restore Daemon/h1></center>";
|
let index = "<center><h1>Proxmox Backup Restore Daemon/h1></center>";
|
||||||
|
|
||||||
Response::builder()
|
Response::builder()
|
||||||
|
|
|
@ -9,9 +9,9 @@ use anyhow::{bail, format_err, Error};
|
||||||
use lazy_static::lazy_static;
|
use lazy_static::lazy_static;
|
||||||
use log::{info, warn};
|
use log::{info, warn};
|
||||||
|
|
||||||
use proxmox_sys::fs;
|
|
||||||
use proxmox_sys::command::run_command;
|
|
||||||
use proxmox_schema::const_regex;
|
use proxmox_schema::const_regex;
|
||||||
|
use proxmox_sys::command::run_command;
|
||||||
|
use proxmox_sys::fs;
|
||||||
|
|
||||||
use pbs_api_types::BLOCKDEVICE_NAME_REGEX;
|
use pbs_api_types::BLOCKDEVICE_NAME_REGEX;
|
||||||
|
|
||||||
|
@ -371,12 +371,9 @@ impl DiskState {
|
||||||
|
|
||||||
// create mapping for virtio drives and .fidx files (via serial description)
|
// create mapping for virtio drives and .fidx files (via serial description)
|
||||||
// note: disks::DiskManager relies on udev, which we don't have
|
// note: disks::DiskManager relies on udev, which we don't have
|
||||||
for entry in proxmox_sys::fs::scan_subdir(
|
for entry in
|
||||||
libc::AT_FDCWD,
|
proxmox_sys::fs::scan_subdir(libc::AT_FDCWD, "/sys/block", &BLOCKDEVICE_NAME_REGEX)?
|
||||||
"/sys/block",
|
.filter_map(Result::ok)
|
||||||
&BLOCKDEVICE_NAME_REGEX,
|
|
||||||
)?
|
|
||||||
.filter_map(Result::ok)
|
|
||||||
{
|
{
|
||||||
let name = unsafe { entry.file_name_utf8_unchecked() };
|
let name = unsafe { entry.file_name_utf8_unchecked() };
|
||||||
if !name.starts_with("vd") {
|
if !name.starts_with("vd") {
|
||||||
|
@ -416,12 +413,8 @@ impl DiskState {
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut parts = Vec::new();
|
let mut parts = Vec::new();
|
||||||
for entry in proxmox_sys::fs::scan_subdir(
|
for entry in proxmox_sys::fs::scan_subdir(libc::AT_FDCWD, sys_path, &VIRTIO_PART_REGEX)?
|
||||||
libc::AT_FDCWD,
|
.filter_map(Result::ok)
|
||||||
sys_path,
|
|
||||||
&VIRTIO_PART_REGEX,
|
|
||||||
)?
|
|
||||||
.filter_map(Result::ok)
|
|
||||||
{
|
{
|
||||||
let part_name = unsafe { entry.file_name_utf8_unchecked() };
|
let part_name = unsafe { entry.file_name_utf8_unchecked() };
|
||||||
let dev_node = format!("/dev/{}", part_name);
|
let dev_node = format!("/dev/{}", part_name);
|
||||||
|
@ -730,18 +723,15 @@ impl DiskState {
|
||||||
};
|
};
|
||||||
|
|
||||||
// bucket found, check mount
|
// bucket found, check mount
|
||||||
let mountpoint = self
|
let mountpoint = self.filesystems.ensure_mounted(bucket).map_err(|err| {
|
||||||
.filesystems
|
format_err!(
|
||||||
.ensure_mounted(bucket)
|
"mounting '{}/{}/{}' failed: {}",
|
||||||
.map_err(|err| {
|
req_fidx,
|
||||||
format_err!(
|
bucket_type,
|
||||||
"mounting '{}/{}/{}' failed: {}",
|
components.join("/"),
|
||||||
req_fidx,
|
err
|
||||||
bucket_type,
|
)
|
||||||
components.join("/"),
|
})?;
|
||||||
err
|
|
||||||
)
|
|
||||||
})?;
|
|
||||||
|
|
||||||
let mut local_path = PathBuf::new();
|
let mut local_path = PathBuf::new();
|
||||||
local_path.push(mountpoint);
|
local_path.push(mountpoint);
|
||||||
|
|
Loading…
Reference in New Issue