Mercurial > crates > nonstick
annotate libpam-sys/libpam-sys-impls/README.md @ 183:4f46681b3f54 default tip
Catch a few stray cargo fmt things.
author | Paul Fisher <paul@pfish.zone> |
---|---|
date | Wed, 30 Jul 2025 18:43:07 -0400 |
parents | 0730f5f2ee2a |
children |
rev | line source |
---|---|
176
0730f5f2ee2a
Turn `libpam-sys-consts` back into `libpam-sys-impls`.
Paul Fisher <paul@pfish.zone>
parents:
162
diff
changeset
|
1 # `libpam-sys-impls`: LibPAM library detection |
0730f5f2ee2a
Turn `libpam-sys-consts` back into `libpam-sys-impls`.
Paul Fisher <paul@pfish.zone>
parents:
162
diff
changeset
|
2 |
0730f5f2ee2a
Turn `libpam-sys-consts` back into `libpam-sys-impls`.
Paul Fisher <paul@pfish.zone>
parents:
162
diff
changeset
|
3 This crate detects what implementation of LibPAM should be used, as part of the build script, and exports that information to downstream crates. |
148
4b3a5095f68c
Move libpam-sys helpers into their own library.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
4 |
162
180237d0b498
Improve README files for libpam-sys and libpam-sys-consts.
Paul Fisher <paul@pfish.zone>
parents:
161
diff
changeset
|
5 This is mostly a backend crate for [libpam-sys](https://crates.io/crates/libpam-sys/). |
180237d0b498
Improve README files for libpam-sys and libpam-sys-consts.
Paul Fisher <paul@pfish.zone>
parents:
161
diff
changeset
|
6 That crate re-exports pretty much everything we provide. |
180237d0b498
Improve README files for libpam-sys and libpam-sys-consts.
Paul Fisher <paul@pfish.zone>
parents:
161
diff
changeset
|
7 In most cases, you can just use that instead of depending upon this directly. |
180237d0b498
Improve README files for libpam-sys and libpam-sys-consts.
Paul Fisher <paul@pfish.zone>
parents:
161
diff
changeset
|
8 |
176
0730f5f2ee2a
Turn `libpam-sys-consts` back into `libpam-sys-impls`.
Paul Fisher <paul@pfish.zone>
parents:
162
diff
changeset
|
9 ## Usage |
148
4b3a5095f68c
Move libpam-sys helpers into their own library.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
10 |
4b3a5095f68c
Move libpam-sys helpers into their own library.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
11 Different PAM implementations have different constants and some different behaviors. |
4b3a5095f68c
Move libpam-sys helpers into their own library.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
12 If you need to change your library's behavior based on PAM implementation, there are a few ways to do so. |
4b3a5095f68c
Move libpam-sys helpers into their own library.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
13 |
4b3a5095f68c
Move libpam-sys helpers into their own library.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
14 ### Constants |
4b3a5095f68c
Move libpam-sys helpers into their own library.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
15 |
162
180237d0b498
Improve README files for libpam-sys and libpam-sys-consts.
Paul Fisher <paul@pfish.zone>
parents:
161
diff
changeset
|
16 You can match on the current PAM implementation at runtime. |
180237d0b498
Improve README files for libpam-sys and libpam-sys-consts.
Paul Fisher <paul@pfish.zone>
parents:
161
diff
changeset
|
17 All known PAM implementations are in the `PamImpl` enumeration, and `PamImpl::CURRENT` is set to the current implementation. |
148
4b3a5095f68c
Move libpam-sys helpers into their own library.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
18 This is present as a string literal macro in `pam_impl_name!`. |
4b3a5095f68c
Move libpam-sys helpers into their own library.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
19 |
4b3a5095f68c
Move libpam-sys helpers into their own library.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
20 ### Conditional compilation |
4b3a5095f68c
Move libpam-sys helpers into their own library.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
21 |
4b3a5095f68c
Move libpam-sys helpers into their own library.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
22 This package provides custom `#[cfg]`s to compile based on the current PAM implementation. |
4b3a5095f68c
Move libpam-sys helpers into their own library.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
23 |
4b3a5095f68c
Move libpam-sys helpers into their own library.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
24 First, **enable custom `#[cfg]`s in your build.rs**: |
4b3a5095f68c
Move libpam-sys helpers into their own library.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
25 |
4b3a5095f68c
Move libpam-sys helpers into their own library.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
26 ```rust |
4b3a5095f68c
Move libpam-sys helpers into their own library.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
27 // build.rs |
176
0730f5f2ee2a
Turn `libpam-sys-consts` back into `libpam-sys-impls`.
Paul Fisher <paul@pfish.zone>
parents:
162
diff
changeset
|
28 use libpam_sys_impls::pam_impl; |
148
4b3a5095f68c
Move libpam-sys helpers into their own library.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
29 |
4b3a5095f68c
Move libpam-sys helpers into their own library.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
30 fn main() { |
4b3a5095f68c
Move libpam-sys helpers into their own library.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
31 pam_impl::enable_pam_impl_cfg(); |
4b3a5095f68c
Move libpam-sys helpers into their own library.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
32 |
4b3a5095f68c
Move libpam-sys helpers into their own library.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
33 // everything else you do at build time |
4b3a5095f68c
Move libpam-sys helpers into their own library.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
34 } |
4b3a5095f68c
Move libpam-sys helpers into their own library.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
35 ``` |
4b3a5095f68c
Move libpam-sys helpers into their own library.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
36 |
4b3a5095f68c
Move libpam-sys helpers into their own library.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
37 This will then allow you to use the `pam_impl` configuration variable at compile time: |
4b3a5095f68c
Move libpam-sys helpers into their own library.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
38 |
4b3a5095f68c
Move libpam-sys helpers into their own library.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
39 ```rust |
4b3a5095f68c
Move libpam-sys helpers into their own library.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
40 #[cfg(pam_impl = "LinuxPam")] |
4b3a5095f68c
Move libpam-sys helpers into their own library.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
41 fn handle_pam() { |
4b3a5095f68c
Move libpam-sys helpers into their own library.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
42 // do things in a Linux-PAM specific way |
4b3a5095f68c
Move libpam-sys helpers into their own library.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
43 } |
4b3a5095f68c
Move libpam-sys helpers into their own library.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
44 |
4b3a5095f68c
Move libpam-sys helpers into their own library.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
45 #[cfg(not(pam_impl = "LinuxPam"))] |
4b3a5095f68c
Move libpam-sys helpers into their own library.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
46 fn handle_pam() { |
4b3a5095f68c
Move libpam-sys helpers into their own library.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
47 // do things in another, more different way |
4b3a5095f68c
Move libpam-sys helpers into their own library.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
48 } |
4b3a5095f68c
Move libpam-sys helpers into their own library.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
49 ``` |
4b3a5095f68c
Move libpam-sys helpers into their own library.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
50 |
4b3a5095f68c
Move libpam-sys helpers into their own library.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
51 ## Configuration |
4b3a5095f68c
Move libpam-sys helpers into their own library.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
52 |
158
d5b7b28d754e
Add `__TARGET_DEFAULT__` PamImpl and set up for docsrs build.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
53 Known implementations of PAM are listed in the `PamImpl` enum, and your currently installed implementation is automatically detected. |
d5b7b28d754e
Add `__TARGET_DEFAULT__` PamImpl and set up for docsrs build.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
54 |
d5b7b28d754e
Add `__TARGET_DEFAULT__` PamImpl and set up for docsrs build.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
55 If you need to configure this, you can override it **at build time** with the `LIBPAMSYS_IMPL` environment variable: |
148
4b3a5095f68c
Move libpam-sys helpers into their own library.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
56 |
160
09dff285ff5e
Switch default PAM detection strategy to target-based.
Paul Fisher <paul@pfish.zone>
parents:
158
diff
changeset
|
57 - Unset or empty (the default): Use the version of PAM most commonly found on the target OS. |
09dff285ff5e
Switch default PAM detection strategy to target-based.
Paul Fisher <paul@pfish.zone>
parents:
158
diff
changeset
|
58 If we don't know what kind of PAM is usually installed on this OS, we fall back to `__installed__`. |
09dff285ff5e
Switch default PAM detection strategy to target-based.
Paul Fisher <paul@pfish.zone>
parents:
158
diff
changeset
|
59 - `__installed__`: Looks at the PAM library installed on the current machine. |
09dff285ff5e
Switch default PAM detection strategy to target-based.
Paul Fisher <paul@pfish.zone>
parents:
158
diff
changeset
|
60 If none is recognized, falls back to `XSso`. |
162
180237d0b498
Improve README files for libpam-sys and libpam-sys-consts.
Paul Fisher <paul@pfish.zone>
parents:
161
diff
changeset
|
61 - The name of a `PamImpl` entry: The named PAM implementation. |
158
d5b7b28d754e
Add `__TARGET_DEFAULT__` PamImpl and set up for docsrs build.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
62 For instance, `LIBPAMSYS_IMPL=OpenPam cargo build` will build this library for OpenPAM. |
148
4b3a5095f68c
Move libpam-sys helpers into their own library.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
63 |
4b3a5095f68c
Move libpam-sys helpers into their own library.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
64 ## MSRV |
4b3a5095f68c
Move libpam-sys helpers into their own library.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
65 |
4b3a5095f68c
Move libpam-sys helpers into their own library.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
66 This library supports **Rust 1.75**, as the version currently (July 2025) available in Debian Trixie and Ubuntu 24.04 LTS. |