sbuild-chroot.h

Go to the documentation of this file.
00001 /* Copyright © 2005-2008  Roger Leigh <rleigh@debian.org>
00002  *
00003  * schroot is free software: you can redistribute it and/or modify it
00004  * under the terms of the GNU General Public License as published by
00005  * the Free Software Foundation, either version 3 of the License, or
00006  * (at your option) any later version.
00007  *
00008  * schroot is distributed in the hope that it will be useful, but
00009  * WITHOUT ANY WARRANTY; without even the implied warranty of
00010  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011  * General Public License for more details.
00012  *
00013  * You should have received a copy of the GNU General Public License
00014  * along with this program.  If not, see
00015  * <http://www.gnu.org/licenses/>.
00016  *
00017  *********************************************************************/
00018 
00019 #ifndef SBUILD_CHROOT_H
00020 #define SBUILD_CHROOT_H
00021 
00022 #include <sbuild/sbuild-custom-error.h>
00023 #include <sbuild/sbuild-environment.h>
00024 #include <sbuild/sbuild-format-detail.h>
00025 #include <sbuild/sbuild-keyfile.h>
00026 #include <sbuild/sbuild-personality.h>
00027 #include <sbuild/sbuild-regex.h>
00028 #include <sbuild/sbuild-tr1types.h>
00029 
00030 #include <ostream>
00031 #include <string>
00032 
00033 namespace sbuild
00034 {
00035 
00043   class chroot
00044   {
00045   public:
00047     enum setup_type
00048       {
00049         SETUP_START,   
00050         SETUP_RECOVER, 
00051         SETUP_STOP,    
00052         EXEC_START,    
00053         EXEC_STOP      
00054       };
00055 
00057     enum session_flags
00058       {
00059         SESSION_NOFLAGS = 0,     
00060         SESSION_CREATE = 1 << 0, 
00061         SESSION_CLONE  = 1 << 1, 
00062         SESSION_PURGE  = 1 << 2  
00063       };
00064 
00066     enum error_code
00067       {
00068         CHROOT_CREATE,   
00069         CHROOT_DEVICE,   
00070         CHROOT_TYPE,     
00071         DEVICE_ABS,      
00072         DEVICE_LOCK,     
00073         DEVICE_NOTBLOCK, 
00074         DEVICE_UNLOCK,   
00075         FILE_ABS,        
00076         FILE_LOCK,       
00077         FILE_NOTREG,     
00078         FILE_OWNER,      
00079         FILE_PERMS,      
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       string_list used;
00577       rhs->set_keyfile(keyfile, used);
00578       keyfile.check_keys(rhs->get_name(), used);
00579       return keyfile;
00580     }
00581 
00585     friend
00586     keyfile&
00587     operator << (keyfile&   keyfile,
00588                  ptr const& rhs)
00589     {
00590       rhs->get_keyfile(keyfile);
00591       return keyfile;
00592     }
00593 
00594 
00595   protected:
00601     virtual void
00602     get_details (format_detail& detail) const;
00603 
00611     void
00612     print_details (std::ostream& stream) const;
00613 
00621     virtual void
00622     get_keyfile (keyfile& keyfile) const;
00623 
00632     virtual void
00633     set_keyfile (keyfile const& keyfile,
00634                  string_list&   used_keys);
00635 
00636   private:
00638     std::string   name;
00640     std::string   description;
00642     unsigned int  priority;
00644     string_list   users;
00646     string_list   groups;
00648     string_list   root_users;
00650     string_list   root_groups;
00652     string_list   aliases;
00654     regex         environment_filter;
00656     std::string   mount_location;
00658     std::string   location;
00660     std::string   mount_device;
00662     bool          active;
00664     bool          original;
00666     bool          run_setup_scripts;
00668     bool          run_exec_scripts;
00670     std::string   script_config;
00672     string_list   command_prefix;
00674     personality   persona;
00675   };
00676 
00683   chroot::session_flags
00684   inline operator | (chroot::session_flags const& lhs,
00685                      chroot::session_flags const& rhs)
00686   {
00687     return static_cast<chroot::session_flags>
00688       (static_cast<int>(lhs) | static_cast<int>(rhs));
00689   }
00690 
00697   chroot::session_flags
00698   inline operator & (chroot::session_flags const& lhs,
00699                      chroot::session_flags const& rhs)
00700   {
00701     return static_cast<chroot::session_flags>
00702       (static_cast<int>(lhs) & static_cast<int>(rhs));
00703   }
00704 
00705 }
00706 
00707 #endif /* SBUILD_CHROOT_H */
00708 
00709 /*
00710  * Local Variables:
00711  * mode:C++
00712  * End:
00713  */

Generated on Mon May 5 09:25:41 2008 for sbuild by  doxygen 1.5.5