| 1 |
/* SPDX-License-Identifier: LGPL-2.1-or-later */ |
| 2 |
#pragma once |
| 3 |
|
| 4 |
#include "shared-forward.h" |
| 5 |
|
| 6 |
typedef struct SubMount { |
| 7 |
char *path; |
| 8 |
int mount_fd; |
| 9 |
} SubMount; |
| 10 |
|
| 11 |
void sub_mount_array_free(SubMount *array, size_t n); |
| 12 |
|
| 13 |
int get_sub_mounts(const char *prefix, SubMount **ret_mounts, size_t *ret_n_mounts); |
| 14 |
int bind_mount_submounts( |
| 15 |
const char *source, |
| 16 |
const char *target); |
| 17 |
|
| 18 |
int repeat_unmount(const char *path, int flags); |
| 19 |
|
| 20 |
int umount_recursive_full(const char *prefix, int flags, char **keep); |
| 21 |
static inline int umount_recursive(const char *prefix, int flags) { |
| 22 |
return umount_recursive_full(prefix, flags, NULL); |
| 23 |
} |
| 24 |
|
| 25 |
int bind_remount_recursive_with_mountinfo(const char *prefix, unsigned long new_flags, unsigned long flags_mask, char **deny_list, FILE *proc_self_mountinfo); |
| 26 |
static inline int bind_remount_recursive(const char *prefix, unsigned long new_flags, unsigned long flags_mask, char **deny_list) { |
| 27 |
return bind_remount_recursive_with_mountinfo(prefix, new_flags, flags_mask, deny_list, NULL); |
| 28 |
} |
| 29 |
|
| 30 |
int bind_remount_one_with_mountinfo(const char *path, unsigned long new_flags, unsigned long flags_mask, FILE *proc_self_mountinfo); |
| 31 |
int bind_remount_one(const char *path, unsigned long new_flags, unsigned long flags_mask); |
| 32 |
|
| 33 |
int mount_switch_root_full(const char *path, unsigned long mount_propagation_flag, bool force_ms_move); |
| 34 |
static inline int mount_switch_root(const char *path, unsigned long mount_propagation_flag) { |
| 35 |
return mount_switch_root_full(path, mount_propagation_flag, false); |
| 36 |
} |
| 37 |
|
| 38 |
int mount_verbose_full( |
| 39 |
int error_log_level, |
| 40 |
const char *what, |
| 41 |
const char *where, |
| 42 |
const char *fstype, |
| 43 |
unsigned long flags, |
| 44 |
const char *options, |
| 45 |
bool follow_symlink); |
| 46 |
|
| 47 |
static inline int mount_follow_verbose( |
| 48 |
int error_log_level, |
| 49 |
const char *what, |
| 50 |
const char *where, |
| 51 |
const char *fstype, |
| 52 |
unsigned long flags, |
| 53 |
const char *options) { |
| 54 |
return mount_verbose_full(error_log_level, what, where, fstype, flags, options, true); |
| 55 |
} |
| 56 |
|
| 57 |
static inline int mount_nofollow_verbose( |
| 58 |
int error_log_level, |
| 59 |
const char *what, |
| 60 |
const char *where, |
| 61 |
const char *fstype, |
| 62 |
unsigned long flags, |
| 63 |
const char *options) { |
| 64 |
return mount_verbose_full(error_log_level, what, where, fstype, flags, options, false); |
| 65 |
} |
| 66 |
|
| 67 |
int umount_verbose( |
| 68 |
int error_log_level, |
| 69 |
const char *where, |
| 70 |
int flags); |
| 71 |
|
| 72 |
int umountat_detach_verbose( |
| 73 |
int error_log_level, |
| 74 |
int fd, |
| 75 |
const char *where); |
| 76 |
|
| 77 |
int mount_option_mangle( |
| 78 |
const char *options, |
| 79 |
unsigned long mount_flags, |
| 80 |
unsigned long *ret_mount_flags, |
| 81 |
char **ret_remaining_options); |
| 82 |
|
| 83 |
int mode_to_inaccessible_node(const char *runtime_dir, mode_t mode, char **ret); |
| 84 |
int mount_flags_to_string(unsigned long flags, char **ret); |
| 85 |
|
| 86 |
/* Useful for usage with _cleanup_(), unmounts, removes a directory and frees the pointer */ |
| 87 |
char* umount_and_rmdir_and_free(char *p); |
| 88 |
DEFINE_TRIVIAL_CLEANUP_FUNC(char*, umount_and_rmdir_and_free); |
| 89 |
|
| 90 |
char* umount_and_free(char *p); |
| 91 |
DEFINE_TRIVIAL_CLEANUP_FUNC(char*, umount_and_free); |
| 92 |
|
| 93 |
char* umount_and_unlink_and_free(char *p); |
| 94 |
DEFINE_TRIVIAL_CLEANUP_FUNC(char*, umount_and_unlink_and_free); |
| 95 |
|
| 96 |
int mount_exchange_graceful(int fsmount_fd, const char *dest, bool mount_beneath); |
| 97 |
|
| 98 |
typedef enum MountInNamespaceFlags { |
| 99 |
MOUNT_IN_NAMESPACE_READ_ONLY = 1 << 0, |
| 100 |
MOUNT_IN_NAMESPACE_MAKE_FILE_OR_DIRECTORY = 1 << 1, |
| 101 |
MOUNT_IN_NAMESPACE_IS_IMAGE = 1 << 2, |
| 102 |
} MountInNamespaceFlags; |
| 103 |
|
| 104 |
int bind_mount_in_namespace( |
| 105 |
const PidRef *target, |
| 106 |
const char *propagate_path, |
| 107 |
const char *incoming_path, |
| 108 |
const char *src, |
| 109 |
const char *dest, |
| 110 |
MountInNamespaceFlags flags); |
| 111 |
int mount_image_in_namespace( |
| 112 |
const PidRef *target, |
| 113 |
const char *propagate_path, |
| 114 |
const char *incoming_path, |
| 115 |
const char *src, |
| 116 |
const char *dest, |
| 117 |
MountInNamespaceFlags flags, |
| 118 |
const MountOptions *options, |
| 119 |
const ImagePolicy *image_policy); |
| 120 |
|
| 121 |
int make_mount_point(const char *path); |
| 122 |
int fd_make_mount_point(int fd); |
| 123 |
|
| 124 |
int mount_fd_clone(int mount_fd, bool recursive, int *replacement_fd); |
| 125 |
|
| 126 |
typedef enum RemountIdmapping { |
| 127 |
REMOUNT_IDMAPPING_NONE, |
| 128 |
/* Include a mapping from UID_MAPPED_ROOT (i.e. UID 2^31-2) on the backing fs to UID 0 on the |
| 129 |
* uidmapped fs. This is useful to ensure that the host root user can safely add inodes to the |
| 130 |
* uidmapped fs (which otherwise wouldn't work as the host root user is not defined on the uidmapped |
| 131 |
* mount and any attempts to create inodes will then be refused with EOVERFLOW). The idea is that |
| 132 |
* these inodes are quickly re-chown()ed to more suitable UIDs/GIDs. Any code that intends to be able |
| 133 |
* to add inodes to file systems mapped this way should set this flag, but given it comes with |
| 134 |
* certain security implications defaults to off, and requires explicit opt-in. */ |
| 135 |
REMOUNT_IDMAPPING_HOST_ROOT, |
| 136 |
/* Much like REMOUNT_IDMAPPING_HOST_ROOT, but the source mapping is not from 0…65535 but from the |
| 137 |
* foreign UID range. */ |
| 138 |
REMOUNT_IDMAPPING_FOREIGN_WITH_HOST_ROOT, |
| 139 |
/* Define a mapping from root user within the container to the owner of the bind mounted directory. |
| 140 |
* This ensures no root-owned files will be written in a bind-mounted directory owned by a different |
| 141 |
* user. No other users are mapped. */ |
| 142 |
REMOUNT_IDMAPPING_HOST_OWNER, |
| 143 |
/* Define a mapping from bind-target owner within the container to the host owner of the bind mounted |
| 144 |
* directory. No other users are mapped. */ |
| 145 |
REMOUNT_IDMAPPING_HOST_OWNER_TO_TARGET_OWNER, |
| 146 |
_REMOUNT_IDMAPPING_MAX, |
| 147 |
_REMOUNT_IDMAPPING_INVALID = -EINVAL, |
| 148 |
} RemountIdmapping; |
| 149 |
|
| 150 |
int open_tree_attr_with_fallback(int dir_fd, const char *path, unsigned flags, struct mount_attr *attr); |
| 151 |
int open_tree_try_drop_idmap(int dir_fd, const char *path, unsigned flags); |
| 152 |
|
| 153 |
int make_userns(uid_t uid_shift, uid_t uid_range, uid_t source_owner, uid_t dest_owner, RemountIdmapping idmapping); |
| 154 |
int remount_idmap_fd(char **p, int userns_fd, uint64_t extra_mount_attr_set); |
| 155 |
int remount_idmap( |
| 156 |
char **p, |
| 157 |
uid_t uid_shift, |
| 158 |
uid_t uid_range, |
| 159 |
uid_t source_owner, |
| 160 |
uid_t dest_owner, |
| 161 |
RemountIdmapping idmapping); |
| 162 |
|
| 163 |
/* Creates a mount point (without any parents) based on the source path or mode - i.e., a file or a directory */ |
| 164 |
int make_mount_point_inode_from_mode(int dir_fd, const char *dest, mode_t source_mode, mode_t target_mode); |
| 165 |
int make_mount_point_inode_from_path(const char *source, const char *dest, mode_t mode); |
| 166 |
|
| 167 |
int trigger_automount_at(int dir_fd, const char *path); |
| 168 |
|
| 169 |
unsigned long credentials_fs_mount_flags(bool ro) _const_; |
| 170 |
int fsmount_credentials_fs(int *ret_fsfd); |
| 171 |
int mount_credentials_fs(const char *path); |
| 172 |
|
| 173 |
int make_fsmount(int error_log_level, const char *what, const char *type, unsigned long flags, const char *options, int userns_fd); |
| 174 |
|
| 175 |
int path_get_mount_info_at(int dir_fd, const char *path, char **ret_fstype, char **ret_options, char **ret_source); |
| 176 |
static inline int path_get_mount_info(const char *path, char **ret_fstype, char **ret_options, char **ret_source) { |
| 177 |
return path_get_mount_info_at(AT_FDCWD, path, ret_fstype, ret_options, ret_source); |
| 178 |
} |
| 179 |
|
| 180 |
int path_is_network_fs_harder_at(int dir_fd, const char *path); |
| 181 |
static inline int path_is_network_fs_harder(const char *path) { |
| 182 |
return path_is_network_fs_harder_at(AT_FDCWD, path); |
| 183 |
} |