pub struct EnvList(/* private fields */);Expand description
A PAM environment list
The PAM environment represents the contents of the regular environment variables of the authenticated user when service is granted and can be used to prepare the environment of child processes run as the authenticated user.
See Context::envlist().
§Examples
// Print the PAM environment
for item in &context.envlist() {
println!("VAR: {}", item);
}The environment can be passed to std::process::Command by using EnvList::iter_tuples():
use std::process::Command;
// Spawn a process in the PAM environment
let command = Command::new("/usr/bin/some_program")
.env_clear()
.envs(context.envlist().iter_tuples());The environment can be passed to NIX’s execve by using EnvList::as_ref():
use nix::unistd::execve;
// Replace this process with another program in the PAM environment
execve(
&CString::new("/usr/bin/some_program").unwrap(),
&[CString::new("some_program").unwrap()],
context.envlist().as_ref()
).expect("replacing the current process failed");Implementations§
Source§impl EnvList
impl EnvList
Sourcepub fn get<T: AsRef<OsStr>>(&self, name: T) -> Option<&OsStr>
pub fn get<T: AsRef<OsStr>>(&self, name: T) -> Option<&OsStr>
Returns a reference to the value of the named environment variable.
Returns None if the variable doesn’t exist in this list.
Sourcepub fn iter(&self) -> Iter<'_>
pub fn iter(&self) -> Iter<'_>
Returns an iterator over all contained variables as EnvItems.
The iteration happens in deterministic, but unspecified order.
Sourcepub fn iter_tuples(&self) -> TupleIter<'_> ⓘ
pub fn iter_tuples(&self) -> TupleIter<'_> ⓘ
Returns an iterator over all contained variables as
(key: &OsStr, value: &OsStr) tuples.
The iteration happens in deterministic, but unspecified order.
Provides compatibility with std::process::Command::envs().
Trait Implementations§
Source§impl AsRef<[EnvItem]> for EnvList
Provide compatibility with the 3rd parameter of nix::unistd::execve.
impl AsRef<[EnvItem]> for EnvList
Provide compatibility with the 3rd parameter of nix::unistd::execve.
Source§impl Display for EnvList
Display and string conversion of the environment list.
impl Display for EnvList
Display and string conversion of the environment list.
Also causes .to_string() to be implemented.
Source§impl<'a, S> From<&'a EnvList> for HashMap<&'a OsStr, &'a OsStr, S>where
S: BuildHasher + Default,
Reference conversion to a referencing hash map
impl<'a, S> From<&'a EnvList> for HashMap<&'a OsStr, &'a OsStr, S>where
S: BuildHasher + Default,
Reference conversion to a referencing hash map
Source§impl<'a> From<&'a EnvList> for Vec<&'a CStr>
Reference conversion to a vector of “key=value” &CStrs.
impl<'a> From<&'a EnvList> for Vec<&'a CStr>
Reference conversion to a vector of “key=value” &CStrs.
Source§impl<'a> From<&'a EnvList> for Vec<(&'a OsStr, &'a OsStr)>
Reference conversion to a vector of (&key, &value) tuples.
impl<'a> From<&'a EnvList> for Vec<(&'a OsStr, &'a OsStr)>
Reference conversion to a vector of (&key, &value) tuples.
Source§impl<S> From<EnvList> for HashMap<OsString, OsString, S>where
S: BuildHasher + Default,
Conversion to a hash map
impl<S> From<EnvList> for HashMap<OsString, OsString, S>where
S: BuildHasher + Default,
Conversion to a hash map
Source§impl From<EnvList> for Vec<(OsString, OsString)>
Conversion to a vector of (key, value) tuples.
impl From<EnvList> for Vec<(OsString, OsString)>
Conversion to a vector of (key, value) tuples.
Source§impl<'a> IntoIterator for &'a EnvList
Provide direct for-loop support.
impl<'a> IntoIterator for &'a EnvList
Provide direct for-loop support.
See EnvList::iter().