19 #ifndef SBUILD_CHROOT_CHROOT_H
20 #define SBUILD_CHROOT_CHROOT_H
22 #include <sbuild/chroot/facet/facet.h>
23 #include <sbuild/custom-error.h>
24 #include <sbuild/environment.h>
25 #include <sbuild/format-detail.h>
26 #include <sbuild/keyfile.h>
27 #include <sbuild/regex.h>
28 #include <sbuild/util.h>
103 typedef std::shared_ptr<chroot>
ptr;
130 create (
const std::string& type);
151 const std::string& alias,
152 const std::string& user,
568 template <
typename T>
579 template <
typename T>
580 const std::shared_ptr<const T>
590 template <
typename T>
601 template <
typename T>
602 const std::shared_ptr<const T>
628 template <
typename T>
650 template <
typename T>
659 template <
typename T>
668 template <
typename T>
702 rhs->print_details(stream);
718 rhs->set_keyfile(keyfile);
734 rhs->get_keyfile(keyfile);
831 template <
typename T>
835 std::shared_ptr<T> ret;
837 for (
const auto& facet :
facets)
839 if (ret = std::dynamic_pointer_cast<T>(facet))
846 template <
typename T>
847 const std::shared_ptr<const T>
848 chroot::get_facet ()
const
850 std::shared_ptr<T> ret;
852 for (
const auto& facet :
facets)
854 if (ret = std::dynamic_pointer_cast<T>(facet))
858 return std::const_pointer_cast<T>(ret);
861 template <
typename T>
863 chroot::get_facet_strict ()
865 auto ret = get_facet<T>();
873 template <
typename T>
874 const std::shared_ptr<const T>
875 chroot::get_facet_strict ()
const
877 auto ret = get_facet<T>();
885 template <
typename T>
887 chroot::add_facet (std::shared_ptr<T> facet,
894 for (
const auto& facet :
facets)
896 if (std::dynamic_pointer_cast<T>(facet))
900 new_facet->set_chroot(*
this, copy);
901 facets.push_back(new_facet);
908 for (facet_list::iterator lfacet =
facets.begin();
911 facet_list::iterator current = lfacet++;
912 if ((*current)->get_name() == facet->get_name())
916 facet->set_chroot(*
this, copy);
920 template <
typename T>
922 chroot::remove_facet ()
924 for (facet_list::iterator facet =
facets.begin();
928 if (std::dynamic_pointer_cast<T>(*facet))
936 template <
typename T>
938 chroot::remove_facet (std::shared_ptr<T> facet)
943 template <
typename T>
945 chroot::replace_facet (std::shared_ptr<T> facet)
void add_facet(std::shared_ptr< T > facet, bool copy=false)
Add a chroot facet.
Definition: chroot.h:887
POSIX extended regular expression.
Definition: regex.h:66
std::shared_ptr< const chroot > const_ptr
A shared_ptr to a const chroot object.
Definition: chroot.h:106
void print_details(std::ostream &stream) const
Print detailed information about the chroot to a stream.
Definition: chroot.cc:637
void remove_facet()
Remove a chroot facet.
Definition: chroot.h:922
void set_description(const std::string &description)
Set the description of the chroot.
Definition: chroot.cc:234
chroot::ptr clone_source() const
Create a source chroot.
Definition: chroot.cc:185
void set_preserve_environment(bool preserve_environment)
Set if the environment should be preserved in the chroot.
Definition: chroot.cc:346
bool preserve_environment
Preserve environment?
Definition: chroot.h:801
Directory must have an absolute path.
Definition: chroot.h:81
Debian source builder components.
Definition: ctty.cc:31
Print all messages.
Definition: chroot.h:68
std::string default_shell
Default shell.
Definition: chroot.h:803
void set_environment_filter(const regex &environment_filter)
Set the environment filter of the chroot.
Definition: chroot.cc:370
std::string const & get_default_shell() const
Get default shell.
Definition: chroot.cc:352
void set_root_groups(const string_list &groups)
Set the groups allowed to access the chroot as root.
Definition: chroot.cc:302
bool get_active() const
Get the activity status of the chroot.
string_list const & get_groups() const
Get the groups allowed to access the chroot.
Definition: chroot.cc:272
Attempt to use facet which is not present.
Definition: chroot.h:82
void set_root_users(const string_list &users)
Set the users allowed to access the chroot as root.
Definition: chroot.cc:290
void unlock(setup_type type, int status)
Unlock a chroot during setup.
Definition: chroot.cc:571
Deactivate a chroot.
Definition: chroot.h:58
std::shared_ptr< facet::facet > facet_ptr
A shared pointer to a chroot facet.
Definition: chroot.h:109
Invalid name.
Definition: chroot.h:92
facet_list & get_facets()
Get the list of all chroot facets.
Definition: chroot.cc:507
regex environment_filter
Environment filter regex.
Definition: chroot.h:805
std::string const & get_name() const
Get the name of the chroot.
Definition: chroot.cc:198
string_list const & get_root_users() const
Get the users allowed to access the chroot as root.
Definition: chroot.cc:284
string_list const & get_root_groups() const
Get the groups allowed to access the chroot as root.
Definition: chroot.cc:296
string_list groups
Groups allowed to access the chroot.
Definition: chroot.h:793
bool original
Was the chroot automatically generated?
Definition: chroot.h:809
void set_default_shell(const std::string &default_shell)
Set the default shell.
Definition: chroot.cc:358
std::string const & get_description() const
Get the description of the chroot.
Definition: chroot.cc:228
Failed to unlink session file.
Definition: chroot.h:94
void get_keyfile(keyfile &keyfile) const
Copy the chroot properties into a keyfile.
Definition: chroot.cc:689
Container of environment variables.
Definition: environment.h:38
const char * get_verbosity_string() const
Get the message verbosity as a readable string.
Definition: chroot.cc:461
string_list users
Users allowed to access the chroot.
Definition: chroot.h:791
void set_original(bool original)
Set the originality of the chroot.
Definition: chroot.cc:382
Common chroot data.
Definition: chroot.h:50
void setup_env(environment &env) const
Set environment.
Definition: chroot.cc:538
Print messages (the default).
Definition: chroot.h:67
Advisory locking.
Definition: lock.h:38
Only print essential messages.
Definition: chroot.h:66
string_list list_facets() const
List all registered chroot facets.
Definition: chroot.cc:519
string_list root_groups
Groups allowed to access the chroot as root.
Definition: chroot.h:797
Device must have an absolute path.
Definition: chroot.h:77
verbosity message_verbosity
The message verbosity.
Definition: chroot.h:817
Unknown chroot type.
Definition: chroot.h:76
Location must have an absolute path.
Definition: chroot.h:91
verbosity get_verbosity() const
Get the message verbosity.
Definition: chroot.cc:455
File is not a regular file.
Definition: chroot.h:87
std::shared_ptr< T > get_facet()
Get a chroot facet.
Definition: chroot.h:833
void add_facet_by_name(facet::facet::ptr facet, bool copy=false)
Add a chroot facet by name (rather than type).
Definition: chroot.h:905
chroot::ptr clone_session(const std::string &session_id, const std::string &alias, const std::string &user, bool root) const
Create a session chroot.
Definition: chroot.cc:168
void set_verbosity(verbosity verbosity)
Set the message verbosity.
Definition: chroot.cc:488
Failed to discard lock.
Definition: chroot.h:90
void set_name(const std::string &name)
Set the name of the chroot.
Definition: chroot.cc:204
Message verbosity is invalid.
Definition: chroot.h:96
session_flags
Chroot session properties.
Definition: facet.h:54
std::string name
Chroot name.
Definition: chroot.h:787
std::string const & get_chroot_type() const
Get the type of the chroot.
Definition: chroot.cc:530
void set_keyfile(const keyfile &keyfile)
Set the chroot properties from a keyfile.
Definition: chroot.cc:767
static chroot::ptr create(const std::string &type)
Create a chroot.
Definition: chroot.cc:144
Failed to write session file.
Definition: chroot.h:95
Base class for all facets.
Definition: facet.h:50
Failed to unlock device.
Definition: chroot.h:80
void set_users(const string_list &users)
Set the users allowed to access the chroot.
Definition: chroot.cc:266
std::vector< std::string > string_list
A string vector.
Definition: types.h:38
File must have an absolute path.
Definition: chroot.h:85
File is not a block device.
Definition: chroot.h:79
std::string const & get_profile() const
Get the configuration profile for the chroot.
Definition: chroot.cc:421
void setup_lock(setup_type type, bool lock, int status)
Unlock a chroot during setup.
Definition: chroot.cc:578
std::string profile
Configuration profile for setup scripts (replaces script_config).
Definition: chroot.h:813
Chroot device name not set.
Definition: chroot.h:75
string_list command_prefix
Command prefix.
Definition: chroot.h:815
string_list root_users
Users allowed to access the chroot as root.
Definition: chroot.h:795
string_list get_used_keys() const
Get a list of the keys used during keyfile parsing.
Definition: chroot.cc:654
Custom error.
Definition: custom-error.h:31
void replace_facet(std::shared_ptr< T > facet)
Replace an existing chroot facet with a new facet.
Definition: chroot.h:945
string_list aliases
Alternative names for the chroot.
Definition: chroot.h:799
Reactivate a chroot.
Definition: chroot.h:57
void set_aliases(const string_list &aliases)
Set the aliases of the chroot.
Definition: chroot.cc:314
std::shared_ptr< chroot > ptr
A shared_ptr to a chroot object.
Definition: chroot.h:103
virtual ~chroot()
The destructor.
Definition: chroot.cc:139
std::string description
Chroot description.
Definition: chroot.h:789
void set_command_prefix(const string_list &command_prefix)
Set the command_prefix for the chroot.
Definition: chroot.cc:449
std::string get_path() const
Get the path to the chroot.
Definition: chroot.cc:254
friend keyfile const & operator>>(const keyfile &keyfile, ptr &rhs)
Chroot initialisation from a keyfile.
Definition: chroot.h:715
void set_profile(const std::string &profile)
Set configuration profile for the chroot.
Definition: chroot.cc:427
Attempt to add facet which is already in use.
Definition: chroot.h:84
facet_list facets
Contained chroot facets.
Definition: chroot.h:820
Configuration file parser.
Definition: keyfile.h:46
Could not set profile from script configuration path.
Definition: chroot.h:93
facet::facet::session_flags get_session_flags() const
Get the session flags of the chroot.
Definition: chroot.cc:586
std::string const & get_script_config() const
Get the script configuration file for the chroot.
Definition: chroot.cc:396
Attempt to add object which is not a facet.
Definition: chroot.h:83
std::string mount_location
Location to mount chroot in the filesystem (if any).
Definition: chroot.h:807
regex const & get_environment_filter() const
Get the environment filter of the chroot.
Definition: chroot.cc:364
void set_groups(const string_list &groups)
Set the users allowed to access the chroot.
Definition: chroot.cc:278
File has write permissions for others.
Definition: chroot.h:89
bool get_run_setup_scripts() const
Check if chroot setup scripts will be run.
Definition: chroot.cc:388
File is not owned by user root.
Definition: chroot.h:88
Activate a chroot.
Definition: chroot.h:56
string_list const & get_aliases() const
Get the aliases of the chroot.
Definition: chroot.cc:308
std::list< facet_ptr > facet_list
A list of chroot facets.
Definition: chroot.h:112
std::shared_ptr< facet > ptr
A shared_ptr to a chroot facet object.
Definition: facet.h:63
bool get_preserve_environment() const
Check if the environment should be preserved in the chroot.
Definition: chroot.cc:340
custom_error< error_code > error
Exception type.
Definition: chroot.h:100
error_code
Error codes.
Definition: chroot.h:72
std::string const & get_mount_location() const
Get the mount location of the chroot.
Definition: chroot.cc:240
chroot()
The constructor.
Definition: chroot.cc:86
Clean up after executing a command.
Definition: chroot.h:60
Failed to acquire lock.
Definition: chroot.h:86
string_list const & get_command_prefix() const
Get the command_prefix for the chroot.
Definition: chroot.cc:443
chroot::ptr clone() const
Copy the chroot.
Definition: chroot.cc:160
std::shared_ptr< T > get_facet_strict()
Get a chroot facet.
Definition: chroot.h:863
std::string script_config
Configuration of the setup and exec scripts.
Definition: chroot.h:811
setup_type
Type of setup to perform.
Definition: chroot.h:54
bool get_original() const
Get the originality of the chroot.
Definition: chroot.cc:376
void lock(setup_type type)
Lock a chroot during setup.
Definition: chroot.cc:565
void get_details(format_detail &detail) const
Get detailed information about the chroot for output.
Definition: chroot.cc:597
void set_script_config(const std::string &script_config)
Set the script configuration file for the chroot.
Definition: chroot.cc:402
Prepare for executing a command.
Definition: chroot.h:59
verbosity
Message verbosity.
Definition: chroot.h:64
friend std::ostream & operator<<(std::ostream &stream, const ptr &rhs)
Print detailed information about the chroot to a stream.
Definition: chroot.h:699
Chroot creation failed.
Definition: chroot.h:74
Failed to lock device.
Definition: chroot.h:78
void set_mount_location(const std::string &location)
Set the mount location of the chroot.
Definition: chroot.cc:246
string_list const & get_users() const
Get the users allowed to access the chroot.
Definition: chroot.cc:260