Client

Struct Client 

Source
pub struct Client<'a, C: Conversation> {
    pub close_on_drop: bool,
    /* private fields */
}
Expand description

Main struct to authenticate a user

You need to create an instance of it to start an authentication process. If you want a simple password-based authentication, you can use Client::with_password, and to the following flow:

use pam::Client;

let mut client = Client::with_password("system-auth")
        .expect("Failed to init PAM client.");
// Preset the login & password we will use for authentication
client.conversation_mut().set_credentials("login", "password");
// Actually try to authenticate:
client.authenticate().expect("Authentication failed!");
// Now that we are authenticated, it's possible to open a sesssion:
client.open_session().expect("Failed to open a session!");

If you wish to customise the PAM conversation function, you should rather create your client with Client::with_handler, providing a struct implementing the conv::Conversation trait. You can then mutably access your conversation handler using the Client::handler_mut method.

By default, the Client will close any opened session when dropped. If you don’t want this, you can change its close_on_drop field to False.

Fields§

§close_on_drop: bool

Flag indicating whether the Client should close the session on drop

Implementations§

Source§

impl<'a> Client<'a, PasswordConv>

Source

pub fn with_password(service: &str) -> PamResult<Client<'a, PasswordConv>>

Create a new Client with the given service name and a password-based conversation

Source§

impl<'a, C: Conversation> Client<'a, C>

Source

pub fn with_conversation( service: &str, conversation: C, ) -> PamResult<Client<'a, C>>

Create a new Client with the given service name and conversation handler

Source

pub fn conversation(&self) -> &C

Immutable access to the conversation handler of this Client

Source

pub fn conversation_mut(&mut self) -> &mut C

Mutable access to the conversation handler of this Client

Source

pub fn authenticate(&mut self, flags: PamFlag) -> PamResult<()>

Perform authentication with the provided credentials

Source

pub fn change_authentication_token(&mut self, flags: PamFlag) -> PamResult<()>

Perform the chauthtok to support password update

Source

pub fn get_user(&mut self) -> PamResult<String>

Perform the get_item / PAM_USER to retrive the username

Source

pub fn open_session(&mut self) -> PamResult<()>

Open a session for a previously authenticated user and initialize the environment appropriately (in PAM and regular enviroment variables).

Trait Implementations§

Source§

impl<'a, C: Conversation> Drop for Client<'a, C>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<'a, C> Freeze for Client<'a, C>

§

impl<'a, C> RefUnwindSafe for Client<'a, C>
where C: RefUnwindSafe,

§

impl<'a, C> Send for Client<'a, C>
where C: Send,

§

impl<'a, C> Sync for Client<'a, C>
where C: Sync,

§

impl<'a, C> Unpin for Client<'a, C>

§

impl<'a, C> !UnwindSafe for Client<'a, C>

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.