xref: /freebsd/sys/contrib/openzfs/include/sys/zfs_acl.h (revision 61145dc2b94f12f6a47344fb9aac702321880e43)
1 // SPDX-License-Identifier: CDDL-1.0
2 /*
3  * CDDL HEADER START
4  *
5  * The contents of this file are subject to the terms of the
6  * Common Development and Distribution License (the "License").
7  * You may not use this file except in compliance with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or https://opensource.org/licenses/CDDL-1.0.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
24  */
25 
26 #ifndef	_SYS_FS_ZFS_ACL_H
27 #define	_SYS_FS_ZFS_ACL_H
28 
29 #ifdef _KERNEL
30 #include <sys/isa_defs.h>
31 #include <sys/types32.h>
32 #include <sys/xvattr.h>
33 #endif
34 #include <sys/acl.h>
35 #include <sys/dmu.h>
36 #include <sys/zfs_fuid.h>
37 #include <sys/sa.h>
38 
39 #ifdef	__cplusplus
40 extern "C" {
41 #endif
42 
43 struct znode_phys;
44 
45 #define	ACE_SLOT_CNT	6
46 #define	ZFS_ACL_VERSION_INITIAL 0ULL
47 #define	ZFS_ACL_VERSION_FUID	1ULL
48 #define	ZFS_ACL_VERSION		ZFS_ACL_VERSION_FUID
49 
50 /*
51  * ZFS ACLs (Access Control Lists) are stored in various forms.
52  *
53  * Files created with ACL version ZFS_ACL_VERSION_INITIAL
54  * will all be created with fixed length ACEs of type
55  * zfs_oldace_t.
56  *
57  * Files with ACL version ZFS_ACL_VERSION_FUID will be created
58  * with various sized ACEs.  The abstraction entries will utilize
59  * zfs_ace_hdr_t, normal user/group entries will use zfs_ace_t
60  * and some specialized CIFS ACEs will use zfs_object_ace_t.
61  */
62 
63 /*
64  * All ACEs have a common hdr.  For
65  * owner@, group@, and everyone@ this is all
66  * that's needed.
67  */
68 typedef struct zfs_ace_hdr {
69 	uint16_t z_type;
70 	uint16_t z_flags;
71 	uint32_t z_access_mask;
72 } zfs_ace_hdr_t;
73 
74 typedef zfs_ace_hdr_t zfs_ace_abstract_t;
75 
76 /*
77  * Standard ACE
78  */
79 typedef struct zfs_ace {
80 	zfs_ace_hdr_t	z_hdr;
81 	uint64_t	z_fuid;
82 } zfs_ace_t;
83 
84 /*
85  * The following type only applies to ACE_ACCESS_ALLOWED|DENIED_OBJECT_ACE_TYPE
86  * and will only be set/retrieved in a CIFS context.
87  */
88 
89 typedef struct zfs_object_ace {
90 	zfs_ace_t	z_ace;
91 	uint8_t		z_object_type[16]; /* object type */
92 	uint8_t		z_inherit_type[16]; /* inherited object type */
93 } zfs_object_ace_t;
94 
95 typedef struct zfs_oldace {
96 	uint32_t	z_fuid;		/* "who" */
97 	uint32_t	z_access_mask;  /* access mask */
98 	uint16_t	z_flags;	/* flags, i.e inheritance */
99 	uint16_t	z_type;		/* type of entry allow/deny */
100 } zfs_oldace_t;
101 
102 typedef struct zfs_acl_phys_v0 {
103 	uint64_t	z_acl_extern_obj;	/* ext acl pieces */
104 	uint32_t	z_acl_count;		/* Number of ACEs */
105 	uint16_t	z_acl_version;		/* acl version */
106 	uint16_t	z_acl_pad;		/* pad */
107 	zfs_oldace_t	z_ace_data[ACE_SLOT_CNT]; /* 6 standard ACEs */
108 } zfs_acl_phys_v0_t;
109 
110 #define	ZFS_ACE_SPACE	(sizeof (zfs_oldace_t) * ACE_SLOT_CNT)
111 
112 /*
113  * Size of ACL count is always 2 bytes.
114  * Necessary to for dealing with both V0 ACL and V1 ACL layout
115  */
116 #define	ZFS_ACL_COUNT_SIZE	(sizeof (uint16_t))
117 
118 typedef struct zfs_acl_phys {
119 	uint64_t	z_acl_extern_obj;	  /* ext acl pieces */
120 	uint32_t	z_acl_size;		  /* Number of bytes in ACL */
121 	uint16_t	z_acl_version;		  /* acl version */
122 	uint16_t	z_acl_count;		  /* ace count */
123 	uint8_t	z_ace_data[ZFS_ACE_SPACE]; /* space for embedded ACEs */
124 } zfs_acl_phys_t;
125 
126 typedef struct acl_ops {
127 	uint32_t	(*ace_mask_get) (void *acep); /* get  access mask */
128 	void 		(*ace_mask_set) (void *acep,
129 			    uint32_t mask); /* set access mask */
130 	uint16_t	(*ace_flags_get) (void *acep);	/* get flags */
131 	void		(*ace_flags_set) (void *acep,
132 			    uint16_t flags); /* set flags */
133 	uint16_t	(*ace_type_get)(void *acep); /* get type */
134 	void		(*ace_type_set)(void *acep,
135 			    uint16_t type); /* set type */
136 	uint64_t	(*ace_who_get)(void *acep); /* get who/fuid */
137 	void		(*ace_who_set)(void *acep,
138 			    uint64_t who); /* set who/fuid */
139 	size_t		(*ace_size)(void *acep); /* how big is this ace */
140 	size_t		(*ace_abstract_size)(void); /* sizeof abstract entry */
141 	int		(*ace_mask_off)(void); /* off of access mask in ace */
142 	/* ptr to data if any */
143 	int		(*ace_data)(void *acep, void **datap);
144 } acl_ops_t;
145 
146 /*
147  * A zfs_acl_t structure is composed of a list of zfs_acl_node_t's.
148  * Each node will have one or more ACEs associated with it.  You will
149  * only have multiple nodes during a chmod operation.   Normally only
150  * one node is required.
151  */
152 typedef struct zfs_acl_node {
153 	list_node_t	z_next;		/* Next chunk of ACEs */
154 	void		*z_acldata;	/* pointer into actual ACE(s) */
155 	void		*z_allocdata;	/* pointer to kmem allocated memory */
156 	size_t		z_allocsize;	/* Size of blob in bytes */
157 	size_t		z_size;		/* length of ACL data */
158 	uint64_t	z_ace_count;	/* number of ACEs in this acl node */
159 	int		z_ace_idx;	/* ace iterator positioned on */
160 } zfs_acl_node_t;
161 
162 typedef struct zfs_acl {
163 	uint64_t	z_acl_count;	/* Number of ACEs */
164 	size_t		z_acl_bytes;	/* Number of bytes in ACL */
165 	uint_t		z_version;	/* version of ACL */
166 	void		*z_next_ace;	/* pointer to next ACE */
167 	uint64_t	z_hints;	/* ACL hints (ZFS_INHERIT_ACE ...) */
168 	zfs_acl_node_t	*z_curr_node;	/* current node iterator is handling */
169 	list_t		z_acl;		/* chunks of ACE data */
170 	const acl_ops_t	*z_ops;		/* ACL operations */
171 } zfs_acl_t;
172 
173 typedef struct acl_locator_cb {
174 	zfs_acl_t *cb_aclp;
175 	zfs_acl_node_t *cb_acl_node;
176 } zfs_acl_locator_cb_t;
177 
178 #define	ACL_DATA_ALLOCED	0x1
179 #define	ZFS_ACL_SIZE(aclcnt)	(sizeof (ace_t) * (aclcnt))
180 
181 struct zfs_fuid_info;
182 
183 typedef struct zfs_acl_ids {
184 	uint64_t		z_fuid;		/* file owner fuid */
185 	uint64_t		z_fgid;		/* file group owner fuid */
186 	uint64_t		z_mode;		/* mode to set on create */
187 	zfs_acl_t		*z_aclp;	/* ACL to create with file */
188 	struct zfs_fuid_info 	*z_fuidp;	/* for tracking fuids for log */
189 } zfs_acl_ids_t;
190 
191 /*
192  * Property values for acl_mode and acl_inherit.
193  *
194  * acl_mode can take discard, noallow, groupmask and passthrough.
195  * whereas acl_inherit has secure instead of groupmask.
196  */
197 
198 #define	ZFS_ACL_DISCARD		0
199 #define	ZFS_ACL_NOALLOW		1
200 #define	ZFS_ACL_GROUPMASK	2
201 #define	ZFS_ACL_PASSTHROUGH	3
202 #define	ZFS_ACL_RESTRICTED	4
203 #define	ZFS_ACL_PASSTHROUGH_X	5
204 
205 struct znode;
206 struct zfsvfs;
207 
208 #ifdef _KERNEL
209 int zfs_acl_ids_create(struct znode *, int, vattr_t *,
210     cred_t *, vsecattr_t *, zfs_acl_ids_t *, zidmap_t *);
211 void zfs_acl_ids_free(zfs_acl_ids_t *);
212 boolean_t zfs_acl_ids_overquota(struct zfsvfs *, zfs_acl_ids_t *, uint64_t);
213 int zfs_getacl(struct znode *, vsecattr_t *, boolean_t, cred_t *);
214 int zfs_setacl(struct znode *, vsecattr_t *, boolean_t, cred_t *);
215 void zfs_acl_rele(void *);
216 void zfs_oldace_byteswap(ace_t *, int);
217 void zfs_ace_byteswap(void *, size_t, boolean_t);
218 extern boolean_t zfs_has_access(struct znode *zp, cred_t *cr);
219 extern int zfs_zaccess(struct znode *, int, int, boolean_t, cred_t *,
220     zidmap_t *);
221 int zfs_fastaccesschk_execute(struct znode *, cred_t *);
222 extern int zfs_zaccess_rwx(struct znode *, mode_t, int, cred_t *, zidmap_t *);
223 extern int zfs_zaccess_unix(void *, int, cred_t *);
224 extern int zfs_acl_access(struct znode *, int, cred_t *);
225 int zfs_acl_chmod_setattr(struct znode *, zfs_acl_t **, uint64_t);
226 int zfs_zaccess_delete(struct znode *, struct znode *, cred_t *, zidmap_t *);
227 int zfs_zaccess_rename(struct znode *, struct znode *,
228     struct znode *, struct znode *, cred_t *cr, zidmap_t *mnt_ns);
229 void zfs_acl_free(zfs_acl_t *);
230 int zfs_vsec_2_aclp(struct zfsvfs *, umode_t, vsecattr_t *, cred_t *,
231     struct zfs_fuid_info **, zfs_acl_t **);
232 int zfs_aclset_common(struct znode *, zfs_acl_t *, cred_t *, dmu_tx_t *);
233 uint64_t zfs_external_acl(struct znode *);
234 int zfs_znode_acl_version(struct znode *);
235 int zfs_acl_size(struct znode *, int *);
236 zfs_acl_t *zfs_acl_alloc(int);
237 zfs_acl_node_t *zfs_acl_node_alloc(size_t);
238 void zfs_acl_xform(struct znode *, zfs_acl_t *, cred_t *);
239 void zfs_acl_data_locator(void **, uint32_t *, uint32_t, boolean_t, void *);
240 uint64_t zfs_mode_compute(uint64_t, zfs_acl_t *,
241     uint64_t *, uint64_t, uint64_t);
242 int zfs_acl_node_read(struct znode *, boolean_t, zfs_acl_t **, boolean_t);
243 int zfs_acl_chown_setattr(struct znode *);
244 
245 #endif
246 
247 #ifdef	__cplusplus
248 }
249 #endif
250 #endif	/* _SYS_FS_ZFS_ACL_H */
251