• source navigation  • diff markup  • identifier search  • freetext search  • 

Sources/procd/jail/fs.h

  1 /*
  2  * Copyright (C) 2015 Etienne Champetier <champetier.etienne@gmail.com>
  3  *
  4  * This program is free software; you can redistribute it and/or modify
  5  * it under the terms of the GNU Lesser General Public License version 2.1
  6  * as published by the Free Software Foundation
  7  *
  8  * This program is distributed in the hope that it will be useful,
  9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 11  * GNU General Public License for more details.
 12  */
 13 #ifndef _JAIL_FS_H_
 14 #define _JAIL_FS_H_
 15 
 16 #include <fcntl.h>
 17 #include <sys/mount.h>
 18 #include <linux/mount.h>
 19 #include <linux/openat2.h>
 20 #include <libubox/blobmsg.h>
 21 
 22 #include "../container.h"
 23 
 24 #define JAIL_NOAFILE "/dev/.ujailnoafile"
 25 
 26 int sys_openat2(int dfd, const char *path, struct open_how *how, size_t size);
 27 int build_userns_fd(struct blob_attr *uidmappings, struct blob_attr *gidmappings);
 28 int jail_idmap_build(const char *extroot,
 29                      struct blob_attr *uidmap, struct blob_attr *gidmap,
 30                      int *fds, int maxfds);
 31 int jail_idmap_assign(bool have_extroot, bool have_overlay, const int *fds, int nfds,
 32                       int *extroot_fd, int *overlay_fd);
 33 bool jail_dir_is_fresh(const char *path);
 34 void jail_chown_fresh_volumes(uid_t uid, gid_t gid);
 35 void jail_set_idmap_offset(unsigned int offset);
 36 bool jail_propagation_flags_add(const char *opt, unsigned long *flags);
 37 
 38 int add_mount(const char *source, const char *target, const char *filesystemtype,
 39               unsigned long mountflags, unsigned long propflags, const char *optstr, int error);
 40 int add_mount_inner(const char *source, const char *target, const char *filesystemtype,
 41               unsigned long mountflags, unsigned long propflags, const char *optstr, int error);
 42 int add_mount_bind(const char *path, int readonly, int error);
 43 int add_mount_volume(const char *source, const char *target, int error);
 44 int fs_mount_enable_idmap(const char *target, uint32_t uid, uint32_t gid);
 45 char *resolve_mount_source(const char *source);
 46 int add_mount_fd(int fd, const char *target, int error);
 47 int mask_path_now(const char *path);
 48 int remount_readonly(const char *path, unsigned long flags);
 49 int bind_remount_readonly(const char *path, unsigned long flags);
 50 
 51 /* open_tree()/mount_setattr() wrappers - no glibc wrappers yet.
 52  * Fields must match the kernel's struct mount_attr layout exactly
 53  * (__u64, not unsigned long - many OpenWrt targets are 32-bit). */
 54 #include <stdint.h>
 55 struct ujail_mount_attr {
 56         uint64_t attr_set, attr_clr, propagation, userns_fd;
 57 };
 58 int sys_open_tree(int dfd, const char *path, unsigned flags);
 59 int sys_move_mount(int from_dfd, const char *from_path, int to_dfd,
 60                    const char *to_path, unsigned flags);
 61 int sys_mount_setattr(int dfd, const char *path, unsigned flags, struct ujail_mount_attr *attr, size_t size);
 62 int sys_fsopen(const char *fsname, unsigned flags);
 63 int sys_fsconfig(int fd, unsigned cmd, const char *key, const void *value, int aux);
 64 int sys_fsmount(int fd, unsigned flags, unsigned attr_flags);
 65 int premount_sysfs(void);
 66 
 67 #ifndef FSOPEN_CLOEXEC
 68 #define FSOPEN_CLOEXEC 0x00000001
 69 #endif
 70 #ifndef FSMOUNT_CLOEXEC
 71 #define FSMOUNT_CLOEXEC 0x00000001
 72 #endif
 73 #ifndef FSCONFIG_CMD_CREATE
 74 #define FSCONFIG_CMD_CREATE 6
 75 #endif
 76 #ifndef MOUNT_ATTR_NOSUID
 77 #define MOUNT_ATTR_NOSUID 0x00000002
 78 #endif
 79 #ifndef MOUNT_ATTR_NODEV
 80 #define MOUNT_ATTR_NODEV 0x00000004
 81 #endif
 82 #ifndef MOUNT_ATTR_NOEXEC
 83 #define MOUNT_ATTR_NOEXEC 0x00000008
 84 #endif
 85 
 86 #ifndef OPEN_TREE_CLONE
 87 #define OPEN_TREE_CLONE 1
 88 #endif
 89 #ifndef OPEN_TREE_CLOEXEC
 90 #define OPEN_TREE_CLOEXEC O_CLOEXEC
 91 #endif
 92 #ifndef MOUNT_ATTR_RDONLY
 93 #define MOUNT_ATTR_RDONLY 0x00000001
 94 #endif
 95 #ifndef MOVE_MOUNT_F_EMPTY_PATH
 96 #define MOVE_MOUNT_F_EMPTY_PATH 0x00000004
 97 #endif
 98 #ifndef AT_EMPTY_PATH
 99 #define AT_EMPTY_PATH 0x1000
100 #endif
101 int parseOCImount(struct blob_attr *msg);
102 bool mount_is_defined(const char *target);
103 int add_2paths_and_deps(const char *path, const char *path2, int readonly, int error, int lib);
104 unsigned long detect_atime_flag(const char *mountpoint);
105 int add_2paths_nodeps(const char *path, const char *path2, int readonly, int error);
106 
107 static inline int add_path_and_deps(const char *path, int readonly, int error, int lib)
108 {
109         return add_2paths_and_deps(path, path, readonly, error, lib);
110 }
111 
112 void mount_stage_dev(const char *jail_dev);
113 int mount_all(const char *jailroot, const char *jail_dev);
114 void mount_list_init(void);
115 void mount_free(void);
116 void jail_fs_set_userns(bool enabled);
117 
118 #endif
119 

This page was automatically generated by LXR 0.3.1.  •  OpenWrt