sbuild  1.7.1
Public Types | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | List of all members
sbuild::auth::pam_conv_tty Class Reference

Authentication conversation handler for terminal devices. More...

#include <pam-conv-tty.h>

+ Inheritance diagram for sbuild::auth::pam_conv_tty:
+ Collaboration diagram for sbuild::auth::pam_conv_tty:

Public Types

enum  error_code {
  CTTY, TIMEOUT, TIMEOUT_PENDING, TERMIOS,
  CONV_TYPE
}
 Error codes. More...
 
typedef custom_error< error_codeerror
 Exception type.
 
- Public Types inherited from sbuild::auth::pam_conv
typedef std::vector< pam_messagemessage_list
 A list of messages.
 
typedef std::shared_ptr< pamauth_ptr
 A shared pointer to an pam object.
 
typedef std::weak_ptr< pamweak_auth_ptr
 A weak pointer to an pam object.
 
typedef std::shared_ptr< pam_convptr
 A shared_ptr to an pam_conv object.
 

Public Member Functions

virtual ~pam_conv_tty ()
 The destructor.
 
virtual auth_ptr get_auth ()
 Get the auth object. More...
 
virtual void set_auth (auth_ptr auth)
 Set the auth object. More...
 
virtual time_t get_warning_timeout ()
 Get the time at which the user will be warned. More...
 
virtual void set_warning_timeout (time_t timeout)
 Set the time at which the user will be warned. More...
 
virtual time_t get_fatal_timeout ()
 Get the time at which the conversation will be terminated with an error. More...
 
virtual void set_fatal_timeout (time_t timeout)
 Set the time at which the conversation will be terminated with an error. More...
 
virtual void conversation (pam_conv::message_list &messages)
 Hold a conversation with the user. More...
 
- Public Member Functions inherited from sbuild::auth::pam_conv
virtual ~pam_conv ()
 The destructor.
 

Static Public Member Functions

static ptr create (auth_ptr auth)
 Create an pam_conv_tty object. More...
 

Private Member Functions

 pam_conv_tty (auth_ptr auth)
 The constructor. More...
 
int get_delay ()
 Get the time delay before the next SIGALRM signal. More...
 
std::string read_string (std::string message, bool echo)
 Read user input from standard input. More...
 

Private Attributes

weak_auth_ptr auth
 The auth object.
 
time_t warning_timeout
 The time to warn at.
 
time_t fatal_timeout
 The time to end at.
 
time_t start_time
 The time the current delay was obtained at.
 

Additional Inherited Members

- Protected Member Functions inherited from sbuild::auth::pam_conv
 pam_conv ()
 The constructor.
 

Detailed Description

Authentication conversation handler for terminal devices.

This class is an implementation of the auth_pam_conv interface, and is used to interact with the user on a terminal (TTY) interface.

In order to implement timeouts, this class uses alarm(2). This has some important implications. Global state is modified by the object, so only one may be used at once in a single process. In addition, no other part of the process may set or unset the SIGALRM handlers and the alarm(2) timer during the time PAM authentication is proceeding.

Member Enumeration Documentation

Error codes.

Enumerator
CTTY 

No controlling terminal.

TIMEOUT 

Timed out.

TIMEOUT_PENDING 

Time is running out...

TERMIOS 

Failed to get terminal settings.

CONV_TYPE 

Unsupported conversation type.

Constructor & Destructor Documentation

sbuild::auth::pam_conv_tty::pam_conv_tty ( auth_ptr  auth)
private

The constructor.

Parameters
authThe authentication object this conversation handler will be associated with.

Referenced by create().

+ Here is the caller graph for this function:

Member Function Documentation

void sbuild::auth::pam_conv_tty::conversation ( pam_conv::message_list messages)
virtual

Hold a conversation with the user.

Each of the messages detailed in messages should be displayed to the user, asking for input where required. The type of message is indicated in the pam_message::type field of the pam_message. The pam_message::response field of the pam_message should be filled in if input is required.

On error, an exception will be thrown.

Parameters
messagesthe messages to display to the user, and responses to return to the caller.

Implements sbuild::auth::pam_conv.

References CONV_TYPE, sbuild::DEBUG_NOTICE, sbuild::log_ctty_error(), sbuild::log_ctty_info(), sbuild::log_debug(), sbuild::auth::pam_message::MESSAGE_ERROR, sbuild::auth::pam_message::MESSAGE_INFO, sbuild::auth::pam_message::MESSAGE_PROMPT_ECHO, sbuild::auth::pam_message::MESSAGE_PROMPT_NOECHO, and read_string().

pam_conv::ptr sbuild::auth::pam_conv_tty::create ( auth_ptr  auth)
static

Create an pam_conv_tty object.

Parameters
authThe authentication object this conversation handler will be associated with.
Returns
a shared pointer to the created object.

References pam_conv_tty().

pam_conv::auth_ptr sbuild::auth::pam_conv_tty::get_auth ( )
virtual

Get the auth object.

Returns
the auth object.

Implements sbuild::auth::pam_conv.

int sbuild::auth::pam_conv_tty::get_delay ( )
private

Get the time delay before the next SIGALRM signal.

If either the warning timeout or the fatal timeout have expired, a message to notify the user is printed to stderr. If the fatal timeout is reached, an exception is thrown.

Returns
the delay in seconds, or 0 if no delay is set.

References fatal_timeout, sbuild::log_ctty_exception_warning(), start_time, TIMEOUT, TIMEOUT_PENDING, and warning_timeout.

Referenced by read_string().

+ Here is the caller graph for this function:

time_t sbuild::auth::pam_conv_tty::get_fatal_timeout ( )
virtual

Get the time at which the conversation will be terminated with an error.

Returns
the time.

Implements sbuild::auth::pam_conv.

References fatal_timeout.

time_t sbuild::auth::pam_conv_tty::get_warning_timeout ( )
virtual

Get the time at which the user will be warned.

Returns
the time.

Implements sbuild::auth::pam_conv.

References warning_timeout.

std::string sbuild::auth::pam_conv_tty::read_string ( std::string  message,
bool  echo 
)
private

Read user input from standard input.

The prompt message is printed to prompt the user for input. If echo is true, the user input it echoed back to the terminal, but if false, echoing is suppressed using termios(3).

If the SIGALRM timer expires while waiting for input, this is handled by re-checking the delay time which will warn the user or cause the input routine to terminate if the fatal timeout has expired.

Parameters
messagethe message to prompt the user for input.
echoecho user input to screen.
Returns
a string, which is empty on failure.

References sbuild::cctty, CTTY, sbuild::CTTY_FILENO, get_delay(), and TERMIOS.

Referenced by conversation().

+ Here is the caller graph for this function:

void sbuild::auth::pam_conv_tty::set_auth ( auth_ptr  auth)
virtual

Set the auth object.

Parameters
auththe auth object.

Implements sbuild::auth::pam_conv.

void sbuild::auth::pam_conv_tty::set_fatal_timeout ( time_t  timeout)
virtual

Set the time at which the conversation will be terminated with an error.

Parameters
timeoutthe time to set.

Implements sbuild::auth::pam_conv.

References fatal_timeout.

void sbuild::auth::pam_conv_tty::set_warning_timeout ( time_t  timeout)
virtual

Set the time at which the user will be warned.

Parameters
timeoutthe time to set.

Implements sbuild::auth::pam_conv.

References warning_timeout.


The documentation for this class was generated from the following files: