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: boolFlag indicating whether the Client should close the session on drop
Implementations§
Source§impl<'a> Client<'a, PasswordConv>
impl<'a> Client<'a, PasswordConv>
Sourcepub fn with_password(service: &str) -> PamResult<Client<'a, PasswordConv>>
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>
impl<'a, C: Conversation> Client<'a, C>
Sourcepub fn with_conversation(
service: &str,
conversation: C,
) -> PamResult<Client<'a, C>>
pub fn with_conversation( service: &str, conversation: C, ) -> PamResult<Client<'a, C>>
Create a new Client with the given service name and conversation handler
Sourcepub fn conversation(&self) -> &C
pub fn conversation(&self) -> &C
Immutable access to the conversation handler of this Client
Sourcepub fn conversation_mut(&mut self) -> &mut C
pub fn conversation_mut(&mut self) -> &mut C
Mutable access to the conversation handler of this Client
Sourcepub fn authenticate(&mut self, flags: PamFlag) -> PamResult<()>
pub fn authenticate(&mut self, flags: PamFlag) -> PamResult<()>
Perform authentication with the provided credentials
Sourcepub fn change_authentication_token(&mut self, flags: PamFlag) -> PamResult<()>
pub fn change_authentication_token(&mut self, flags: PamFlag) -> PamResult<()>
Perform the chauthtok to support password update
Sourcepub fn get_user(&mut self) -> PamResult<String>
pub fn get_user(&mut self) -> PamResult<String>
Perform the get_item / PAM_USER to retrive the username
Sourcepub fn open_session(&mut self) -> PamResult<()>
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).