From eb4b25719bc639c8baed96b91b872d62871611f3 Mon Sep 17 00:00:00 2001 From: James Hodgkinson Date: Sun, 8 Aug 2021 09:54:21 +1000 Subject: [PATCH] fixes #557, adds a check for the kanidm_unixd socket file and bails if not (#560) --- kanidm_unix_int/src/client.rs | 3 ++- kanidm_unix_int/src/ssh_authorizedkeys.rs | 22 ++++++++++++++++++---- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/kanidm_unix_int/src/client.rs b/kanidm_unix_int/src/client.rs index d7606509b..fb928b70d 100644 --- a/kanidm_unix_int/src/client.rs +++ b/kanidm_unix_int/src/client.rs @@ -49,6 +49,7 @@ impl ClientCodec { } } +/// Makes a call to kanidm_unixd via a unix socket at `path` pub async fn call_daemon(path: &str, req: ClientRequest) -> Result> { let stream = UnixStream::connect(path).await?; @@ -63,7 +64,7 @@ pub async fn call_daemon(path: &str, req: ClientRequest) -> Result { - error!("Error"); + error!("Error making request to kanidm_unixd"); Err(Box::new(IoError::new(ErrorKind::Other, "oh no!"))) } } diff --git a/kanidm_unix_int/src/ssh_authorizedkeys.rs b/kanidm_unix_int/src/ssh_authorizedkeys.rs index 367930e6c..174185137 100644 --- a/kanidm_unix_int/src/ssh_authorizedkeys.rs +++ b/kanidm_unix_int/src/ssh_authorizedkeys.rs @@ -12,6 +12,7 @@ extern crate log; use log::debug; +use std::path::PathBuf; use structopt::StructOpt; use futures::executor::block_on; @@ -37,12 +38,25 @@ async fn main() { let cfg = match KanidmUnixdConfig::new().read_options_from_optional_config("/etc/kanidm/unixd") { Ok(c) => c, - Err(_e) => { - error!("Failed to parse /etc/kanidm/unixd"); + Err(e) => { + error!("Failed to parse /etc/kanidm/unixd: {:?}", e); std::process::exit(1); } }; + debug!( + "Using kanidm_unixd socket path: {:?}", + cfg.sock_path.as_str() + ); + + // see if the kanidm_unixd socket exists and quit if not + if !PathBuf::from(&cfg.sock_path).exists() { + error!( + "Failed to find unix socket at {}, quitting!", + cfg.sock_path.as_str() + ); + std::process::exit(1); + } let req = ClientRequest::SshKey(opt.account_id); match block_on(call_daemon(cfg.sock_path.as_str(), req)) { @@ -51,11 +65,11 @@ async fn main() { println!("{}", k); }), _ => { - error!("Error: unexpected response -> {:?}", r); + error!("Error calling kanidm_unixd: unexpected response -> {:?}", r); } }, Err(e) => { - error!("Error -> {:?}", e); + error!("Error calling kanidm_unixd -> {:?}", e); } } }