Mercurial > crates > nonstick
comparison src/libpam/environ.rs @ 144:56b559b7ecea
Big rename: separate concepts of Transaction from Handle.
- An application that uses PAM creates a Transaction.
- The Transaction has a Handle.
Currently, a module still get something called a "handle",
but that's probably going to change soon.
| author | Paul Fisher <paul@pfish.zone> |
|---|---|
| date | Sun, 06 Jul 2025 11:59:26 -0400 |
| parents | ebb71a412b58 |
| children | a75a66cb4181 |
comparison
equal
deleted
inserted
replaced
| 143:ebb71a412b58 | 144:56b559b7ecea |
|---|---|
| 1 use crate::environ::{EnvironMap, EnvironMapMut}; | 1 use crate::environ::{EnvironMap, EnvironMapMut}; |
| 2 use crate::libpam::memory::{CHeapBox, CHeapString}; | 2 use crate::libpam::memory::{CHeapBox, CHeapString}; |
| 3 use crate::libpam::{memory, RawPamHandle}; | 3 use crate::libpam::{memory, LibPamHandle}; |
| 4 use std::ffi::{c_char, CStr, CString, OsStr, OsString}; | 4 use std::ffi::{c_char, CStr, CString, OsStr, OsString}; |
| 5 use std::marker::PhantomData; | 5 use std::marker::PhantomData; |
| 6 use std::os::unix::ffi::{OsStrExt, OsStringExt}; | 6 use std::os::unix::ffi::{OsStrExt, OsStringExt}; |
| 7 use std::ptr; | 7 use std::ptr; |
| 8 use std::ptr::NonNull; | 8 use std::ptr::NonNull; |
| 9 | 9 |
| 10 impl RawPamHandle { | 10 impl LibPamHandle { |
| 11 fn environ_get(&self, key: &OsStr) -> Option<OsString> { | 11 fn environ_get(&self, key: &OsStr) -> Option<OsString> { |
| 12 let key = CString::new(key.as_bytes()).ok()?; | 12 let key = CString::new(key.as_bytes()).ok()?; |
| 13 // SAFETY: We are a valid handle and are calling with a good key. | 13 // SAFETY: We are a valid handle and are calling with a good key. |
| 14 let src = unsafe { libpam_sys::pam_getenv(self.raw_ref(), key.as_ptr()) }; | 14 let src = unsafe { libpam_sys::pam_getenv(self.raw_ref(), key.as_ptr()) }; |
| 15 let val = match NonNull::new(src) { | 15 let val = match NonNull::new(src) { |
| 53 } | 53 } |
| 54 } | 54 } |
| 55 | 55 |
| 56 /// A view to the environment stored in a PAM handle. | 56 /// A view to the environment stored in a PAM handle. |
| 57 pub struct LibPamEnviron<'a> { | 57 pub struct LibPamEnviron<'a> { |
| 58 source: &'a RawPamHandle, | 58 source: &'a LibPamHandle, |
| 59 } | 59 } |
| 60 | 60 |
| 61 /// A mutable view to the environment stored in a PAM handle. | 61 /// A mutable view to the environment stored in a PAM handle. |
| 62 pub struct LibPamEnvironMut<'a> { | 62 pub struct LibPamEnvironMut<'a> { |
| 63 source: &'a mut RawPamHandle, | 63 source: &'a mut LibPamHandle, |
| 64 } | 64 } |
| 65 | 65 |
| 66 impl<'a> LibPamEnviron<'a> { | 66 impl<'a> LibPamEnviron<'a> { |
| 67 pub fn new(source: &'a RawPamHandle) -> Self { | 67 pub fn new(source: &'a LibPamHandle) -> Self { |
| 68 Self { source } | 68 Self { source } |
| 69 } | 69 } |
| 70 } | 70 } |
| 71 | 71 |
| 72 impl<'a> LibPamEnvironMut<'a> { | 72 impl<'a> LibPamEnvironMut<'a> { |
| 73 pub fn new(source: &'a mut RawPamHandle) -> Self { | 73 pub fn new(source: &'a mut LibPamHandle) -> Self { |
| 74 Self { source } | 74 Self { source } |
| 75 } | 75 } |
| 76 } | 76 } |
| 77 | 77 |
| 78 impl EnvironMap<'_> for LibPamEnviron<'_> { | 78 impl EnvironMap<'_> for LibPamEnviron<'_> { |
| 111 /// This can't be a `CHeapBox` because it's not just a single | 111 /// This can't be a `CHeapBox` because it's not just a single |
| 112 /// `Option<EnvVar>`. | 112 /// `Option<EnvVar>`. |
| 113 start: NonNull<Option<EnvVar>>, | 113 start: NonNull<Option<EnvVar>>, |
| 114 /// The environment variable we're about to iterate into. | 114 /// The environment variable we're about to iterate into. |
| 115 current: NonNull<Option<EnvVar>>, | 115 current: NonNull<Option<EnvVar>>, |
| 116 _owner: PhantomData<&'a RawPamHandle>, | 116 _owner: PhantomData<&'a LibPamHandle>, |
| 117 } | 117 } |
| 118 | 118 |
| 119 impl EnvList<'_> { | 119 impl EnvList<'_> { |
| 120 fn empty() -> Self { | 120 fn empty() -> Self { |
| 121 let none: CHeapBox<Option<EnvVar>> = CHeapBox::new(None); | 121 let none: CHeapBox<Option<EnvVar>> = CHeapBox::new(None); |
