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>
104 typedef std::shared_ptr<chroot>
ptr;
127 create (std::string
const& type);
148 std::string
const& alias,
149 std::string
const& user,
150 bool root)
const = 0;
501 virtual std::string
const&
591 template <
typename T>
602 template <
typename T>
603 const std::shared_ptr<const T>
611 template <
typename T>
619 template <
typename T>
628 template <
typename T>
637 template <
typename T>
681 rhs->print_details(stream);
697 rhs->set_keyfile(keyfile);
713 rhs->get_keyfile(keyfile);
849 (
static_cast<int>(lhs) | static_cast<int>(rhs));
863 (
static_cast<int>(lhs) & static_cast<int>(rhs));
868 #include <sbuild/sbuild-chroot-facet.h>
873 template <
typename T>
877 std::shared_ptr<T> ret;
879 for (facet_list::const_iterator pos =
facets.begin();
883 if (ret = std::dynamic_pointer_cast<T>(*pos))
890 template <
typename T>
891 const std::shared_ptr<const T>
894 std::shared_ptr<T> ret;
896 for (facet_list::const_iterator pos =
facets.begin();
900 if (ret = std::dynamic_pointer_cast<T>(*pos))
904 return std::const_pointer_cast<T>(ret);
907 template <
typename T>
915 for (facet_list::const_iterator pos =
facets.begin();
919 if (std::dynamic_pointer_cast<T>(*pos))
923 new_facet->set_chroot(*
this);
924 facets.push_back(new_facet);
927 template <
typename T>
931 for (facet_list::iterator pos =
facets.begin();
935 if (std::dynamic_pointer_cast<T>(*pos))
943 template <
typename T>
950 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:55
static ptr create(std::string const &type)
Create a chroot.
Definition: sbuild-chroot.cc:170
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:806
std::string const & get_description() const
Get the description of the chroot.
Definition: sbuild-chroot.cc:238
Could not set profile from script configuration path.
Definition: sbuild-chroot.h:94
regex const & get_environment_filter() const
Get the environment filter of the chroot.
Definition: sbuild-chroot.cc:370
Device must have an absolute path.
Definition: sbuild-chroot.h:79
void set_verbosity(verbosity verbosity)
Set the message verbosity.
Definition: sbuild-chroot.cc:498
void replace_facet(std::shared_ptr< T > facet)
Replace an existing chroot facet with a new facet.
Definition: sbuild-chroot.h:952
Activate a chroot.
Definition: sbuild-chroot.h:51
Only print essential messages.
Definition: sbuild-chroot.h:68
File is not a block device.
Definition: sbuild-chroot.h:81
string_list users
Users allowed to access the chroot.
Definition: sbuild-chroot.h:800
virtual ~chroot()
The destructor.
Definition: sbuild-chroot.cc:165
std::string const & get_script_config() const
Get the script configuration file for the chroot.
Definition: sbuild-chroot.cc:406
void set_environment_filter(regex const &environment_filter)
Set the environment filter of the chroot.
Definition: sbuild-chroot.cc:376
std::shared_ptr< chroot_facet > facet_ptr
A shared pointer to a chroot facet.
Definition: sbuild-chroot.h:831
chroot()
The constructor.
Definition: sbuild-chroot.cc:107
Message verbosity is invalid.
Definition: sbuild-chroot.h:97
void set_aliases(string_list const &aliases)
Set the aliases of the chroot.
Definition: sbuild-chroot.cc:318
std::list< facet_ptr > facet_list
A list of chroot facets.
Definition: sbuild-chroot.h:833
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:66
Attempt to add facet which is already in use.
Definition: sbuild-chroot.h:85
Failed to lock device.
Definition: sbuild-chroot.h:80
friend std::ostream & operator<<(std::ostream &stream, ptr const &rhs)
Print detailed information about the chroot to a stream.
Definition: sbuild-chroot.h:678
Directory must have an absolute path.
Definition: sbuild-chroot.h:83
std::string default_shell
Default shell.
Definition: sbuild-chroot.h:812
chroot::session_flags operator&(chroot::session_flags const &lhs, chroot::session_flags const &rhs)
Bitwise-AND of specifed session properties.
Definition: sbuild-chroot.h:859
bool get_original() const
Get the originality of the chroot.
Definition: sbuild-chroot.cc:382
Chroot device name not set.
Definition: sbuild-chroot.h:77
verbosity get_verbosity() const
Get the message verbosity.
Definition: sbuild-chroot.cc:465
void setup_env(environment &env) const
Set environment.
Definition: sbuild-chroot.cc:532
bool preserve_environment
Preserve environment?
Definition: sbuild-chroot.h:810
Container of environment variables.
Definition: sbuild-environment.h:38
Attempt to add object which is not a facet.
Definition: sbuild-chroot.h:84
Unknown chroot type.
Definition: sbuild-chroot.h:78
friend keyfile const & operator>>(keyfile const &keyfile, ptr &rhs)
Chroot initialisation from a keyfile.
Definition: sbuild-chroot.h:694
verbosity message_verbosity
The message verbosity.
Definition: sbuild-chroot.h:828
void set_original(bool original)
Set the originality of the chroot.
Definition: sbuild-chroot.cc:388
File has write permissions for others.
Definition: sbuild-chroot.h:90
void set_preserve_environment(bool preserve_environment)
Set if the environment should be preserved in the chroot.
Definition: sbuild-chroot.cc:352
std::string const & get_name() const
Get the name of the chroot.
Definition: sbuild-chroot.cc:208
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:86
File is not a regular file.
Definition: sbuild-chroot.h:88
Failed to unlink session file.
Definition: sbuild-chroot.h:95
regex environment_filter
Environment filter regex.
Definition: sbuild-chroot.h:814
string_list root_users
Users allowed to access the chroot as root.
Definition: sbuild-chroot.h:804
std::string const & get_default_shell() const
Get default shell.
Definition: sbuild-chroot.cc:358
string_list root_groups
Groups allowed to access the chroot as root.
Definition: sbuild-chroot.h:806
Chroot creation failed.
Definition: sbuild-chroot.h:76
string_list list_facets() const
List all registered chroot facets.
Definition: sbuild-chroot.cc:517
std::string name
Chroot name.
Definition: sbuild-chroot.h:796
chroot::session_flags operator|(chroot::session_flags const &lhs, chroot::session_flags const &rhs)
Bitwise-OR of specifed session properties.
Definition: sbuild-chroot.h:845
string_list const & get_command_prefix() const
Get the command_prefix for the chroot.
Definition: sbuild-chroot.cc:453
string_list aliases
Alternative names for the chroot.
Definition: sbuild-chroot.h:808
void lock(setup_type type)
Lock a chroot during setup.
Definition: sbuild-chroot.cc:621
bool get_run_setup_scripts() const
Check if chroot setup scripts will be run.
Definition: sbuild-chroot.cc:394
string_list const & get_groups() const
Get the groups allowed to access the chroot.
Definition: sbuild-chroot.cc:276
void set_users(string_list const &users)
Set the users allowed to access the chroot.
Definition: sbuild-chroot.cc:270
Invalid name.
Definition: sbuild-chroot.h:93
virtual void setup_session_info(bool start)
Set up persistent session information.
Definition: sbuild-chroot.cc:570
string_list const & get_root_users() const
Get the users allowed to access the chroot as root.
Definition: sbuild-chroot.cc:288
void set_script_config(std::string const &script_config)
Set the script configuration file for the chroot.
Definition: sbuild-chroot.cc:412
Failed to unlock device.
Definition: sbuild-chroot.h:82
File is not owned by user root.
Definition: sbuild-chroot.h:89
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:802
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:634
string_list const & get_root_groups() const
Get the groups allowed to access the chroot as root.
Definition: sbuild-chroot.cc:300
bool original
Was the chroot automatically generated?
Definition: sbuild-chroot.h:818
void set_root_groups(string_list const &groups)
Set the groups allowed to access the chroot as root.
Definition: sbuild-chroot.cc:306
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:87
void set_mount_location(std::string const &location)
Set the mount location of the chroot.
Definition: sbuild-chroot.cc:256
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:312
void set_run_setup_scripts(bool run_setup_scripts)
Set whether chroot setup scripts will be run.
Definition: sbuild-chroot.cc:400
bool run_setup_scripts
Run chroot setup scripts?
Definition: sbuild-chroot.h:820
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:875
Print all messages.
Definition: sbuild-chroot.h:70
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:627
custom_error< error_code > error
Exception type.
Definition: sbuild-chroot.h:101
void remove_facet()
Remove a chroot facet.
Definition: sbuild-chroot.h:929
Reactivate a chroot.
Definition: sbuild-chroot.h:52
std::string description
Chroot description.
Definition: sbuild-chroot.h:798
std::string profile
Configuration profile for setup scripts (replaces script_config).
Definition: sbuild-chroot.h:824
std::shared_ptr< const chroot > const_ptr
A shared_ptr to a const chroot object.
Definition: sbuild-chroot.h:107
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:346
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:74
facet_list facets
Contained chroot facets.
Definition: sbuild-chroot.h:835
std::string const & get_profile() const
Get the configuration profile for the chroot.
Definition: sbuild-chroot.cc:431
void set_profile(std::string const &profile)
Set configuration profile for the chroot.
Definition: sbuild-chroot.cc:437
Failed to write session file.
Definition: sbuild-chroot.h:96
std::string mount_location
Location to mount chroot in the filesystem (if any).
Definition: sbuild-chroot.h:816
void get_keyfile(keyfile &keyfile) const
Copy the chroot properties into a keyfile.
Definition: sbuild-chroot.cc:717
void set_command_prefix(string_list const &command_prefix)
Set the command_prefix for the chroot.
Definition: sbuild-chroot.cc:459
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:364
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:909
Failed to discard lock.
Definition: sbuild-chroot.h:91
void get_details(format_detail &detail) const
Get detailed information about the chroot for output.
Definition: sbuild-chroot.cc:649
std::string script_config
Configuration of the setup and exec scripts.
Definition: sbuild-chroot.h:822
const char * get_verbosity_string() const
Get the message verbosity as a readable string.
Definition: sbuild-chroot.cc:471
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:104
std::string const & get_mount_location() const
Get the mount location of the chroot.
Definition: sbuild-chroot.cc:250
void set_name(std::string const &name)
Set the name of the chroot.
Definition: sbuild-chroot.cc:214
Print messages (the default).
Definition: sbuild-chroot.h:69
void print_details(std::ostream &stream) const
Print detailed information about the chroot to a stream.
Definition: sbuild-chroot.cc:700
void set_root_users(string_list const &users)
Set the users allowed to access the chroot as root.
Definition: sbuild-chroot.cc:294
No flags are set.
Definition: sbuild-chroot.h:59
Location must have an absolute path.
Definition: sbuild-chroot.h:92
void set_description(std::string const &description)
Set the description of the chroot.
Definition: sbuild-chroot.cc:244
string_list const & get_users() const
Get the users allowed to access the chroot.
Definition: sbuild-chroot.cc:264
void set_groups(string_list const &groups)
Set the users allowed to access the chroot.
Definition: sbuild-chroot.cc:282
string_list command_prefix
Command prefix.
Definition: sbuild-chroot.h:826