00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef SBUILD_CHROOT_H
00021 #define SBUILD_CHROOT_H
00022
00023 #include <sbuild/sbuild-custom-error.h>
00024 #include <sbuild/sbuild-environment.h>
00025 #include <sbuild/sbuild-format-detail.h>
00026 #include <sbuild/sbuild-keyfile.h>
00027 #include <sbuild/sbuild-personality.h>
00028 #include <sbuild/sbuild-regex.h>
00029 #include <sbuild/sbuild-tr1types.h>
00030
00031 #include <ostream>
00032 #include <string>
00033
00034 namespace sbuild
00035 {
00036
00044 class chroot
00045 {
00046 public:
00048 enum setup_type
00049 {
00050 SETUP_START,
00051 SETUP_RECOVER,
00052 SETUP_STOP,
00053 EXEC_START,
00054 EXEC_STOP
00055 };
00056
00058 enum session_flags
00059 {
00060 SESSION_CREATE = 1 << 0
00061 };
00062
00064 enum error_code
00065 {
00066 CHROOT_CREATE,
00067 CHROOT_DEVICE,
00068 CHROOT_TYPE,
00069 DEVICE_ABS,
00070 DEVICE_LOCK,
00071 DEVICE_NOTBLOCK,
00072 DEVICE_STAT,
00073 DEVICE_UNLOCK,
00074 FILE_ABS,
00075 FILE_LOCK,
00076 FILE_NOTREG,
00077 FILE_OWNER,
00078 FILE_PERMS,
00079 FILE_STAT,
00080 FILE_UNLOCK,
00081 LOCATION_ABS,
00082 SESSION_UNLINK,
00083 SESSION_WRITE
00084 };
00085
00087 typedef custom_error<error_code> error;
00088
00090 typedef std::tr1::shared_ptr<chroot> ptr;
00091
00092 protected:
00094 chroot ();
00095
00096 public:
00098 virtual ~chroot ();
00099
00106 static ptr
00107 create (std::string const& type);
00108
00114 virtual ptr
00115 clone () const = 0;
00116
00122 std::string const&
00123 get_name () const;
00124
00130 void
00131 set_name (std::string const& name);
00132
00138 std::string const&
00139 get_description () const;
00140
00146 void
00147 set_description (std::string const& description);
00148
00154 virtual std::string const&
00155 get_mount_location () const;
00156
00162 void
00163 set_mount_location (std::string const& location);
00164
00172 virtual std::string const&
00173 get_location () const;
00174
00175 protected:
00183 virtual void
00184 set_location (std::string const& location);
00185
00186 public:
00195 virtual std::string
00196 get_path () const;
00197
00203 virtual std::string const&
00204 get_mount_device () const;
00205
00211 void
00212 set_mount_device (std::string const& device);
00213
00220 unsigned int
00221 get_priority () const;
00222
00232 void
00233 set_priority (unsigned int priority);
00234
00240 string_list const&
00241 get_users () const;
00242
00248 void
00249 set_users (string_list const& users);
00250
00256 string_list const&
00257 get_groups () const;
00258
00264 void
00265 set_groups (string_list const& groups);
00266
00274 string_list const&
00275 get_root_users () const;
00276
00284 void
00285 set_root_users (string_list const& users);
00286
00294 string_list const&
00295 get_root_groups () const;
00296
00304 void
00305 set_root_groups (string_list const& groups);
00306
00313 string_list const&
00314 get_aliases () const;
00315
00322 void
00323 set_aliases (string_list const& aliases);
00324
00332 regex const&
00333 get_environment_filter () const;
00334
00342 void
00343 set_environment_filter (regex const& environment_filter);
00344
00350 bool
00351 get_active () const;
00352
00358 void
00359 set_active (bool active);
00360
00366 bool
00367 get_original () const;
00368
00374 void
00375 set_original (bool original);
00376
00382 bool
00383 get_run_setup_scripts () const;
00384
00391 void
00392 set_run_setup_scripts (bool run_setup_scripts);
00393
00399 bool
00400 get_run_exec_scripts () const;
00401
00408 void
00409 set_run_exec_scripts (bool run_exec_scripts);
00410
00418 std::string const&
00419 get_script_config () const;
00420
00428 void
00429 set_script_config (std::string const& script_config);
00430
00437 string_list const&
00438 get_command_prefix () const;
00439
00446 void
00447 set_command_prefix (string_list const& command_prefix);
00448
00454 personality const&
00455 get_persona () const;
00456
00462 void
00463 set_persona (personality const& persona);
00464
00470 virtual std::string const&
00471 get_chroot_type () const = 0;
00472
00479 virtual void
00480 setup_env (environment& env);
00481
00493 void
00494 lock (setup_type type);
00495
00509 void
00510 unlock (setup_type type,
00511 int status);
00512
00513 protected:
00519 virtual void
00520 setup_session_info (bool start);
00521
00536 virtual void
00537 setup_lock(setup_type type,
00538 bool lock,
00539 int status) = 0;
00540
00541 public:
00548 virtual session_flags
00549 get_session_flags () const = 0;
00550
00560 friend std::ostream&
00561 operator << (std::ostream& stream,
00562 ptr const& rhs)
00563 {
00564 rhs->print_details(stream);
00565 return stream;
00566 }
00567
00571 friend
00572 keyfile const&
00573 operator >> (keyfile const& keyfile,
00574 ptr& rhs)
00575 {
00576 rhs->set_keyfile(keyfile);
00577 return keyfile;
00578 }
00579
00583 friend
00584 keyfile&
00585 operator << (keyfile& keyfile,
00586 ptr const& rhs)
00587 {
00588 rhs->get_keyfile(keyfile);
00589 return keyfile;
00590 }
00591
00592
00593 protected:
00599 virtual void
00600 get_details (format_detail& detail) const;
00601
00609 void
00610 print_details (std::ostream& stream) const;
00611
00619 virtual void
00620 get_keyfile (keyfile& keyfile) const;
00621
00629 virtual void
00630 set_keyfile (keyfile const& keyfile);
00631
00632 private:
00634 std::string name;
00636 std::string description;
00638 unsigned int priority;
00640 string_list users;
00642 string_list groups;
00644 string_list root_users;
00646 string_list root_groups;
00648 string_list aliases;
00650 regex environment_filter;
00652 std::string mount_location;
00654 std::string location;
00656 std::string mount_device;
00658 bool active;
00660 bool original;
00662 bool run_setup_scripts;
00664 bool run_exec_scripts;
00666 std::string script_config;
00668 string_list command_prefix;
00670 personality persona;
00671 };
00672
00673 }
00674
00675 #endif
00676
00677
00678
00679
00680
00681