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§
Sourcefn prompt_echo_on(&mut self, prompt: &CStr) -> Result<CString, ErrorCode>
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.
ErrorCode::CONV_ERR: Conversation failure.ErrorCode::BUF_ERR: Memory allocation error.ErrorCode::CONV_AGAIN: no result yet, the PAM library should passErrorCode::INCOMPLETEto the application and let it try again later.
Sourcefn prompt_echo_off(&mut self, prompt: &CStr) -> Result<CString, ErrorCode>
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.
ErrorCode::CONV_ERR: Conversation failure.ErrorCode::BUF_ERR: Memory allocation error.ErrorCode::CONV_AGAIN: no result yet, the PAM library should passErrorCode::INCOMPLETEto the application and let it try again later.
Provided Methods§
Sourcefn init(&mut self, _default_user: Option<&str>)
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.
Sourcefn radio_prompt(&mut self, prompt: &CStr) -> Result<bool, ErrorCode>
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.
ErrorCode::CONV_ERR: Conversation failure.ErrorCode::BUF_ERR: Memory allocation error.ErrorCode::CONV_AGAIN: no result yet, the PAM library should passErrorCode::INCOMPLETEto the application and let it try again later.
Sourcefn binary_prompt(
&mut self,
_type: u8,
_data: &[u8],
) -> Result<(u8, Vec<u8>), ErrorCode>
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.
ErrorCode::CONV_ERR: Conversation failure.ErrorCode::BUF_ERR: Memory allocation error.ErrorCode::CONV_AGAIN: no result yet, the PAM library should passErrorCode::INCOMPLETEto the application and let it try again later.