From b62edce929a7c5f6403e30af97e6878ddd3c134c Mon Sep 17 00:00:00 2001 From: Wolfgang Bumiller Date: Wed, 29 Sep 2021 13:58:07 +0200 Subject: [PATCH] remove pbs_client::connect_to_localhost It also used `CertInfo` from pbs-tools which is also server specific. The original helper is now in the main crate's client_helpers instead. Signed-off-by: Wolfgang Bumiller --- pbs-client/src/lib.rs | 23 ----------------------- src/client_helpers.rs | 23 +++++++++++++++++------ 2 files changed, 17 insertions(+), 29 deletions(-) diff --git a/pbs-client/src/lib.rs b/pbs-client/src/lib.rs index eeeff71e..c4783f92 100644 --- a/pbs-client/src/lib.rs +++ b/pbs-client/src/lib.rs @@ -3,13 +3,6 @@ //! This library implements the client side to access the backups //! server using https. -use anyhow::Error; -use openssl::pkey::{PKey, Private}; - -use pbs_api_types::{Authid, Userid}; -use pbs_tools::ticket::Ticket; -use pbs_tools::cert::CertInfo; - pub mod catalog_shell; pub mod dynamic_index; pub mod pxar; @@ -49,19 +42,3 @@ mod chunk_stream; pub use chunk_stream::{ChunkStream, FixedChunkStream}; pub const PROXMOX_BACKUP_TCP_KEEPALIVE_TIME: u32 = 120; - -/// Connect to localhost:8007 as root@pam -/// -/// This automatically creates a ticket if run as 'root' user. -pub fn connect_to_localhost(auth_key: Option<&PKey>) -> Result { - let options = if let Some(auth_key) = auth_key { - let ticket = Ticket::new("PBS", Userid::root_userid())? - .sign(auth_key, None)?; - let fingerprint = CertInfo::new()?.fingerprint()?; - HttpClientOptions::new_non_interactive(ticket, Some(fingerprint)) - } else { - HttpClientOptions::new_interactive(None, None) - }; - - HttpClient::new("localhost", 8007, Authid::root_auth_id(), options) -} diff --git a/src/client_helpers.rs b/src/client_helpers.rs index 154d7fd0..d08403f4 100644 --- a/src/client_helpers.rs +++ b/src/client_helpers.rs @@ -1,13 +1,24 @@ use anyhow::Error; +use pbs_api_types::{Authid, Userid}; +use pbs_client::{HttpClient, HttpClientOptions}; +use pbs_tools::cert::CertInfo; +use pbs_tools::ticket::Ticket; + use crate::auth_helpers::private_auth_key; -/// As root we have access to the private key file and can use it directly. Otherwise the connect -/// call will interactively query the password. +/// Connect to localhost:8007 as root@pam +/// +/// This automatically creates a ticket if run as 'root' user. pub fn connect_to_localhost() -> Result { - pbs_client::connect_to_localhost(if nix::unistd::Uid::current().is_root() { - Some(private_auth_key()) + let options = if nix::unistd::Uid::current().is_root() { + let auth_key = private_auth_key(); + let ticket = Ticket::new("PBS", Userid::root_userid())?.sign(auth_key, None)?; + let fingerprint = CertInfo::new()?.fingerprint()?; + HttpClientOptions::new_non_interactive(ticket, Some(fingerprint)) } else { - None - }) + HttpClientOptions::new_interactive(None, None) + }; + + HttpClient::new("localhost", 8007, Authid::root_auth_id(), options) }