]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/nspawn/nspawn-mount.h
nspawn: explicitly refuse mounts over /
[thirdparty/systemd.git] / src / nspawn / nspawn-mount.h
CommitLineData
53e1b683 1/* SPDX-License-Identifier: LGPL-2.1+ */
e83bebef
LP
2#pragma once
3
e83bebef
LP
4#include <stdbool.h>
5
5da38d07 6#include "cgroup-util.h"
a4c35b6b 7#include "volatile-util.h"
5da38d07 8
4f086aab 9typedef enum MountSettingsMask {
ef31828d
LP
10 MOUNT_FATAL = 1 << 0, /* if set, a mount error is considered fatal */
11 MOUNT_USE_USERNS = 1 << 1, /* if set, mounts are patched considering uid/gid shifts in a user namespace */
12 MOUNT_IN_USERNS = 1 << 2, /* if set, the mount is executed in the inner child, otherwise in the outer child */
13 MOUNT_APPLY_APIVFS_RO = 1 << 3, /* if set, /proc/sys, and /sys will be mounted read-only, otherwise read-write. */
14 MOUNT_APPLY_APIVFS_NETNS = 1 << 4, /* if set, /proc/sys/net will be mounted read-write.
d4b653c5 15 Works only if MOUNT_APPLY_APIVFS_RO is also set. */
ef31828d 16 MOUNT_INACCESSIBLE_REG = 1 << 5, /* if set, create an inaccessible regular file first and use as bind mount source */
1099ceeb 17 MOUNT_APPLY_TMPFS_TMP = 1 << 6, /* if set, /tmp will be mounted as tmpfs */
4f086aab
SU
18} MountSettingsMask;
19
e83bebef
LP
20typedef enum CustomMountType {
21 CUSTOM_MOUNT_BIND,
22 CUSTOM_MOUNT_TMPFS,
23 CUSTOM_MOUNT_OVERLAY,
24 _CUSTOM_MOUNT_TYPE_MAX,
25 _CUSTOM_MOUNT_TYPE_INVALID = -1
26} CustomMountType;
27
28typedef struct CustomMount {
29 CustomMountType type;
30 bool read_only;
31 char *source; /* for overlayfs this is the upper directory */
32 char *destination;
33 char *options;
34 char *work_dir;
35 char **lower;
c7a4890c 36 char *rm_rf_tmpdir;
e83bebef
LP
37} CustomMount;
38
88614c8a
LP
39CustomMount* custom_mount_add(CustomMount **l, size_t *n, CustomMountType t);
40void custom_mount_free_all(CustomMount *l, size_t n);
41int custom_mount_prepare_all(const char *dest, CustomMount *l, size_t n);
ad85779a 42
88614c8a
LP
43int bind_mount_parse(CustomMount **l, size_t *n, const char *s, bool read_only);
44int tmpfs_mount_parse(CustomMount **l, size_t *n, const char *s);
45int overlay_mount_parse(CustomMount **l, size_t *n, const char *s, bool read_only);
e83bebef 46
2fa017f1 47int mount_all(const char *dest, MountSettingsMask mount_settings, uid_t uid_shift, const char *selinux_apifs_context);
4f086aab 48int mount_sysfs(const char *dest, MountSettingsMask mount_settings);
e83bebef 49
88614c8a 50int mount_custom(const char *dest, CustomMount *mounts, size_t n, bool userns, uid_t uid_shift, uid_t uid_range, const char *selinux_apifs_context);
e83bebef
LP
51
52int setup_volatile(const char *directory, VolatileMode mode, bool userns, uid_t uid_shift, uid_t uid_range, const char *selinux_apifs_context);
53int setup_volatile_state(const char *directory, VolatileMode mode, bool userns, uid_t uid_shift, uid_t uid_range, const char *selinux_apifs_context);
b53ede69
PW
54
55int pivot_root_parse(char **pivot_root_new, char **pivot_root_old, const char *s);
56int setup_pivot_root(const char *directory, const char *pivot_root_new, const char *pivot_root_old);
04029482
LS
57
58int tmpfs_patch_options(const char *options,uid_t uid_shift, const char *selinux_apifs_context, char **ret);