]>
Commit | Line | Data |
---|---|---|
15ae422b LP |
1 | /*** |
2 | This file is part of systemd. | |
3 | ||
4 | Copyright 2010 Lennart Poettering | |
5 | ||
6 | systemd is free software; you can redistribute it and/or modify it | |
5430f7f2 LP |
7 | under the terms of the GNU Lesser General Public License as published by |
8 | the Free Software Foundation; either version 2.1 of the License, or | |
15ae422b LP |
9 | (at your option) any later version. |
10 | ||
11 | systemd is distributed in the hope that it will be useful, but | |
12 | WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
5430f7f2 | 14 | Lesser General Public License for more details. |
15ae422b | 15 | |
5430f7f2 | 16 | You should have received a copy of the GNU Lesser General Public License |
15ae422b LP |
17 | along with systemd; If not, see <http://www.gnu.org/licenses/>. |
18 | ***/ | |
19 | ||
20 | #include <stdlib.h> | |
15ae422b | 21 | #include <unistd.h> |
15ae422b | 22 | |
15ae422b | 23 | #include "log.h" |
cf0fbc49 | 24 | #include "namespace.h" |
15ae422b LP |
25 | |
26 | int main(int argc, char *argv[]) { | |
27 | const char * const writable[] = { | |
28 | "/home", | |
29 | NULL | |
30 | }; | |
31 | ||
ac0930c8 | 32 | const char * const readonly[] = { |
5dcfe57b LP |
33 | "/", |
34 | "/usr", | |
35 | "/boot", | |
15ae422b LP |
36 | NULL |
37 | }; | |
38 | ||
ee818b89 | 39 | const char *inaccessible[] = { |
15ae422b LP |
40 | "/home/lennart/projects", |
41 | NULL | |
42 | }; | |
ee818b89 AC |
43 | char *root_directory; |
44 | char *projects_directory; | |
15ae422b LP |
45 | |
46 | int r; | |
c17ec25e MS |
47 | char tmp_dir[] = "/tmp/systemd-private-XXXXXX", |
48 | var_tmp_dir[] = "/var/tmp/systemd-private-XXXXXX"; | |
15ae422b | 49 | |
c17ec25e MS |
50 | assert_se(mkdtemp(tmp_dir)); |
51 | assert_se(mkdtemp(var_tmp_dir)); | |
52 | ||
ee818b89 AC |
53 | root_directory = getenv("TEST_NS_CHROOT"); |
54 | projects_directory = getenv("TEST_NS_PROJECTS"); | |
55 | ||
56 | if (projects_directory) | |
57 | inaccessible[0] = projects_directory; | |
58 | ||
59 | log_info("Inaccessible directory: '%s'", inaccessible[0]); | |
60 | if (root_directory) | |
61 | log_info("Chroot: '%s'", root_directory); | |
62 | else | |
63 | log_info("Not chrooted"); | |
64 | ||
65 | r = setup_namespace(root_directory, | |
66 | (char **) writable, | |
c17ec25e MS |
67 | (char **) readonly, |
68 | (char **) inaccessible, | |
69 | tmp_dir, | |
70 | var_tmp_dir, | |
7f112f50 | 71 | true, |
59eeb84b LP |
72 | true, |
73 | true, | |
1b8689f9 LP |
74 | PROTECT_HOME_NO, |
75 | PROTECT_SYSTEM_NO, | |
c17ec25e | 76 | 0); |
ac0930c8 | 77 | if (r < 0) { |
da927ba9 | 78 | log_error_errno(r, "Failed to setup namespace: %m"); |
ee818b89 AC |
79 | |
80 | log_info("Usage:\n" | |
81 | " sudo TEST_NS_PROJECTS=/home/lennart/projects ./test-ns\n" | |
82 | " sudo TEST_NS_CHROOT=/home/alban/debian-tree TEST_NS_PROJECTS=/home/alban/debian-tree/home/alban/Documents ./test-ns"); | |
83 | ||
15ae422b LP |
84 | return 1; |
85 | } | |
86 | ||
87 | execl("/bin/sh", "/bin/sh", NULL); | |
56f64d95 | 88 | log_error_errno(errno, "execl(): %m"); |
15ae422b LP |
89 | |
90 | return 1; | |
91 | } |