00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef SBUILD_SESSION_H
00021 #define SBUILD_SESSION_H
00022
00023 #include <sbuild/sbuild-auth.h>
00024 #include <sbuild/sbuild-chroot-config.h>
00025 #include <sbuild/sbuild-custom-error.h>
00026
00027 #include <string>
00028
00029 #include <signal.h>
00030 #include <sys/types.h>
00031 #include <termios.h>
00032 #include <unistd.h>
00033
00034 namespace sbuild
00035 {
00036
00048 class session : public auth
00049 {
00050 public:
00052 enum operation
00053 {
00054 OPERATION_AUTOMATIC,
00055 OPERATION_BEGIN,
00056 OPERATION_RECOVER,
00057 OPERATION_END,
00058 OPERATION_RUN
00059 };
00060
00062 enum error_code
00063 {
00064 CHDIR,
00065 CHDIR_FB,
00066 CHILD_CORE,
00067 CHILD_FAIL,
00068 CHILD_FORK,
00069 CHILD_SIGNAL,
00070 CHILD_WAIT,
00071 CHROOT,
00072 CHROOT_ALIAS,
00073 CHROOT_LOCK,
00074 CHROOT_SETUP,
00075 CHROOT_UNKNOWN,
00076 CHROOT_UNLOCK,
00077 COMMAND_ABS,
00078 EXEC,
00079 GROUP_GET_SUP,
00080 GROUP_GET_SUPC,
00081 GROUP_SET,
00082 GROUP_SET_SUP,
00083 GROUP_UNKNOWN,
00084 PAM,
00085 ROOT_DROP,
00086 SET_SESSION_ID,
00087 SHELL,
00088 SHELL_FB,
00089 SIGNAL_CATCH,
00090 SIGNAL_SET,
00091 USER_SET,
00092 USER_SWITCH
00093 };
00094
00096 typedef custom_error<error_code> error;
00097
00099 typedef std::tr1::shared_ptr<chroot_config> config_ptr;
00100
00102 typedef std::tr1::shared_ptr<session> ptr;
00103
00112 session (std::string const& service,
00113 config_ptr& config,
00114 operation operation,
00115 string_list const& chroots);
00116
00118 virtual ~session ();
00119
00125 config_ptr const&
00126 get_config () const;
00127
00133 void
00134 set_config (config_ptr& config);
00135
00141 string_list const&
00142 get_chroots () const;
00143
00149 void
00150 set_chroots (string_list const& chroots);
00151
00157 operation
00158 get_operation () const;
00159
00165 void
00166 set_operation (operation operation);
00167
00174 std::string const&
00175 get_session_id () const;
00176
00183 void
00184 set_session_id (std::string const& session_id);
00185
00191 bool
00192 get_force () const;
00193
00199 void
00200 set_force (bool force);
00201
00205 void
00206 save_termios ();
00207
00211 void
00212 restore_termios ();
00213
00220 int
00221 get_child_status () const;
00222
00223 protected:
00229 virtual auth::status
00230 get_chroot_auth_status (auth::status status,
00231 chroot::ptr const& chroot) const;
00232
00233 public:
00239 virtual sbuild::auth::status
00240 get_auth_status () const;
00241
00242 protected:
00250 virtual void
00251 run_impl ();
00252
00259 virtual string_list
00260 get_login_directories () const;
00261
00268 virtual string_list
00269 get_command_directories () const;
00270
00278 virtual std::string
00279 get_shell () const;
00280
00289 virtual void
00290 get_command (chroot::ptr& session_chroot,
00291 std::string& file,
00292 string_list& command) const;
00293
00302 virtual void
00303 get_login_command (chroot::ptr& session_chroot,
00304 std::string& file,
00305 string_list& command) const;
00306
00315 virtual void
00316 get_user_command (chroot::ptr& session_chroot,
00317 std::string& file,
00318 string_list& command) const;
00319
00320 private:
00334 void
00335 setup_chroot (chroot::ptr& session_chroot,
00336 chroot::setup_type setup_type);
00337
00346 void
00347 run_chroot (chroot::ptr& session_chroot);
00348
00357 void
00358 run_child (chroot::ptr& session_chroot);
00359
00368 void
00369 wait_for_child (pid_t pid,
00370 int& child_status);
00371
00377 void
00378 set_sighup_handler ();
00379
00383 void
00384 clear_sighup_handler ();
00385
00391 void
00392 set_sigterm_handler ();
00393
00397 void
00398 clear_sigterm_handler ();
00399
00408 void
00409 set_signal_handler (int signal,
00410 struct sigaction *saved_signal,
00411 void (*handler)(int));
00412
00420 void
00421 clear_signal_handler (int signal,
00422 struct sigaction *saved_signal);
00423
00425 config_ptr config;
00427 string_list chroots;
00429 int chroot_status;
00431 bool lock_status;
00433 int child_status;
00435 operation session_operation;
00437 std::string session_id;
00439 bool force;
00441 struct sigaction saved_sighup_signal;
00443 struct sigaction saved_sigterm_signal;
00445 struct termios saved_termios;
00447 bool termios_ok;
00448
00449 protected:
00451 std::string cwd;
00452 };
00453
00454 }
00455
00456 #endif
00457
00458
00459
00460
00461
00462