sbuild-session.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 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_SESSION_H
00020 #define SBUILD_SESSION_H
00021 
00022 #include <sbuild/sbuild-auth.h>
00023 #include <sbuild/sbuild-chroot-config.h>
00024 #include <sbuild/sbuild-custom-error.h>
00025 
00026 #include <string>
00027 
00028 #include <signal.h>
00029 #include <sys/types.h>
00030 #include <termios.h>
00031 #include <unistd.h>
00032 
00033 namespace sbuild
00034 {
00035 
00047   class session : public auth
00048   {
00049   public:
00051     enum operation
00052       {
00053         OPERATION_AUTOMATIC, 
00054         OPERATION_BEGIN,     
00055         OPERATION_RECOVER,   
00056         OPERATION_END,       
00057         OPERATION_RUN        
00058       };
00059 
00061     enum error_code
00062       {
00063         CHDIR,          
00064         CHDIR_FB,       
00065         CHILD_CORE,     
00066         CHILD_FAIL,     
00067         CHILD_FORK,     
00068         CHILD_SIGNAL,   
00069         CHILD_WAIT,     
00070         CHROOT,         
00071         CHROOT_ALIAS,   
00072         CHROOT_LOCK,    
00073         CHROOT_SETUP,   
00074         CHROOT_UNKNOWN, 
00075         CHROOT_UNLOCK,  
00076         COMMAND_ABS,    
00077         EXEC,           
00078         GROUP_GET_SUP,  
00079         GROUP_GET_SUPC, 
00080         GROUP_SET,      
00081         GROUP_SET_SUP,  
00082         GROUP_UNKNOWN,  
00083         PAM,            
00084         ROOT_DROP,      
00085         SET_SESSION_ID, 
00086         SHELL,          
00087         SHELL_FB,       
00088         SIGNAL_CATCH,   
00089         SIGNAL_SET,     
00090         USER_SET,       
00091         USER_SWITCH     
00092       };
00093 
00095     typedef custom_error<error_code> error;
00096 
00098     typedef std::tr1::shared_ptr<chroot_config> config_ptr;
00099 
00101     typedef std::tr1::shared_ptr<session> ptr;
00102 
00111     session (std::string const& service,
00112              config_ptr&        config,
00113              operation          operation,
00114              string_list const& chroots);
00115 
00117     virtual ~session ();
00118 
00124     config_ptr const&
00125     get_config () const;
00126 
00132     void
00133     set_config (config_ptr& config);
00134 
00140     string_list const&
00141     get_chroots () const;
00142 
00148     void
00149     set_chroots (string_list const& chroots);
00150 
00156     operation
00157     get_operation () const;
00158 
00164     void
00165     set_operation (operation operation);
00166 
00173     std::string const&
00174     get_session_id () const;
00175 
00182     void
00183     set_session_id (std::string const& session_id);
00184 
00190     bool
00191     get_force () const;
00192 
00198     void
00199     set_force (bool force);
00200 
00204     void
00205     save_termios ();
00206 
00210     void
00211     restore_termios ();
00212 
00219     int
00220     get_child_status () const;
00221 
00222   protected:
00228     virtual auth::status
00229     get_chroot_auth_status (auth::status status,
00230                             chroot::ptr const& chroot) const;
00231 
00232   public:
00238     virtual sbuild::auth::status
00239     get_auth_status () const;
00240 
00241   protected:
00249     virtual void
00250     run_impl ();
00251 
00258     virtual string_list
00259     get_login_directories () const;
00260 
00267     virtual string_list
00268     get_command_directories () const;
00269 
00277     virtual std::string
00278     get_shell () const;
00279 
00288     virtual void
00289     get_command (chroot::ptr& session_chroot,
00290                  std::string& file,
00291                  string_list& command) const;
00292 
00301     virtual void
00302     get_login_command (chroot::ptr& session_chroot,
00303                        std::string& file,
00304                        string_list& command) const;
00305 
00314     virtual void
00315     get_user_command (chroot::ptr& session_chroot,
00316                       std::string& file,
00317                       string_list& command) const;
00318 
00319   private:
00333     void
00334     setup_chroot (chroot::ptr&       session_chroot,
00335                   chroot::setup_type setup_type);
00336 
00345     void
00346     run_chroot (chroot::ptr& session_chroot);
00347 
00356     void
00357     run_child (chroot::ptr& session_chroot);
00358 
00367     void
00368     wait_for_child (pid_t pid,
00369                     int&  child_status);
00370 
00376     void
00377     set_sighup_handler ();
00378 
00382     void
00383     clear_sighup_handler ();
00384 
00390     void
00391     set_sigterm_handler ();
00392 
00396     void
00397     clear_sigterm_handler ();
00398 
00407     void
00408     set_signal_handler (int                signal,
00409                         struct sigaction  *saved_signal,
00410                         void             (*handler)(int));
00411 
00419     void
00420     clear_signal_handler (int               signal,
00421                           struct sigaction *saved_signal);
00422 
00424     config_ptr       config;
00426     string_list      chroots;
00428     int              chroot_status;
00430     bool lock_status;
00432     int              child_status;
00434     operation        session_operation;
00436     std::string      session_id;
00438     bool             force;
00440     struct sigaction saved_sighup_signal;
00442     struct sigaction saved_sigterm_signal;
00444     struct termios saved_termios;
00446     bool termios_ok;
00447 
00448   protected:
00450     std::string      cwd;
00451   };
00452 
00453 }
00454 
00455 #endif /* SBUILD_SESSION_H */
00456 
00457 /*
00458  * Local Variables:
00459  * mode:C++
00460  * End:
00461  */

Generated on Sat Jul 5 11:58:47 2008 for sbuild by  doxygen 1.5.6