Skip to main content

PtrPtrVec

Struct PtrPtrVec 

Source
pub struct PtrPtrVec<T> { /* private fields */ }
Expand description

A pointer-to-pointer-to-message container for PAM’s conversation callback.

The PAM conversation callback requires a pointer to a pointer of pam_messages. Linux-PAM handles this differently than all other PAM implementations (including the X/SSO PAM standard).

X/SSO appears to specify a pointer-to-pointer-to-array:

          points to  ┌────────────┐       ╔═ Message[] ═╗
messages ┄┄┄┄┄┄┄┄┄┄> │ *messages ┄┼┄┄┄┄┄> ║ style       ║
                     └────────────┘       ║ data ┄┄┄┄┄┄┄╫┄┄> ...
                                          ╟─────────────╢
                                          ║ style       ║
                                          ║ data ┄┄┄┄┄┄┄╫┄┄> ...
                                          ╟─────────────╢
                                          ║ ...         ║

whereas Linux-PAM uses an **argv-style pointer-to-array-of-pointers:

          points to  ┌──────────────┐      ╔═ Message ═╗
messages ┄┄┄┄┄┄┄┄┄┄> │ messages[0] ┄┼┄┄┄┄> ║ style     ║
                     │ messages[1] ┄┼┄┄┄╮  ║ data ┄┄┄┄┄╫┄┄> ...
                     │ ...          │   ┆  ╚═══════════╝
                                        ┆
                                        ┆    ╔═ Message ═╗
                                        ╰┄┄> ║ style     ║
                                             ║ data ┄┄┄┄┄╫┄┄> ...
                                             ╚═══════════╝

Because the messages remain owned by the application which calls into PAM, we can solve this with One Simple Trick: make the intermediate list point into the same array:

          points to  ┌──────────────┐      ╔═ Message[] ═╗
messages ┄┄┄┄┄┄┄┄┄┄> │ messages[0] ┄┼┄┄┄┄> ║ style       ║
                     │ messages[1] ┄┼┄┄╮   ║ data ┄┄┄┄┄┄┄╫┄┄> ...
                     │ ...          │  ┆   ╟─────────────╢
                                       ╰┄> ║ style       ║
                                           ║ data ┄┄┄┄┄┄┄╫┄┄> ...
                                           ╟─────────────╢
                                           ║ ...         ║

Implementations§

Source§

impl<T> PtrPtrVec<T>

Source

pub fn new(data: Vec<T>) -> Self

Takes ownership of the given Vec and creates a vec of pointers to it.

Source

pub fn into_inner(self) -> Vec<T>

Gives you back your Vec.

Source

pub fn as_ptr<Dest>(&self) -> *const *const Dest

Gets a pointer-to-pointer suitable for passing into the Conversation.

Source

pub unsafe fn iter_over_linux<'a, Src>( ptr_ptr: *const *const Src, count: usize, ) -> impl Iterator<Item = &'a T>
where T: 'a,

👎Deprecated:

use Self::iter_over instead, unless you really need this specific version

Iterates over a Linux-PAM–style pointer-to-array-of-pointers.

§Safety

ptr_ptr must be a valid pointer to an array of pointers, there must be at least count valid pointers in the array, and each pointer in that array must point to a valid T.

Source

pub unsafe fn iter_over_xsso<'a, Src>( ptr_ptr: *const *const Src, count: usize, ) -> impl Iterator<Item = &'a T>
where T: 'a,

👎Deprecated:

use Self::iter_over instead, unless you really need this specific version

Iterates over an X/SSO–style pointer-to-pointer-to-array.

§Safety

You must pass a valid pointer to a valid pointer to an array, there must be at least count elements in the array, and each value in that array must be a valid T.

Source

pub unsafe fn iter_over<'a, Src>( ptr_ptr: *const *const Src, count: usize, ) -> impl Iterator<Item = &'a T>
where T: 'a,

Iterates over a PAM message list appropriate to your system’s impl.

This selects the correct pointer/array structure to use for a message that was given to you by your system.

§Safety

ptr_ptr must point to a valid message list, there must be at least count messages in the list, and all messages must be a valid Src.

Trait Implementations§

Source§

impl<T: Debug> Debug for PtrPtrVec<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T> Send for PtrPtrVec<T>
where Vec<T>: Send,

Source§

impl<T> Sync for PtrPtrVec<T>
where Vec<T>: Sync,

Auto Trait Implementations§

§

impl<T> Freeze for PtrPtrVec<T>

§

impl<T> RefUnwindSafe for PtrPtrVec<T>
where T: RefUnwindSafe,

§

impl<T> Unpin for PtrPtrVec<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for PtrPtrVec<T>

§

impl<T> UnwindSafe for PtrPtrVec<T>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.