Mercurial > crates > nonstick
diff src/libpam/environ.rs @ 103:dfcd96a74ac4 default tip
write a truly prodigious amount of documentation
adds a bunch of links to the OpenPAM man pages and the XSSO spec
as well as just a bunch of prose and stuff.
author | Paul Fisher <paul@pfish.zone> |
---|---|
date | Wed, 25 Jun 2025 00:59:24 -0400 |
parents | 3f11b8d30f63 |
children |
line wrap: on
line diff
--- a/src/libpam/environ.rs Tue Jun 24 18:11:38 2025 -0400 +++ b/src/libpam/environ.rs Wed Jun 25 00:59:24 2025 -0400 @@ -1,4 +1,3 @@ -#![allow(unused_variables)] // for now use crate::constants::{ErrorCode, Result}; use crate::environ::{EnvironMap, EnvironMapMut}; use crate::libpam::memory::CHeapString; @@ -31,6 +30,11 @@ fn environ_set(&mut self, key: &OsStr, value: Option<&OsStr>) -> Result<Option<OsString>> { let old = self.environ_get(key); + if old.is_none() && value.is_none() { + // pam_putenv returns an error if we try to remove a non-existent + // environment variable, so just avoid that entirely. + return Ok(None) + } let total_len = key.len() + value.map(OsStr::len).unwrap_or_default() + 2; let mut result = Vec::with_capacity(total_len); result.extend(key.as_bytes()); @@ -45,7 +49,7 @@ } fn environ_iter(&self) -> Result<impl Iterator<Item = (OsString, OsString)>> { - // SAFETY: This is a valid PAM handle. + // SAFETY: This is a valid PAM handle. It will return valid data. unsafe { NonNull::new(pam_ffi::pam_getenvlist( (self as *const LibPamHandle).cast_mut(),