diff --git a/kanidm_client/src/lib.rs b/kanidm_client/src/lib.rs index 243ef7b17..a416a57c8 100644 --- a/kanidm_client/src/lib.rs +++ b/kanidm_client/src/lib.rs @@ -165,6 +165,7 @@ impl KanidmClientBuilder { }) } + #[allow(clippy::result_unit_err)] pub fn read_options_from_optional_config + std::fmt::Debug>( self, config_path: P, @@ -268,6 +269,7 @@ impl KanidmClientBuilder { } } + #[allow(clippy::result_unit_err)] pub fn add_root_certificate_filepath(self, ca_path: &str) -> Result { //Okay we have a ca to add. Let's read it in and setup. let ca = Self::parse_certificate(ca_path)?; diff --git a/kanidm_tools/src/cli/account.rs b/kanidm_tools/src/cli/account.rs index 82573405d..7a4951654 100644 --- a/kanidm_tools/src/cli/account.rs +++ b/kanidm_tools/src/cli/account.rs @@ -200,14 +200,14 @@ impl AccountOpt { let mut totp_input = String::new(); let input_result = io::stdin().read_line(&mut totp_input); // Finish the line? - eprintln!(""); + eprintln!(); if let Err(e) = input_result { eprintln!("Failed to read from stdin -> {:?}", e); break; }; // Convert to a u32. - let totp = match u32::from_str_radix(totp_input.trim(), 10) { + let totp = match totp_input.trim().parse::() { Ok(v) => v, Err(e) => { eprintln!("Invalid TOTP -> {:?}", e); @@ -227,17 +227,14 @@ impl AccountOpt { } Err(ClientError::TotpInvalidSha1(session)) => { eprintln!("⚠️ WARNING - It appears your authenticator app may be broken ⚠️ "); - eprintln!(" The TOTP authenticator you are using is forcing the use of SHA1"); - eprintln!(""); + eprintln!(" The TOTP authenticator you are using is forcing the use of SHA1\n"); eprintln!(" -- If you accept this risk, and wish to proceed, type 'I am sure' "); - eprintln!(" -- Otherwise press ENTER to cancel this operation"); - eprintln!(""); + eprintln!(" -- Otherwise press ENTER to cancel this operation\n"); eprint!("Are you sure: "); let mut confirm_input = String::new(); if let Err(e) = io::stdin().read_line(&mut confirm_input) { eprintln!("Failed to read from stdin -> {:?}", e); - break; }; if confirm_input.to_lowercase().trim() == "i am sure" { @@ -252,11 +249,10 @@ impl AccountOpt { eprintln!("Error Completing -> {:?}", e); } }; - break; } else { eprintln!("Cancelling TOTP registration"); - break; } + break; } Err(ClientError::TotpVerifyFailed(_, _)) => { eprintln!("Incorrect TOTP code - try again"); diff --git a/kanidm_tools/src/cli/common.rs b/kanidm_tools/src/cli/common.rs index 295980011..7d4ca6e97 100644 --- a/kanidm_tools/src/cli/common.rs +++ b/kanidm_tools/src/cli/common.rs @@ -84,12 +84,18 @@ impl CommonOpt { for option in tokens.iter() { options.push(String::from(option.0)); } - let selection = Select::with_theme(&ColorfulTheme::default()) + let user_select = Select::with_theme(&ColorfulTheme::default()) .with_prompt("Multiple authentication tokens exist. Please select one") .default(0) .items(&options) - .interact() - .unwrap(); + .interact(); + let selection = match user_select { + Err(error) => { + eprintln!("Failed to handle user input: {:?}", error); + std::process::exit(1); + } + Ok(value) => value, + }; debug!("Index of the chosen menu item: {:?}", selection); let (f_uname, f_token) = diff --git a/kanidm_tools/src/cli/session.rs b/kanidm_tools/src/cli/session.rs index 8b413db0b..7965a0dbe 100644 --- a/kanidm_tools/src/cli/session.rs +++ b/kanidm_tools/src/cli/session.rs @@ -13,6 +13,7 @@ use webauthn_authenticator_rs::{u2fhid::U2FHid, RequestChallengeResponse, Webaut static TOKEN_DIR: &str = "~/.cache"; static TOKEN_PATH: &str = "~/.cache/kanidm_tokens"; +#[allow(clippy::result_unit_err)] pub fn read_tokens() -> Result, ()> { let token_path = PathBuf::from(shellexpand::tilde(TOKEN_PATH).into_owned()); if !token_path.exists() { @@ -59,6 +60,7 @@ pub fn read_tokens() -> Result, ()> { }) } +#[allow(clippy::result_unit_err)] pub fn write_tokens(tokens: &BTreeMap) -> Result<(), ()> { let token_dir = PathBuf::from(shellexpand::tilde(TOKEN_DIR).into_owned()); let token_path = PathBuf::from(shellexpand::tilde(TOKEN_PATH).into_owned()); @@ -116,7 +118,7 @@ fn get_index_choice(len: usize) -> Result { return Err(ClientError::SystemError); }; let response = buffer.trim(); - match u8::from_str_radix(response, 10) { + match response.parse::() { Ok(i) => { if (i as usize) < len { return Ok(i); @@ -145,6 +147,7 @@ impl LoginOpt { fn do_backup_code(&self, client: &mut KanidmClient) -> Result { print!("Enter Backup Code: "); // We flush stdout so it'll write the buffer to screen, continuing operation. Without it, the application halts. + #[allow(clippy::unwrap_used)] io::stdout().flush().unwrap(); let mut backup_code = String::new(); loop { @@ -152,7 +155,7 @@ impl LoginOpt { eprintln!("Failed to read from stdin -> {:?}", e); return Err(ClientError::SystemError); }; - if backup_code.trim().len() > 0 { + if !backup_code.trim().is_empty() { break; }; } @@ -171,7 +174,7 @@ impl LoginOpt { }; let response = buffer.trim(); - match u32::from_str_radix(response, 10) { + match response.parse::() { Ok(i) => break i, Err(_) => eprintln!("Invalid Number"), }; diff --git a/kanidm_unix_int/build.rs b/kanidm_unix_int/build.rs index a492a7f9f..126759b88 100644 --- a/kanidm_unix_int/build.rs +++ b/kanidm_unix_int/build.rs @@ -60,15 +60,15 @@ fn main() { println!("cargo:rerun-if-changed={}", profile_path.to_str().unwrap()); - let mut f = - File::open(&profile_path).expect(format!("Failed to open {:?}", profile_path).as_str()); + let mut f = File::open(&profile_path) + .unwrap_or_else(|_| panic!("Failed to open build profile {:?}", profile_path)); let mut contents = String::new(); f.read_to_string(&mut contents) - .expect(format!("Failed to read {:?}", profile_path).as_str()); + .unwrap_or_else(|_| panic!("Failed to read build profile {:?}", profile_path)); let profile_cfg: ProfileConfig = toml::from_str(contents.as_str()) - .expect(format!("Failed to parse {:?}", profile_path).as_str()); + .unwrap_or_else(|_| panic!("Failed to parse build profile {:?}", profile_path)); match profile_cfg.cpu_flags { CpuOptLevel::none => {} diff --git a/kanidmd/src/lib/actors/v1_read.rs b/kanidmd/src/lib/actors/v1_read.rs index 9a95a6663..37da30f06 100644 --- a/kanidmd/src/lib/actors/v1_read.rs +++ b/kanidmd/src/lib/actors/v1_read.rs @@ -225,8 +225,16 @@ impl QueryServerReadV1 { // cleanup of maximum backup versions to keep let mut backup_file_list: Vec = Vec::new(); // pattern to find automatically generated backup files - let re = Regex::new(r"^backup-\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z\.json$") - .expect("Failed to parse regexp for online backup files."); + let re = match Regex::new(r"^backup-\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z\.json$") { + Ok(value) => value, + Err(error) => { + eprintln!( + "Failed to parse regexp for online backup files: {:?}", + error + ); + return; + } + }; // get a list of backup files match fs::read_dir(outpath) { diff --git a/kanidmd/src/lib/be/mod.rs b/kanidmd/src/lib/be/mod.rs index 3bc590533..fd7282d33 100644 --- a/kanidmd/src/lib/be/mod.rs +++ b/kanidmd/src/lib/be/mod.rs @@ -303,8 +303,7 @@ pub trait BackendTransaction { let mut f_rem_count = f_rem.len() + f_andnot.len() - 1; // Setup the query plan tracker - let mut plan = Vec::new(); - plan.push(fp); + let mut plan = vec![fp]; match &cand_idl { IdList::Indexed(idl) | IdList::Partial(idl) | IdList::PartialThreshold(idl) => { diff --git a/kanidmd/src/lib/credential/mod.rs b/kanidmd/src/lib/credential/mod.rs index 5c50eb579..365c55283 100644 --- a/kanidmd/src/lib/credential/mod.rs +++ b/kanidmd/src/lib/credential/mod.rs @@ -91,7 +91,7 @@ impl TryFrom<&str> for Password { let hash = django_pbkdf[3]; match algo { "pbkdf2_sha256" => { - let c = usize::from_str_radix(cost, 10).map_err(|_| ())?; + let c = cost.parse::().map_err(|_| ())?; let s: Vec<_> = salt.as_bytes().to_vec(); let h = base64::decode(hash).map_err(|_| ())?; if h.len() < PBKDF2_IMPORT_MIN_LEN { @@ -808,12 +808,7 @@ impl Credential { Some(mut backup_codes) => { backup_codes.remove(&code_to_remove); Ok(Credential { - type_: CredentialType::PasswordMfa( - pw.clone(), - totp.clone(), - wan.clone(), - Some(backup_codes), - ), + type_: CredentialType::PasswordMfa(pw, totp, wan, Some(backup_codes)), claims: self.claims.clone(), uuid: self.uuid, }) @@ -846,9 +841,9 @@ impl Credential { match &self.type_ { CredentialType::PasswordMfa(_, _, _, opt_bc) => opt_bc .as_ref() - .ok_or(OperationError::InvalidAccountState( - "No backup codes are available for this account".to_string(), - )) + .ok_or(OperationError::InvalidAccountState(String::from( + "No backup codes are available for this account", + ))) .and_then(|bc| { Ok(BackupCodesView { backup_codes: bc.code_set.clone().into_iter().collect(), diff --git a/kanidmd/src/lib/filter.rs b/kanidmd/src/lib/filter.rs index 3cf5d4b11..a2767f0e2 100644 --- a/kanidmd/src/lib/filter.rs +++ b/kanidmd/src/lib/filter.rs @@ -90,7 +90,7 @@ pub fn f_id(id: &str) -> FC<'static> { let nf = FC::Eq("name", PartialValue::new_iname(id)); let f: Vec<_> = iter::once(uf) .chain(iter::once(spnf)) - .filter_map(|v| v) + .flatten() .chain(iter::once(nf)) .collect(); FC::Or(f) @@ -100,10 +100,7 @@ pub fn f_id(id: &str) -> FC<'static> { pub fn f_spn_name(id: &str) -> FC<'static> { let spnf = PartialValue::new_spn_s(id).map(|spn| FC::Eq("spn", spn)); let nf = FC::Eq("name", PartialValue::new_iname(id)); - let f: Vec<_> = iter::once(spnf) - .filter_map(|v| v) - .chain(iter::once(nf)) - .collect(); + let f: Vec<_> = iter::once(spnf).flatten().chain(iter::once(nf)).collect(); FC::Or(f) } diff --git a/kanidmd/src/lib/idm/radius.rs b/kanidmd/src/lib/idm/radius.rs index a5af0c92c..006755e39 100644 --- a/kanidmd/src/lib/idm/radius.rs +++ b/kanidmd/src/lib/idm/radius.rs @@ -68,8 +68,8 @@ impl RadiusAccount { Ok(RadiusAccount { name, - uuid, displayname, + uuid, groups, radius_secret, valid_from, diff --git a/kanidmd/src/lib/ldap.rs b/kanidmd/src/lib/ldap.rs index 8d385b20d..ec185bc6a 100644 --- a/kanidmd/src/lib/ldap.rs +++ b/kanidmd/src/lib/ldap.rs @@ -98,8 +98,8 @@ impl LdapServer { }; Ok(LdapServer { - basedn, rootdse, + basedn, dnre, binddnre, }) diff --git a/kanidmd/src/lib/repl/cid.rs b/kanidmd/src/lib/repl/cid.rs index 7d0a97f53..f8e14cb7c 100644 --- a/kanidmd/src/lib/repl/cid.rs +++ b/kanidmd/src/lib/repl/cid.rs @@ -22,7 +22,7 @@ impl Cid { } else { *max_ts + Duration::from_nanos(1) }; - Cid { d_uuid, s_uuid, ts } + Cid { ts, d_uuid, s_uuid } } #[cfg(test)] diff --git a/kanidmd/src/lib/schema.rs b/kanidmd/src/lib/schema.rs index 261a6ed50..74001632e 100644 --- a/kanidmd/src/lib/schema.rs +++ b/kanidmd/src/lib/schema.rs @@ -347,8 +347,8 @@ impl SchemaClass { uuid, description, systemmay, - systemmust, may, + systemmust, must, }) } diff --git a/kanidmd/src/lib/value.rs b/kanidmd/src/lib/value.rs index 7b36dc5ba..e2849f801 100644 --- a/kanidmd/src/lib/value.rs +++ b/kanidmd/src/lib/value.rs @@ -484,7 +484,7 @@ impl PartialValue { } pub fn new_uint32_str(u: &str) -> Option { - u32::from_str_radix(u, 10).ok().map(PartialValue::Uint32) + u.parse::().ok().map(PartialValue::Uint32) } pub fn is_uint32(&self) -> bool { diff --git a/kanidmd/src/lib/valueset.rs b/kanidmd/src/lib/valueset.rs index 182ab5d38..13b046cd1 100644 --- a/kanidmd/src/lib/valueset.rs +++ b/kanidmd/src/lib/valueset.rs @@ -136,7 +136,7 @@ impl<'a> IntoIterator for &'a ValueSet { fn into_iter(self) -> Self::IntoIter { Iter { - iter: (&self.inner).into_iter(), + iter: (&self.inner).iter(), } } } diff --git a/orca/src/data.rs b/orca/src/data.rs index 946bd8213..59b3f2b9a 100644 --- a/orca/src/data.rs +++ b/orca/src/data.rs @@ -80,8 +80,8 @@ impl Group { Group { name, - members, uuid, + members, } } } diff --git a/orca/src/main.rs b/orca/src/main.rs index 855f29ec1..09fdbdd7f 100644 --- a/orca/src/main.rs +++ b/orca/src/main.rs @@ -54,6 +54,7 @@ pub enum TargetServerBuilder { } impl TargetServerBuilder { + #[allow(clippy::result_unit_err)] pub fn build(self) -> Result { match self { TargetServerBuilder::Kanidm(a, b) => KaniHttpServer::build(a, b), diff --git a/orca/src/preprocess.rs b/orca/src/preprocess.rs index 0dbf14aec..6d232b94d 100644 --- a/orca/src/preprocess.rs +++ b/orca/src/preprocess.rs @@ -69,8 +69,8 @@ fn parse_rtime(s: &str) -> Result { return Err(()); } - let hh = u32::from_str_radix(v[0], 10).map_err(|_| ())?; - let mm = u32::from_str_radix(v[1], 10).map_err(|_| ())?; + let hh = v[0].parse::().map_err(|_| ())?; + let mm = v[1].parse::().map_err(|_| ())?; let ss = f64::from_str(v[2]).map_err(|_| ())?; let ext_secs = ((mm * 60) + (hh * 3600)) as f64; @@ -161,7 +161,7 @@ impl TryFrom for Record { op_type, } = value; - let conn = i32::from_str_radix(&conn, 10).map_err(|_| ())?; + let conn = conn.parse::().map_err(|_| ())?; let etime = f64::from_str(&etime) .map(Duration::from_secs_f64) .map_err(|_| ())?; diff --git a/orca/src/runner/mod.rs b/orca/src/runner/mod.rs index 885c322f0..6c576eaf7 100644 --- a/orca/src/runner/mod.rs +++ b/orca/src/runner/mod.rs @@ -1,13 +1,13 @@ use crate::setup::config; use crate::{TargetOpt, TestTypeOpt}; -use std::path::PathBuf; +use std::path::{Path, PathBuf}; mod search; pub(crate) async fn doit( testtype: &TestTypeOpt, target: &TargetOpt, - profile_path: &PathBuf, + profile_path: &Path, ) -> Result<(), ()> { info!( "Performing test {} against {:?} from {}", diff --git a/orca/src/setup.rs b/orca/src/setup.rs index 4d066a62b..b8a5c8210 100644 --- a/orca/src/setup.rs +++ b/orca/src/setup.rs @@ -12,7 +12,7 @@ use uuid::Uuid; pub(crate) fn config( target: &TargetOpt, - profile_path: &PathBuf, + profile_path: &Path, ) -> Result<(TestData, Profile, TargetServer), ()> { // read the profile that we are going to be using/testing let mut f = File::open(profile_path).map_err(|e| { @@ -91,7 +91,7 @@ pub(crate) fn config( Ok((data, profile, server)) } -pub(crate) async fn doit(target: &TargetOpt, profile_path: &PathBuf) -> Result<(), ()> { +pub(crate) async fn doit(target: &TargetOpt, profile_path: &Path) -> Result<(), ()> { info!( "Performing setup of {:?} from {}", target,