| 1 |
/* SPDX-License-Identifier: LGPL-2.1-or-later */ |
| 2 |
#pragma once |
| 3 |
|
| 4 |
#include "sd-id128.h" |
| 5 |
|
| 6 |
#include "capability-util.h" |
| 7 |
#include "conf-parser-forward.h" |
| 8 |
#include "cpu-set-util.h" |
| 9 |
#include "rlimit-util.h" |
| 10 |
#include "seccomp-util.h" |
| 11 |
#include "shared-forward.h" |
| 12 |
#include "volatile-util.h" |
| 13 |
|
| 14 |
typedef struct CustomMount CustomMount; |
| 15 |
typedef struct ExposePort ExposePort; |
| 16 |
|
| 17 |
typedef enum StartMode { |
| 18 |
START_PID1, /* Run parameters as command line as process 1 */ |
| 19 |
START_PID2, /* Use stub init process as PID 1, run parameters as command line as process 2 */ |
| 20 |
START_BOOT, /* Search for init system, pass arguments as parameters */ |
| 21 |
_START_MODE_MAX, |
| 22 |
_START_MODE_INVALID = -EINVAL, |
| 23 |
} StartMode; |
| 24 |
|
| 25 |
typedef enum UserNamespaceMode { |
| 26 |
USER_NAMESPACE_NO, |
| 27 |
USER_NAMESPACE_FIXED, |
| 28 |
USER_NAMESPACE_PICK, |
| 29 |
USER_NAMESPACE_MANAGED, |
| 30 |
_USER_NAMESPACE_MODE_MAX, |
| 31 |
_USER_NAMESPACE_MODE_INVALID = -EINVAL, |
| 32 |
} UserNamespaceMode; |
| 33 |
|
| 34 |
typedef enum UserNamespaceOwnership { |
| 35 |
USER_NAMESPACE_OWNERSHIP_OFF, /* do not change ownership */ |
| 36 |
USER_NAMESPACE_OWNERSHIP_CHOWN, /* chown to target range */ |
| 37 |
USER_NAMESPACE_OWNERSHIP_MAP, /* map from 0x00000000…0x0000FFFF range to target range */ |
| 38 |
USER_NAMESPACE_OWNERSHIP_FOREIGN, /* map from 0x7FFE0000…0x7FFEFFFF range to target range */ |
| 39 |
USER_NAMESPACE_OWNERSHIP_AUTO, |
| 40 |
_USER_NAMESPACE_OWNERSHIP_MAX, |
| 41 |
_USER_NAMESPACE_OWNERSHIP_INVALID = -1, |
| 42 |
} UserNamespaceOwnership; |
| 43 |
|
| 44 |
typedef enum ResolvConfMode { |
| 45 |
RESOLV_CONF_OFF, |
| 46 |
RESOLV_CONF_COPY_HOST, /* /etc/resolv.conf */ |
| 47 |
RESOLV_CONF_COPY_STATIC, /* /usr/lib/systemd/resolv.conf */ |
| 48 |
RESOLV_CONF_COPY_UPLINK, /* /run/systemd/resolve/resolv.conf */ |
| 49 |
RESOLV_CONF_COPY_STUB, /* /run/systemd/resolve/stub-resolv.conf */ |
| 50 |
RESOLV_CONF_REPLACE_HOST, |
| 51 |
RESOLV_CONF_REPLACE_STATIC, |
| 52 |
RESOLV_CONF_REPLACE_UPLINK, |
| 53 |
RESOLV_CONF_REPLACE_STUB, |
| 54 |
RESOLV_CONF_BIND_HOST, |
| 55 |
RESOLV_CONF_BIND_STATIC, |
| 56 |
RESOLV_CONF_BIND_UPLINK, |
| 57 |
RESOLV_CONF_BIND_STUB, |
| 58 |
RESOLV_CONF_DELETE, |
| 59 |
RESOLV_CONF_AUTO, |
| 60 |
_RESOLV_CONF_MODE_MAX, |
| 61 |
_RESOLV_CONF_MODE_INVALID = -EINVAL, |
| 62 |
} ResolvConfMode; |
| 63 |
|
| 64 |
typedef enum LinkJournal { |
| 65 |
LINK_NO, |
| 66 |
LINK_AUTO, |
| 67 |
LINK_HOST, |
| 68 |
LINK_GUEST, |
| 69 |
_LINK_JOURNAL_MAX, |
| 70 |
_LINK_JOURNAL_INVALID = -EINVAL, |
| 71 |
} LinkJournal; |
| 72 |
|
| 73 |
typedef enum TimezoneMode { |
| 74 |
TIMEZONE_OFF, |
| 75 |
TIMEZONE_COPY, |
| 76 |
TIMEZONE_BIND, |
| 77 |
TIMEZONE_SYMLINK, |
| 78 |
TIMEZONE_DELETE, |
| 79 |
TIMEZONE_AUTO, |
| 80 |
_TIMEZONE_MODE_MAX, |
| 81 |
_TIMEZONE_MODE_INVALID = -EINVAL, |
| 82 |
} TimezoneMode; |
| 83 |
|
| 84 |
typedef enum ConsoleMode { |
| 85 |
CONSOLE_AUTOPIPE, |
| 86 |
CONSOLE_INTERACTIVE, |
| 87 |
CONSOLE_READ_ONLY, |
| 88 |
CONSOLE_PASSIVE, |
| 89 |
CONSOLE_PIPE, |
| 90 |
_CONSOLE_MODE_MAX, |
| 91 |
_CONSOLE_MODE_INVALID = -EINVAL, |
| 92 |
} ConsoleMode; |
| 93 |
|
| 94 |
typedef enum SettingsMask { |
| 95 |
SETTING_START_MODE = UINT64_C(1) << 0, |
| 96 |
SETTING_ENVIRONMENT = UINT64_C(1) << 1, |
| 97 |
SETTING_USER = UINT64_C(1) << 2, |
| 98 |
SETTING_CAPABILITY = UINT64_C(1) << 3, |
| 99 |
SETTING_KILL_SIGNAL = UINT64_C(1) << 4, |
| 100 |
SETTING_PERSONALITY = UINT64_C(1) << 5, |
| 101 |
SETTING_MACHINE_ID = UINT64_C(1) << 6, |
| 102 |
SETTING_NETWORK = UINT64_C(1) << 7, |
| 103 |
SETTING_EXPOSE_PORTS = UINT64_C(1) << 8, |
| 104 |
SETTING_READ_ONLY = UINT64_C(1) << 9, |
| 105 |
SETTING_VOLATILE_MODE = UINT64_C(1) << 10, |
| 106 |
SETTING_CUSTOM_MOUNTS = UINT64_C(1) << 11, |
| 107 |
SETTING_WORKING_DIRECTORY = UINT64_C(1) << 12, |
| 108 |
SETTING_USERNS = UINT64_C(1) << 13, |
| 109 |
SETTING_NOTIFY_READY = UINT64_C(1) << 14, |
| 110 |
SETTING_PIVOT_ROOT = UINT64_C(1) << 15, |
| 111 |
SETTING_SYSCALL_FILTER = UINT64_C(1) << 16, |
| 112 |
SETTING_HOSTNAME = UINT64_C(1) << 17, |
| 113 |
SETTING_NO_NEW_PRIVILEGES = UINT64_C(1) << 18, |
| 114 |
SETTING_OOM_SCORE_ADJUST = UINT64_C(1) << 19, |
| 115 |
SETTING_CPU_AFFINITY = UINT64_C(1) << 20, |
| 116 |
SETTING_RESOLV_CONF = UINT64_C(1) << 21, |
| 117 |
SETTING_LINK_JOURNAL = UINT64_C(1) << 22, |
| 118 |
SETTING_TIMEZONE = UINT64_C(1) << 23, |
| 119 |
SETTING_EPHEMERAL = UINT64_C(1) << 24, |
| 120 |
SETTING_SLICE = UINT64_C(1) << 25, |
| 121 |
SETTING_DIRECTORY = UINT64_C(1) << 26, |
| 122 |
SETTING_USE_CGNS = UINT64_C(1) << 27, |
| 123 |
SETTING_CLONE_NS_FLAGS = UINT64_C(1) << 28, |
| 124 |
SETTING_CONSOLE_MODE = UINT64_C(1) << 29, |
| 125 |
SETTING_CREDENTIALS = UINT64_C(1) << 30, |
| 126 |
SETTING_BIND_USER = UINT64_C(1) << 31, |
| 127 |
SETTING_BIND_USER_SHELL = UINT64_C(1) << 32, |
| 128 |
SETTING_SUPPRESS_SYNC = UINT64_C(1) << 33, |
| 129 |
SETTING_RESTRICT_ADDRESS_FAMILIES = UINT64_C(1) << 34, |
| 130 |
SETTING_RLIMIT_FIRST = UINT64_C(1) << 35, /* we define one bit per resource limit here */ |
| 131 |
SETTING_RLIMIT_LAST = UINT64_C(1) << (35 + _RLIMIT_MAX - 1), |
| 132 |
_SETTINGS_MASK_ALL = (UINT64_C(1) << (35 + _RLIMIT_MAX)) -1, |
| 133 |
_SETTING_FORCE_ENUM_WIDTH = UINT64_MAX |
| 134 |
} SettingsMask; |
| 135 |
|
| 136 |
/* We want to use SETTING_RLIMIT_FIRST in shifts, so make sure it is really 64 bits |
| 137 |
* when used in expressions. */ |
| 138 |
#define SETTING_RLIMIT_FIRST ((uint64_t) SETTING_RLIMIT_FIRST) |
| 139 |
#define SETTING_RLIMIT_LAST ((uint64_t) SETTING_RLIMIT_LAST) |
| 140 |
|
| 141 |
assert_cc(sizeof(SettingsMask) == 8); |
| 142 |
assert_cc(sizeof(SETTING_RLIMIT_FIRST) == 8); |
| 143 |
assert_cc(sizeof(SETTING_RLIMIT_LAST) == 8); |
| 144 |
|
| 145 |
typedef struct DeviceNode { |
| 146 |
char *path; |
| 147 |
unsigned major; |
| 148 |
unsigned minor; |
| 149 |
mode_t mode; |
| 150 |
uid_t uid; |
| 151 |
gid_t gid; |
| 152 |
} DeviceNode; |
| 153 |
|
| 154 |
typedef struct OciHook { |
| 155 |
char *path; |
| 156 |
char **args; |
| 157 |
char **env; |
| 158 |
usec_t timeout; |
| 159 |
} OciHook; |
| 160 |
|
| 161 |
typedef struct Settings { |
| 162 |
/* [Exec] */ |
| 163 |
StartMode start_mode; |
| 164 |
int ephemeral; |
| 165 |
char **parameters; |
| 166 |
char **environment; |
| 167 |
char *user; |
| 168 |
uint64_t capability; |
| 169 |
uint64_t drop_capability; |
| 170 |
uint64_t ambient_capability; |
| 171 |
int kill_signal; |
| 172 |
unsigned long personality; |
| 173 |
sd_id128_t machine_id; |
| 174 |
char *working_directory; |
| 175 |
char *pivot_root_new; |
| 176 |
char *pivot_root_old; |
| 177 |
UserNamespaceMode userns_mode; |
| 178 |
uid_t uid_shift, uid_range; |
| 179 |
unsigned delegate_container_ranges; |
| 180 |
int notify_ready; |
| 181 |
char **syscall_allow_list; |
| 182 |
char **syscall_deny_list; |
| 183 |
struct rlimit *rlimit[_RLIMIT_MAX]; |
| 184 |
char *hostname; |
| 185 |
int no_new_privileges; |
| 186 |
int oom_score_adjust; |
| 187 |
bool oom_score_adjust_set; |
| 188 |
CPUSet cpu_set; |
| 189 |
ResolvConfMode resolv_conf; |
| 190 |
LinkJournal link_journal; |
| 191 |
bool link_journal_try; |
| 192 |
TimezoneMode timezone; |
| 193 |
int suppress_sync; |
| 194 |
Set *restrict_address_families; |
| 195 |
bool restrict_address_families_is_allowlist; |
| 196 |
|
| 197 |
/* [Files] */ |
| 198 |
int read_only; |
| 199 |
VolatileMode volatile_mode; |
| 200 |
CustomMount *custom_mounts; |
| 201 |
size_t n_custom_mounts; |
| 202 |
UserNamespaceOwnership userns_ownership; |
| 203 |
char **bind_user; |
| 204 |
char *bind_user_shell; |
| 205 |
bool bind_user_shell_copy; |
| 206 |
bool bind_user_shell_set; |
| 207 |
|
| 208 |
/* [Network] */ |
| 209 |
int private_network; |
| 210 |
int network_veth; |
| 211 |
char *network_bridge; |
| 212 |
char *network_zone; |
| 213 |
char **network_interfaces; |
| 214 |
char **network_macvlan; |
| 215 |
char **network_ipvlan; |
| 216 |
char **network_veth_extra; |
| 217 |
ExposePort *expose_ports; |
| 218 |
|
| 219 |
/* Additional fields, that are specific to OCI runtime case */ |
| 220 |
char *bundle; |
| 221 |
char *root; |
| 222 |
OciHook *oci_hooks_prestart, *oci_hooks_poststart, *oci_hooks_poststop; |
| 223 |
size_t n_oci_hooks_prestart, n_oci_hooks_poststart, n_oci_hooks_poststop; |
| 224 |
char *slice; |
| 225 |
sd_bus_message *properties; |
| 226 |
CapabilityQuintet full_capabilities; |
| 227 |
uid_t uid; |
| 228 |
gid_t gid; |
| 229 |
gid_t *supplementary_gids; |
| 230 |
size_t n_supplementary_gids; |
| 231 |
unsigned console_width, console_height; |
| 232 |
ConsoleMode console_mode; |
| 233 |
DeviceNode *extra_nodes; |
| 234 |
size_t n_extra_nodes; |
| 235 |
unsigned long clone_ns_flags; |
| 236 |
char *network_namespace_path; |
| 237 |
int use_cgns; |
| 238 |
char **sysctl; |
| 239 |
#if HAVE_SECCOMP |
| 240 |
scmp_filter_ctx seccomp; |
| 241 |
#endif |
| 242 |
} Settings; |
| 243 |
|
| 244 |
Settings *settings_new(void); |
| 245 |
int settings_load(FILE *f, const char *path, Settings **ret); |
| 246 |
Settings* settings_free(Settings *s); |
| 247 |
|
| 248 |
bool settings_network_veth(Settings *s); |
| 249 |
bool settings_private_network(Settings *s); |
| 250 |
bool settings_network_configured(Settings *s); |
| 251 |
|
| 252 |
int settings_allocate_properties(Settings *s); |
| 253 |
|
| 254 |
DEFINE_TRIVIAL_CLEANUP_FUNC(Settings*, settings_free); |
| 255 |
|
| 256 |
const struct ConfigPerfItem* nspawn_gperf_lookup(const char *str, GPERF_LEN_TYPE length); |
| 257 |
|
| 258 |
CONFIG_PARSER_PROTOTYPE(config_parse_capability); |
| 259 |
CONFIG_PARSER_PROTOTYPE(config_parse_expose_port); |
| 260 |
CONFIG_PARSER_PROTOTYPE(config_parse_volatile_mode); |
| 261 |
CONFIG_PARSER_PROTOTYPE(config_parse_pivot_root); |
| 262 |
CONFIG_PARSER_PROTOTYPE(config_parse_bind); |
| 263 |
CONFIG_PARSER_PROTOTYPE(config_parse_tmpfs); |
| 264 |
CONFIG_PARSER_PROTOTYPE(config_parse_overlay); |
| 265 |
CONFIG_PARSER_PROTOTYPE(config_parse_inaccessible); |
| 266 |
CONFIG_PARSER_PROTOTYPE(config_parse_veth_extra); |
| 267 |
CONFIG_PARSER_PROTOTYPE(config_parse_network_iface_pair); |
| 268 |
CONFIG_PARSER_PROTOTYPE(config_parse_macvlan_iface_pair); |
| 269 |
CONFIG_PARSER_PROTOTYPE(config_parse_ipvlan_iface_pair); |
| 270 |
CONFIG_PARSER_PROTOTYPE(config_parse_network_zone); |
| 271 |
CONFIG_PARSER_PROTOTYPE(config_parse_boot); |
| 272 |
CONFIG_PARSER_PROTOTYPE(config_parse_pid2); |
| 273 |
CONFIG_PARSER_PROTOTYPE(config_parse_private_users); |
| 274 |
CONFIG_PARSER_PROTOTYPE(config_parse_syscall_filter); |
| 275 |
CONFIG_PARSER_PROTOTYPE(config_parse_oom_score_adjust); |
| 276 |
CONFIG_PARSER_PROTOTYPE(config_parse_resolv_conf); |
| 277 |
CONFIG_PARSER_PROTOTYPE(config_parse_link_journal); |
| 278 |
CONFIG_PARSER_PROTOTYPE(config_parse_timezone_mode); |
| 279 |
CONFIG_PARSER_PROTOTYPE(config_parse_userns_chown); |
| 280 |
CONFIG_PARSER_PROTOTYPE(config_parse_userns_ownership); |
| 281 |
CONFIG_PARSER_PROTOTYPE(config_parse_bind_user); |
| 282 |
CONFIG_PARSER_PROTOTYPE(config_parse_bind_user_shell); |
| 283 |
CONFIG_PARSER_PROTOTYPE(config_parse_restrict_address_families); |
| 284 |
|
| 285 |
DECLARE_STRING_TABLE_LOOKUP(resolv_conf_mode, ResolvConfMode); |
| 286 |
|
| 287 |
DECLARE_STRING_TABLE_LOOKUP(timezone_mode, TimezoneMode); |
| 288 |
|
| 289 |
DECLARE_STRING_TABLE_LOOKUP(console_mode, ConsoleMode); |
| 290 |
|
| 291 |
DECLARE_STRING_TABLE_LOOKUP(user_namespace_ownership, UserNamespaceOwnership); |
| 292 |
|
| 293 |
int parse_link_journal(const char *s, LinkJournal *ret_mode, bool *ret_try); |
| 294 |
|
| 295 |
void device_node_array_free(DeviceNode *node, size_t n); |