19 #ifndef SBUILD_CHROOT_H 20 #define SBUILD_CHROOT_H 22 #include <sbuild/sbuild-custom-error.h> 23 #include <sbuild/sbuild-environment.h> 24 #include <sbuild/sbuild-format-detail.h> 25 #include <sbuild/sbuild-keyfile.h> 26 #include <sbuild/sbuild-regex.h> 45 class chroot :
public std::enable_shared_from_this<chroot>
105 typedef std::shared_ptr<chroot>
ptr;
128 create (std::string
const& type);
149 std::string
const& alias,
150 std::string
const& user,
151 bool root)
const = 0;
502 virtual std::string
const&
592 template <
typename T>
603 template <
typename T>
604 const std::shared_ptr<const T>
612 template <
typename T>
620 template <
typename T>
629 template <
typename T>
638 template <
typename T>
682 rhs->print_details(stream);
698 rhs->set_keyfile(keyfile);
714 rhs->get_keyfile(keyfile);
767 keyfile& keyfile)
const = 0;
792 keyfile
const& keyfile,
850 (
static_cast<int>(lhs) | static_cast<int>(rhs));
864 (
static_cast<int>(lhs) & static_cast<int>(rhs));
869 #include <sbuild/sbuild-chroot-facet.h> 874 template <
typename T>
878 std::shared_ptr<T> ret;
880 for (facet_list::const_iterator pos =
facets.begin();
884 if (ret = std::dynamic_pointer_cast<T>(*pos))
891 template <
typename T>
892 const std::shared_ptr<const T>
895 std::shared_ptr<T> ret;
897 for (facet_list::const_iterator pos =
facets.begin();
901 if (ret = std::dynamic_pointer_cast<T>(*pos))
905 return std::const_pointer_cast<T>(ret);
908 template <
typename T>
916 for (facet_list::const_iterator pos =
facets.begin();
920 if (std::dynamic_pointer_cast<T>(*pos))
924 new_facet->set_chroot(*
this);
925 facets.push_back(new_facet);
928 template <
typename T>
932 for (facet_list::iterator pos =
facets.begin();
936 if (std::dynamic_pointer_cast<T>(*pos))
944 template <
typename T>
951 template <
typename T>
virtual std::string const & get_chroot_type() const =0
Get the type of the chroot.
POSIX extended regular expression.
Definition: sbuild-regex.h:66
static ptr create(std::string const &type)
Create a chroot.
Definition: sbuild-chroot.cc:172
virtual ptr clone() const =0
Copy the chroot.
void set_keyfile(keyfile const &keyfile)
Set the chroot properties from a keyfile.
Definition: sbuild-chroot.cc:810
std::string const & get_description() const
Get the description of the chroot.
Definition: sbuild-chroot.cc:240
Could not set profile from script configuration path.
Definition: sbuild-chroot.h:95
regex const & get_environment_filter() const
Get the environment filter of the chroot.
Definition: sbuild-chroot.cc:372
Device must have an absolute path.
Definition: sbuild-chroot.h:80
void set_verbosity(verbosity verbosity)
Set the message verbosity.
Definition: sbuild-chroot.cc:500
void replace_facet(std::shared_ptr< T > facet)
Replace an existing chroot facet with a new facet.
Definition: sbuild-chroot.h:953
Activate a chroot.
Definition: sbuild-chroot.h:51
Only print essential messages.
Definition: sbuild-chroot.h:69
File is not a block device.
Definition: sbuild-chroot.h:82
Debian source builder components.
Definition: sbuild-auth-null.h:24
string_list users
Users allowed to access the chroot.
Definition: sbuild-chroot.h:801
virtual ~chroot()
The destructor.
Definition: sbuild-chroot.cc:167
std::string const & get_script_config() const
Get the script configuration file for the chroot.
Definition: sbuild-chroot.cc:408
void set_environment_filter(regex const &environment_filter)
Set the environment filter of the chroot.
Definition: sbuild-chroot.cc:378
std::shared_ptr< chroot_facet > facet_ptr
A shared pointer to a chroot facet.
Definition: sbuild-chroot.h:832
chroot()
The constructor.
Definition: sbuild-chroot.cc:107
Message verbosity is invalid.
Definition: sbuild-chroot.h:98
void set_aliases(string_list const &aliases)
Set the aliases of the chroot.
Definition: sbuild-chroot.cc:320
std::list< facet_ptr > facet_list
A list of chroot facets.
Definition: sbuild-chroot.h:834
virtual chroot::ptr clone_session(std::string const &session_id, std::string const &alias, std::string const &user, bool root) const =0
Create a session chroot.
verbosity
Message verbosity.
Definition: sbuild-chroot.h:67
Attempt to add facet which is already in use.
Definition: sbuild-chroot.h:86
Failed to lock device.
Definition: sbuild-chroot.h:81
friend std::ostream & operator<<(std::ostream &stream, ptr const &rhs)
Print detailed information about the chroot to a stream.
Definition: sbuild-chroot.h:679
Directory must have an absolute path.
Definition: sbuild-chroot.h:84
std::string default_shell
Default shell.
Definition: sbuild-chroot.h:813
chroot::session_flags operator&(chroot::session_flags const &lhs, chroot::session_flags const &rhs)
Bitwise-AND of specifed session properties.
Definition: sbuild-chroot.h:860
The chroot is a source chroot.
Definition: sbuild-chroot.h:63
bool get_original() const
Get the originality of the chroot.
Definition: sbuild-chroot.cc:384
Chroot device name not set.
Definition: sbuild-chroot.h:78
verbosity get_verbosity() const
Get the message verbosity.
Definition: sbuild-chroot.cc:467
void setup_env(environment &env) const
Set environment.
Definition: sbuild-chroot.cc:534
bool preserve_environment
Preserve environment?
Definition: sbuild-chroot.h:811
Container of environment variables.
Definition: sbuild-environment.h:38
Attempt to add object which is not a facet.
Definition: sbuild-chroot.h:85
Unknown chroot type.
Definition: sbuild-chroot.h:79
friend keyfile const & operator>>(keyfile const &keyfile, ptr &rhs)
Chroot initialisation from a keyfile.
Definition: sbuild-chroot.h:695
verbosity message_verbosity
The message verbosity.
Definition: sbuild-chroot.h:829
void set_original(bool original)
Set the originality of the chroot.
Definition: sbuild-chroot.cc:390
File has write permissions for others.
Definition: sbuild-chroot.h:91
void set_preserve_environment(bool preserve_environment)
Set if the environment should be preserved in the chroot.
Definition: sbuild-chroot.cc:354
std::string const & get_name() const
Get the name of the chroot.
Definition: sbuild-chroot.cc:210
Advisory locking.
Definition: sbuild-lock.h:38
virtual void setup_lock(setup_type type, bool lock, int status)=0
Unlock a chroot during setup.
Configuration file parser.
Definition: sbuild-basic-keyfile.h:138
File must have an absolute path.
Definition: sbuild-chroot.h:87
File is not a regular file.
Definition: sbuild-chroot.h:89
Failed to unlink session file.
Definition: sbuild-chroot.h:96
regex environment_filter
Environment filter regex.
Definition: sbuild-chroot.h:815
string_list root_users
Users allowed to access the chroot as root.
Definition: sbuild-chroot.h:805
std::string const & get_default_shell() const
Get default shell.
Definition: sbuild-chroot.cc:360
string_list root_groups
Groups allowed to access the chroot as root.
Definition: sbuild-chroot.h:807
Chroot creation failed.
Definition: sbuild-chroot.h:77
string_list list_facets() const
List all registered chroot facets.
Definition: sbuild-chroot.cc:519
std::string name
Chroot name.
Definition: sbuild-chroot.h:797
chroot::session_flags operator|(chroot::session_flags const &lhs, chroot::session_flags const &rhs)
Bitwise-OR of specifed session properties.
Definition: sbuild-chroot.h:846
string_list const & get_command_prefix() const
Get the command_prefix for the chroot.
Definition: sbuild-chroot.cc:455
string_list aliases
Alternative names for the chroot.
Definition: sbuild-chroot.h:809
void lock(setup_type type)
Lock a chroot during setup.
Definition: sbuild-chroot.cc:625
bool get_run_setup_scripts() const
Check if chroot setup scripts will be run.
Definition: sbuild-chroot.cc:396
string_list const & get_groups() const
Get the groups allowed to access the chroot.
Definition: sbuild-chroot.cc:278
void set_users(string_list const &users)
Set the users allowed to access the chroot.
Definition: sbuild-chroot.cc:272
Invalid name.
Definition: sbuild-chroot.h:94
virtual void setup_session_info(bool start)
Set up persistent session information.
Definition: sbuild-chroot.cc:574
string_list const & get_root_users() const
Get the users allowed to access the chroot as root.
Definition: sbuild-chroot.cc:290
void set_script_config(std::string const &script_config)
Set the script configuration file for the chroot.
Definition: sbuild-chroot.cc:414
Failed to unlock device.
Definition: sbuild-chroot.h:83
File is not owned by user root.
Definition: sbuild-chroot.h:90
std::vector< std::string > string_list
A string vector.
Definition: sbuild-types.h:38
string_list groups
Groups allowed to access the chroot.
Definition: sbuild-chroot.h:803
The chroot supports session creation.
Definition: sbuild-chroot.h:60
Custom error.
Definition: sbuild-custom-error.h:32
session_flags get_session_flags() const
Get the session flags of the chroot.
Definition: sbuild-chroot.cc:638
string_list const & get_root_groups() const
Get the groups allowed to access the chroot as root.
Definition: sbuild-chroot.cc:302
bool original
Was the chroot automatically generated?
Definition: sbuild-chroot.h:819
void set_root_groups(string_list const &groups)
Set the groups allowed to access the chroot as root.
Definition: sbuild-chroot.cc:308
basic_keyfile< keyfile_traits, keyfile_parser< keyfile_traits > > keyfile
Configuration file parser.
Definition: sbuild-keyfile.h:159
Failed to acquire lock.
Definition: sbuild-chroot.h:88
void set_mount_location(std::string const &location)
Set the mount location of the chroot.
Definition: sbuild-chroot.cc:258
session_flags
Chroot session properties.
Definition: sbuild-chroot.h:57
virtual std::string get_path() const =0
Get the path to the chroot.
string_list const & get_aliases() const
Get the aliases of the chroot.
Definition: sbuild-chroot.cc:314
void set_run_setup_scripts(bool run_setup_scripts)
Set whether chroot setup scripts will be run.
Definition: sbuild-chroot.cc:402
bool run_setup_scripts
Run chroot setup scripts?
Definition: sbuild-chroot.h:821
setup_type
Type of setup to perform.
Definition: sbuild-chroot.h:49
std::shared_ptr< T > get_facet()
Get a chroot facet.
Definition: sbuild-chroot.h:876
Print all messages.
Definition: sbuild-chroot.h:71
bool get_active() const
Get the activity status of the chroot.
void unlock(setup_type type, int status)
Unlock a chroot during setup.
Definition: sbuild-chroot.cc:631
custom_error< error_code > error
Exception type.
Definition: sbuild-chroot.h:102
void remove_facet()
Remove a chroot facet.
Definition: sbuild-chroot.h:930
Reactivate a chroot.
Definition: sbuild-chroot.h:52
std::string description
Chroot description.
Definition: sbuild-chroot.h:799
std::string profile
Configuration profile for setup scripts (replaces script_config).
Definition: sbuild-chroot.h:825
std::shared_ptr< const chroot > const_ptr
A shared_ptr to a const chroot object.
Definition: sbuild-chroot.h:108
virtual chroot::ptr clone_source() const =0
Create a source chroot.
bool get_preserve_environment() const
Check if the environment should be preserved in the chroot.
Definition: sbuild-chroot.cc:348
The chroot supports cloning.
Definition: sbuild-chroot.h:61
Common chroot data.
Definition: sbuild-chroot.h:45
error_code
Error codes.
Definition: sbuild-chroot.h:75
facet_list facets
Contained chroot facets.
Definition: sbuild-chroot.h:836
std::string const & get_profile() const
Get the configuration profile for the chroot.
Definition: sbuild-chroot.cc:433
void set_profile(std::string const &profile)
Set configuration profile for the chroot.
Definition: sbuild-chroot.cc:439
Failed to write session file.
Definition: sbuild-chroot.h:97
std::string mount_location
Location to mount chroot in the filesystem (if any).
Definition: sbuild-chroot.h:817
void get_keyfile(keyfile &keyfile) const
Copy the chroot properties into a keyfile.
Definition: sbuild-chroot.cc:721
void set_command_prefix(string_list const &command_prefix)
Set the command_prefix for the chroot.
Definition: sbuild-chroot.cc:461
Deactivate a chroot.
Definition: sbuild-chroot.h:53
void set_default_shell(std::string const &default_shell)
Set the default shell.
Definition: sbuild-chroot.cc:366
The chroot should be purged.
Definition: sbuild-chroot.h:62
void add_facet(std::shared_ptr< T > facet)
Add a chroot facet.
Definition: sbuild-chroot.h:910
Failed to discard lock.
Definition: sbuild-chroot.h:92
void get_details(format_detail &detail) const
Get detailed information about the chroot for output.
Definition: sbuild-chroot.cc:653
std::string script_config
Configuration of the setup and exec scripts.
Definition: sbuild-chroot.h:823
const char * get_verbosity_string() const
Get the message verbosity as a readable string.
Definition: sbuild-chroot.cc:473
Common chroot data.
Definition: sbuild-chroot-facet.h:40
std::shared_ptr< chroot > ptr
A shared_ptr to a chroot object.
Definition: sbuild-chroot.h:105
std::string const & get_mount_location() const
Get the mount location of the chroot.
Definition: sbuild-chroot.cc:252
void set_name(std::string const &name)
Set the name of the chroot.
Definition: sbuild-chroot.cc:216
Print messages (the default).
Definition: sbuild-chroot.h:70
void print_details(std::ostream &stream) const
Print detailed information about the chroot to a stream.
Definition: sbuild-chroot.cc:704
void set_root_users(string_list const &users)
Set the users allowed to access the chroot as root.
Definition: sbuild-chroot.cc:296
No flags are set.
Definition: sbuild-chroot.h:59
Location must have an absolute path.
Definition: sbuild-chroot.h:93
void set_description(std::string const &description)
Set the description of the chroot.
Definition: sbuild-chroot.cc:246
string_list const & get_users() const
Get the users allowed to access the chroot.
Definition: sbuild-chroot.cc:266
void set_groups(string_list const &groups)
Set the users allowed to access the chroot.
Definition: sbuild-chroot.cc:284
string_list command_prefix
Command prefix.
Definition: sbuild-chroot.h:827