- Main Page
- Namespaces
- Classes
- Files
- Directories
- Related Pages

- File List
- File Members

# 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     virtual std::string const&
    00430     get_chroot_type () const = 0;
    00431
    00438     virtual void
    00439     setup_env (environment& env);
    00440
    00452     void
    00453     lock (setup_type type);
    00454
    00468     void
    00469     unlock (setup_type type,
    00470             int        status);
    00471
    00472   protected:
    00478     virtual void
    00479     setup_session_info (bool start);
    00480
    00495     virtual void
    00496     setup_lock(setup_type type,
    00497                bool       lock,
    00498                int        status) = 0;
    00499
    00500   public:
    00507     virtual session_flags
    00508     get_session_flags () const = 0;
    00509
    00519     friend std::ostream&
    00520     operator << (std::ostream& stream,
    00521                  ptr const&    rhs)
    00522     {
    00523       rhs->print_details(stream);
    00524       return stream;
    00525     }
    00526
    00530     friend
    00531     keyfile const&
    00532     operator >> (keyfile const& keyfile,
    00533                  ptr&           rhs)
    00534     {
    00535       rhs->set_keyfile(keyfile);
    00536       return keyfile;
    00537     }
    00538
    00542     friend
    00543     keyfile&
    00544     operator << (keyfile&   keyfile,
    00545                  ptr const& rhs)
    00546     {
    00547       rhs->get_keyfile(keyfile);
    00548       return keyfile;
    00549     }
    00550
    00551
    00552   protected:
    00558     virtual void
    00559     get_details (format_detail& detail) const;
    00560
    00568     void
    00569     print_details (std::ostream& stream) const;
    00570
    00578     virtual void
    00579     get_keyfile (keyfile& keyfile) const;
    00580
    00588     virtual void
    00589     set_keyfile (keyfile const& keyfile);
    00590
    00591   private:
    00593     std::string   name;
    00595     std::string   description;
    00597     unsigned int  priority;
    00599     string_list   users;
    00601     string_list   groups;
    00603     string_list   root_users;
    00605     string_list   root_groups;
    00607     string_list   aliases;
    00609     std::string   mount_location;
    00611     std::string   location;
    00613     std::string   mount_device;
    00615     bool          active;
    00617     bool          original;
    00619     bool          run_setup_scripts;
    00621     bool          run_exec_scripts;
    00623     string_list   command_prefix;
    00625     personality   persona;
    00626   };
    00627
    00628 }
    00629
    00630 #endif /* SBUILD_CHROOT_H */
    00631
    00632 /*
    00633  * Local Variables:
    00634  * mode:C++
    00635  * End:
    00636  */