Debian Codegraph @

src/sudo/env/environment.rs

raw symbols SCIP
1 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::{
2 collectionsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/::{HashMaprust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/HashMap#, HashSetrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/HashSet#},
3 ffirust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/::{OsStrrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/OsStr#, OsStringrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/OsString#},
4 osrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/::unixrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/unix/::preluderust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/unix/prelude/::OsStrExtrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/unix/ffi/os_str/OsStrExt#,
5 };
6
7 use craterust-analyzer cargo sudo-rs 0.2.14 crate/::commonrust-analyzer cargo sudo-rs 0.2.14 common/::{CommandAndArgumentsrust-analyzer cargo sudo-rs 0.2.14 common/command/CommandAndArguments#, Contextrust-analyzer cargo sudo-rs 0.2.14 common/context/Context#, Errorrust-analyzer cargo sudo-rs 0.2.14 common/error/Error#, contextrust-analyzer cargo sudo-rs 0.2.14 common/context/::LaunchTyperust-analyzer cargo sudo-rs 0.2.14 common/context/LaunchType#};
8 use craterust-analyzer cargo sudo-rs 0.2.14 crate/::sudoersrust-analyzer cargo sudo-rs 0.2.14 sudoers/::Restrictionsrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/Restrictions#;
9 use craterust-analyzer cargo sudo-rs 0.2.14 crate/::systemrust-analyzer cargo sudo-rs 0.2.14 system/::{PATH_MAXrust-analyzer cargo libc 0.2.186 unix/linux_like/PATH_MAX., auditrust-analyzer cargo sudo-rs 0.2.14 system/audit/::zoneinfo_pathrust-analyzer cargo sudo-rs 0.2.14 system/audit/zoneinfo_path().};
10
11 use superrust-analyzer cargo sudo-rs 0.2.14 sudo/env/::wildcard_matchrust-analyzer cargo sudo-rs 0.2.14 sudo/env/wildcard_match/::wildcard_matchrust-analyzer cargo sudo-rs 0.2.14 sudo/env/wildcard_match/wildcard_match().;
12
13 // TODO: use _PATH_STDPATH from paths.h
14 pub(craterust-analyzer cargo sudo-rs 0.2.14 crate/) const PATH_DEFAULTrust-analyzer cargo sudo-rs 0.2.14 sudo/env/environment/PATH_DEFAULT.: &str = "/usr/bin:/bin:/usr/sbin:/sbin";
15
16 pub type Environmentrust-analyzer cargo sudo-rs 0.2.14 sudo/env/environment/Environment# = HashMaprust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/HashMap#<OsStringrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/OsString#, OsStringrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/OsString#>;
17
18 /// obtain the system environment
19 pub fn system_environmentrust-analyzer cargo sudo-rs 0.2.14 sudo/env/environment/system_environment().() -> Environmentrust-analyzer cargo sudo-rs 0.2.14 sudo/env/environment/Environment# {
20 stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::envrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/::vars_osrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/vars_os().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().()
21 }
22
23 /// check byte slice contains with given byte slice
24 fn contains_subsequencerust-analyzer cargo sudo-rs 0.2.14 sudo/env/environment/contains_subsequence().(haystack: &[u8], needle: &[u8]) -> bool {
25 haystack
26 .windowsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]windows().(needle.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().())
27 .anyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#any().(|window| window rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().needle)
28 }
29
30 /// Formats the command and arguments passed for the SUDO_COMMAND
31 /// environment variable. Limit the length to 4096 bytes to prevent
32 /// execve failure for very long argument vectors
33 fn format_commandrust-analyzer cargo sudo-rs 0.2.14 sudo/env/environment/format_command().(command_and_arguments: &CommandAndArgumentsrust-analyzer cargo sudo-rs 0.2.14 common/command/CommandAndArguments#) -> OsStringrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/OsString# {
34 let mut formatted: OsStringrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/OsString# = command_and_arguments.commandrust-analyzer cargo sudo-rs 0.2.14 common/command/CommandAndArguments#command..clonerust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[PathBuf][Clone]clone().().intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().();
35
36 for arg in &command_and_arguments.argumentsrust-analyzer cargo sudo-rs 0.2.14 common/command/CommandAndArguments#arguments. {
37 if formatted.lenrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/impl#[OsStr]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().arg.lenrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/impl#[OsStr]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().4096 {
38 formatted.pushrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/impl#[OsString]push().(" ");
39 formatted.pushrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/impl#[OsString]push().(arg);
40 }
41 }
42
43 formatted
44 }
45
46 /// Construct sudo-specific environment variables
47 fn add_extra_envrust-analyzer cargo sudo-rs 0.2.14 sudo/env/environment/add_extra_env().(
48 context: &Contextrust-analyzer cargo sudo-rs 0.2.14 common/context/Context#,
49 cfg: &Restrictionsrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/Restrictions#,
50 sudo_ps1: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<OsStringrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/OsString#>,
51 environment: &mut Environmentrust-analyzer cargo sudo-rs 0.2.14 sudo/env/environment/Environment#,
52 ) {
53 // current user
54 environment.insertrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]insert().("SUDO_COMMAND".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), format_commandrust-analyzer cargo sudo-rs 0.2.14 sudo/env/environment/format_command().(&context.commandrust-analyzer cargo sudo-rs 0.2.14 common/context/Context#command.));
55 environment.insertrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]insert().(
56 "SUDO_UID".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(),
57 context.current_userrust-analyzer cargo sudo-rs 0.2.14 common/context/Context#current_user..uidrust-analyzer cargo sudo-rs 0.2.14 system/User#uid..to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().().intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(),
58 );
59 environment.insertrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]insert().(
60 "SUDO_GID".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(),
61 context.current_userrust-analyzer cargo sudo-rs 0.2.14 common/context/Context#current_user..gidrust-analyzer cargo sudo-rs 0.2.14 system/User#gid..to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().().intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(),
62 );
63 environment.insertrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]insert().("SUDO_USER".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), context.current_userrust-analyzer cargo sudo-rs 0.2.14 common/context/Context#current_user..namerust-analyzer cargo sudo-rs 0.2.14 system/User#name..clonerust-analyzer cargo sudo-rs 0.2.14 common/string/impl#[SudoString][Clone]clone().().intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().());
64 environment.insertrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]insert().("SUDO_HOME".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), context.current_userrust-analyzer cargo sudo-rs 0.2.14 common/context/Context#current_user..homerust-analyzer cargo sudo-rs 0.2.14 system/User#home..clonerust-analyzer cargo sudo-rs 0.2.14 common/path/impl#[SudoPath][Clone]clone().().intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().());
65 // The current SHELL variable should determine the shell to run when -s is passed, if none set use passwd entry
66 environment
67 .entryrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]entry().("SHELL".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().())
68 .or_insert_withrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`Entry<'a, K, V, A>`]or_insert_with().(|| context.target_userrust-analyzer cargo sudo-rs 0.2.14 common/context/Context#target_user..shellrust-analyzer cargo sudo-rs 0.2.14 system/User#shell..clonerust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[PathBuf][Clone]clone().().intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().());
69 // HOME: Set to the home directory of the target user if -i or -H are specified, env_reset or always_set_home are
70 // set in sudoers, or when the -s option is specified and set_home is set in sudoers.
71 // In sudo-rs env_reset is mandatory, so we always set HOME unless it's in the env_keep list.
72 environment
73 .entryrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]entry().("HOME".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().())
74 .or_insert_withrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`Entry<'a, K, V, A>`]or_insert_with().(|| context.target_userrust-analyzer cargo sudo-rs 0.2.14 common/context/Context#target_user..homerust-analyzer cargo sudo-rs 0.2.14 system/User#home..clonerust-analyzer cargo sudo-rs 0.2.14 common/path/impl#[SudoPath][Clone]clone().().intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().());
75
76 match (
77 environment.getrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]get().(OsStrrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/OsStr#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/impl#[OsStr]new().("LOGNAME")),
78 environment.getrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]get().(OsStrrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/OsStr#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/impl#[OsStr]new().("USER")),
79 ) {
80 // Set to the login name of the target user when the -i option is specified,
81 // when the set_logname option is enabled in sudoers, or when the env_reset option
82 // is enabled in sudoers (unless LOGNAME is present in the env_keep list).
83 // Since we always want to do env_reset -> always set these except when present in env
84 (Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#) => {
85 environment.insertrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]insert().("LOGNAME".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), context.target_userrust-analyzer cargo sudo-rs 0.2.14 common/context/Context#target_user..namerust-analyzer cargo sudo-rs 0.2.14 system/User#name..clonerust-analyzer cargo sudo-rs 0.2.14 common/string/impl#[SudoString][Clone]clone().().intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().());
86 environment.insertrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]insert().("USER".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), context.target_userrust-analyzer cargo sudo-rs 0.2.14 common/context/Context#target_user..namerust-analyzer cargo sudo-rs 0.2.14 system/User#name..clonerust-analyzer cargo sudo-rs 0.2.14 common/string/impl#[SudoString][Clone]clone().().intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().());
87 }
88 // LOGNAME should be set to the same value as USER if the latter is preserved.
89 (Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(user)) => {
90 environment.insertrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]insert().("LOGNAME".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), user.clonerust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/impl#[OsString][Clone]clone().());
91 }
92 // USER should be set to the same value as LOGNAME if the latter is preserved.
93 (Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(logname), Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#) => {
94 environment.insertrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]insert().("USER".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), logname.clonerust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/impl#[OsString][Clone]clone().());
95 }
96 (Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(_), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(_)) => {}
97 }
98
99 // Overwrite PATH when secure_path is set
100 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(secure_path) = &cfg.pathrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/Restrictions#path. {
101 // assign path by env path or secure_path configuration
102 environment.insertrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]insert().("PATH".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), secure_path.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().());
103 }
104 // If the PATH and TERM variables are not preserved from the user's environment, they will be set to default value
105 environment
106 .entryrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]entry().("PATH".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().())
107 .or_insert_withrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`Entry<'a, K, V, A>`]or_insert_with().(|| PATH_DEFAULTrust-analyzer cargo sudo-rs 0.2.14 sudo/env/environment/PATH_DEFAULT..intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().());
108 // If the TERM variable is not preserved from the user's environment, it will be set to default value
109 environment
110 .entryrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]entry().("TERM".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().())
111 .or_insert_withrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`Entry<'a, K, V, A>`]or_insert_with().(|| "unknown".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().());
112 // The SUDO_PS1 variable requires special treatment as the PS1 variable must be set in the
113 // target environment to the same value of SUDO_PS1 if the latter is set.
114 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(sudo_ps1_value) = sudo_ps1 {
115 // set PS1 to the SUDO_PS1 value in the target environment
116 environment.insertrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]insert().("PS1".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), sudo_ps1_value);
117 }
118 }
119
120 /// Check a string only contains printable (non-space) characters
121 fn is_printablerust-analyzer cargo sudo-rs 0.2.14 sudo/env/environment/is_printable().(input: &[u8]) -> bool {
122 input
123 .iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().()
124 .allrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/iter/impl#[`Iter<'a, T>`][Iterator]all().(|c| c.is_ascii_alphanumericrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u8]is_ascii_alphanumeric().() || c.is_ascii_punctuationrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u8]is_ascii_punctuation().())
125 }
126
127 /// The TZ variable is considered unsafe if any of the following are true:
128 /// It consists of a fully-qualified path name, optionally prefixed with a colon (‘:’), that does not match the location of the zoneinfo directory.
129 /// It contains a .. path element.
130 /// It contains white space or non-printable characters.
131 /// It is longer than the value of PATH_MAX.
132 fn is_safe_tzrust-analyzer cargo sudo-rs 0.2.14 sudo/env/environment/is_safe_tz().(value: &[u8]) -> bool {
133 let check_value = if value.starts_withrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]starts_with().(b":") {
134 &value[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().1..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFrom#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().
135 } else {
136 value
137 };
138
139 if check_value.starts_withrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]starts_with().(b"/") {
140 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(path_zoneinfo) = zoneinfo_pathrust-analyzer cargo sudo-rs 0.2.14 system/audit/zoneinfo_path().() {
141 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().check_value.starts_withrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]starts_with().(path_zoneinfo.as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().())
142 || check_value.getrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]get().(path_zoneinfo.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]len().()) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#ne().Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(&b'/')
143 {
144 return false;
145 }
146 } else {
147 return false;
148 }
149 }
150
151 !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().contains_subsequencerust-analyzer cargo sudo-rs 0.2.14 sudo/env/environment/contains_subsequence().(check_value, "..".as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().())
152 && is_printablerust-analyzer cargo sudo-rs 0.2.14 sudo/env/environment/is_printable().(check_value)
153 && check_value.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().PATH_MAXrust-analyzer cargo libc 0.2.186 unix/linux_like/PATH_MAX. as usize
154 }
155
156 /// Check whether the needle exists in a haystack, in which the haystack is a list of patterns, possibly containing wildcards
157 fn in_tablerust-analyzer cargo sudo-rs 0.2.14 sudo/env/environment/in_table().(needle: (&OsStrrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/OsStr#, &OsStrrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/OsStr#), haystack: &HashSetrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/HashSet#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>) -> bool {
158 haystack.iterrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`]iter().().anyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#any().(|pattern| {
159 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((key, value)) = pattern.split_oncerust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]split_once().('=') {
160 wildcard_matchrust-analyzer cargo sudo-rs 0.2.14 sudo/env/wildcard_match/wildcard_match().(needle.0.as_bytesrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/unix/ffi/os_str/impl#[OsStr][OsStrExt]as_bytes().(), key.as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().())
161 && wildcard_matchrust-analyzer cargo sudo-rs 0.2.14 sudo/env/wildcard_match/wildcard_match().(needle.1.as_bytesrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/unix/ffi/os_str/impl#[OsStr][OsStrExt]as_bytes().(), value.as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().())
162 } else {
163 wildcard_matchrust-analyzer cargo sudo-rs 0.2.14 sudo/env/wildcard_match/wildcard_match().(needle.0.as_bytesrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/unix/ffi/os_str/impl#[OsStr][OsStrExt]as_bytes().(), pattern.as_bytesrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]as_bytes().())
164 }
165 })
166 }
167
168 /// Determine whether a specific environment variable should be kept
169 fn should_keeprust-analyzer cargo sudo-rs 0.2.14 sudo/env/environment/should_keep().(key: &OsStrrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/OsStr#, value: &OsStrrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/OsStr#, cfg: &Restrictionsrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/Restrictions#) -> bool {
170 if value.as_bytesrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/unix/ffi/os_str/impl#[OsStr][OsStrExt]as_bytes().().starts_withrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]starts_with().("()".as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().()) {
171 return false;
172 }
173
174 if cfg.pathrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/Restrictions#path..is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().() && key rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq()."PATH" {
175 return false;
176 }
177
178 if key rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq()."TZ" {
179 return in_tablerust-analyzer cargo sudo-rs 0.2.14 sudo/env/environment/in_table().((key, value), cfg.env_keeprust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/Restrictions#env_keep.)
180 || (in_tablerust-analyzer cargo sudo-rs 0.2.14 sudo/env/environment/in_table().((key, value), cfg.env_checkrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/Restrictions#env_check.) && is_safe_tzrust-analyzer cargo sudo-rs 0.2.14 sudo/env/environment/is_safe_tz().(value.as_bytesrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/unix/ffi/os_str/impl#[OsStr][OsStrExt]as_bytes().()));
181 }
182
183 if in_tablerust-analyzer cargo sudo-rs 0.2.14 sudo/env/environment/in_table().((key, value), cfg.env_checkrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/Restrictions#env_check.) {
184 return !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().value.as_bytesrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/unix/ffi/os_str/impl#[OsStr][OsStrExt]as_bytes().().iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().anyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/iter/impl#[`Iter<'a, T>`][Iterator]any().(|c| *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().c rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().b'%' || *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().c rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().b'/');
185 }
186
187 in_tablerust-analyzer cargo sudo-rs 0.2.14 sudo/env/environment/in_table().((key, value), cfg.env_keeprust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/Restrictions#env_keep.)
188 }
189
190 /// Construct the final environment from the current one and a sudo context
191 /// see <https://github.com/sudo-project/sudo/blob/main/plugins/sudoers/env.c> for the original implementation
192 /// see <https://www.sudo.ws/docs/man/sudoers.man/#Command_environment> for the original documentation
193 ///
194 /// The HOME, SHELL, LOGNAME and USER environment variables are initialized based on the target user
195 /// and the SUDO_* variables are set based on the invoking user.
196 ///
197 /// Additional variables, such as DISPLAY, PATH and TERM, are preserved from the invoking user's
198 /// environment if permitted by the env_check, or env_keep options
199 ///
200 /// If the PATH and TERM variables are not preserved from the user's environment, they will be set to default value
201 ///
202 /// Environment variables with a value beginning with ‘()’ are removed
203 pub fn get_target_environmentrust-analyzer cargo sudo-rs 0.2.14 sudo/env/environment/get_target_environment().(
204 current_env: Environmentrust-analyzer cargo sudo-rs 0.2.14 sudo/env/environment/Environment#,
205 additional_env: impl IntoIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#Item# = (OsStringrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/OsString#, OsStringrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/OsString#)>,
206 user_override: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<(Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#)>,
207 context: &Contextrust-analyzer cargo sudo-rs 0.2.14 common/context/Context#,
208 settings: &Restrictionsrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/Restrictions#,
209 ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Environmentrust-analyzer cargo sudo-rs 0.2.14 sudo/env/environment/Environment#, Errorrust-analyzer cargo sudo-rs 0.2.14 common/error/Error#> {
210 // retrieve SUDO_PS1 value to set a PS1 value as additional environment
211 let sudo_ps1 = current_env.getrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]get().(OsStrrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/OsStr#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/impl#[OsStr]new().("SUDO_PS1")).clonedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<&T>`]cloned().();
212
213 // variables preserved from the invoking user's environment by the
214 // env_keep list take precedence over those in the PAM environment
215 let mut environment: HashMaprust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/HashMap#<_, _> = additional_env.into_iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#into_iter().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().();
216
217 let login_vars: &[_] = if context.launchrust-analyzer cargo sudo-rs 0.2.14 common/context/Context#launch. rust-analyzer cargo sudo-rs 0.2.14 common/context/impl#[LaunchType][`PartialEq<Self>`]eq().==rust-analyzer cargo sudo-rs 0.2.14 common/context/impl#[LaunchType][`PartialEq<Self>`]eq(). rust-analyzer cargo sudo-rs 0.2.14 common/context/impl#[LaunchType][`PartialEq<Self>`]eq().LaunchTyperust-analyzer cargo sudo-rs 0.2.14 common/context/LaunchType#::Loginrust-analyzer cargo sudo-rs 0.2.14 common/context/LaunchType#Login# {
218 &["HOME", "SHELL", "USER", "LOGNAME"].maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`]map().(OsStrrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/OsStr#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/impl#[OsStr]new().)
219 } else {
220 &[]
221 };
222
223 environment.extendrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`][`Extend<(K, V)>`]extend().(current_env.into_iterrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`][IntoIterator]into_iter().().filterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#filter().(|(key, value)| {
224 !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().login_vars.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]contains().(&key.as_os_strrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/impl#[OsString]as_os_str().()) && should_keeprust-analyzer cargo sudo-rs 0.2.14 sudo/env/environment/should_keep().(key, value, settings)
225 }));
226
227 add_extra_envrust-analyzer cargo sudo-rs 0.2.14 sudo/env/environment/add_extra_env().(context, settings, sudo_ps1, &mut environment);
228
229 let mut rejected_vars = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().();
230 for (key, value) in user_override {
231 if should_keeprust-analyzer cargo sudo-rs 0.2.14 sudo/env/environment/should_keep().(OsStrrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/OsStr#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/impl#[OsStr]new().(&key), OsStrrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/OsStr#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/impl#[OsStr]new().(&value), settings) {
232 environment.insertrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]insert().(key.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), value.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().());
233 } else {
234 rejected_vars.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(key);
235 }
236 }
237 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().rejected_vars.is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().() {
238 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo sudo-rs 0.2.14 common/error/Error#::EnvironmentVarrust-analyzer cargo sudo-rs 0.2.14 common/error/Error#EnvironmentVar#(rejected_vars));
239 }
240
241 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(environment)
242 }
243
244 /// Extend the environment with user-supplied info
245 pub fn dangerous_extendrust-analyzer cargo sudo-rs 0.2.14 sudo/env/environment/dangerous_extend().<S>(env: &mut Environmentrust-analyzer cargo sudo-rs 0.2.14 sudo/env/environment/Environment#, user_override: impl IntoIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#Item# = (S, S)>)
246 where
247 S: Intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#<OsStringrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/OsString#>,
248 {
249 env.extendrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`][`Extend<(K, V)>`]extend().(
250 user_override
251 .into_iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#into_iter().()
252 .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|(key, value)| (key.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#into().(), value.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#into().())),
253 )
254 }
255
256 #[cfg(test)]
257 mod testsrust-analyzer cargo sudo-rs 0.2.14 sudo/env/environment/tests/ {
258 use superrust-analyzer cargo sudo-rs 0.2.14 sudo/env/environment/::{is_safe_tzrust-analyzer cargo sudo-rs 0.2.14 sudo/env/environment/is_safe_tz()., should_keeprust-analyzer cargo sudo-rs 0.2.14 sudo/env/environment/should_keep()., zoneinfo_pathrust-analyzer cargo sudo-rs 0.2.14 system/audit/zoneinfo_path().};
259 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::{collectionsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/::HashSetrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/HashSet#, ffirust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/::OsStrrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/OsStr#};
260
261 struct TestConfigurationrust-analyzer cargo sudo-rs 0.2.14 sudo/env/environment/tests/TestConfiguration# {
262 keeprust-analyzer cargo sudo-rs 0.2.14 sudo/env/environment/tests/TestConfiguration#keep.: HashSetrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/HashSet#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>,
263 checkrust-analyzer cargo sudo-rs 0.2.14 sudo/env/environment/tests/TestConfiguration#check.: HashSetrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/HashSet#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>,
264 pathrust-analyzer cargo sudo-rs 0.2.14 sudo/env/environment/tests/TestConfiguration#path.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>,
265 }
266
267 impl TestConfigurationrust-analyzer cargo sudo-rs 0.2.14 sudo/env/environment/tests/TestConfiguration# {
268 pub fn check_should_keeprust-analyzer cargo sudo-rs 0.2.14 sudo/env/environment/tests/impl#[TestConfiguration]check_should_keep().(&self, key: &str, value: &str, expected: bool) {
269 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
270 should_keeprust-analyzer cargo sudo-rs 0.2.14 sudo/env/environment/should_keep().(
271 OsStrrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/OsStr#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/impl#[OsStr]new().(key),
272 OsStrrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/OsStr#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/impl#[OsStr]new().(value),
273 &craterust-analyzer cargo sudo-rs 0.2.14 crate/::sudoersrust-analyzer cargo sudo-rs 0.2.14 sudoers/::Restrictionsrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/Restrictions# {
274 env_keeprust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/Restrictions#env_keep.: &self.keeprust-analyzer cargo sudo-rs 0.2.14 sudo/env/environment/tests/TestConfiguration#keep.,
275 env_checkrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/Restrictions#env_check.: &self.checkrust-analyzer cargo sudo-rs 0.2.14 sudo/env/environment/tests/TestConfiguration#check.,
276 pathrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/Restrictions#path.: self.pathrust-analyzer cargo sudo-rs 0.2.14 sudo/env/environment/tests/TestConfiguration#path..as_derefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_deref().(),
277 chdirrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/Restrictions#chdir.: craterust-analyzer cargo sudo-rs 0.2.14 crate/::sudoersrust-analyzer cargo sudo-rs 0.2.14 sudoers/::DirChangerust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/DirChange#::Strictrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/DirChange#Strict#(Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#),
278 trust_environmentrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/Restrictions#trust_environment.: false,
279 use_ptyrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/Restrictions#use_pty.: true,
280 umaskrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/Restrictions#umask.: craterust-analyzer cargo sudo-rs 0.2.14 crate/::execrust-analyzer cargo sudo-rs 0.2.14 exec/::Umaskrust-analyzer cargo sudo-rs 0.2.14 exec/Umask#::Preserverust-analyzer cargo sudo-rs 0.2.14 exec/Umask#Preserve#,
281 #[cfg(feature = "apparmor")]
282 apparmor_profilerust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/Restrictions#apparmor_profile.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
283 noexecrust-analyzer cargo sudo-rs 0.2.14 sudoers/policy/Restrictions#noexec.: false,
284 }
285 ),
286 expected,
287 "{} should {}",
288 key,
289 if expected { "be kept" } else { "not be kept" }
290 );
291 }
292 }
293
294 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
295 fn test_filteringrust-analyzer cargo sudo-rs 0.2.14 sudo/env/environment/tests/test_filtering().() {
296 let mut config = TestConfigurationrust-analyzer cargo sudo-rs 0.2.14 sudo/env/environment/tests/TestConfiguration# {
297 keeprust-analyzer cargo sudo-rs 0.2.14 sudo/env/environment/tests/TestConfiguration#keep.: HashSetrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/HashSet#::fromrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T>`][`From<[T; N]>`]from().(["AAP".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), "NOOT".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()]),
298 checkrust-analyzer cargo sudo-rs 0.2.14 sudo/env/environment/tests/TestConfiguration#check.: HashSetrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/HashSet#::fromrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T>`][`From<[T; N]>`]from().(["MIES".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), "TZ".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()]),
299 pathrust-analyzer cargo sudo-rs 0.2.14 sudo/env/environment/tests/TestConfiguration#path.: Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("/bin".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()),
300 };
301
302 config.check_should_keeprust-analyzer cargo sudo-rs 0.2.14 sudo/env/environment/tests/impl#[TestConfiguration]check_should_keep().("AAP", "FOO", true);
303 config.check_should_keeprust-analyzer cargo sudo-rs 0.2.14 sudo/env/environment/tests/impl#[TestConfiguration]check_should_keep().("MIES", "BAR", true);
304 config.check_should_keeprust-analyzer cargo sudo-rs 0.2.14 sudo/env/environment/tests/impl#[TestConfiguration]check_should_keep().("AAP", "()=foo", false);
305 config.check_should_keeprust-analyzer cargo sudo-rs 0.2.14 sudo/env/environment/tests/impl#[TestConfiguration]check_should_keep().("TZ", "Europe/Amsterdam", true);
306 config.check_should_keeprust-analyzer cargo sudo-rs 0.2.14 sudo/env/environment/tests/impl#[TestConfiguration]check_should_keep().("TZ", "../Europe/Berlin", false);
307 config.check_should_keeprust-analyzer cargo sudo-rs 0.2.14 sudo/env/environment/tests/impl#[TestConfiguration]check_should_keep().("MIES", "FOO/BAR", false);
308 config.check_should_keeprust-analyzer cargo sudo-rs 0.2.14 sudo/env/environment/tests/impl#[TestConfiguration]check_should_keep().("MIES", "FOO/BAR", false);
309
310 config.keeprust-analyzer cargo sudo-rs 0.2.14 sudo/env/environment/tests/TestConfiguration#keep..insertrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`]insert().("PATH".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().());
311 config.check_should_keeprust-analyzer cargo sudo-rs 0.2.14 sudo/env/environment/tests/impl#[TestConfiguration]check_should_keep().("PATH", "FOO", false);
312 config.pathrust-analyzer cargo sudo-rs 0.2.14 sudo/env/environment/tests/TestConfiguration#path. = Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#;
313 config.check_should_keeprust-analyzer cargo sudo-rs 0.2.14 sudo/env/environment/tests/impl#[TestConfiguration]check_should_keep().("PATH", "FOO", true);
314 }
315
316 #[allow(clippy::bool_assert_comparison)]
317 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
318 fn test_tzinforust-analyzer cargo sudo-rs 0.2.14 sudo/env/environment/tests/test_tzinfo().() {
319 let path_zoneinfo = zoneinfo_pathrust-analyzer cargo sudo-rs 0.2.14 system/audit/zoneinfo_path().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
320 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(is_safe_tzrust-analyzer cargo sudo-rs 0.2.14 sudo/env/environment/is_safe_tz().(b"Europe/Amsterdam"), true);
321 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
322 is_safe_tzrust-analyzer cargo sudo-rs 0.2.14 sudo/env/environment/is_safe_tz().(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{path_zoneinfo}/Europe/London").as_bytesrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]as_bytes().()),
323 true
324 );
325 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
326 is_safe_tzrust-analyzer cargo sudo-rs 0.2.14 sudo/env/environment/is_safe_tz().(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!(":{path_zoneinfo}/Europe/Amsterdam").as_bytesrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]as_bytes().()),
327 true
328 );
329 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(is_safe_tzrust-analyzer cargo sudo-rs 0.2.14 sudo/env/environment/is_safe_tz().(b"/Europe/Amsterdam"), false);
330 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(is_safe_tzrust-analyzer cargo sudo-rs 0.2.14 sudo/env/environment/is_safe_tz().(b"/schaap/Europe/Amsterdam"), false);
331 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
332 is_safe_tzrust-analyzer cargo sudo-rs 0.2.14 sudo/env/environment/is_safe_tz().(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{path_zoneinfo}/../Europe/London").as_bytesrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]as_bytes().()),
333 false
334 );
335 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
336 is_safe_tzrust-analyzer cargo sudo-rs 0.2.14 sudo/env/environment/is_safe_tz().(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{path_zoneinfo}/../Europe/London").as_bytesrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]as_bytes().()),
337 false
338 );
339 }
340 }