From 36e8c2c1cc0644c9431d3262ea0dc8c398007e81 Mon Sep 17 00:00:00 2001 From: coastalwhite Date: Tue, 23 Jul 2024 21:38:54 +0200 Subject: [PATCH] chore: fix clippy errors --- src/auth/mod.rs | 2 ++ src/auth/pam.rs | 18 ++++++++++-------- src/chvt.rs | 8 ++++---- 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/auth/mod.rs b/src/auth/mod.rs index a3e3bfb..627f36c 100644 --- a/src/auth/mod.rs +++ b/src/auth/mod.rs @@ -13,7 +13,9 @@ pub struct AuthUserInfo<'a> { #[allow(dead_code)] authenticator: Authenticator<'a, PasswordConv>, + #[allow(dead_code)] pub username: String, + pub uid: libc::uid_t, pub primary_gid: libc::gid_t, pub all_gids: Vec, diff --git a/src/auth/pam.rs b/src/auth/pam.rs index ed5dc84..0d00294 100644 --- a/src/auth/pam.rs +++ b/src/auth/pam.rs @@ -1,3 +1,5 @@ +use std::fmt; + use log::info; use pam::Authenticator; @@ -16,15 +18,15 @@ pub enum AuthenticationError { SessionOpen, } -impl ToString for AuthenticationError { - fn to_string(&self) -> String { +impl fmt::Display for AuthenticationError { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { - AuthenticationError::PamService(service) => format!("Failed to create authenticator with PAM service '{service}'"), - AuthenticationError::AccountValidation => "Invalid login credentials".to_string(), - AuthenticationError::HomeDirInvalidUtf8 => "User home directory path contains invalid UTF-8".to_string(), - AuthenticationError::ShellInvalidUtf8 => "User shell path contains invalid UTF-8".to_string(), - AuthenticationError::UsernameNotFound => "Login creditionals are valid, but username is not found. This should not be possible :(".to_string(), - AuthenticationError::SessionOpen => "Failed to open a PAM session".to_string(), + Self::PamService(service) => write!(f, "Failed to create authenticator with PAM service '{service}'"), + Self::AccountValidation => f.write_str("Invalid login credentials"), + Self::HomeDirInvalidUtf8 => f.write_str("User home directory path contains invalid UTF-8"), + Self::ShellInvalidUtf8 => f.write_str("User shell path contains invalid UTF-8"), + Self::UsernameNotFound => f.write_str("Login creditionals are valid, but username is not found. This should not be possible :("), + Self::SessionOpen => f.write_str("Failed to open a PAM session"), } } } diff --git a/src/chvt.rs b/src/chvt.rs index 49ed084..359850f 100644 --- a/src/chvt.rs +++ b/src/chvt.rs @@ -24,8 +24,8 @@ const KB_84: u8 = 0x01; #[derive(Debug)] pub enum ChvtError { - Activate(i32), - WaitActive(i32), + Activate, + WaitActive, Close, OpenConsole, NotAConsole, @@ -103,12 +103,12 @@ pub unsafe fn chvt(ttynum: i32) -> Result<(), ChvtError> { let activate = unsafe { libc::ioctl(fd, VT_ACTIVATE, ttynum as c_int) }; if activate > 0 { - return Err(ChvtError::Activate(activate)); + return Err(ChvtError::Activate); } let wait = unsafe { libc::ioctl(fd, VT_WAITACTIVE, ttynum) }; if wait > 0 { - return Err(ChvtError::WaitActive(wait)); + return Err(ChvtError::WaitActive); } close(fd).map_err(|_| ChvtError::Close)?;