00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
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
00046 class session
00047 {
00048 public:
00050 enum operation
00051 {
00052 OPERATION_AUTOMATIC,
00053 OPERATION_BEGIN,
00054 OPERATION_RECOVER,
00055 OPERATION_END,
00056 OPERATION_RUN
00057 };
00058
00060 enum error_code
00061 {
00062 CHDIR,
00063 CHDIR_FB,
00064 CHILD_CORE,
00065 CHILD_FAIL,
00066 CHILD_FORK,
00067 CHILD_SIGNAL,
00068 CHILD_WAIT,
00069 CHROOT,
00070 CHROOT_ALIAS,
00071 CHROOT_LOCK,
00072 CHROOT_SETUP,
00073 CHROOT_UNKNOWN,
00074 CHROOT_UNLOCK,
00075 COMMAND_ABS,
00076 EXEC,
00077 GROUP_GET_SUP,
00078 GROUP_GET_SUPC,
00079 GROUP_SET,
00080 GROUP_SET_SUP,
00081 GROUP_UNKNOWN,
00082 PAM,
00083 ROOT_DROP,
00084 SET_SESSION_ID,
00085 SHELL,
00086 SHELL_FB,
00087 SIGNAL_CATCH,
00088 SIGNAL_SET,
00089 USER_SET,
00090 USER_SWITCH
00091 };
00092
00094 typedef custom_error<error_code> error;
00095
00097 typedef std::tr1::shared_ptr<chroot_config> config_ptr;
00098
00100 typedef std::tr1::shared_ptr<session> ptr;
00101
00110 session (std::string const& service,
00111 config_ptr& config,
00112 operation operation,
00113 string_list const& chroots);
00114
00116 virtual ~session ();
00117
00123 auth::ptr const&
00124 get_auth () const;
00125
00131 void
00132 set_auth (auth::ptr& auth);
00133
00139 config_ptr const&
00140 get_config () const;
00141
00147 void
00148 set_config (config_ptr& config);
00149
00155 string_list const&
00156 get_chroots () const;
00157
00163 void
00164 set_chroots (string_list const& chroots);
00165
00171 operation
00172 get_operation () const;
00173
00179 void
00180 set_operation (operation operation);
00181
00188 std::string const&
00189 get_session_id () const;
00190
00197 void
00198 set_session_id (std::string const& session_id);
00199
00205 bool
00206 get_force () const;
00207
00213 void
00214 set_force (bool force);
00215
00219 void
00220 save_termios ();
00221
00225 void
00226 restore_termios ();
00227
00234 int
00235 get_child_status () const;
00236
00237 protected:
00241 void
00242 get_chroot_membership (chroot::ptr const& chroot,
00243 bool& in_users,
00244 bool& in_root_users,
00245 bool& in_groups,
00246 bool& in_root_groups) const;
00247
00253 virtual auth::status
00254 get_chroot_auth_status (auth::status status,
00255 chroot::ptr const& chroot) const;
00256
00257 public:
00263 virtual sbuild::auth::status
00264 get_auth_status () const;
00265
00272 void
00273 run ();
00274
00275 protected:
00283 virtual void
00284 run_impl ();
00285
00292 virtual string_list
00293 get_login_directories () const;
00294
00301 virtual string_list
00302 get_command_directories () const;
00303
00311 virtual std::string
00312 get_shell () const;
00313
00322 virtual void
00323 get_command (chroot::ptr& session_chroot,
00324 std::string& file,
00325 string_list& command) const;
00326
00335 virtual void
00336 get_login_command (chroot::ptr& session_chroot,
00337 std::string& file,
00338 string_list& command) const;
00339
00348 virtual void
00349 get_user_command (chroot::ptr& session_chroot,
00350 std::string& file,
00351 string_list& command) const;
00352
00353 private:
00367 void
00368 setup_chroot (chroot::ptr& session_chroot,
00369 chroot::setup_type setup_type);
00370
00379 void
00380 run_chroot (chroot::ptr& session_chroot);
00381
00390 void
00391 run_child (chroot::ptr& session_chroot);
00392
00401 void
00402 wait_for_child (pid_t pid,
00403 int& child_status);
00404
00410 void
00411 set_sighup_handler ();
00412
00416 void
00417 clear_sighup_handler ();
00418
00424 void
00425 set_sigterm_handler ();
00426
00430 void
00431 clear_sigterm_handler ();
00432
00441 void
00442 set_signal_handler (int signal,
00443 struct sigaction *saved_signal,
00444 void (*handler)(int));
00445
00453 void
00454 clear_signal_handler (int signal,
00455 struct sigaction *saved_signal);
00456
00458 auth::ptr authstat;
00460 config_ptr config;
00462 string_list chroots;
00464 int chroot_status;
00466 bool lock_status;
00468 int child_status;
00470 operation session_operation;
00472 std::string session_id;
00474 bool force;
00476 struct sigaction saved_sighup_signal;
00478 struct sigaction saved_sigterm_signal;
00480 struct termios saved_termios;
00482 bool termios_ok;
00483
00484 protected:
00486 std::string cwd;
00487 };
00488
00489 }
00490
00491 #endif
00492
00493
00494
00495
00496
00497