]>
Commit | Line | Data |
---|---|---|
d6c9574f | 1 | /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ |
15ae422b LP |
2 | |
3 | /*** | |
4 | This file is part of systemd. | |
5 | ||
6 | Copyright 2010 Lennart Poettering | |
7 | ||
8 | systemd is free software; you can redistribute it and/or modify it | |
5430f7f2 LP |
9 | under the terms of the GNU Lesser General Public License as published by |
10 | the Free Software Foundation; either version 2.1 of the License, or | |
15ae422b LP |
11 | (at your option) any later version. |
12 | ||
13 | systemd is distributed in the hope that it will be useful, but | |
14 | WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
5430f7f2 | 16 | Lesser General Public License for more details. |
15ae422b | 17 | |
5430f7f2 | 18 | You should have received a copy of the GNU Lesser General Public License |
15ae422b LP |
19 | along with systemd; If not, see <http://www.gnu.org/licenses/>. |
20 | ***/ | |
21 | ||
22 | #include <stdlib.h> | |
23 | #include <string.h> | |
24 | #include <unistd.h> | |
25 | #include <sys/mount.h> | |
25e870b5 | 26 | #include <linux/fs.h> |
15ae422b LP |
27 | |
28 | #include "namespace.h" | |
c17ec25e | 29 | #include "execute.h" |
15ae422b LP |
30 | #include "log.h" |
31 | ||
32 | int main(int argc, char *argv[]) { | |
33 | const char * const writable[] = { | |
34 | "/home", | |
35 | NULL | |
36 | }; | |
37 | ||
ac0930c8 | 38 | const char * const readonly[] = { |
5dcfe57b LP |
39 | "/", |
40 | "/usr", | |
41 | "/boot", | |
15ae422b LP |
42 | NULL |
43 | }; | |
44 | ||
45 | const char * const inaccessible[] = { | |
46 | "/home/lennart/projects", | |
47 | NULL | |
48 | }; | |
49 | ||
50 | int r; | |
c17ec25e MS |
51 | char tmp_dir[] = "/tmp/systemd-private-XXXXXX", |
52 | var_tmp_dir[] = "/var/tmp/systemd-private-XXXXXX"; | |
15ae422b | 53 | |
c17ec25e MS |
54 | assert_se(mkdtemp(tmp_dir)); |
55 | assert_se(mkdtemp(var_tmp_dir)); | |
56 | ||
57 | r = setup_namespace((char **) writable, | |
58 | (char **) readonly, | |
59 | (char **) inaccessible, | |
60 | tmp_dir, | |
61 | var_tmp_dir, | |
a610cc4f | 62 | NULL, |
7f112f50 | 63 | true, |
1b8689f9 LP |
64 | PROTECT_HOME_NO, |
65 | PROTECT_SYSTEM_NO, | |
c17ec25e | 66 | 0); |
ac0930c8 | 67 | if (r < 0) { |
da927ba9 | 68 | log_error_errno(r, "Failed to setup namespace: %m"); |
15ae422b LP |
69 | return 1; |
70 | } | |
71 | ||
72 | execl("/bin/sh", "/bin/sh", NULL); | |
73 | log_error("execl(): %m"); | |
74 | ||
75 | return 1; | |
76 | } |