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