Struct pam_client::env_list::EnvList
source · [−]pub struct EnvList(_);
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
sourceimpl 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 EnvItem
s.
The iteration happens in deterministic, but unspecified order.
sourcepub fn iter_tuples(&self) -> TupleIter<'_>ⓘNotable traits for TupleIter<'a>impl<'a> Iterator for TupleIter<'a> type Item = (&'a OsStr, &'a OsStr);
pub fn iter_tuples(&self) -> TupleIter<'_>ⓘNotable traits for TupleIter<'a>impl<'a> Iterator for TupleIter<'a> type Item = (&'a OsStr, &'a OsStr);
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
sourceimpl AsRef<[EnvItem]> for EnvList
impl AsRef<[EnvItem]> for EnvList
Provide compatibility with the 3rd parameter of nix::unistd::execve
.
sourceimpl Display for EnvList
impl Display for EnvList
Display and string conversion of the environment list.
Also causes .to_string()
to be implemented.
sourceimpl<'a, S> From<&'a EnvList> for HashMap<&'a OsStr, &'a OsStr, S> where
S: BuildHasher + Default,
impl<'a, S> From<&'a EnvList> for HashMap<&'a OsStr, &'a OsStr, S> where
S: BuildHasher + Default,
Reference conversion to a referencing hash map
sourceimpl<'a> From<&'a EnvList> for Vec<&'a CStr>
impl<'a> From<&'a EnvList> for Vec<&'a CStr>
Reference conversion to a vector of “key=value” &CStr
s.
sourceimpl<'a> From<&'a EnvList> for Vec<(&'a OsStr, &'a OsStr)>
impl<'a> From<&'a EnvList> for Vec<(&'a OsStr, &'a OsStr)>
Reference conversion to a vector of (&key, &value) tuples.
sourceimpl<S> From<EnvList> for HashMap<OsString, OsString, S> where
S: BuildHasher + Default,
impl<S> From<EnvList> for HashMap<OsString, OsString, S> where
S: BuildHasher + Default,
Conversion to a hash map
sourceimpl From<EnvList> for Vec<(OsString, OsString)>
impl From<EnvList> for Vec<(OsString, OsString)>
Conversion to a vector of (key, value) tuples.
sourceimpl<'a> IntoIterator for &'a EnvList
impl<'a> IntoIterator for &'a EnvList
Provide direct for
-loop support.
See EnvList::iter()
.
Auto Trait Implementations
impl RefUnwindSafe for EnvList
impl Send for EnvList
impl Sync for EnvList
impl Unpin for EnvList
impl UnwindSafe for EnvList
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more