15 releases

Uses old Rust 2015

0.5.4 Feb 9, 2024
0.5.3 Sep 1, 2023
0.5.2 May 2, 2022
0.5.1 Mar 27, 2022
0.1.0 Jun 25, 2017

#148 in Authentication

Download history 36/week @ 2023-12-29 25/week @ 2024-01-05 60/week @ 2024-01-12 8/week @ 2024-01-19 14/week @ 2024-01-26 9/week @ 2024-02-02 14/week @ 2024-02-09 141/week @ 2024-02-16 76/week @ 2024-02-23 34/week @ 2024-03-01 15/week @ 2024-03-08 22/week @ 2024-03-15 6/week @ 2024-03-22 64/week @ 2024-03-29 8/week @ 2024-04-05 10/week @ 2024-04-12

89 downloads per month
Used in shavee_pam

GPL-3.0 license

30KB
540 lines

PAM SM

Crates.io version shield Crates.io license shield

Rust FFI wrapper to implement PAM service modules for Linux.

Documentation - Cargo - Repository

Features

This crate supports the following optional features:

  • libpam: this enables the extension trait PamLibExt and linking against libpam.so for its native implementation.

lib.rs:

PAM Service Module wrappers

Usage

For example, here is a time based authentication module :

#[macro_use] extern crate pamsm;
extern crate time;

use pamsm::{PamServiceModule, Pam, PamFlags, PamError};

struct PamTime;

impl PamServiceModule for PamTime {
    fn authenticate(pamh: Pam, _: PamFlags, args: Vec<String>) -> PamError {
        let hour = time::OffsetDateTime::now_utc().hour();
        if hour != 4 {
            // Only allow authentication when it's 4 AM
            PamError::SUCCESS
        } else {
            PamError::AUTH_ERR
        }
    }
}

pam_module!(PamTime);

Dependencies

~92KB