]>
Commit | Line | Data |
---|---|---|
53e1b683 | 1 | /* SPDX-License-Identifier: LGPL-2.1+ */ |
c2f1db8f | 2 | #pragma once |
15ae422b LP |
3 | |
4 | /*** | |
96b2fb93 | 5 | Copyright © 2016 Djalal Harouni |
15ae422b LP |
6 | ***/ |
7 | ||
bb0ff3fb | 8 | typedef struct NamespaceInfo NamespaceInfo; |
d2d6c096 | 9 | typedef struct BindMount BindMount; |
2abd4e38 | 10 | typedef struct TemporaryFileSystem TemporaryFileSystem; |
c575770b | 11 | |
15ae422b LP |
12 | #include <stdbool.h> |
13 | ||
915e6d16 | 14 | #include "dissect-image.h" |
417116f2 LP |
15 | #include "macro.h" |
16 | ||
1b8689f9 LP |
17 | typedef enum ProtectHome { |
18 | PROTECT_HOME_NO, | |
19 | PROTECT_HOME_YES, | |
20 | PROTECT_HOME_READ_ONLY, | |
e4da7d8c | 21 | PROTECT_HOME_TMPFS, |
1b8689f9 LP |
22 | _PROTECT_HOME_MAX, |
23 | _PROTECT_HOME_INVALID = -1 | |
24 | } ProtectHome; | |
25 | ||
6e2d7c4f MS |
26 | typedef enum NamespaceType { |
27 | NAMESPACE_MOUNT, | |
28 | NAMESPACE_CGROUP, | |
29 | NAMESPACE_UTS, | |
30 | NAMESPACE_IPC, | |
31 | NAMESPACE_USER, | |
32 | NAMESPACE_PID, | |
33 | NAMESPACE_NET, | |
34 | _NAMESPACE_TYPE_MAX, | |
35 | _NAMESPACE_TYPE_INVALID = -1, | |
36 | } NamespaceType; | |
37 | ||
1b8689f9 LP |
38 | typedef enum ProtectSystem { |
39 | PROTECT_SYSTEM_NO, | |
40 | PROTECT_SYSTEM_YES, | |
41 | PROTECT_SYSTEM_FULL, | |
3f815163 | 42 | PROTECT_SYSTEM_STRICT, |
1b8689f9 LP |
43 | _PROTECT_SYSTEM_MAX, |
44 | _PROTECT_SYSTEM_INVALID = -1 | |
45 | } ProtectSystem; | |
417116f2 | 46 | |
bb0ff3fb | 47 | struct NamespaceInfo { |
af964954 | 48 | bool ignore_protect_paths:1; |
c575770b | 49 | bool private_dev:1; |
228af36f | 50 | bool private_mounts:1; |
c575770b DH |
51 | bool protect_control_groups:1; |
52 | bool protect_kernel_tunables:1; | |
53 | bool protect_kernel_modules:1; | |
94a7b275 | 54 | bool protect_kernel_logs:1; |
5d997827 | 55 | bool mount_apivfs:1; |
aecd5ac6 | 56 | bool protect_hostname:1; |
c575770b DH |
57 | }; |
58 | ||
d2d6c096 LP |
59 | struct BindMount { |
60 | char *source; | |
61 | char *destination; | |
62 | bool read_only:1; | |
9ce4e4b0 | 63 | bool nosuid:1; |
d2d6c096 LP |
64 | bool recursive:1; |
65 | bool ignore_enoent:1; | |
66 | }; | |
67 | ||
2abd4e38 YW |
68 | struct TemporaryFileSystem { |
69 | char *path; | |
70 | char *options; | |
71 | }; | |
72 | ||
d2d6c096 LP |
73 | int setup_namespace( |
74 | const char *root_directory, | |
915e6d16 | 75 | const char *root_image, |
bb0ff3fb | 76 | const NamespaceInfo *ns_info, |
d2d6c096 LP |
77 | char **read_write_paths, |
78 | char **read_only_paths, | |
79 | char **inaccessible_paths, | |
6c47cd7d | 80 | char **empty_directories, |
d2d6c096 | 81 | const BindMount *bind_mounts, |
da6053d0 | 82 | size_t n_bind_mounts, |
2abd4e38 | 83 | const TemporaryFileSystem *temporary_filesystems, |
da6053d0 | 84 | size_t n_temporary_filesystems, |
d2d6c096 LP |
85 | const char *tmp_dir, |
86 | const char *var_tmp_dir, | |
91dd5f7c | 87 | const char *log_namespace, |
d2d6c096 LP |
88 | ProtectHome protect_home, |
89 | ProtectSystem protect_system, | |
915e6d16 | 90 | unsigned long mount_flags, |
7cc5ef5f ZJS |
91 | DissectImageFlags dissected_image_flags, |
92 | char **error_path); | |
d2d6c096 LP |
93 | |
94 | int setup_tmp_dirs( | |
95 | const char *id, | |
96 | char **tmp_dir, | |
97 | char **var_tmp_dir); | |
613b411c | 98 | |
2caa38e9 LP |
99 | int setup_netns(const int netns_storage_socket[static 2]); |
100 | int open_netns_path(const int netns_storage_socket[static 2], const char *path); | |
417116f2 | 101 | |
1b8689f9 LP |
102 | const char* protect_home_to_string(ProtectHome p) _const_; |
103 | ProtectHome protect_home_from_string(const char *s) _pure_; | |
104 | ||
105 | const char* protect_system_to_string(ProtectSystem p) _const_; | |
106 | ProtectSystem protect_system_from_string(const char *s) _pure_; | |
d2d6c096 | 107 | |
da6053d0 LP |
108 | void bind_mount_free_many(BindMount *b, size_t n); |
109 | int bind_mount_add(BindMount **b, size_t *n, const BindMount *item); | |
6e2d7c4f | 110 | |
da6053d0 LP |
111 | void temporary_filesystem_free_many(TemporaryFileSystem *t, size_t n); |
112 | int temporary_filesystem_add(TemporaryFileSystem **t, size_t *n, | |
2abd4e38 YW |
113 | const char *path, const char *options); |
114 | ||
6e2d7c4f MS |
115 | const char* namespace_type_to_string(NamespaceType t) _const_; |
116 | NamespaceType namespace_type_from_string(const char *s) _pure_; | |
117 | ||
118 | bool ns_type_supported(NamespaceType type); |