1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
10 int main(int argc
, char *argv
[]) {
11 const char * const writable
[] = {
13 "-/home/lennart/projects/foobar", /* this should be masked automatically */
17 const char * const readonly
[] = {
28 const char * const exec
[] = {
36 const char * const no_exec
[] = {
41 const char *inaccessible
[] = {
42 "/home/lennart/projects",
46 static const BindMount bind_mount
= {
47 .source
= (char*) "/usr/bin",
48 .destination
= (char*) "/etc/systemd",
52 static const TemporaryFileSystem tmpfs
= {
53 .path
= (char*) "/var",
54 .options
= (char*) "ro",
58 char *projects_directory
;
60 char tmp_dir
[] = "/tmp/systemd-private-XXXXXX",
61 var_tmp_dir
[] = "/var/tmp/systemd-private-XXXXXX";
63 test_setup_logging(LOG_DEBUG
);
65 assert_se(mkdtemp(tmp_dir
));
66 assert_se(mkdtemp(var_tmp_dir
));
68 root_directory
= getenv("TEST_NS_CHROOT");
69 projects_directory
= getenv("TEST_NS_PROJECTS");
71 if (projects_directory
)
72 inaccessible
[0] = projects_directory
;
74 log_info("Inaccessible directory: '%s'", inaccessible
[0]);
76 log_info("Chroot: '%s'", root_directory
);
78 log_info("Not chrooted");
80 NamespaceParameters p
= {
81 .runtime_scope
= RUNTIME_SCOPE_SYSTEM
,
83 .root_directory
= root_directory
,
85 .read_write_paths
= (char**) writable
,
86 .read_only_paths
= (char**) readonly
,
87 .inaccessible_paths
= (char**) inaccessible
,
89 .exec_paths
= (char**) exec
,
90 .no_exec_paths
= (char**) no_exec
,
93 .var_tmp_dir
= var_tmp_dir
,
95 .bind_mounts
= &bind_mount
,
98 .temporary_filesystems
= &tmpfs
,
99 .n_temporary_filesystems
= 1,
102 .protect_control_groups
= true,
103 .protect_kernel_tunables
= true,
104 .protect_kernel_modules
= true,
105 .protect_proc
= PROTECT_PROC_NOACCESS
,
106 .proc_subset
= PROC_SUBSET_PID
,
109 r
= setup_namespace(&p
, NULL
);
111 log_error_errno(r
, "Failed to set up namespace: %m");
114 " sudo TEST_NS_PROJECTS=/home/lennart/projects ./test-ns\n"
115 " sudo TEST_NS_CHROOT=/home/alban/debian-tree TEST_NS_PROJECTS=/home/alban/debian-tree/home/alban/Documents ./test-ns");
120 execl("/bin/sh", "/bin/sh", NULL
);
121 log_error_errno(errno
, "execl(): %m");