annotate libpam-sys/libpam-sys-impls/src/lib.rs @ 190:995aca290452

Restructure the way libpam-sys-impls works to fix cross-compilation. The previous structure of libpam-sys-impls meant that things got confusing (including for me) between what constants were build-time and what constants were run-time. This broke cross-compilation. This simplifies the way that works so that `libpam-sys-impls` has *no* build script itself and is intended mostly as a library to be included in other libraries' build scripts (while also exporting the PamImpl enum).
author Paul Fisher <paul@pfish.zone>
date Sat, 02 Aug 2025 18:47:46 -0400
parents 0730f5f2ee2a
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
190
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
1 #![allow(clippy::needless_doctest_main)]
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
2 //! An enumeration of PAM implementations and tools to detect them.
176
0730f5f2ee2a Turn `libpam-sys-consts` back into `libpam-sys-impls`.
Paul Fisher <paul@pfish.zone>
parents: 161
diff changeset
3 //!
190
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
4 //! # Configuration
176
0730f5f2ee2a Turn `libpam-sys-consts` back into `libpam-sys-impls`.
Paul Fisher <paul@pfish.zone>
parents: 161
diff changeset
5 //!
190
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
6 //! When used at compile time, this crate uses the target OS by default,
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
7 //! but can be overridden with the `LIBPAMSYS_IMPL` environment variable.
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
8 //! See the documentation of [`build_target_impl`] for details.
176
0730f5f2ee2a Turn `libpam-sys-consts` back into `libpam-sys-impls`.
Paul Fisher <paul@pfish.zone>
parents: 161
diff changeset
9 //!
190
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
10 //! # Detecting PAM
176
0730f5f2ee2a Turn `libpam-sys-consts` back into `libpam-sys-impls`.
Paul Fisher <paul@pfish.zone>
parents: 161
diff changeset
11 //!
190
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
12 //! ## Build time
176
0730f5f2ee2a Turn `libpam-sys-consts` back into `libpam-sys-impls`.
Paul Fisher <paul@pfish.zone>
parents: 161
diff changeset
13 //!
0730f5f2ee2a Turn `libpam-sys-consts` back into `libpam-sys-impls`.
Paul Fisher <paul@pfish.zone>
parents: 161
diff changeset
14 //! Use [`enable_pam_impl_cfg`] in your `build.rs` to generate custom `#[cfg]`s
0730f5f2ee2a Turn `libpam-sys-consts` back into `libpam-sys-impls`.
Paul Fisher <paul@pfish.zone>
parents: 161
diff changeset
15 //! for conditional compilation based on PAM implementation.
0730f5f2ee2a Turn `libpam-sys-consts` back into `libpam-sys-impls`.
Paul Fisher <paul@pfish.zone>
parents: 161
diff changeset
16 //!
190
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
17 //! To detect the implementation that will be used at runtime, use the
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
18 //! [`build_target_impl`] function.
176
0730f5f2ee2a Turn `libpam-sys-consts` back into `libpam-sys-impls`.
Paul Fisher <paul@pfish.zone>
parents: 161
diff changeset
19 //!
190
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
20 //! ## Run time
176
0730f5f2ee2a Turn `libpam-sys-consts` back into `libpam-sys-impls`.
Paul Fisher <paul@pfish.zone>
parents: 161
diff changeset
21 //!
190
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
22 //! The implementation of PAM installed on the machine where the code is running
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
23 //! can be detected with [`currently_installed`], or you can use
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
24 //! [`os_default`] to see what implementation is used on a given target.
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
25
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
26 use std::env;
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
27 use std::env::VarError;
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
28 use std::ffi::c_void;
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
29 use std::ptr::NonNull;
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
30
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
31 /// An enum that knows its own values.
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
32 macro_rules! self_aware_enum {
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
33 (
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
34 $(#[$enumeta:meta])*
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
35 $viz:vis enum $name:ident {
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
36 $(
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
37 $(#[$itemeta:meta])*
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
38 $item:ident,
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
39 )*
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
40 }
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
41 ) => {
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
42 $(#[$enumeta])*
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
43 $viz enum $name {
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
44 $(
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
45 $(#[$itemeta])*
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
46 $item,
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
47 )*
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
48 }
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
49
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
50 // The implementations in this block are private for now
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
51 // to avoid putting a contract into the public API.
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
52 #[allow(dead_code)]
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
53 impl $name {
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
54 /// Iterator over the items in the enum. For internal use.
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
55 pub(crate) fn items() -> Vec<Self> {
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
56 vec![$(Self::$item),*]
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
57 }
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
58
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
59 /// Attempts to parse the enum from the string. For internal use.
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
60 pub(crate) fn try_from(value: &str) -> Result<Self, String> {
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
61 match value {
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
62 $(stringify!($item) => Ok(Self::$item),)*
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
63 _ => Err(value.into()),
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
64 }
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
65 }
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
66 }
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
67 };
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
68 }
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
69
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
70 self_aware_enum! {
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
71 /// The PAM implementations supported by `libpam-sys`.
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
72 #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
73 #[non_exhaustive]
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
74 pub enum PamImpl {
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
75 /// [Linux-PAM] is provided by most Linux distributions.
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
76 ///
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
77 /// [Linux-PAM]: https://github.com/linux-pam/linux-pam
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
78 LinuxPam,
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
79 /// [OpenPAM] is used by most BSDs, including Mac OS X.
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
80 ///
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
81 /// [OpenPAM]: https://git.des.dev/OpenPAM/OpenPAM
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
82 OpenPam,
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
83 /// Illumos and Solaris use a derivative of [Sun's implementation][sun].
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
84 ///
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
85 /// [sun]: https://code.illumos.org/plugins/gitiles/illumos-gate/+/refs/heads/master/usr/src/lib/libpam
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
86 Sun,
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
87 /// Only the functionality and constants in [the PAM spec].
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
88 ///
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
89 /// [the PAM spec]: https://pubs.opengroup.org/onlinepubs/8329799/toc.htm
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
90 XSso,
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
91 }
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
92 }
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
93
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
94 #[allow(clippy::needless_doctest_main)]
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
95 /// Generates `cargo` directives for build scripts to enable `cfg(pam_impl)`.
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
96 ///
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
97 /// Print this in your `build.rs` script to be able to use the custom `pam_impl`
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
98 /// configuration directive.
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
99 ///
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
100 /// ```
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
101 /// // Your package's build.rs:
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
102 ///
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
103 /// fn main() {
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
104 /// // Also available at libpam_sys::pam_impl::enable_pam_impl_cfg().
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
105 /// libpam_sys_impls::enable_pam_impl_cfg();
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
106 /// // whatever else you do in your build script.
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
107 /// }
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
108 /// ```
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
109 ///
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
110 /// This will set the current `pam_impl` as well as registering all known
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
111 /// PAM implementations with `rustc-check-cfg` to get cfg-checking.
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
112 ///
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
113 /// The names that appear in the `cfg` variables are the same as the values
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
114 /// in the [`PamImpl`] enum.
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
115 ///
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
116 /// ```ignore
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
117 /// #[cfg(pam_impl = "OpenPam")]
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
118 /// fn openpam_specific_func(handle: *const libpam_sys::pam_handle) {
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
119 /// let environ = libpam_sys::pam_getenvlist(handle);
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
120 /// // ...
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
121 /// libpam_sys::openpam_free_envlist()
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
122 /// }
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
123 ///
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
124 /// // This will give you a warning since "UnknownImpl" is not a known
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
125 /// // PAM implementation.
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
126 /// #[cfg(not(pam_impl = "UnknownImpl"))]
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
127 /// fn do_something() {
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
128 /// // ...
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
129 /// }
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
130 /// ```
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
131 pub fn enable_pam_impl_cfg() {
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
132 println!("{}", pam_impl_cfg_string())
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
133 }
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
134
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
135 /// [`enable_pam_impl_cfg`], but returned as a string.
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
136 pub fn pam_impl_cfg_string() -> String {
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
137 generate_cfg(build_target_impl())
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
138 }
118
39760dfc9b3b Detect PAM library based only on system lib; rename minimal lib to XSso.
Paul Fisher <paul@pfish.zone>
parents: 117
diff changeset
139
190
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
140 fn generate_cfg(pam_impl: Option<PamImpl>) -> String {
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
141 let impls: Vec<_> = PamImpl::items()
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
142 .into_iter()
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
143 .map(|i| format!(r#""{i:?}""#))
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
144 .collect();
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
145 let mut lines = vec![
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
146 format!(
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
147 "cargo:rustc-check-cfg=cfg(pam_impl, values({impls}))",
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
148 impls = impls.join(",")
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
149 ),
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
150 "cargo:rustc-cfg=pam_impl".into(),
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
151 ];
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
152 if let Some(pam_impl) = pam_impl {
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
153 lines.push("cargo:rustc-cfg=pam_impl".into());
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
154 lines.push(format!("cargo:rustc-cfg=pam_impl=\"{pam_impl:?}\""));
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
155 }
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
156 lines.join("\n")
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
157 }
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
158
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
159 /// The strategy to use to detect PAM.
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
160 enum Detect {
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
161 /// Use the default PAM implementation based on the target OS.
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
162 TargetDefault,
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
163 /// Detect the installed implementation.
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
164 Installed,
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
165 /// Use the named version of PAM.
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
166 Specified(PamImpl),
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
167 }
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
168
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
169 const INSTALLED: &str = "__installed__";
118
39760dfc9b3b Detect PAM library based only on system lib; rename minimal lib to XSso.
Paul Fisher <paul@pfish.zone>
parents: 117
diff changeset
170
190
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
171 /// For `build.rs` use: Detects the PAM implementation that should be used
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
172 /// for the target of the currently-running build script.
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
173 ///
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
174 /// # Configuration
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
175 ///
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
176 /// The PAM implementation selected depends upon the value of the
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
177 /// `LIBPAMSYS_IMPL` environment variable.
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
178 ///
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
179 /// - Empty or unset (default): Use the default PAM implementation for the
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
180 /// Cargo target OS (as specified by `CARGO_CFG_TARGET_OS`).
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
181 /// - Linux: Linux-PAM
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
182 /// - BSD (and Mac): OpenPAM
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
183 /// - Illumos/Solaris: Sun PAM
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
184 /// - `__installed__`: Use the PAM implementation installed on the host system.
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
185 /// This opens the `libpam` library and looks for specific functions.
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
186 /// - The name of a [PamImpl] member: Use that PAM implementation.
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
187 ///
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
188 /// # Panics
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
189 ///
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
190 /// If an unknown PAM implementation is provided in `LIBPAMSYS_IMPL`.
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
191 pub fn build_target_impl() -> Option<PamImpl> {
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
192 let detection = match env::var("LIBPAMSYS_IMPL").as_deref() {
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
193 Ok("") | Err(VarError::NotPresent) => Detect::TargetDefault,
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
194 Ok(INSTALLED) => Detect::Installed,
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
195 Ok(val) => Detect::Specified(PamImpl::try_from(val).unwrap_or_else(|_| {
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
196 panic!(
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
197 "unknown PAM implementation {val:?}. \
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
198 valid LIBPAMSYS_IMPL values are {:?}, \
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
199 {INSTALLED:?} to use the currently-installed version, \
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
200 or unset to use the OS default",
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
201 PamImpl::items()
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
202 )
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
203 })),
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
204 Err(other) => panic!("Couldn't detect PAM version: {other}"),
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
205 };
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
206 match detection {
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
207 Detect::TargetDefault => env::var("CARGO_CFG_TARGET_OS")
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
208 .ok()
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
209 .as_deref()
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
210 .and_then(os_default),
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
211 Detect::Installed => currently_installed(),
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
212 Detect::Specified(other) => Some(other),
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
213 }
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
214 }
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
215
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
216 /// Gets the PAM version based on the target OS.
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
217 ///
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
218 /// The target OS name passed in is one of the [Cargo target OS values][os].
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
219 ///
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
220 /// [os]: https://doc.rust-lang.org/reference/conditional-compilation.html#r-cfg.target_os.values
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
221 pub fn os_default(target_os: &str) -> Option<PamImpl> {
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
222 match target_os {
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
223 "linux" => Some(PamImpl::LinuxPam),
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
224 "macos" | "freebsd" | "netbsd" | "dragonfly" | "openbsd" => Some(PamImpl::OpenPam),
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
225 "illumos" | "solaris" => Some(PamImpl::Sun),
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
226 _ => None,
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
227 }
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
228 }
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
229
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
230 /// The version of LibPAM installed on this machine (as found by `dlopen`).
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
231 pub fn currently_installed() -> Option<PamImpl> {
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
232 LibPam::open().map(|lib| {
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
233 if lib.has(b"pam_syslog\0") {
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
234 PamImpl::LinuxPam
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
235 } else if lib.has(b"_openpam_log\0") {
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
236 PamImpl::OpenPam
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
237 } else if lib.has(b"__pam_get_authtok\0") {
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
238 PamImpl::Sun
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
239 } else {
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
240 PamImpl::XSso
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
241 }
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
242 })
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
243 }
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
244
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
245 struct LibPam(NonNull<c_void>);
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
246
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
247 impl LibPam {
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
248 fn open() -> Option<Self> {
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
249 let dlopen = |s: &[u8]| unsafe { libc::dlopen(s.as_ptr().cast(), libc::RTLD_LAZY) };
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
250 NonNull::new(dlopen(b"libpam.so\0"))
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
251 .or_else(|| NonNull::new(dlopen(b"libpam.dylib\0")))
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
252 .map(Self)
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
253 }
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
254
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
255 fn has(&self, name: &[u8]) -> bool {
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
256 let symbol = unsafe { libc::dlsym(self.0.as_ptr(), name.as_ptr().cast()) };
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
257 !symbol.is_null()
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
258 }
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
259 }
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
260
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
261 impl Drop for LibPam {
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
262 fn drop(&mut self) {
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
263 unsafe {
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
264 libc::dlclose(self.0.as_ptr());
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
265 }
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
266 }
995aca290452 Restructure the way libpam-sys-impls works to fix cross-compilation.
Paul Fisher <paul@pfish.zone>
parents: 176
diff changeset
267 }