diff --git a/.cargo/config.toml b/.cargo/config.toml index bf3e4b1..40a89fe 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -1,2 +1,2 @@ [alias] -test-integration = 'run --package xtask-test-integration --' \ No newline at end of file +integration-test = 'run --package xtask-integration-test --' \ No newline at end of file diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index b5dedbe..83b6b58 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -64,7 +64,7 @@ cargo test -p util #### Integration testing Edit the constants in the `test-pam-auth.rs` file to a user on your system. The test will build the library and use the systems pam service to test authentication. The test will run with evelated privileges. Run the integration tests: ```console -cargo test-integration +cargo integration-test ``` ### Building Build library: diff --git a/Cargo.lock b/Cargo.lock index a804e69..f8aa448 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -280,9 +280,9 @@ version = "0.9.9" dependencies = [ "clap", "colored", + "common", "log", "tempdir", - "util", ] [[package]] @@ -346,6 +346,20 @@ dependencies = [ "windows-sys 0.48.0", ] +[[package]] +name = "common" +version = "0.9.9" +dependencies = [ + "chrono", + "log", + "pam-bindings", + "sysinfo", + "syslog", + "tempdir", + "toml", + "uzers", +] + [[package]] name = "core-foundation-sys" version = "0.8.6" @@ -556,12 +570,12 @@ name = "lib" version = "0.9.9" dependencies = [ "chrono", + "common", "libc", "log", "pam-bindings", "tempdir", "toml", - "util", "uzers", ] @@ -1275,20 +1289,6 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" -[[package]] -name = "util" -version = "0.9.9" -dependencies = [ - "chrono", - "log", - "pam-bindings", - "sysinfo", - "syslog", - "tempdir", - "toml", - "uzers", -] - [[package]] name = "uzers" version = "0.11.3" @@ -1582,7 +1582,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7e2c411759b501fb9501aac2b1b2d287a6e93e5bdcf13c25306b23e1b716dd0e" [[package]] -name = "xtask-test-integration" +name = "xtask-integration-test" version = "0.9.9" dependencies = [ "anyhow", diff --git a/Cargo.toml b/Cargo.toml index 8f54021..627e53d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [workspace] resolver= "2" -members = [ "crates/lib", "crates/cli", "crates/util", "crates/xtask-test-integration" ] +members = [ "crates/lib", "crates/cli", "crates/common", "crates/xtask-integration-test" ] [workspace.package] edition = "2021" diff --git a/README.md b/README.md index bca7766..5acdcf3 100644 --- a/README.md +++ b/README.md @@ -96,10 +96,25 @@ delay = r * (f - f₀) * log(f - f₀) + b ``` ### Reset user -The cli uses the reads the same configuration in `authramp.conf` -To reset the user use the `authramp` command: +The cli uses the reads the same configuration in `authramp.conf`. ```console -sudo authramp reset --user + + █████ ██ ████████████ ████████ █████ ███ █████████ +██ ████ ██ ██ ██ ████ ████ ██████ ██████ ██ +█████████ ██ ██ █████████████ █████████ ████ ████████ +██ ████ ██ ██ ██ ████ ████ ████ ██ ████ +██ ██ ██████ ██ ██ ████ ████ ████ ████ + +by 34n0@immerda.ch + +Usage: authramp [COMMAND] + +Commands: + reset Reset a locked PAM user + help Print this message or the help of the given subcommand(s) + +Options: + -h, --help Print help ``` ## Logging diff --git a/crates/cli/Cargo.toml b/crates/cli/Cargo.toml index ee411d2..4da9ab8 100644 --- a/crates/cli/Cargo.toml +++ b/crates/cli/Cargo.toml @@ -17,7 +17,7 @@ doc = false clap = { workspace = true, features = ["derive"] } colored.workspace = true log.workspace = true -util = { path = "../util" } +common = { path = "../common" } [dev-dependencies] tempdir.workspace = true diff --git a/crates/cli/src/cmd/reset.rs b/crates/cli/src/cmd/reset.rs index 38d97ad..341326f 100644 --- a/crates/cli/src/cmd/reset.rs +++ b/crates/cli/src/cmd/reset.rs @@ -23,8 +23,8 @@ //! along with this program. If not, see . use colored::Colorize; +use common::config::Config; use std::{fs, path::PathBuf}; -use util::config::Config; use crate::{ArCliError, ArCliInfo, ArCliResult as Acr, ArCliSuccess}; diff --git a/crates/cli/src/main.rs b/crates/cli/src/main.rs index 1b3a35e..dc1a7ce 100644 --- a/crates/cli/src/main.rs +++ b/crates/cli/src/main.rs @@ -48,8 +48,8 @@ use clap::{Parser, Subcommand}; use cmd::reset; use colored::Colorize; +use common::{log_error, log_info, util::syslog}; use std::fmt; -use util::{log_error, log_info, syslog}; mod cmd; const BANNER: &str = r" diff --git a/crates/util/Cargo.toml b/crates/common/Cargo.toml similarity index 93% rename from crates/util/Cargo.toml rename to crates/common/Cargo.toml index f061c9f..983dece 100644 --- a/crates/util/Cargo.toml +++ b/crates/common/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "util" +name = "common" edition.workspace = true version.workspace = true description.workspace = true @@ -9,7 +9,7 @@ homepage.workspace = true repository.workspace = true [lib] -name = "util" +name = "common" path = "src/lib.rs" doc = false diff --git a/crates/util/src/types.rs b/crates/common/src/actions.rs similarity index 95% rename from crates/util/src/types.rs rename to crates/common/src/actions.rs index 96e0076..472dc41 100644 --- a/crates/util/src/types.rs +++ b/crates/common/src/actions.rs @@ -30,10 +30,9 @@ //! along with this program. If not, see . // Action argument defines position in PAM stack -#[derive(Debug, Default, Clone, Copy, PartialEq)] +#[derive(Debug, Clone, Copy, PartialEq)] pub enum Actions { PREAUTH, AUTHSUCC, - #[default] AUTHFAIL, } diff --git a/crates/util/src/config.rs b/crates/common/src/config.rs similarity index 100% rename from crates/util/src/config.rs rename to crates/common/src/config.rs diff --git a/crates/util/src/lib.rs b/crates/common/src/lib.rs similarity index 83% rename from crates/util/src/lib.rs rename to crates/common/src/lib.rs index 6b324a6..f296f7d 100644 --- a/crates/util/src/lib.rs +++ b/crates/common/src/lib.rs @@ -1,6 +1,6 @@ -//! # `AuthRamp` Utility Crate +//! # `AuthRamp` Common Crate //! -//! The `util` crate provides utility modules and functionality used across the `AuthRamp` library, +//! The `common` crate provides types, utility modules and functionality used across the `AuthRamp` library, //! including configuration management, settings handling, syslog initialization, and custom types. //! //! # Modules @@ -23,10 +23,10 @@ //! and the CLI binary. It ensures that log messages are sent to the appropriate syslog facility, //! making it easy to monitor `AuthRamp` activity. //! -//! ## `types` +//! ## `actions` //! -//! The `types` module defines custom types and enumerations used across the `AuthRamp` library. -//! It includes types such as `Actions` and other utility types. +//! The `actions` module defines Action type which represents the current parameter with which the +//! library is called. //! //! ## License //! @@ -46,7 +46,7 @@ //! You should have received a copy of the GNU General Public License //! along with this program. If not, see . +pub mod actions; pub mod config; pub mod settings; -pub mod syslog; -pub mod types; +pub mod util; diff --git a/crates/util/src/settings.rs b/crates/common/src/settings.rs similarity index 99% rename from crates/util/src/settings.rs rename to crates/common/src/settings.rs index 40dc95f..11602e6 100644 --- a/crates/util/src/settings.rs +++ b/crates/common/src/settings.rs @@ -25,9 +25,9 @@ //! You should have received a copy of the GNU General Public License //! along with this program. If not, see . +use crate::actions::Actions; use crate::config::Config; use crate::log_info; -use crate::types::Actions; use pam::constants::{PamFlag, PamResultCode}; use std::collections::HashMap; use std::ffi::CStr; diff --git a/crates/common/src/util/mod.rs b/crates/common/src/util/mod.rs new file mode 100644 index 0000000..432e473 --- /dev/null +++ b/crates/common/src/util/mod.rs @@ -0,0 +1,29 @@ +//! # `AuthRamp` Util Crate +//! +//! General utilities. +//! +//! ## `syslog` +//! +//! The `syslog` module provides functionality for initializing syslog logging in both the PAM module +//! and the CLI binary. It ensures that log messages are sent to the appropriate syslog facility, +//! making it easy to monitor `AuthRamp` activity. +//! +//! ## License +//! +//! pam-authramp +//! Copyright (C) 2023 github.com/34N0 +//! +//! This program is free software: you can redistribute it and/or modify +//! it under the terms of the GNU General Public License as published by +//! the Free Software Foundation, either version 3 of the License, or +//! (at your option) any later version. +//! +//! This program is distributed in the hope that it will be useful, +//! but WITHOUT ANY WARRANTY; without even the implied warranty of +//! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//! GNU General Public License for more details. +//! +//! You should have received a copy of the GNU General Public License +//! along with this program. If not, see . + +pub mod syslog; diff --git a/crates/util/src/syslog.rs b/crates/common/src/util/syslog.rs similarity index 95% rename from crates/util/src/syslog.rs rename to crates/common/src/util/syslog.rs index ae9c61d..eb3d92d 100644 --- a/crates/util/src/syslog.rs +++ b/crates/common/src/util/syslog.rs @@ -168,8 +168,8 @@ macro_rules! log_info { ($($arg:tt)*) => { { unsafe { - if $crate::syslog::SYSLOG_STATE.logger_initialized { - if let Some(ref pre_log) = $crate::syslog::SYSLOG_STATE.pre_log { + if $crate::util::syslog::SYSLOG_STATE.logger_initialized { + if let Some(ref pre_log) = $crate::util::syslog::SYSLOG_STATE.pre_log { log::info!("{}: {}", pre_log, format_args!($($arg)*)); } } @@ -187,8 +187,8 @@ macro_rules! log_error { ($($arg:tt)*) => { { unsafe { - if $crate::syslog::SYSLOG_STATE.logger_initialized { - if let Some(ref pre_log) = $crate::syslog::SYSLOG_STATE.pre_log { + if $crate::util::syslog::SYSLOG_STATE.logger_initialized { + if let Some(ref pre_log) = $crate::util::syslog::SYSLOG_STATE.pre_log { log::error!("{}: {}", pre_log, format_args!($($arg)*)); } } diff --git a/crates/lib/Cargo.toml b/crates/lib/Cargo.toml index 6cc3ba5..950cb4f 100644 --- a/crates/lib/Cargo.toml +++ b/crates/lib/Cargo.toml @@ -20,7 +20,7 @@ libc.workspace = true log.workspace = true pam-bindings.workspace = true toml.workspace = true -util = { path = "../util" } +common = { path = "../common" } uzers.workspace = true [dev-dependencies] diff --git a/crates/lib/src/lib.rs b/crates/lib/src/lib.rs index ce27967..49a5f01 100644 --- a/crates/lib/src/lib.rs +++ b/crates/lib/src/lib.rs @@ -50,15 +50,15 @@ mod tally; use chrono::{Duration, Utc}; +use common::actions::Actions; +use common::settings::Settings; +use common::{log_error, log_info}; use pam::constants::{PamFlag, PamResultCode, PAM_TEXT_INFO}; use pam::conv::Conv; use pam::module::{PamHandle, PamHooks}; use pam::pam_try; use std::cmp::min; use std::ffi::CStr; -use util::settings::Settings; -use util::types::Actions; -use util::{log_error, log_info}; use uzers::get_user_by_name; use tally::Tally; @@ -154,7 +154,7 @@ where // Read configuration file let settings = Settings::build(user.clone(), args, flags, pam_hook_desc)?; - util::syslog::init_pam_log(pamh, &settings)?; + common::util::syslog::init_pam_log(pamh, &settings)?; // Get and Set tally let tally = Tally::new_from_tally_file(&settings)?; diff --git a/crates/lib/src/tally.rs b/crates/lib/src/tally.rs index 313a1a3..eff4612 100644 --- a/crates/lib/src/tally.rs +++ b/crates/lib/src/tally.rs @@ -43,10 +43,10 @@ use std::{ }; use chrono::{DateTime, Duration, Utc}; +use common::actions::Actions; +use common::settings::Settings; +use common::{log_error, log_info}; use pam::constants::PamResultCode; -use util::settings::Settings; -use util::types::Actions; -use util::{log_error, log_info}; use uzers::User; /// The `Tally` struct represents the account lockout information, including @@ -320,7 +320,7 @@ mod tests { use tempdir::TempDir; use uzers::User; - use util::config::Config; + use common::config::Config; #[test] fn test_open_existing_tally_file() { diff --git a/crates/xtask-test-integration/Cargo.toml b/crates/xtask-integration-test/Cargo.toml similarity index 85% rename from crates/xtask-test-integration/Cargo.toml rename to crates/xtask-integration-test/Cargo.toml index 565bd7b..fae526e 100644 --- a/crates/xtask-test-integration/Cargo.toml +++ b/crates/xtask-integration-test/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "xtask-test-integration" +name = "xtask-integration-test" edition.workspace = true version.workspace = true publish = false diff --git a/crates/xtask-test-integration/src/main.rs b/crates/xtask-integration-test/src/main.rs similarity index 97% rename from crates/xtask-test-integration/src/main.rs rename to crates/xtask-integration-test/src/main.rs index fe16e98..30e32ff 100644 --- a/crates/xtask-test-integration/src/main.rs +++ b/crates/xtask-integration-test/src/main.rs @@ -39,7 +39,7 @@ const RUNNER: &str = " runner = 'sudo -E'"; const ALIAS: &str = "[alias] \n\ -test-integration = 'run --package xtask-test-integration --'"; +integration-test = 'run --package xtask-integration-test --'"; /// Sets specific Cargo configurations and executes a closure that performs additional tasks. ///