Skip to content

Commit

Permalink
chore: fix clippy errors
Browse files Browse the repository at this point in the history
  • Loading branch information
coastalwhite committed Jul 23, 2024
1 parent 9e77e70 commit 53b45c1
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
2 changes: 2 additions & 0 deletions src/auth/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<libc::gid_t>,
Expand Down
18 changes: 10 additions & 8 deletions src/auth/pam.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::fmt;

use log::info;

use pam::Authenticator;
Expand All @@ -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"),
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/chvt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ const KB_84: u8 = 0x01;

#[derive(Debug)]
pub enum ChvtError {
Activate(i32),
WaitActive(i32),
Activate,
WaitActive,
Close,
OpenConsole,
NotAConsole,
Expand Down Expand Up @@ -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)?;
Expand Down

0 comments on commit 53b45c1

Please sign in to comment.