]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/core/namespace.h
5528b6c40bd1933cf7b89fe511ece84ec19963dc
[thirdparty/systemd.git] / src / core / namespace.h
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2 #pragma once
3
4 /***
5 Copyright 2010 Lennart Poettering
6 Copyright 2016 Djalal Harouni
7 ***/
8
9 typedef struct NamespaceInfo NamespaceInfo;
10 typedef struct BindMount BindMount;
11 typedef struct TemporaryFileSystem TemporaryFileSystem;
12
13 #include <stdbool.h>
14
15 #include "dissect-image.h"
16 #include "macro.h"
17
18 typedef enum ProtectHome {
19 PROTECT_HOME_NO,
20 PROTECT_HOME_YES,
21 PROTECT_HOME_READ_ONLY,
22 PROTECT_HOME_TMPFS,
23 _PROTECT_HOME_MAX,
24 _PROTECT_HOME_INVALID = -1
25 } ProtectHome;
26
27 typedef enum NamespaceType {
28 NAMESPACE_MOUNT,
29 NAMESPACE_CGROUP,
30 NAMESPACE_UTS,
31 NAMESPACE_IPC,
32 NAMESPACE_USER,
33 NAMESPACE_PID,
34 NAMESPACE_NET,
35 _NAMESPACE_TYPE_MAX,
36 _NAMESPACE_TYPE_INVALID = -1,
37 } NamespaceType;
38
39 typedef enum ProtectSystem {
40 PROTECT_SYSTEM_NO,
41 PROTECT_SYSTEM_YES,
42 PROTECT_SYSTEM_FULL,
43 PROTECT_SYSTEM_STRICT,
44 _PROTECT_SYSTEM_MAX,
45 _PROTECT_SYSTEM_INVALID = -1
46 } ProtectSystem;
47
48 struct NamespaceInfo {
49 bool ignore_protect_paths:1;
50 bool private_dev:1;
51 bool private_mounts:1;
52 bool protect_control_groups:1;
53 bool protect_kernel_tunables:1;
54 bool protect_kernel_modules:1;
55 bool mount_apivfs:1;
56 };
57
58 struct BindMount {
59 char *source;
60 char *destination;
61 bool read_only:1;
62 bool recursive:1;
63 bool ignore_enoent:1;
64 };
65
66 struct TemporaryFileSystem {
67 char *path;
68 char *options;
69 };
70
71 int setup_namespace(
72 const char *root_directory,
73 const char *root_image,
74 const NamespaceInfo *ns_info,
75 char **read_write_paths,
76 char **read_only_paths,
77 char **inaccessible_paths,
78 char **empty_directories,
79 const BindMount *bind_mounts,
80 size_t n_bind_mounts,
81 const TemporaryFileSystem *temporary_filesystems,
82 size_t n_temporary_filesystems,
83 const char *tmp_dir,
84 const char *var_tmp_dir,
85 ProtectHome protect_home,
86 ProtectSystem protect_system,
87 unsigned long mount_flags,
88 DissectImageFlags dissected_image_flags);
89
90 int setup_tmp_dirs(
91 const char *id,
92 char **tmp_dir,
93 char **var_tmp_dir);
94
95 int setup_netns(int netns_storage_socket[2]);
96
97 const char* protect_home_to_string(ProtectHome p) _const_;
98 ProtectHome protect_home_from_string(const char *s) _pure_;
99 ProtectHome protect_home_or_bool_from_string(const char *s);
100
101 const char* protect_system_to_string(ProtectSystem p) _const_;
102 ProtectSystem protect_system_from_string(const char *s) _pure_;
103 ProtectSystem protect_system_or_bool_from_string(const char *s);
104
105 void bind_mount_free_many(BindMount *b, size_t n);
106 int bind_mount_add(BindMount **b, size_t *n, const BindMount *item);
107
108 void temporary_filesystem_free_many(TemporaryFileSystem *t, size_t n);
109 int temporary_filesystem_add(TemporaryFileSystem **t, size_t *n,
110 const char *path, const char *options);
111
112 const char* namespace_type_to_string(NamespaceType t) _const_;
113 NamespaceType namespace_type_from_string(const char *s) _pure_;
114
115 bool ns_type_supported(NamespaceType type);