Skip to content

Commit

Permalink
Try to support FreeBSD/openPAM
Browse files Browse the repository at this point in the history
  • Loading branch information
1wilkens committed Sep 12, 2021
1 parent 4fa9761 commit ed735d3
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ This project adheres to [Semantic Versioning](http://semver.org/).
-->

## [Unreleased]
### Changed
- Support FreeBSD by manually setting `PAM_SILENT`

## [1.0.0-alpha3] - 2021-03-28
### Changed
Expand Down
32 changes: 23 additions & 9 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ fn main() {
// Tell cargo to tell rustc to link the system pam
// shared library.
println!("cargo:rustc-link-lib=pam");

// pam_misc is only supported on Linux afaik
if cfg!(target_os = "linux") {
println!("cargo:rustc-link-lib=pam_misc");
Expand All @@ -15,15 +16,12 @@ fn main() {
// Tell cargo to invalidate the built crate whenever the wrapper changes
println!("cargo:rerun-if-changed=wrapper.h");

// The bindgen::Builder is the main entry point
// to bindgen, and lets you build up options for
// the resulting bindings.
let bindings = bindgen::Builder::default()
// The input header we would like to generate
// bindings for.
// Prepare bindgen builder
let mut builder = bindgen::Builder::default()
// Our header
.header("wrapper.h")
// Import libc so our signatures are slightly nicer
.raw_line("use libc::{uid_t, gid_t, group, passwd, spwd};")
.raw_line("use libc::{uid_t, gid_t, group, passwd};")
.ctypes_prefix("libc")
// Set macro constants to signed int, as all functions that accept
// these constants use signed int as the parameter type
Expand All @@ -36,18 +34,34 @@ fn main() {
.blacklist_type("__builtin_va_list")
.blacklist_type("__va_list_tag")
.blacklist_function("pam_v.*")
.blacklist_function("pam_syslog")
.blacklist_function("pam_prompt")
// Blacklist types we use from libc
.blacklist_type(".*gid_t")
.blacklist_type(".*uid_t")
.blacklist_type("group")
.blacklist_type("passwd")
.blacklist_type("spwd")
// Whitelist all PAM constants
.whitelist_var("PAM_.*")
// Whitelist all PAM functions..
.whitelist_function("pam_.*")
// ..except module related functions (pam_sm_*)
.blacklist_function("pam_sm_.*")
.blacklist_function("pam_sm_.*");

// Platform-specific adaptions
if cfg!(target_os = "linux") {
// On Linux we also use spwd from libc
builder = builder
.raw_line("use libc::spwd;")
.blacklist_type("spwd");
} else if cfg!(target_os = "freebsd") {
// XXX: this should include all OS that use openPAM
builder = builder
.raw_line("pub const PAM_SILENT: libc::c_uint = 0x8000_0000;")
.blacklist_type("PAM_SILENT");
}

let bindings = builder
// Finish the builder and generate the bindings.
.generate()
// Unwrap the Result and panic on failure.
Expand Down

0 comments on commit ed735d3

Please sign in to comment.