sbuild-chroot.h

Go to the documentation of this file.
00001 /* Copyright © 2005-2006  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-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_CREATE = 1 << 0 
00060       };
00061 
00063     enum error_code
00064       {
00065         CHROOT_CREATE,   
00066         CHROOT_DEVICE,   
00067         CHROOT_TYPE,     
00068         DEVICE_ABS,      
00069         DEVICE_LOCK,     
00070         DEVICE_NOTBLOCK, 
00071         DEVICE_STAT,     
00072         DEVICE_UNLOCK,   
00073         FILE_ABS,        
00074         FILE_LOCK,       
00075         FILE_NOTREG,     
00076         FILE_OWNER,      
00077         FILE_PERMS,      
00078         FILE_STAT,       
00079         FILE_UNLOCK,     
00080         LOCATION_ABS,    
00081         SESSION_UNLINK,  
00082         SESSION_WRITE    
00083       };
00084 
00086     typedef custom_error<error_code> error;
00087 
00089     typedef std::tr1::shared_ptr<chroot> ptr;
00090 
00091   protected:
00093     chroot ();
00094 
00095   public:
00097     virtual ~chroot ();
00098 
00105     static ptr
00106     create (std::string const& type);
00107 
00113     virtual ptr
00114     clone () const = 0;
00115 
00121     std::string const&
00122     get_name () const;
00123 
00129     void
00130     set_name (std::string const& name);
00131 
00137     std::string const&
00138     get_description () const;
00139 
00145     void
00146     set_description (std::string const& description);
00147 
00153     virtual std::string const&
00154     get_mount_location () const;
00155 
00161     void
00162     set_mount_location (std::string const& location);
00163 
00171     virtual std::string const&
00172     get_location () const;
00173 
00174   protected:
00182     virtual void
00183     set_location (std::string const& location);
00184 
00185   public:
00194     virtual std::string
00195     get_path () const;
00196 
00202     virtual std::string const&
00203     get_mount_device () const;
00204 
00210     void
00211     set_mount_device (std::string const& device);
00212 
00219     unsigned int
00220     get_priority () const;
00221 
00231     void
00232     set_priority (unsigned int priority);
00233 
00239     string_list const&
00240     get_users () const;
00241 
00247     void
00248     set_users (string_list const& users);
00249 
00255     string_list const&
00256     get_groups () const;
00257 
00263     void
00264     set_groups (string_list const& groups);
00265 
00273     string_list const&
00274     get_root_users () const;
00275 
00283     void
00284     set_root_users (string_list const& users);
00285 
00293     string_list const&
00294     get_root_groups () const;
00295 
00303     void
00304     set_root_groups (string_list const& groups);
00305 
00312     string_list const&
00313     get_aliases () const;
00314 
00321     void
00322     set_aliases (string_list const& aliases);
00323 
00329     bool
00330     get_active () const;
00331 
00337     void
00338     set_active (bool active);
00339 
00345     bool
00346     get_original () const;
00347 
00353     void
00354     set_original (bool original);
00355 
00361     bool
00362     get_run_setup_scripts () const;
00363 
00370     void
00371     set_run_setup_scripts (bool run_setup_scripts);
00372 
00378     bool
00379     get_run_exec_scripts () const;
00380 
00387     void
00388     set_run_exec_scripts (bool run_exec_scripts);
00389 
00396     string_list const&
00397     get_command_prefix () const;
00398 
00405     void
00406     set_command_prefix (string_list const& command_prefix);
00407 
00413     personality const&
00414     get_persona () const;
00415 
00421     void
00422     set_persona (personality const& persona);
00423 
00429     void
00430     set_persona (std::string const& persona);
00431 
00437     virtual std::string const&
00438     get_chroot_type () const = 0;
00439 
00446     virtual void
00447     setup_env (environment& env);
00448 
00460     void
00461     lock (setup_type type);
00462 
00476     void
00477     unlock (setup_type type,
00478             int        status);
00479 
00480   protected:
00486     virtual void
00487     setup_session_info (bool start);
00488 
00503     virtual void
00504     setup_lock(setup_type type,
00505                bool       lock,
00506                int        status) = 0;
00507 
00508   public:
00515     virtual session_flags
00516     get_session_flags () const = 0;
00517 
00527     friend std::ostream&
00528     operator << (std::ostream& stream,
00529                  ptr const&    rhs)
00530     {
00531       rhs->print_details(stream);
00532       return stream;
00533     }
00534 
00538     friend
00539     keyfile const&
00540     operator >> (keyfile const& keyfile,
00541                  ptr&           rhs)
00542     {
00543       rhs->set_keyfile(keyfile);
00544       return keyfile;
00545     }
00546 
00550     friend
00551     keyfile&
00552     operator << (keyfile&   keyfile,
00553                  ptr const& rhs)
00554     {
00555       rhs->get_keyfile(keyfile);
00556       return keyfile;
00557     }
00558 
00559 
00560   protected:
00566     virtual void
00567     get_details (format_detail& detail) const;
00568 
00576     void
00577     print_details (std::ostream& stream) const;
00578 
00586     virtual void
00587     get_keyfile (keyfile& keyfile) const;
00588 
00596     virtual void
00597     set_keyfile (keyfile const& keyfile);
00598 
00599   private:
00601     std::string   name;
00603     std::string   description;
00605     unsigned int  priority;
00607     string_list   users;
00609     string_list   groups;
00611     string_list   root_users;
00613     string_list   root_groups;
00615     string_list   aliases;
00617     std::string   mount_location;
00619     std::string   location;
00621     std::string   mount_device;
00623     bool          active;
00625     bool          original;
00627     bool          run_setup_scripts;
00629     bool          run_exec_scripts;
00631     string_list   command_prefix;
00633     personality   persona;
00634   };
00635 
00636 }
00637 
00638 #endif /* SBUILD_CHROOT_H */
00639 
00640 /*
00641  * Local Variables:
00642  * mode:C++
00643  * End:
00644  */

Generated on Fri Jul 14 19:52:17 2006 for schroot by  doxygen 1.4.7