Skip to content

Commit 603a2a8

Browse files
committed
Remove most uses of build.rs
1 parent 6f6c909 commit 603a2a8

File tree

6 files changed

+14
-24
lines changed

6 files changed

+14
-24
lines changed

build.rs

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,14 @@
1-
use std::path::Path;
2-
3-
// Return the first existing path given a list of paths as string slices
4-
fn get_first_path(paths: &[&'static str]) -> Option<&'static str> {
5-
paths.iter().find(|p| Path::new(p).exists()).copied()
6-
}
7-
81
fn main() {
9-
let path_zoneinfo: &str = get_first_path(&[
2+
let path_zoneinfo = [
103
"/usr/share/zoneinfo",
114
"/usr/share/lib/zoneinfo",
125
"/usr/lib/zoneinfo",
136
"/usr/lib/zoneinfo",
14-
])
7+
]
8+
.into_iter()
9+
.find(|p| std::path::Path::new(p).exists())
1510
.expect("no zoneinfo database");
1611

17-
// TODO: use _PATH_STDPATH and _PATH_DEFPATH_ROOT from paths.h
18-
println!("cargo:rustc-env=SUDO_PATH_DEFAULT=/usr/bin:/bin:/usr/sbin:/sbin");
19-
println!(
20-
"cargo:rustc-env=SU_PATH_DEFAULT_ROOT=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
21-
);
22-
println!(
23-
"cargo:rustc-env=SU_PATH_DEFAULT=/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games"
24-
);
25-
2612
println!("cargo:rustc-env=PATH_ZONEINFO={path_zoneinfo}");
2713
println!("cargo:rerun-if-changed=build.rs");
28-
29-
println!("cargo:rustc-link-lib=pam");
3014
}

src/pam/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ mod securemem;
2525
#[allow(nonstandard_style)]
2626
pub mod sys;
2727

28+
#[link(name = "pam")]
29+
extern "C" {}
30+
2831
#[cfg(target_os = "freebsd")]
2932
const PAM_DATA_SILENT: std::ffi::c_int = 0;
3033

src/su/context.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@ use super::cli::SuRunOptions;
1919
const VALID_LOGIN_SHELLS_LIST: &str = "/etc/shells";
2020
const FALLBACK_LOGIN_SHELL: &str = "/bin/sh";
2121

22-
const PATH_DEFAULT: &str = env!("SU_PATH_DEFAULT");
23-
const PATH_DEFAULT_ROOT: &str = env!("SU_PATH_DEFAULT_ROOT");
22+
// TODO: use _PATH_STDPATH and _PATH_DEFPATH_ROOT from paths.h
23+
const PATH_DEFAULT: &str = "/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games";
24+
const PATH_DEFAULT_ROOT: &str = "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin";
2425

2526
#[derive(Debug)]
2627
pub(crate) struct SuContext {

src/sudo/env/environment.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ use crate::system::PATH_MAX;
1111
use super::wildcard_match::wildcard_match;
1212

1313
const PATH_ZONEINFO: &str = env!("PATH_ZONEINFO");
14-
const PATH_DEFAULT: &str = env!("SUDO_PATH_DEFAULT");
14+
// TODO: use _PATH_STDPATH from paths.h
15+
pub(crate) const PATH_DEFAULT: &str = "/usr/bin:/bin:/usr/sbin:/sbin";
1516

1617
pub type Environment = HashMap<OsString, OsString>;
1718

src/sudo/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ mod edit;
1919

2020
pub(crate) mod diagnostic;
2121
mod env;
22+
pub(crate) use env::environment::PATH_DEFAULT;
2223
mod pam;
2324
mod pipeline;
2425

src/sudoers/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ fn select_editor(settings: &Settings, trusted_env: bool) -> PathBuf {
321321
editor
322322
} else if let Some(editor) = resolve_path(
323323
&editor,
324-
&std::env::var("PATH").unwrap_or(env!("SUDO_PATH_DEFAULT").to_string()),
324+
&std::env::var("PATH").unwrap_or(crate::sudo::PATH_DEFAULT.to_string()),
325325
) {
326326
editor
327327
} else {

0 commit comments

Comments
 (0)