sbuild  1.7.1
session.h
1 /* Copyright © 2005-2013 Roger Leigh <rleigh@debian.org>
2  *
3  * schroot is free software: you can redistribute it and/or modify it
4  * under the terms of the GNU General Public License as published by
5  * the Free Software Foundation, either version 3 of the License, or
6  * (at your option) any later version.
7  *
8  * schroot is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11  * General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program. If not, see
15  * <http://www.gnu.org/licenses/>.
16  *
17  *********************************************************************/
18 
19 #ifndef SBUILD_SESSION_H
20 #define SBUILD_SESSION_H
21 
22 #include <sbuild/auth/auth.h>
23 #include <sbuild/chroot/chroot.h>
24 #include <sbuild/custom-error.h>
25 
26 #include <string>
27 
28 #include <signal.h>
29 #include <sys/types.h>
30 #include <termios.h>
31 #include <unistd.h>
32 
33 namespace sbuild
34 {
35 
46  class session
47  {
48  public:
50  {
52  std::string alias;
55  };
56 
58  typedef std::vector<chroot_list_entry> chroot_list;
59 
61  enum operation
62  {
68  };
69 
72  {
87  EXEC,
93  PAM,
102  };
103 
106 
108  typedef std::shared_ptr<session> ptr;
109 
117  session (const std::string& service,
119  const chroot_list& chroots);
120 
122  virtual ~session ();
123 
129  auth::auth::ptr const&
130  get_auth () const;
131 
137  void
138  set_auth (auth::auth::ptr& auth);
139 
145  chroot_list const&
146  get_chroots () const;
147 
153  void
155 
161  operation
162  get_operation () const;
163 
169  void
171 
178  std::string const&
179  get_session_id () const;
180 
187  void
188  set_session_id (const std::string& session_id);
189 
195  std::string const&
196  get_verbosity () const;
197 
204  void
205  set_verbosity (const std::string& verbosity);
206 
212  bool
213  get_preserve_environment () const;
214 
220  void
222 
228  std::string const&
229  get_shell_override () const;
230 
236  void
237  set_shell_override (const std::string& shell);
238 
244  string_map const&
245  get_user_options () const;
246 
252  void
254 
260  bool
261  get_force () const;
262 
268  void
269  set_force (bool force);
270 
274  void
275  save_termios ();
276 
280  void
281  restore_termios ();
282 
289  int
290  get_child_status () const;
291 
298  bool
299  is_group_member (const std::string& groupname) const;
300 
301  protected:
305  void
307  bool& in_users,
308  bool& in_root_users,
309  bool& in_groups,
310  bool& in_root_groups) const;
311 
317  virtual auth::auth::status
319  const chroot::chroot::ptr& chroot) const;
320 
321  public:
327  virtual auth::auth::status
328  get_auth_status () const;
329 
336  void
337  run ();
338 
339  protected:
347  virtual void
348  run_impl ();
349 
358  virtual string_list
360  const environment& env) const;
361 
370  virtual string_list
372  const environment& env) const;
373 
382  virtual string_list
383  get_shells (chroot::chroot::ptr& session_chroot) const;
384 
393  virtual std::string
394  get_shell (chroot::chroot::ptr& session_chroot) const;
395 
404  virtual void
405  get_command (chroot::chroot::ptr& session_chroot,
406  std::string& file,
407  string_list& command,
408  environment& env) const;
409 
418  virtual void
419  get_login_command (chroot::chroot::ptr& session_chroot,
420  std::string& file,
421  string_list& command,
422  environment& env) const;
423 
432  virtual void
433  get_user_command (chroot::chroot::ptr& session_chroot,
434  std::string& file,
435  string_list& command,
436  const environment& env) const;
437 
438  private:
451  void
452  setup_chroot (chroot::chroot::ptr& session_chroot,
453  chroot::chroot::setup_type setup_type);
454 
462  void
463  run_chroot (chroot::chroot::ptr& session_chroot);
464 
472  void
473  run_child (chroot::chroot::ptr& session_chroot);
474 
483  void
484  wait_for_child (pid_t pid,
485  int& child_status);
486 
492  void
494 
498  void
500 
506  void
508 
512  void
514 
520  void
522 
526  void
528 
537  void
538  set_signal_handler (int signal,
539  struct sigaction *saved_signal,
540  void (*handler)(int));
541 
549  void
550  clear_signal_handler (int signal,
551  struct sigaction *saved_signal);
552 
566  std::string session_id;
568  bool force;
570  struct sigaction saved_sighup_signal;
572  struct sigaction saved_sigint_signal;
574  struct sigaction saved_sigterm_signal;
576  struct termios saved_termios;
580  std::string verbosity;
584  std::string shell;
587 
588  protected:
590  std::string cwd;
591  };
592 
593 }
594 
595 #endif /* SBUILD_SESSION_H */
596 
597 /*
598  * Local Variables:
599  * mode:C++
600  * End:
601  */