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) }