Mercurial > crates > nonstick
annotate build.rs @ 81:a8f4718fed5d
When dynamically linking against the wrong PAM, fail.
author | Paul Fisher <paul@pfish.zone> |
---|---|
date | Tue, 10 Jun 2025 01:16:39 -0400 |
parents | 5aa1a010f1e8 |
children | 73c3f8e3b49d |
rev | line source |
---|---|
80
5aa1a010f1e8
Start using PAM headers; improve owned/borrowed distinction.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
1 use bindgen::MacroTypeVariation; |
5aa1a010f1e8
Start using PAM headers; improve owned/borrowed distinction.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
2 use std::env; |
5aa1a010f1e8
Start using PAM headers; improve owned/borrowed distinction.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
3 use std::path::PathBuf; |
5aa1a010f1e8
Start using PAM headers; improve owned/borrowed distinction.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
4 |
5aa1a010f1e8
Start using PAM headers; improve owned/borrowed distinction.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
5 fn main() { |
5aa1a010f1e8
Start using PAM headers; improve owned/borrowed distinction.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
6 if cfg!(feature = "link") { |
5aa1a010f1e8
Start using PAM headers; improve owned/borrowed distinction.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
7 println!("cargo::rustc-check-cfg=cfg(pam_impl, values(\"linux-pam\",\"openpam\"))"); |
5aa1a010f1e8
Start using PAM headers; improve owned/borrowed distinction.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
8 let common_builder = bindgen::Builder::default() |
5aa1a010f1e8
Start using PAM headers; improve owned/borrowed distinction.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
9 .merge_extern_blocks(true) |
5aa1a010f1e8
Start using PAM headers; improve owned/borrowed distinction.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
10 .parse_callbacks(Box::new(bindgen::CargoCallbacks::new())) |
5aa1a010f1e8
Start using PAM headers; improve owned/borrowed distinction.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
11 .blocklist_type("pam_handle") |
5aa1a010f1e8
Start using PAM headers; improve owned/borrowed distinction.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
12 .blocklist_type("pam_conv") |
5aa1a010f1e8
Start using PAM headers; improve owned/borrowed distinction.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
13 .allowlist_var(".*") |
5aa1a010f1e8
Start using PAM headers; improve owned/borrowed distinction.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
14 .allowlist_function("pam_start") |
5aa1a010f1e8
Start using PAM headers; improve owned/borrowed distinction.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
15 .allowlist_function("pam_[gs]et_item") |
5aa1a010f1e8
Start using PAM headers; improve owned/borrowed distinction.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
16 .allowlist_function("pam_get_user") |
5aa1a010f1e8
Start using PAM headers; improve owned/borrowed distinction.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
17 .allowlist_function("pam_get_authtok") |
5aa1a010f1e8
Start using PAM headers; improve owned/borrowed distinction.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
18 .allowlist_function("pam_end") |
5aa1a010f1e8
Start using PAM headers; improve owned/borrowed distinction.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
19 .dynamic_link_require_all(true) |
5aa1a010f1e8
Start using PAM headers; improve owned/borrowed distinction.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
20 .default_macro_constant_type(MacroTypeVariation::Signed); |
5aa1a010f1e8
Start using PAM headers; improve owned/borrowed distinction.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
21 |
81
a8f4718fed5d
When dynamically linking against the wrong PAM, fail.
Paul Fisher <paul@pfish.zone>
parents:
80
diff
changeset
|
22 let linux_builder = common_builder |
a8f4718fed5d
When dynamically linking against the wrong PAM, fail.
Paul Fisher <paul@pfish.zone>
parents:
80
diff
changeset
|
23 .clone() |
a8f4718fed5d
When dynamically linking against the wrong PAM, fail.
Paul Fisher <paul@pfish.zone>
parents:
80
diff
changeset
|
24 // This function is not available in OpenPAM. |
a8f4718fed5d
When dynamically linking against the wrong PAM, fail.
Paul Fisher <paul@pfish.zone>
parents:
80
diff
changeset
|
25 // We don't use it, but we include it so that if the user |
a8f4718fed5d
When dynamically linking against the wrong PAM, fail.
Paul Fisher <paul@pfish.zone>
parents:
80
diff
changeset
|
26 // tries to run this against the wrong PAM library, it fails. |
a8f4718fed5d
When dynamically linking against the wrong PAM, fail.
Paul Fisher <paul@pfish.zone>
parents:
80
diff
changeset
|
27 .allowlist_function("pam_start_confdir") |
a8f4718fed5d
When dynamically linking against the wrong PAM, fail.
Paul Fisher <paul@pfish.zone>
parents:
80
diff
changeset
|
28 .header_contents( |
a8f4718fed5d
When dynamically linking against the wrong PAM, fail.
Paul Fisher <paul@pfish.zone>
parents:
80
diff
changeset
|
29 "linux-pam.h", |
a8f4718fed5d
When dynamically linking against the wrong PAM, fail.
Paul Fisher <paul@pfish.zone>
parents:
80
diff
changeset
|
30 r#" |
80
5aa1a010f1e8
Start using PAM headers; improve owned/borrowed distinction.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
31 #include <security/_pam_types.h> |
5aa1a010f1e8
Start using PAM headers; improve owned/borrowed distinction.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
32 #include <security/pam_appl.h> |
5aa1a010f1e8
Start using PAM headers; improve owned/borrowed distinction.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
33 #include <security/pam_ext.h> |
5aa1a010f1e8
Start using PAM headers; improve owned/borrowed distinction.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
34 #include <security/pam_modules.h> |
5aa1a010f1e8
Start using PAM headers; improve owned/borrowed distinction.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
35 "#, |
81
a8f4718fed5d
When dynamically linking against the wrong PAM, fail.
Paul Fisher <paul@pfish.zone>
parents:
80
diff
changeset
|
36 ); |
a8f4718fed5d
When dynamically linking against the wrong PAM, fail.
Paul Fisher <paul@pfish.zone>
parents:
80
diff
changeset
|
37 let openpam_builder = common_builder |
a8f4718fed5d
When dynamically linking against the wrong PAM, fail.
Paul Fisher <paul@pfish.zone>
parents:
80
diff
changeset
|
38 .clone() |
a8f4718fed5d
When dynamically linking against the wrong PAM, fail.
Paul Fisher <paul@pfish.zone>
parents:
80
diff
changeset
|
39 // This function is not available in Linux-PAM. |
a8f4718fed5d
When dynamically linking against the wrong PAM, fail.
Paul Fisher <paul@pfish.zone>
parents:
80
diff
changeset
|
40 // We don't use it, but we include it so that if the user |
a8f4718fed5d
When dynamically linking against the wrong PAM, fail.
Paul Fisher <paul@pfish.zone>
parents:
80
diff
changeset
|
41 // tries to run this against the wrong PAM library, it fails. |
a8f4718fed5d
When dynamically linking against the wrong PAM, fail.
Paul Fisher <paul@pfish.zone>
parents:
80
diff
changeset
|
42 .allowlist_function("pam_setenv") |
a8f4718fed5d
When dynamically linking against the wrong PAM, fail.
Paul Fisher <paul@pfish.zone>
parents:
80
diff
changeset
|
43 .header_contents( |
a8f4718fed5d
When dynamically linking against the wrong PAM, fail.
Paul Fisher <paul@pfish.zone>
parents:
80
diff
changeset
|
44 "openpam.h", |
a8f4718fed5d
When dynamically linking against the wrong PAM, fail.
Paul Fisher <paul@pfish.zone>
parents:
80
diff
changeset
|
45 r#" |
80
5aa1a010f1e8
Start using PAM headers; improve owned/borrowed distinction.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
46 #include <security/openpam.h> |
5aa1a010f1e8
Start using PAM headers; improve owned/borrowed distinction.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
47 #include <security/pam_appl.h> |
5aa1a010f1e8
Start using PAM headers; improve owned/borrowed distinction.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
48 #include <security/pam_constants.h> |
5aa1a010f1e8
Start using PAM headers; improve owned/borrowed distinction.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
49 #include <security/pam_types.h> |
5aa1a010f1e8
Start using PAM headers; improve owned/borrowed distinction.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
50 "#, |
81
a8f4718fed5d
When dynamically linking against the wrong PAM, fail.
Paul Fisher <paul@pfish.zone>
parents:
80
diff
changeset
|
51 ); |
80
5aa1a010f1e8
Start using PAM headers; improve owned/borrowed distinction.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
52 |
5aa1a010f1e8
Start using PAM headers; improve owned/borrowed distinction.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
53 let (pam_impl, bindings) = { |
5aa1a010f1e8
Start using PAM headers; improve owned/borrowed distinction.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
54 let bb = linux_builder.generate(); |
5aa1a010f1e8
Start using PAM headers; improve owned/borrowed distinction.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
55 bb.as_ref().unwrap(); |
5aa1a010f1e8
Start using PAM headers; improve owned/borrowed distinction.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
56 if let Ok(bindings) = bb { |
5aa1a010f1e8
Start using PAM headers; improve owned/borrowed distinction.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
57 ("linux-pam", bindings) |
5aa1a010f1e8
Start using PAM headers; improve owned/borrowed distinction.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
58 } else if let Ok(bindings) = openpam_builder.generate() { |
5aa1a010f1e8
Start using PAM headers; improve owned/borrowed distinction.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
59 ("openpam", bindings) |
5aa1a010f1e8
Start using PAM headers; improve owned/borrowed distinction.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
60 } else { |
5aa1a010f1e8
Start using PAM headers; improve owned/borrowed distinction.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
61 panic!("unrecognized PAM implementation") |
5aa1a010f1e8
Start using PAM headers; improve owned/borrowed distinction.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
62 } |
5aa1a010f1e8
Start using PAM headers; improve owned/borrowed distinction.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
63 }; |
5aa1a010f1e8
Start using PAM headers; improve owned/borrowed distinction.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
64 println!("cargo::rustc-cfg=pam_impl={pam_impl:?}"); |
5aa1a010f1e8
Start using PAM headers; improve owned/borrowed distinction.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
65 let out_path = PathBuf::from(env::var("OUT_DIR").unwrap()); |
5aa1a010f1e8
Start using PAM headers; improve owned/borrowed distinction.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
66 bindings |
5aa1a010f1e8
Start using PAM headers; improve owned/borrowed distinction.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
67 .write_to_file(out_path.join("bindings.rs")) |
5aa1a010f1e8
Start using PAM headers; improve owned/borrowed distinction.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
68 .unwrap(); |
5aa1a010f1e8
Start using PAM headers; improve owned/borrowed distinction.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
69 } |
5aa1a010f1e8
Start using PAM headers; improve owned/borrowed distinction.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
70 } |