Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

General refactoring in major release preparations #60

Merged
merged 4 commits into from
Feb 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[alias]
test-integration = 'run --package xtask-test-integration --'
integration-test = 'run --package xtask-integration-test --'
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
34 changes: 17 additions & 17 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
21 changes: 18 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <user>

█████ ██ ████████████ ████████ █████ ███ █████████
██ ████ ██ ██ ██ ████ ████ ██████ ██████ ██
█████████ ██ ██ █████████████ █████████ ████ ████████
██ ████ ██ ██ ██ ████ ████ ████ ██ ████
██ ██ ██████ ██ ██ ████ ████ ████ ████

by [email protected]

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
Expand Down
2 changes: 1 addition & 1 deletion crates/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion crates/cli/src/cmd/reset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
//! along with this program. If not, see <http://www.gnu.org/licenses/>.

use colored::Colorize;
use common::config::Config;
use std::{fs, path::PathBuf};
use util::config::Config;

use crate::{ArCliError, ArCliInfo, ArCliResult as Acr, ArCliSuccess};

Expand Down
2 changes: 1 addition & 1 deletion crates/cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions crates/util/Cargo.toml → crates/common/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "util"
name = "common"
edition.workspace = true
version.workspace = true
description.workspace = true
Expand All @@ -9,7 +9,7 @@ homepage.workspace = true
repository.workspace = true

[lib]
name = "util"
name = "common"
path = "src/lib.rs"
doc = false

Expand Down
3 changes: 1 addition & 2 deletions crates/util/src/types.rs → crates/common/src/actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,9 @@
//! along with this program. If not, see <http://www.gnu.org/licenses/>.

// 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,
}
File renamed without changes.
14 changes: 7 additions & 7 deletions crates/util/src/lib.rs → crates/common/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
//!
Expand All @@ -46,7 +46,7 @@
//! You should have received a copy of the GNU General Public License
//! along with this program. If not, see <http://www.gnu.org/licenses/>.

pub mod actions;
pub mod config;
pub mod settings;
pub mod syslog;
pub mod types;
pub mod util;
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
//! You should have received a copy of the GNU General Public License
//! along with this program. If not, see <http://www.gnu.org/licenses/>.

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;
Expand Down
29 changes: 29 additions & 0 deletions crates/common/src/util/mod.rs
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.

pub mod syslog;
Original file line number Diff line number Diff line change
Expand Up @@ -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)*));
}
}
Expand All @@ -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)*));
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
8 changes: 4 additions & 4 deletions crates/lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)?;
Expand Down
8 changes: 4 additions & 4 deletions crates/lib/src/tally.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "xtask-test-integration"
name = "xtask-integration-test"
edition.workspace = true
version.workspace = true
publish = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
///
Expand Down