Skip to main content

ConversationHandler

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<&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<&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.

Implementations on Foreign Types§

Source§

impl<'a, T: ConversationHandler + ?Sized> ConversationHandler for &'a mut T

Source§

fn init(&mut self, default_user: Option<&str>)

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

impl<T: ConversationHandler + ?Sized> ConversationHandler for Box<T>

Source§

fn init(&mut self, default_user: Option<&str>)

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Implementors§

Source§

impl ConversationHandler for pam_client2::conv_cli::Conversation

Source§

impl ConversationHandler for pam_client2::conv_mock::Conversation

Source§

impl ConversationHandler for pam_client2::conv_null::Conversation