diff --git a/server/core/src/config.rs b/server/core/src/config.rs index 1c4443042..6f9dfb6e7 100644 --- a/server/core/src/config.rs +++ b/server/core/src/config.rs @@ -186,7 +186,11 @@ impl ServerConfig { } else { eprintln!("📜 No config file found at {:?}", config_path.as_ref()); } - } + } else { + eprintln!( + "WARNING: No configuration path was provided, relying on environment variables." + ); + }; // build from the environment variables let res = config.try_from_env().map_err(|e| { diff --git a/server/daemon/src/main.rs b/server/daemon/src/main.rs index 1335e9029..2960803c6 100644 --- a/server/daemon/src/main.rs +++ b/server/daemon/src/main.rs @@ -24,6 +24,7 @@ use sketching::LogLevel; use std::os::unix::fs::MetadataExt; use std::path::PathBuf; use std::process::ExitCode; +use std::str::FromStr; use clap::{Args, Parser, Subcommand}; use futures::{SinkExt, StreamExt}; @@ -319,7 +320,26 @@ async fn kanidm_main() -> ExitCode { let mut config_error: Vec = Vec::new(); let mut config = Configuration::new(); - let sconfig = match ServerConfig::new(opt.config_path()) { + let Ok(default_config_path) = PathBuf::from_str(env!("KANIDM_DEFAULT_CONFIG_PATH")) else { + eprintln!("CRITICAL: Kanidmd was not built correctly and is missing a valid KANIDM_DEFAULT_CONFIG_PATH value"); + return ExitCode::FAILURE; + }; + + let maybe_config_path = if let Some(p) = opt.config_path() { + Some(p) + } else { + // The user didn't ask for a file, lets check if the default path exists? + if default_config_path.exists() { + // It does, lets use it. + Some(default_config_path) + } else { + // No default config, and no config specified, lets assume the user + // has selected environment variables. + None + } + }; + + let sconfig = match ServerConfig::new(maybe_config_path) { Ok(c) => Some(c), Err(e) => { config_error.push(format!("Config Parse failure {:?}", e)); diff --git a/tools/cli/src/cli/session.rs b/tools/cli/src/cli/session.rs index 64fe443e8..0bb85608f 100644 --- a/tools/cli/src/cli/session.rs +++ b/tools/cli/src/cli/session.rs @@ -100,16 +100,20 @@ impl TokenInstance { #[derive(Debug, Serialize, Clone, Deserialize, Default)] pub struct TokenStore { - instances: BTreeMap, TokenInstance>, + instances: BTreeMap, } impl TokenStore { pub fn instances(&self, name: &Option) -> Option<&TokenInstance> { - self.instances.get(name) + let n_lookup = name.clone().unwrap_or_else(|| "".to_string()); + + self.instances.get(&n_lookup) } pub fn instances_mut(&mut self, name: &Option) -> Option<&mut TokenInstance> { - self.instances.get_mut(name) + let n_lookup = name.clone().unwrap_or_else(|| "".to_string()); + + self.instances.get_mut(&n_lookup) } } @@ -409,7 +413,8 @@ async fn process_auth_state( let mut tokens = read_tokens(&client.get_token_cache_path()).unwrap_or_default(); // Select our token instance. Create it if empty. - let token_instance = tokens.instances.entry(instance_name.clone()).or_default(); + let n_lookup = instance_name.clone().unwrap_or_else(|| "".to_string()); + let token_instance = tokens.instances.entry(n_lookup).or_default(); // Add our new one let (spn, tonk) = match client.get_token().await { @@ -480,6 +485,7 @@ async fn process_auth_state( // write them out. if write_tokens(&tokens, &client.get_token_cache_path()).is_err() { + trace!(?tokens); error!("Error persisting authentication token store"); std::process::exit(1); }; @@ -669,7 +675,8 @@ impl LogoutOpt { std::process::exit(1); }); - let Some(token_instance) = tokens.instances.get_mut(instance_name) else { + let n_lookup = instance_name.clone().unwrap_or_else(|| "".to_string()); + let Some(token_instance) = tokens.instances.get_mut(&n_lookup) else { println!("No sessions for {}", spn); return; };