sbuild::Session Class Reference

Session handler. More...

#include <sbuild-session.h>

Inheritance diagram for sbuild::Session:

Inheritance graph
[legend]
Collaboration diagram for sbuild::Session:

Collaboration graph
[legend]
List of all members.

Public Types

typedef runtime_error_custom<
Session
error
 Exception type.
typedef std::tr1::shared_ptr<
Config
config_ptr
 A shared_ptr to a Config object.
enum  Operation {
  OPERATION_AUTOMATIC, OPERATION_BEGIN, OPERATION_RECOVER, OPERATION_END,
  OPERATION_RUN
}
 Session operations. More...

Public Member Functions

 Session (const std::string &service, config_ptr &config, Operation operation, string_list chroots)
 The constructor.
virtual ~Session ()
 The destructor.
config_ptrget_config ()
 Get the configuration associated with this session.
void set_config (config_ptr &config)
 Set the configuration associated with this session.
const string_list & get_chroots () const
 Get the chroots to use in this session.
void set_chroots (const string_list &chroots)
 Set the chroots to use in this session.
Operation get_operation () const
 Get the operation this session will perform.
void set_operation (Operation operation)
 Set the operation this session will perform.
const std::string & get_session_id () const
 Get the session identifier.
void set_session_id (const std::string &session_id)
 Set the session identifier.
bool get_force () const
 Get the force status of this session.
void set_force (bool force)
 Set the force status of this session.
int get_child_status () const
 Get the exit (wait) status of the last child process to run in this session.
virtual sbuild::Auth::Status get_auth_status () const
 Check if authentication is required, taking groups and root-groups membership or all chroots specified into account.
virtual void run_impl ()
 Run a session.

Private Member Functions

int exec (const std::string &file, const string_list &command, const env_list &env)
 execve wrapper.
void setup_chroot (Chroot &session_chroot, Chroot::SetupType setup_type)
 Setup a chroot.
void run_chroot (Chroot &session_chroot)
 Run command or login shell in the specified chroot.
void run_child (Chroot &session_chroot)
 Run a command or login shell as a child process in the specified chroot.
void wait_for_child (int pid, int &child_status)
 Wait for a child process to complete, and check its exit status.

Private Attributes

config_ptr config
 The chroot configuration.
string_list chroots
 The chroots to run the session operation in.
int child_status
 The child exit status.
Operation operation
 The session operation to perform.
std::string session_id
 The session identifier.
bool force
 The session force status.

Detailed Description

Session handler.

This class provides the session handling for schroot. It derives from Auth, which performs all the necessary PAM actions, specialising it by overriding its virtual functions. This allows more sophisticated handling of user authorisation (groups and root-groups membership in the configuration file) and session management (setting up the session, entering the chroot and running the requested command or shell).


Member Enumeration Documentation

enum sbuild::Session::Operation
 

Session operations.

Enumerator:
OPERATION_AUTOMATIC  Begin, end and run a session automatically.
OPERATION_BEGIN  Begin a session.
OPERATION_RECOVER  Recover an existing (but inactive) session.
OPERATION_END  End a session.
OPERATION_RUN  Run a command in an existing session.


Constructor & Destructor Documentation

Session::Session const std::string &  service,
config_ptr config,
Operation  operation,
string_list  chroots
 

The constructor.

Parameters:
service the PAM service name.
config a shared_ptr to the chroot configuration.
operation the session operation to perform.
chroots the chroots to act upon.


Member Function Documentation

int Session::exec const std::string &  file,
const string_list &  command,
const env_list &  env
[private]
 

execve wrapper.

Run the command specified by file (an absolute pathname), using command and env as the argv and environment, respectively.

Parameters:
file the program to execute.
command the arguments to pass to the executable.
env the environment.
Returns:
the return value of the execve system call on failure.

int Session::get_child_status  )  const
 

Get the exit (wait) status of the last child process to run in this session.

Returns:
the exit status.

const string_list & Session::get_chroots  )  const
 

Get the chroots to use in this session.

Returns:
a list of chroots.

Session::config_ptr & Session::get_config  ) 
 

Get the configuration associated with this session.

Returns:
a shared_ptr to the configuration.

bool Session::get_force  )  const
 

Get the force status of this session.

Returns:
true if operation will be forced, otherwise false.

Session::Operation Session::get_operation  )  const
 

Get the operation this session will perform.

Returns:
the operation.

const std::string & Session::get_session_id  )  const
 

Get the session identifier.

The session identifier is a unique string to identify a session.

Returns:
the session id.

void Session::run_child Chroot session_chroot  )  [private]
 

Run a command or login shell as a child process in the specified chroot.

This method is only ever to be run in a child process, and will never return.

Parameters:
session_chroot the chroot to setup. This must be present in the chroot list and the chroot configuration object.

void Session::run_chroot Chroot session_chroot  )  [private]
 

Run command or login shell in the specified chroot.

An error will be thrown on failure.

Parameters:
session_chroot the chroot to setup. This must be present in the chroot list and the chroot configuration object.

void Session::run_impl  )  [virtual]
 

Run a session.

If a command has been specified, this will be run in each of the specified chroots. If no command has been specified, a login shell will run in the specified chroot.

An error will be thrown on failure.

Implements sbuild::Auth.

void Session::set_chroots const string_list &  chroots  ) 
 

Set the chroots to use in this session.

Parameters:
chroots a list of chroots.

void Session::set_config config_ptr config  ) 
 

Set the configuration associated with this session.

Parameters:
config a shared_ptr to the configuration.

void Session::set_force bool  force  ) 
 

Set the force status of this session.

Parameters:
force true to force operation, otherwise false.

void Session::set_operation Operation  operation  ) 
 

Set the operation this session will perform.

Parameters:
operation the operation.

void Session::set_session_id const std::string &  session_id  ) 
 

Set the session identifier.

The session identifier is a unique string to identify a session.

Parameters:
session_id the session id.

void Session::setup_chroot Chroot session_chroot,
Chroot::SetupType  setup_type
[private]
 

Setup a chroot.

This runs all of the commands in setup.d or run.d.

The environment variables CHROOT_NAME, CHROOT_DESCRIPTION, CHROOT_LOCATION, AUTH_USER and AUTH_VERBOSITY are set for use in setup scripts. See schroot-setup(5) for a complete list.

An error will be thrown on failure.

Parameters:
session_chroot the chroot to setup. This must be present in the chroot list and the chroot configuration object.
setup_type the type of setup to perform.

void Session::wait_for_child int  pid,
int &  child_status
[private]
 

Wait for a child process to complete, and check its exit status.

An error will be thrown on failure.

Parameters:
pid the pid to wait for.
child_status the place to store the child exit status.


Member Data Documentation

int sbuild::Session::child_status [private]
 

The child exit status.

Todo:
Remove child exit status.


The documentation for this class was generated from the following files:
Generated on Thu Dec 29 17:20:07 2005 for schroot by  doxygen 1.4.5