From e2e7c2b97faf4b26295fd46ce43bbcdeee0ddac7 Mon Sep 17 00:00:00 2001 From: zSchoen Date: Tue, 5 Dec 2023 19:54:27 +0100 Subject: [PATCH] use extern crate path_ratchet (#41) --- pam-direct-fallback/Cargo.toml | 1 + pam-direct-fallback/src/lib.rs | 5 ++-- pam-direct-fallback/src/path.rs | 41 --------------------------------- 3 files changed, 3 insertions(+), 44 deletions(-) delete mode 100644 pam-direct-fallback/src/path.rs diff --git a/pam-direct-fallback/Cargo.toml b/pam-direct-fallback/Cargo.toml index 9bc32a9..62b502c 100644 --- a/pam-direct-fallback/Cargo.toml +++ b/pam-direct-fallback/Cargo.toml @@ -11,6 +11,7 @@ edition = "2021" [dependencies] pamsm = { version = "0.5", features = ["libpam"] } pam-utils = { path = "../pam-utils" } +path_ratchet = "~0.1" thiserror = "1" error-stack = "0.4" birdcage = { version = "0.3", optional = true } diff --git a/pam-direct-fallback/src/lib.rs b/pam-direct-fallback/src/lib.rs index e2350e8..47cd075 100644 --- a/pam-direct-fallback/src/lib.rs +++ b/pam-direct-fallback/src/lib.rs @@ -2,13 +2,12 @@ extern crate pamsm; mod args; -mod path; use args::Args; use error_stack::{Report, ResultExt}; use pam_utils::do_call_handler; use pamsm::{Pam, PamError, PamFlags, PamServiceModule}; -use path::{PathComponent, PushPathComponent}; +use path_ratchet::prelude::*; use std::fs::{remove_file, File}; use std::path::PathBuf; @@ -36,7 +35,7 @@ type Result = error_stack::Result; fn user_file(dir: PathBuf, username: String) -> Result { let mut user_data_file = dir; - let user_file_name = PathComponent::new(username).ok_or(Error::InvalidUsername)?; + let user_file_name = SinglePathComponent::new(username).ok_or(Error::InvalidUsername)?; user_data_file.push_component(user_file_name); Ok(user_data_file) } diff --git a/pam-direct-fallback/src/path.rs b/pam-direct-fallback/src/path.rs deleted file mode 100644 index b2e1390..0000000 --- a/pam-direct-fallback/src/path.rs +++ /dev/null @@ -1,41 +0,0 @@ -use std::path::PathBuf; - -pub struct PathComponent { - path: PathBuf, -} - -impl PathComponent { - pub fn new>(component: S) -> Option { - let component = Self { - path: component.into(), - }; - - component.is_valid().then_some(component) - } - - fn is_valid(&self) -> bool { - use std::path::Component; - - let mut components = self.path.components(); - matches!( - (components.next(), components.next()), - (Some(Component::Normal(_)), None) - ) - } -} - -impl AsRef for PathComponent { - fn as_ref(&self) -> &std::path::Path { - &self.path - } -} - -pub trait PushPathComponent { - fn push_component(&mut self, component: PathComponent); -} - -impl PushPathComponent for PathBuf { - fn push_component(&mut self, component: PathComponent) { - self.push(component); - } -}