Skip to content

Commit 603a14a

Browse files
committed
Dynamically use getlocalbase(3)
1 parent 0ca3627 commit 603a14a

File tree

3 files changed

+23
-5
lines changed

3 files changed

+23
-5
lines changed

.cargo/config.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[target.freebsd]
2+
rustflags = ["-lutil"]
3+

Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,7 @@ edition = '2021'
1414
# This was arbitrarily chosen on 2025-01-23 as "pretty old" as previously
1515
# key didn't exist in `Cargo.toml` prior to that.
1616
rust-version = '1.60.0'
17+
18+
[target.'cfg(target_os = "freebsd")'.dependencies]
19+
libc = "0.2.177"
20+

src/lib.rs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,17 +53,28 @@ pub fn candidate_cert_dirs() -> impl Iterator<Item = &'static Path> {
5353
.map(Path::new)
5454
.filter(|p| p.exists())
5555
}
56+
5657
#[cfg(target_os = "freebsd")]
5758
pub fn candidate_cert_dirs() -> impl Iterator<Item = &'static Path> {
59+
extern "C" {
60+
fn getlocalbase() -> *const libc::c_char;
61+
}
62+
// see manpage of getlocalbase(3): https://man.freebsd.org/cgi/man.cgi?query=getlocalbase&sektion=3
63+
let localbase = unsafe {
64+
let ptr = getlocalbase();
65+
let c_str = std::ffi::CStr::from_ptr(ptr);
66+
c_str.to_str().unwrap()
67+
};
68+
5869
// see manpage of certctl(8): https://man.freebsd.org/cgi/man.cgi?query=certctl&sektion=8
5970
// see security/openssl* ports
6071
[
61-
"/etc/ssl",
62-
"/usr/local/etc/ssl",
63-
"/usr/local/openssl",
72+
"/etc/ssl".to_string(),
73+
format!("{}/etc/ssl", localbase),
74+
format!("{}/openssl", localbase),
6475
]
65-
.iter()
66-
.map(Path::new)
76+
.into_iter()
77+
.map(|s| Path::new(Box::leak(Box::new(s))))
6778
.filter(|p| p.exists())
6879
}
6980

0 commit comments

Comments
 (0)