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