sbuild
1.7.1
Main Page
Related Pages
Namespaces
Classes
Files
File List
lib
sbuild
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
:
49
struct
chroot_list_entry
50
{
52
std::string
alias
;
54
chroot::chroot::ptr
chroot
;
55
};
56
58
typedef
std::vector<chroot_list_entry>
chroot_list
;
59
61
enum
operation
62
{
63
OPERATION_AUTOMATIC
,
64
OPERATION_BEGIN
,
65
OPERATION_RECOVER
,
66
OPERATION_END
,
67
OPERATION_RUN
68
};
69
71
enum
error_code
72
{
73
CHDIR
,
74
CHDIR_FB
,
75
CHILD_CORE
,
76
CHILD_FAIL
,
77
CHILD_FORK
,
78
CHILD_SIGNAL
,
79
CHILD_WAIT
,
80
CHROOT
,
81
CHROOT_ALIAS
,
82
CHROOT_LOCK
,
83
CHROOT_NOTFOUND
,
84
CHROOT_SETUP
,
85
CHROOT_UNLOCK
,
86
COMMAND_ABS
,
87
EXEC
,
88
GROUP_GET_SUP
,
89
GROUP_GET_SUPC
,
90
GROUP_SET
,
91
GROUP_SET_SUP
,
92
GROUP_UNKNOWN
,
93
PAM
,
94
ROOT_DROP
,
95
SET_SESSION_ID
,
96
SHELL
,
97
SHELL_FB
,
98
SIGNAL_CATCH
,
99
SIGNAL_SET
,
100
USER_SET
,
101
USER_SWITCH
102
};
103
105
typedef
custom_error<error_code>
error
;
106
108
typedef
std::shared_ptr<session>
ptr
;
109
117
session
(
const
std::string& service,
118
operation
operation
,
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
154
set_chroots
(
const
chroot_list
&
chroots
);
155
161
operation
162
get_operation
()
const
;
163
169
void
170
set_operation
(
operation
operation
);
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
221
set_preserve_environment
(
bool
preserve_environment
);
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
253
set_user_options
(
const
string_map
&
user_options
);
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
306
get_chroot_membership
(
const
chroot::chroot::ptr
& chroot,
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
318
get_chroot_auth_status
(
auth::auth::status
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
359
get_login_directories
(
chroot::chroot::ptr
& session_chroot,
360
const
environment
& env)
const
;
361
370
virtual
string_list
371
get_command_directories
(
chroot::chroot::ptr
& session_chroot,
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
493
set_sighup_handler
();
494
498
void
499
clear_sighup_handler
();
500
506
void
507
set_sigint_handler
();
508
512
void
513
clear_sigint_handler
();
514
520
void
521
set_sigterm_handler
();
522
526
void
527
clear_sigterm_handler
();
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
554
auth::auth::ptr
authstat
;
556
chroot_list
chroots
;
558
int
chroot_status
;
560
bool
lock_status
;
562
int
child_status
;
564
operation
session_operation
;
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
;
578
bool
termios_ok
;
580
std::string
verbosity
;
582
bool
preserve_environment
;
584
std::string
shell
;
586
string_map
user_options
;
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
*/
Generated on Wed Oct 2 2013 10:21:07 for sbuild by
1.8.4