Mercurial > crates > nonstick
annotate libpam-sys/libpam-sys-consts/build.rs @ 158:d5b7b28d754e
Add `__TARGET_DEFAULT__` PamImpl and set up for docsrs build.
Also fixes some formatting stuff.
author | Paul Fisher <paul@pfish.zone> |
---|---|
date | Sat, 12 Jul 2025 17:17:37 -0400 |
parents | 4b3a5095f68c |
children | 09dff285ff5e |
rev | line source |
---|---|
134
6c1e1bdb4164
Use standard #[cfg] directives rather than custom proc macros.
Paul Fisher <paul@pfish.zone>
parents:
131
diff
changeset
|
1 #![allow(unexpected_cfgs)] |
127 | 2 |
134
6c1e1bdb4164
Use standard #[cfg] directives rather than custom proc macros.
Paul Fisher <paul@pfish.zone>
parents:
131
diff
changeset
|
3 use std::ffi::{c_void, CString}; |
6c1e1bdb4164
Use standard #[cfg] directives rather than custom proc macros.
Paul Fisher <paul@pfish.zone>
parents:
131
diff
changeset
|
4 use std::ptr::NonNull; |
136
efbc235f01d3
Separate libpam-sys-helpers from libpam-sys.
Paul Fisher <paul@pfish.zone>
parents:
134
diff
changeset
|
5 use std::{env, fs}; |
134
6c1e1bdb4164
Use standard #[cfg] directives rather than custom proc macros.
Paul Fisher <paul@pfish.zone>
parents:
131
diff
changeset
|
6 |
6c1e1bdb4164
Use standard #[cfg] directives rather than custom proc macros.
Paul Fisher <paul@pfish.zone>
parents:
131
diff
changeset
|
7 include!("src/pam_impl.rs"); |
127 | 8 |
158
d5b7b28d754e
Add `__TARGET_DEFAULT__` PamImpl and set up for docsrs build.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
9 /// The strategy to use to detect PAM. |
d5b7b28d754e
Add `__TARGET_DEFAULT__` PamImpl and set up for docsrs build.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
10 enum Detect { |
d5b7b28d754e
Add `__TARGET_DEFAULT__` PamImpl and set up for docsrs build.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
11 /// Automatically detect PAM, using the installed implementation if present |
d5b7b28d754e
Add `__TARGET_DEFAULT__` PamImpl and set up for docsrs build.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
12 /// or the OS default if not. |
d5b7b28d754e
Add `__TARGET_DEFAULT__` PamImpl and set up for docsrs build.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
13 Auto, |
d5b7b28d754e
Add `__TARGET_DEFAULT__` PamImpl and set up for docsrs build.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
14 /// Use the default PAM implementation based on the OS. |
d5b7b28d754e
Add `__TARGET_DEFAULT__` PamImpl and set up for docsrs build.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
15 TargetDefault, |
d5b7b28d754e
Add `__TARGET_DEFAULT__` PamImpl and set up for docsrs build.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
16 /// Use the named version of PAM. |
d5b7b28d754e
Add `__TARGET_DEFAULT__` PamImpl and set up for docsrs build.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
17 Specified(PamImpl), |
d5b7b28d754e
Add `__TARGET_DEFAULT__` PamImpl and set up for docsrs build.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
18 } |
d5b7b28d754e
Add `__TARGET_DEFAULT__` PamImpl and set up for docsrs build.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
19 |
d5b7b28d754e
Add `__TARGET_DEFAULT__` PamImpl and set up for docsrs build.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
20 const TARGET_DEFAULT: &str = "__TARGET_DEFAULT__"; |
d5b7b28d754e
Add `__TARGET_DEFAULT__` PamImpl and set up for docsrs build.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
21 |
106
49d9e2b5c189
An irresponsible mix of implementing libpam-sys and other stuff.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
22 fn main() { |
158
d5b7b28d754e
Add `__TARGET_DEFAULT__` PamImpl and set up for docsrs build.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
23 let detection = match option_env!("LIBPAMSYS_IMPL") { |
d5b7b28d754e
Add `__TARGET_DEFAULT__` PamImpl and set up for docsrs build.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
24 None | Some("") => match option_env!("DOCS_RS") { |
d5b7b28d754e
Add `__TARGET_DEFAULT__` PamImpl and set up for docsrs build.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
25 // docs.rs cross-compiles, so we don't want to look at |
d5b7b28d754e
Add `__TARGET_DEFAULT__` PamImpl and set up for docsrs build.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
26 // its currently-installed PAM; instead we want to use the OS. |
d5b7b28d754e
Add `__TARGET_DEFAULT__` PamImpl and set up for docsrs build.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
27 Some(_) => Detect::TargetDefault, |
d5b7b28d754e
Add `__TARGET_DEFAULT__` PamImpl and set up for docsrs build.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
28 // In other cases, just auto-detect the actual installed library. |
d5b7b28d754e
Add `__TARGET_DEFAULT__` PamImpl and set up for docsrs build.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
29 None => Detect::Auto, |
134
6c1e1bdb4164
Use standard #[cfg] directives rather than custom proc macros.
Paul Fisher <paul@pfish.zone>
parents:
131
diff
changeset
|
30 }, |
158
d5b7b28d754e
Add `__TARGET_DEFAULT__` PamImpl and set up for docsrs build.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
31 Some(TARGET_DEFAULT) => Detect::TargetDefault, |
d5b7b28d754e
Add `__TARGET_DEFAULT__` PamImpl and set up for docsrs build.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
32 Some(val) => Detect::Specified(PamImpl::try_from(val).unwrap_or_else(|_| { |
d5b7b28d754e
Add `__TARGET_DEFAULT__` PamImpl and set up for docsrs build.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
33 panic!( |
d5b7b28d754e
Add `__TARGET_DEFAULT__` PamImpl and set up for docsrs build.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
34 "unknown PAM implementation {val:?}. \ |
d5b7b28d754e
Add `__TARGET_DEFAULT__` PamImpl and set up for docsrs build.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
35 valid LIBPAMSYS_IMPLs are {:?}, \ |
d5b7b28d754e
Add `__TARGET_DEFAULT__` PamImpl and set up for docsrs build.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
36 {TARGET_DEFAULT:?} to use the OS default, \ |
d5b7b28d754e
Add `__TARGET_DEFAULT__` PamImpl and set up for docsrs build.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
37 or unset to detect", |
d5b7b28d754e
Add `__TARGET_DEFAULT__` PamImpl and set up for docsrs build.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
38 PamImpl::items() |
d5b7b28d754e
Add `__TARGET_DEFAULT__` PamImpl and set up for docsrs build.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
39 ) |
d5b7b28d754e
Add `__TARGET_DEFAULT__` PamImpl and set up for docsrs build.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
40 })), |
d5b7b28d754e
Add `__TARGET_DEFAULT__` PamImpl and set up for docsrs build.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
41 }; |
d5b7b28d754e
Add `__TARGET_DEFAULT__` PamImpl and set up for docsrs build.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
42 let pam_impl = match detection { |
d5b7b28d754e
Add `__TARGET_DEFAULT__` PamImpl and set up for docsrs build.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
43 Detect::Auto => LibPam::probe_detect(), |
d5b7b28d754e
Add `__TARGET_DEFAULT__` PamImpl and set up for docsrs build.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
44 Detect::TargetDefault => LibPam::os_default(), |
d5b7b28d754e
Add `__TARGET_DEFAULT__` PamImpl and set up for docsrs build.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
45 Detect::Specified(other) => other, |
134
6c1e1bdb4164
Use standard #[cfg] directives rather than custom proc macros.
Paul Fisher <paul@pfish.zone>
parents:
131
diff
changeset
|
46 }; |
6c1e1bdb4164
Use standard #[cfg] directives rather than custom proc macros.
Paul Fisher <paul@pfish.zone>
parents:
131
diff
changeset
|
47 let impl_str = format!("{pam_impl:?}"); |
136
efbc235f01d3
Separate libpam-sys-helpers from libpam-sys.
Paul Fisher <paul@pfish.zone>
parents:
134
diff
changeset
|
48 println!("{}", generate_cfg(&impl_str)); |
efbc235f01d3
Separate libpam-sys-helpers from libpam-sys.
Paul Fisher <paul@pfish.zone>
parents:
134
diff
changeset
|
49 // We set this environment variable to substitute into docstrings. |
134
6c1e1bdb4164
Use standard #[cfg] directives rather than custom proc macros.
Paul Fisher <paul@pfish.zone>
parents:
131
diff
changeset
|
50 println!("cargo:rustc-env=LIBPAMSYS_IMPL={impl_str}"); |
6c1e1bdb4164
Use standard #[cfg] directives rather than custom proc macros.
Paul Fisher <paul@pfish.zone>
parents:
131
diff
changeset
|
51 fs::write( |
6c1e1bdb4164
Use standard #[cfg] directives rather than custom proc macros.
Paul Fisher <paul@pfish.zone>
parents:
131
diff
changeset
|
52 format!("{}/pam_impl_const.rs", env::var("OUT_DIR").unwrap()), |
136
efbc235f01d3
Separate libpam-sys-helpers from libpam-sys.
Paul Fisher <paul@pfish.zone>
parents:
134
diff
changeset
|
53 generate_consts(&impl_str), |
134
6c1e1bdb4164
Use standard #[cfg] directives rather than custom proc macros.
Paul Fisher <paul@pfish.zone>
parents:
131
diff
changeset
|
54 ) |
6c1e1bdb4164
Use standard #[cfg] directives rather than custom proc macros.
Paul Fisher <paul@pfish.zone>
parents:
131
diff
changeset
|
55 .unwrap(); |
106
49d9e2b5c189
An irresponsible mix of implementing libpam-sys and other stuff.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
56 } |
134
6c1e1bdb4164
Use standard #[cfg] directives rather than custom proc macros.
Paul Fisher <paul@pfish.zone>
parents:
131
diff
changeset
|
57 |
136
efbc235f01d3
Separate libpam-sys-helpers from libpam-sys.
Paul Fisher <paul@pfish.zone>
parents:
134
diff
changeset
|
58 fn generate_consts(impl_str: &str) -> String { |
efbc235f01d3
Separate libpam-sys-helpers from libpam-sys.
Paul Fisher <paul@pfish.zone>
parents:
134
diff
changeset
|
59 format!( |
efbc235f01d3
Separate libpam-sys-helpers from libpam-sys.
Paul Fisher <paul@pfish.zone>
parents:
134
diff
changeset
|
60 "\ |
efbc235f01d3
Separate libpam-sys-helpers from libpam-sys.
Paul Fisher <paul@pfish.zone>
parents:
134
diff
changeset
|
61 impl PamImpl {{ |
efbc235f01d3
Separate libpam-sys-helpers from libpam-sys.
Paul Fisher <paul@pfish.zone>
parents:
134
diff
changeset
|
62 /// The implementation of libpam this was built for (`{impl_str}`). |
efbc235f01d3
Separate libpam-sys-helpers from libpam-sys.
Paul Fisher <paul@pfish.zone>
parents:
134
diff
changeset
|
63 pub const CURRENT: Self = Self::{impl_str}; |
efbc235f01d3
Separate libpam-sys-helpers from libpam-sys.
Paul Fisher <paul@pfish.zone>
parents:
134
diff
changeset
|
64 }} |
efbc235f01d3
Separate libpam-sys-helpers from libpam-sys.
Paul Fisher <paul@pfish.zone>
parents:
134
diff
changeset
|
65 |
efbc235f01d3
Separate libpam-sys-helpers from libpam-sys.
Paul Fisher <paul@pfish.zone>
parents:
134
diff
changeset
|
66 /// String name of [`PamImpl::CURRENT`], for substituting into docs. |
efbc235f01d3
Separate libpam-sys-helpers from libpam-sys.
Paul Fisher <paul@pfish.zone>
parents:
134
diff
changeset
|
67 #[macro_export] |
efbc235f01d3
Separate libpam-sys-helpers from libpam-sys.
Paul Fisher <paul@pfish.zone>
parents:
134
diff
changeset
|
68 macro_rules! pam_impl_name {{ () => ({impl_str:?}) }} |
efbc235f01d3
Separate libpam-sys-helpers from libpam-sys.
Paul Fisher <paul@pfish.zone>
parents:
134
diff
changeset
|
69 " |
efbc235f01d3
Separate libpam-sys-helpers from libpam-sys.
Paul Fisher <paul@pfish.zone>
parents:
134
diff
changeset
|
70 ) |
134
6c1e1bdb4164
Use standard #[cfg] directives rather than custom proc macros.
Paul Fisher <paul@pfish.zone>
parents:
131
diff
changeset
|
71 } |
6c1e1bdb4164
Use standard #[cfg] directives rather than custom proc macros.
Paul Fisher <paul@pfish.zone>
parents:
131
diff
changeset
|
72 |
6c1e1bdb4164
Use standard #[cfg] directives rather than custom proc macros.
Paul Fisher <paul@pfish.zone>
parents:
131
diff
changeset
|
73 struct LibPam(NonNull<c_void>); |
6c1e1bdb4164
Use standard #[cfg] directives rather than custom proc macros.
Paul Fisher <paul@pfish.zone>
parents:
131
diff
changeset
|
74 |
6c1e1bdb4164
Use standard #[cfg] directives rather than custom proc macros.
Paul Fisher <paul@pfish.zone>
parents:
131
diff
changeset
|
75 impl LibPam { |
158
d5b7b28d754e
Add `__TARGET_DEFAULT__` PamImpl and set up for docsrs build.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
76 /// Look at the currently-installed LibPAM, or use [`Self::os_default`] |
d5b7b28d754e
Add `__TARGET_DEFAULT__` PamImpl and set up for docsrs build.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
77 /// if absent. |
d5b7b28d754e
Add `__TARGET_DEFAULT__` PamImpl and set up for docsrs build.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
78 fn probe_detect() -> PamImpl { |
136
efbc235f01d3
Separate libpam-sys-helpers from libpam-sys.
Paul Fisher <paul@pfish.zone>
parents:
134
diff
changeset
|
79 if let Some(lib) = Self::open() { |
efbc235f01d3
Separate libpam-sys-helpers from libpam-sys.
Paul Fisher <paul@pfish.zone>
parents:
134
diff
changeset
|
80 if lib.has("pam_syslog") { |
efbc235f01d3
Separate libpam-sys-helpers from libpam-sys.
Paul Fisher <paul@pfish.zone>
parents:
134
diff
changeset
|
81 return PamImpl::LinuxPam; |
efbc235f01d3
Separate libpam-sys-helpers from libpam-sys.
Paul Fisher <paul@pfish.zone>
parents:
134
diff
changeset
|
82 } else if lib.has("_openpam_log") { |
efbc235f01d3
Separate libpam-sys-helpers from libpam-sys.
Paul Fisher <paul@pfish.zone>
parents:
134
diff
changeset
|
83 return PamImpl::OpenPam; |
efbc235f01d3
Separate libpam-sys-helpers from libpam-sys.
Paul Fisher <paul@pfish.zone>
parents:
134
diff
changeset
|
84 } else if lib.has("__pam_get_authtok") { |
efbc235f01d3
Separate libpam-sys-helpers from libpam-sys.
Paul Fisher <paul@pfish.zone>
parents:
134
diff
changeset
|
85 return PamImpl::Sun; |
efbc235f01d3
Separate libpam-sys-helpers from libpam-sys.
Paul Fisher <paul@pfish.zone>
parents:
134
diff
changeset
|
86 } |
efbc235f01d3
Separate libpam-sys-helpers from libpam-sys.
Paul Fisher <paul@pfish.zone>
parents:
134
diff
changeset
|
87 } |
158
d5b7b28d754e
Add `__TARGET_DEFAULT__` PamImpl and set up for docsrs build.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
88 Self::os_default() |
d5b7b28d754e
Add `__TARGET_DEFAULT__` PamImpl and set up for docsrs build.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
89 } |
d5b7b28d754e
Add `__TARGET_DEFAULT__` PamImpl and set up for docsrs build.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
90 |
d5b7b28d754e
Add `__TARGET_DEFAULT__` PamImpl and set up for docsrs build.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
91 /// Guess the PAM implementation based on the current OS. |
d5b7b28d754e
Add `__TARGET_DEFAULT__` PamImpl and set up for docsrs build.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
92 fn os_default() -> PamImpl { |
136
efbc235f01d3
Separate libpam-sys-helpers from libpam-sys.
Paul Fisher <paul@pfish.zone>
parents:
134
diff
changeset
|
93 if cfg!(target_os = "linux") { |
efbc235f01d3
Separate libpam-sys-helpers from libpam-sys.
Paul Fisher <paul@pfish.zone>
parents:
134
diff
changeset
|
94 PamImpl::LinuxPam |
efbc235f01d3
Separate libpam-sys-helpers from libpam-sys.
Paul Fisher <paul@pfish.zone>
parents:
134
diff
changeset
|
95 } else if cfg!(any( |
efbc235f01d3
Separate libpam-sys-helpers from libpam-sys.
Paul Fisher <paul@pfish.zone>
parents:
134
diff
changeset
|
96 target_os = "macos", |
efbc235f01d3
Separate libpam-sys-helpers from libpam-sys.
Paul Fisher <paul@pfish.zone>
parents:
134
diff
changeset
|
97 target_os = "freebsd", |
efbc235f01d3
Separate libpam-sys-helpers from libpam-sys.
Paul Fisher <paul@pfish.zone>
parents:
134
diff
changeset
|
98 target_os = "netbsd", |
efbc235f01d3
Separate libpam-sys-helpers from libpam-sys.
Paul Fisher <paul@pfish.zone>
parents:
134
diff
changeset
|
99 target_os = "dragonfly", |
efbc235f01d3
Separate libpam-sys-helpers from libpam-sys.
Paul Fisher <paul@pfish.zone>
parents:
134
diff
changeset
|
100 target_os = "openbsd", |
efbc235f01d3
Separate libpam-sys-helpers from libpam-sys.
Paul Fisher <paul@pfish.zone>
parents:
134
diff
changeset
|
101 )) { |
efbc235f01d3
Separate libpam-sys-helpers from libpam-sys.
Paul Fisher <paul@pfish.zone>
parents:
134
diff
changeset
|
102 PamImpl::OpenPam |
efbc235f01d3
Separate libpam-sys-helpers from libpam-sys.
Paul Fisher <paul@pfish.zone>
parents:
134
diff
changeset
|
103 } else if cfg!(any(target_os = "illumos", target_os = "solaris")) { |
efbc235f01d3
Separate libpam-sys-helpers from libpam-sys.
Paul Fisher <paul@pfish.zone>
parents:
134
diff
changeset
|
104 PamImpl::Sun |
efbc235f01d3
Separate libpam-sys-helpers from libpam-sys.
Paul Fisher <paul@pfish.zone>
parents:
134
diff
changeset
|
105 } else { |
efbc235f01d3
Separate libpam-sys-helpers from libpam-sys.
Paul Fisher <paul@pfish.zone>
parents:
134
diff
changeset
|
106 PamImpl::XSso |
efbc235f01d3
Separate libpam-sys-helpers from libpam-sys.
Paul Fisher <paul@pfish.zone>
parents:
134
diff
changeset
|
107 } |
efbc235f01d3
Separate libpam-sys-helpers from libpam-sys.
Paul Fisher <paul@pfish.zone>
parents:
134
diff
changeset
|
108 } |
efbc235f01d3
Separate libpam-sys-helpers from libpam-sys.
Paul Fisher <paul@pfish.zone>
parents:
134
diff
changeset
|
109 |
134
6c1e1bdb4164
Use standard #[cfg] directives rather than custom proc macros.
Paul Fisher <paul@pfish.zone>
parents:
131
diff
changeset
|
110 fn open() -> Option<Self> { |
158
d5b7b28d754e
Add `__TARGET_DEFAULT__` PamImpl and set up for docsrs build.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
111 let dlopen = |s: &[u8]| unsafe { libc::dlopen(s.as_ptr().cast(), libc::RTLD_LAZY) }; |
d5b7b28d754e
Add `__TARGET_DEFAULT__` PamImpl and set up for docsrs build.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
112 NonNull::new(dlopen(b"libpam.so\0")) |
d5b7b28d754e
Add `__TARGET_DEFAULT__` PamImpl and set up for docsrs build.
Paul Fisher <paul@pfish.zone>
parents:
148
diff
changeset
|
113 .or_else(|| NonNull::new(dlopen(b"libpam.dylib\0"))) |
134
6c1e1bdb4164
Use standard #[cfg] directives rather than custom proc macros.
Paul Fisher <paul@pfish.zone>
parents:
131
diff
changeset
|
114 .map(Self) |
6c1e1bdb4164
Use standard #[cfg] directives rather than custom proc macros.
Paul Fisher <paul@pfish.zone>
parents:
131
diff
changeset
|
115 } |
6c1e1bdb4164
Use standard #[cfg] directives rather than custom proc macros.
Paul Fisher <paul@pfish.zone>
parents:
131
diff
changeset
|
116 |
6c1e1bdb4164
Use standard #[cfg] directives rather than custom proc macros.
Paul Fisher <paul@pfish.zone>
parents:
131
diff
changeset
|
117 fn has(&self, name: &str) -> bool { |
6c1e1bdb4164
Use standard #[cfg] directives rather than custom proc macros.
Paul Fisher <paul@pfish.zone>
parents:
131
diff
changeset
|
118 let name = CString::new(name).unwrap(); |
6c1e1bdb4164
Use standard #[cfg] directives rather than custom proc macros.
Paul Fisher <paul@pfish.zone>
parents:
131
diff
changeset
|
119 let symbol = unsafe { libc::dlsym(self.0.as_ptr(), name.as_ptr()) }; |
6c1e1bdb4164
Use standard #[cfg] directives rather than custom proc macros.
Paul Fisher <paul@pfish.zone>
parents:
131
diff
changeset
|
120 !symbol.is_null() |
6c1e1bdb4164
Use standard #[cfg] directives rather than custom proc macros.
Paul Fisher <paul@pfish.zone>
parents:
131
diff
changeset
|
121 } |
6c1e1bdb4164
Use standard #[cfg] directives rather than custom proc macros.
Paul Fisher <paul@pfish.zone>
parents:
131
diff
changeset
|
122 } |
6c1e1bdb4164
Use standard #[cfg] directives rather than custom proc macros.
Paul Fisher <paul@pfish.zone>
parents:
131
diff
changeset
|
123 |
6c1e1bdb4164
Use standard #[cfg] directives rather than custom proc macros.
Paul Fisher <paul@pfish.zone>
parents:
131
diff
changeset
|
124 impl Drop for LibPam { |
6c1e1bdb4164
Use standard #[cfg] directives rather than custom proc macros.
Paul Fisher <paul@pfish.zone>
parents:
131
diff
changeset
|
125 fn drop(&mut self) { |
6c1e1bdb4164
Use standard #[cfg] directives rather than custom proc macros.
Paul Fisher <paul@pfish.zone>
parents:
131
diff
changeset
|
126 unsafe { |
6c1e1bdb4164
Use standard #[cfg] directives rather than custom proc macros.
Paul Fisher <paul@pfish.zone>
parents:
131
diff
changeset
|
127 libc::dlclose(self.0.as_ptr()); |
6c1e1bdb4164
Use standard #[cfg] directives rather than custom proc macros.
Paul Fisher <paul@pfish.zone>
parents:
131
diff
changeset
|
128 } |
6c1e1bdb4164
Use standard #[cfg] directives rather than custom proc macros.
Paul Fisher <paul@pfish.zone>
parents:
131
diff
changeset
|
129 } |
6c1e1bdb4164
Use standard #[cfg] directives rather than custom proc macros.
Paul Fisher <paul@pfish.zone>
parents:
131
diff
changeset
|
130 } |