| 1 | /* SPDX-License-Identifier: GPL-2.0 */ | 
|---|
| 2 | /* | 
|---|
| 3 | File: linux/posix_acl.h | 
|---|
| 4 |  | 
|---|
| 5 | (C) 2002 Andreas Gruenbacher, <a.gruenbacher@computer.org> | 
|---|
| 6 | */ | 
|---|
| 7 |  | 
|---|
| 8 |  | 
|---|
| 9 | #ifndef __LINUX_POSIX_ACL_H | 
|---|
| 10 | #define __LINUX_POSIX_ACL_H | 
|---|
| 11 |  | 
|---|
| 12 | #include <linux/bug.h> | 
|---|
| 13 | #include <linux/slab.h> | 
|---|
| 14 | #include <linux/rcupdate.h> | 
|---|
| 15 | #include <linux/refcount.h> | 
|---|
| 16 | #include <uapi/linux/posix_acl.h> | 
|---|
| 17 |  | 
|---|
| 18 | struct user_namespace; | 
|---|
| 19 |  | 
|---|
| 20 | struct posix_acl_entry { | 
|---|
| 21 | short			e_tag; | 
|---|
| 22 | unsigned short		e_perm; | 
|---|
| 23 | union { | 
|---|
| 24 | kuid_t		e_uid; | 
|---|
| 25 | kgid_t		e_gid; | 
|---|
| 26 | }; | 
|---|
| 27 | }; | 
|---|
| 28 |  | 
|---|
| 29 | struct posix_acl { | 
|---|
| 30 | /* New members MUST be added within the struct_group() macro below. */ | 
|---|
| 31 | struct_group_tagged(posix_acl_hdr, hdr, | 
|---|
| 32 | refcount_t		a_refcount; | 
|---|
| 33 | unsigned int		a_count; | 
|---|
| 34 | struct rcu_head		a_rcu; | 
|---|
| 35 | ); | 
|---|
| 36 | struct posix_acl_entry	a_entries[] __counted_by(a_count); | 
|---|
| 37 | }; | 
|---|
| 38 | static_assert(offsetof(struct posix_acl, a_entries) == sizeof(struct posix_acl_hdr), | 
|---|
| 39 | "struct member likely outside of struct_group_tagged()"); | 
|---|
| 40 |  | 
|---|
| 41 | #define FOREACH_ACL_ENTRY(pa, acl, pe) \ | 
|---|
| 42 | for(pa=(acl)->a_entries, pe=pa+(acl)->a_count; pa<pe; pa++) | 
|---|
| 43 |  | 
|---|
| 44 |  | 
|---|
| 45 | /* | 
|---|
| 46 | * Duplicate an ACL handle. | 
|---|
| 47 | */ | 
|---|
| 48 | static inline struct posix_acl * | 
|---|
| 49 | posix_acl_dup(struct posix_acl *acl) | 
|---|
| 50 | { | 
|---|
| 51 | if (acl) | 
|---|
| 52 | refcount_inc(r: &acl->a_refcount); | 
|---|
| 53 | return acl; | 
|---|
| 54 | } | 
|---|
| 55 |  | 
|---|
| 56 | /* | 
|---|
| 57 | * Free an ACL handle. | 
|---|
| 58 | */ | 
|---|
| 59 | static inline void | 
|---|
| 60 | posix_acl_release(struct posix_acl *acl) | 
|---|
| 61 | { | 
|---|
| 62 | if (acl && refcount_dec_and_test(r: &acl->a_refcount)) | 
|---|
| 63 | kfree_rcu(acl, a_rcu); | 
|---|
| 64 | } | 
|---|
| 65 |  | 
|---|
| 66 |  | 
|---|
| 67 | /* posix_acl.c */ | 
|---|
| 68 |  | 
|---|
| 69 | extern void posix_acl_init(struct posix_acl *, int); | 
|---|
| 70 | extern struct posix_acl *posix_acl_alloc(unsigned int count, gfp_t flags); | 
|---|
| 71 | extern struct posix_acl *posix_acl_from_mode(umode_t, gfp_t); | 
|---|
| 72 | extern int posix_acl_equiv_mode(const struct posix_acl *, umode_t *); | 
|---|
| 73 | extern int __posix_acl_create(struct posix_acl **, gfp_t, umode_t *); | 
|---|
| 74 | extern int __posix_acl_chmod(struct posix_acl **, gfp_t, umode_t); | 
|---|
| 75 |  | 
|---|
| 76 | extern struct posix_acl *get_posix_acl(struct inode *, int); | 
|---|
| 77 | int set_posix_acl(struct mnt_idmap *, struct dentry *, int, | 
|---|
| 78 | struct posix_acl *); | 
|---|
| 79 |  | 
|---|
| 80 | struct posix_acl *get_cached_acl_rcu(struct inode *inode, int type); | 
|---|
| 81 | struct posix_acl *posix_acl_clone(const struct posix_acl *acl, gfp_t flags); | 
|---|
| 82 |  | 
|---|
| 83 | #ifdef CONFIG_FS_POSIX_ACL | 
|---|
| 84 | int posix_acl_chmod(struct mnt_idmap *, struct dentry *, umode_t); | 
|---|
| 85 | extern int posix_acl_create(struct inode *, umode_t *, struct posix_acl **, | 
|---|
| 86 | struct posix_acl **); | 
|---|
| 87 | int posix_acl_update_mode(struct mnt_idmap *, struct inode *, umode_t *, | 
|---|
| 88 | struct posix_acl **); | 
|---|
| 89 |  | 
|---|
| 90 | int simple_set_acl(struct mnt_idmap *, struct dentry *, | 
|---|
| 91 | struct posix_acl *, int); | 
|---|
| 92 | extern int simple_acl_create(struct inode *, struct inode *); | 
|---|
| 93 |  | 
|---|
| 94 | struct posix_acl *get_cached_acl(struct inode *inode, int type); | 
|---|
| 95 | void set_cached_acl(struct inode *inode, int type, struct posix_acl *acl); | 
|---|
| 96 | void forget_cached_acl(struct inode *inode, int type); | 
|---|
| 97 | void forget_all_cached_acls(struct inode *inode); | 
|---|
| 98 | int posix_acl_valid(struct user_namespace *, const struct posix_acl *); | 
|---|
| 99 | int posix_acl_permission(struct mnt_idmap *, struct inode *, | 
|---|
| 100 | const struct posix_acl *, int); | 
|---|
| 101 |  | 
|---|
| 102 | static inline void cache_no_acl(struct inode *inode) | 
|---|
| 103 | { | 
|---|
| 104 | inode->i_acl = NULL; | 
|---|
| 105 | inode->i_default_acl = NULL; | 
|---|
| 106 | } | 
|---|
| 107 |  | 
|---|
| 108 | int vfs_set_acl(struct mnt_idmap *idmap, struct dentry *dentry, | 
|---|
| 109 | const char *acl_name, struct posix_acl *kacl); | 
|---|
| 110 | struct posix_acl *vfs_get_acl(struct mnt_idmap *idmap, | 
|---|
| 111 | struct dentry *dentry, const char *acl_name); | 
|---|
| 112 | int vfs_remove_acl(struct mnt_idmap *idmap, struct dentry *dentry, | 
|---|
| 113 | const char *acl_name); | 
|---|
| 114 | int posix_acl_listxattr(struct inode *inode, char **buffer, | 
|---|
| 115 | ssize_t *remaining_size); | 
|---|
| 116 | #else | 
|---|
| 117 | static inline int posix_acl_chmod(struct mnt_idmap *idmap, | 
|---|
| 118 | struct dentry *dentry, umode_t mode) | 
|---|
| 119 | { | 
|---|
| 120 | return 0; | 
|---|
| 121 | } | 
|---|
| 122 |  | 
|---|
| 123 | #define simple_set_acl		NULL | 
|---|
| 124 |  | 
|---|
| 125 | static inline int simple_acl_create(struct inode *dir, struct inode *inode) | 
|---|
| 126 | { | 
|---|
| 127 | return 0; | 
|---|
| 128 | } | 
|---|
| 129 | static inline void cache_no_acl(struct inode *inode) | 
|---|
| 130 | { | 
|---|
| 131 | } | 
|---|
| 132 |  | 
|---|
| 133 | static inline int posix_acl_create(struct inode *inode, umode_t *mode, | 
|---|
| 134 | struct posix_acl **default_acl, struct posix_acl **acl) | 
|---|
| 135 | { | 
|---|
| 136 | *default_acl = *acl = NULL; | 
|---|
| 137 | return 0; | 
|---|
| 138 | } | 
|---|
| 139 |  | 
|---|
| 140 | static inline void forget_all_cached_acls(struct inode *inode) | 
|---|
| 141 | { | 
|---|
| 142 | } | 
|---|
| 143 |  | 
|---|
| 144 | static inline int vfs_set_acl(struct mnt_idmap *idmap, | 
|---|
| 145 | struct dentry *dentry, const char *name, | 
|---|
| 146 | struct posix_acl *acl) | 
|---|
| 147 | { | 
|---|
| 148 | return -EOPNOTSUPP; | 
|---|
| 149 | } | 
|---|
| 150 |  | 
|---|
| 151 | static inline struct posix_acl *vfs_get_acl(struct mnt_idmap *idmap, | 
|---|
| 152 | struct dentry *dentry, | 
|---|
| 153 | const char *acl_name) | 
|---|
| 154 | { | 
|---|
| 155 | return ERR_PTR(-EOPNOTSUPP); | 
|---|
| 156 | } | 
|---|
| 157 |  | 
|---|
| 158 | static inline int vfs_remove_acl(struct mnt_idmap *idmap, | 
|---|
| 159 | struct dentry *dentry, const char *acl_name) | 
|---|
| 160 | { | 
|---|
| 161 | return -EOPNOTSUPP; | 
|---|
| 162 | } | 
|---|
| 163 | static inline int posix_acl_listxattr(struct inode *inode, char **buffer, | 
|---|
| 164 | ssize_t *remaining_size) | 
|---|
| 165 | { | 
|---|
| 166 | return 0; | 
|---|
| 167 | } | 
|---|
| 168 | #endif /* CONFIG_FS_POSIX_ACL */ | 
|---|
| 169 |  | 
|---|
| 170 | struct posix_acl *get_inode_acl(struct inode *inode, int type); | 
|---|
| 171 |  | 
|---|
| 172 | #endif  /* __LINUX_POSIX_ACL_H */ | 
|---|
| 173 |  | 
|---|