Trait ConversationHandler

Source
pub trait ConversationHandler {
    // Required methods
    fn prompt_echo_on(&mut self, prompt: &CStr) -> Result<CString, ErrorCode>;
    fn prompt_echo_off(&mut self, prompt: &CStr) -> Result<CString, ErrorCode>;
    fn text_info(&mut self, msg: &CStr);
    fn error_msg(&mut self, msg: &CStr);

    // Provided methods
    fn init(&mut self, _default_user: Option<impl AsRef<str>>) { ... }
    fn radio_prompt(&mut self, prompt: &CStr) -> Result<bool, ErrorCode> { ... }
    fn binary_prompt(
        &mut self,
        _type: u8,
        _data: &[u8],
    ) -> Result<(u8, Vec<u8>), ErrorCode> { ... }
}
Expand description

Trait for PAM conversation functions

Implement this for custom behaviour when a PAM module asks for usernames, passwords, etc. or wants to show a message to the user

Required Methods§

Source

fn prompt_echo_on(&mut self, prompt: &CStr) -> Result<CString, ErrorCode>

Obtains a string whilst echoing text (e.g. username)

§Errors

You should return one of the following error codes on failure.

Source

fn prompt_echo_off(&mut self, prompt: &CStr) -> Result<CString, ErrorCode>

Obtains a string without echoing any text (e.g. password)

§Errors

You should return one of the following error codes on failure.

Source

fn text_info(&mut self, msg: &CStr)

Displays some text.

Source

fn error_msg(&mut self, msg: &CStr)

Displays an error message.

Provided Methods§

Source

fn init(&mut self, _default_user: Option<impl AsRef<str>>)

Called by Context directly after taking ownership of the handler.

May be called multiple times if Context::replace_conversation() is used. In this case it is called each time a context takes ownership and passed the current target username of that context (if any) as the argument.

The default implementation does nothing.

Source

fn radio_prompt(&mut self, prompt: &CStr) -> Result<bool, ErrorCode>

Obtains a yes/no answer (Linux specific).

The default implementation calls prompt_echo_on and maps any answer starting with ‘y’ or ‘j’ to “yes” and everything else to “no”.

§Errors

You should return one of the following error codes on failure.

Source

fn binary_prompt( &mut self, _type: u8, _data: &[u8], ) -> Result<(u8, Vec<u8>), ErrorCode>

Exchanges binary data (Linux specific, experimental).

The default implementation returns a conversation error.

§Errors

You should return one of the following error codes on failure.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl ConversationHandler for pam_client::conv_cli::Conversation

Source§

impl ConversationHandler for pam_client::conv_mock::Conversation

Source§

impl ConversationHandler for pam_client::conv_null::Conversation