sbuild-chroot.h

Go to the documentation of this file.
00001 /* Copyright © 2005-2007  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 2 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, write to the Free Software
00015  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
00016  * MA  02111-1307  USA
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 
00417     string_list const&
00418     get_command_prefix () const;
00419 
00426     void
00427     set_command_prefix (string_list const& command_prefix);
00428 
00434     personality const&
00435     get_persona () const;
00436 
00442     void
00443     set_persona (personality const& persona);
00444 
00450     virtual std::string const&
00451     get_chroot_type () const = 0;
00452 
00459     virtual void
00460     setup_env (environment& env);
00461 
00473     void
00474     lock (setup_type type);
00475 
00489     void
00490     unlock (setup_type type,
00491             int        status);
00492 
00493   protected:
00499     virtual void
00500     setup_session_info (bool start);
00501 
00516     virtual void
00517     setup_lock(setup_type type,
00518                bool       lock,
00519                int        status) = 0;
00520 
00521   public:
00528     virtual session_flags
00529     get_session_flags () const = 0;
00530 
00540     friend std::ostream&
00541     operator << (std::ostream& stream,
00542                  ptr const&    rhs)
00543     {
00544       rhs->print_details(stream);
00545       return stream;
00546     }
00547 
00551     friend
00552     keyfile const&
00553     operator >> (keyfile const& keyfile,
00554                  ptr&           rhs)
00555     {
00556       rhs->set_keyfile(keyfile);
00557       return keyfile;
00558     }
00559 
00563     friend
00564     keyfile&
00565     operator << (keyfile&   keyfile,
00566                  ptr const& rhs)
00567     {
00568       rhs->get_keyfile(keyfile);
00569       return keyfile;
00570     }
00571 
00572 
00573   protected:
00579     virtual void
00580     get_details (format_detail& detail) const;
00581 
00589     void
00590     print_details (std::ostream& stream) const;
00591 
00599     virtual void
00600     get_keyfile (keyfile& keyfile) const;
00601 
00609     virtual void
00610     set_keyfile (keyfile const& keyfile);
00611 
00612   private:
00614     std::string   name;
00616     std::string   description;
00618     unsigned int  priority;
00620     string_list   users;
00622     string_list   groups;
00624     string_list   root_users;
00626     string_list   root_groups;
00628     string_list   aliases;
00630     regex         environment_filter;
00632     std::string   mount_location;
00634     std::string   location;
00636     std::string   mount_device;
00638     bool          active;
00640     bool          original;
00642     bool          run_setup_scripts;
00644     bool          run_exec_scripts;
00646     string_list   command_prefix;
00648     personality   persona;
00649   };
00650 
00651 }
00652 
00653 #endif /* SBUILD_CHROOT_H */
00654 
00655 /*
00656  * Local Variables:
00657  * mode:C++
00658  * End:
00659  */

Generated on Thu May 10 23:11:06 2007 for sbuild by  doxygen 1.5.2