Mercurial > crates > nonstick
comparison libpam-sys/libpam-sys-consts/README.md @ 148:4b3a5095f68c
Move libpam-sys helpers into their own library.
- Renames libpam-sys-helpers to libpam-sys-consts.
- Moves libpam-sys-helpers::helpers into libpam-sys-helpers,
which moves them completely out of libpam-sys's dependency chain.
- Moves the aliases from libpam-sys into libpam-sys::aliases.
| author | Paul Fisher <paul@pfish.zone> |
|---|---|
| date | Mon, 07 Jul 2025 12:11:43 -0400 |
| parents | |
| children | d5b7b28d754e |
comparison
equal
deleted
inserted
replaced
| 147:4d7333337569 | 148:4b3a5095f68c |
|---|---|
| 1 # `libpam-sys-consts`: Constants for LibPAM | |
| 2 | |
| 3 This crate does two primary things: | |
| 4 | |
| 5 - Detects which implementation of LibPAM the current machine uses (as part of the build script), and exports that information to downstream crates. | |
| 6 - Exports the constants specific to that version of LibPAM. | |
| 7 These are located in the `constants` module. | |
| 8 | |
| 9 ## Handling different PAM implmementations | |
| 10 | |
| 11 Different PAM implementations have different constants and some different behaviors. | |
| 12 If you need to change your library's behavior based on PAM implementation, there are a few ways to do so. | |
| 13 | |
| 14 ### Constants | |
| 15 | |
| 16 The current PAM implementation is available in `PamImpl::CURRENT`. | |
| 17 This is present as a string literal macro in `pam_impl_name!`. | |
| 18 | |
| 19 ### Conditional compilation | |
| 20 | |
| 21 This package provides custom `#[cfg]`s to compile based on the current PAM implementation. | |
| 22 | |
| 23 First, **enable custom `#[cfg]`s in your build.rs**: | |
| 24 | |
| 25 ```rust | |
| 26 // build.rs | |
| 27 use libpam_sys_helpers::pam_impl; | |
| 28 | |
| 29 fn main() { | |
| 30 pam_impl::enable_pam_impl_cfg(); | |
| 31 | |
| 32 // everything else you do at build time | |
| 33 } | |
| 34 ``` | |
| 35 | |
| 36 This will then allow you to use the `pam_impl` configuration variable at compile time: | |
| 37 | |
| 38 ```rust | |
| 39 #[cfg(pam_impl = "LinuxPam")] | |
| 40 fn handle_pam() { | |
| 41 // do things in a Linux-PAM specific way | |
| 42 } | |
| 43 | |
| 44 #[cfg(not(pam_impl = "LinuxPam"))] | |
| 45 fn handle_pam() { | |
| 46 // do things in another, more different way | |
| 47 } | |
| 48 ``` | |
| 49 | |
| 50 ## Configuration | |
| 51 | |
| 52 By default, this crate automatically detects your libpam version. | |
| 53 Known implementations are listed in the `PamImpl` enum. | |
| 54 | |
| 55 You can override this **at build time** by setting the `LIBPAMSYS_IMPL` environment variable to one of those names. | |
| 56 For example, `LIBPAMSYS_IMPL=OpenPam cargo build` will build this library for OpenPAM. | |
| 57 | |
| 58 ## MSRV | |
| 59 | |
| 60 This library supports **Rust 1.75**, as the version currently (July 2025) available in Debian Trixie and Ubuntu 24.04 LTS. |
