2fa9e406ahrens * CDDL HEADER START
3fa9e406ahrens *
4fa9e406ahrens * The contents of this file are subject to the terms of the
5ea8dc4beschrock * Common Development and Distribution License (the "License").
6ea8dc4beschrock * You may not use this file except in compliance with the License.
7fa9e406ahrens *
8fa9e406ahrens * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9fa9e406ahrens * or http://www.opensolaris.org/os/licensing.
10fa9e406ahrens * See the License for the specific language governing permissions
11fa9e406ahrens * and limitations under the License.
12fa9e406ahrens *
13fa9e406ahrens * When distributing Covered Code, include this CDDL HEADER in each
14fa9e406ahrens * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15fa9e406ahrens * If applicable, add the following below this CDDL HEADER, with the
16fa9e406ahrens * fields enclosed by brackets "[]" replaced with your own identifying
17fa9e406ahrens * information: Portions Copyright [yyyy] [name of copyright owner]
18fa9e406ahrens *
19fa9e406ahrens * CDDL HEADER END
20fa9e406ahrens */
2227dd1e8Mark Shellenbaum * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
23fa9e406ahrens */
25fa9e406ahrens#ifndef	_SYS_FS_ZFS_ACL_H
26fa9e406ahrens#define	_SYS_FS_ZFS_ACL_H
28fa9e406ahrens#ifdef _KERNEL
29fa9e406ahrens#include <sys/isa_defs.h>
30fa9e406ahrens#include <sys/types32.h>
32fa9e406ahrens#include <sys/acl.h>
33fa9e406ahrens#include <sys/dmu.h>
34da6c28aamw#include <sys/zfs_fuid.h>
350a586ceMark Shellenbaum#include <sys/sa.h>
37fa9e406ahrens#ifdef	__cplusplus
38fa9e406ahrensextern "C" {
41fa9e406ahrensstruct znode_phys;
43fa9e406ahrens#define	ACE_SLOT_CNT	6
44da6c28aamw#define	ZFS_ACL_VERSION_INITIAL 0ULL
45da6c28aamw#define	ZFS_ACL_VERSION_FUID	1ULL
49f717074Will Andrews * ZFS ACLs (Access Control Lists) are stored in various forms.
50f717074Will Andrews *
51da6c28aamw * Files created with ACL version ZFS_ACL_VERSION_INITIAL
52da6c28aamw * will all be created with fixed length ACEs of type
53da6c28aamw * zfs_oldace_t.
54da6c28aamw *
55da6c28aamw * Files with ACL version ZFS_ACL_VERSION_FUID will be created
56da6c28aamw * with various sized ACEs.  The abstraction entries will utilize
57da6c28aamw * zfs_ace_hdr_t, normal user/group entries will use zfs_ace_t
58da6c28aamw * and some specialized CIFS ACEs will use zfs_object_ace_t.
59da6c28aamw */
62da6c28aamw * All ACEs have a common hdr.  For
63da6c28aamw * owner@, group@, and everyone@ this is all
64da6c28aamw * thats needed.
65da6c28aamw */
66da6c28aamwtypedef struct zfs_ace_hdr {
67da6c28aamw	uint16_t z_type;
68da6c28aamw	uint16_t z_flags;
69da6c28aamw	uint32_t z_access_mask;
70da6c28aamw} zfs_ace_hdr_t;
72da6c28aamwtypedef zfs_ace_hdr_t zfs_ace_abstract_t;
75da6c28aamw * Standard ACE
76da6c28aamw */
77da6c28aamwtypedef struct zfs_ace {
78da6c28aamw	zfs_ace_hdr_t	z_hdr;
79da6c28aamw	uint64_t	z_fuid;
80da6c28aamw} zfs_ace_t;
83da6c28aamw * The following type only applies to ACE_ACCESS_ALLOWED|DENIED_OBJECT_ACE_TYPE
84da6c28aamw * and will only be set/retrieved in a CIFS context.
85da6c28aamw */
87da6c28aamwtypedef struct zfs_object_ace {
88da6c28aamw	zfs_ace_t	z_ace;
89da6c28aamw	uint8_t		z_object_type[16]; /* object type */
90da6c28aamw	uint8_t		z_inherit_type[16]; /* inherited object type */
91da6c28aamw} zfs_object_ace_t;
93da6c28aamwtypedef struct zfs_oldace {
94da6c28aamw	uint32_t	z_fuid;		/* "who" */
95da6c28aamw	uint32_t	z_access_mask;  /* access mask */
96da6c28aamw	uint16_t	z_flags;	/* flags, i.e inheritance */
97da6c28aamw	uint16_t	z_type;		/* type of entry allow/deny */
98da6c28aamw} zfs_oldace_t;
100da6c28aamwtypedef struct zfs_acl_phys_v0 {
101da6c28aamw	uint64_t	z_acl_extern_obj;	/* ext acl pieces */
102da6c28aamw	uint32_t	z_acl_count;		/* Number of ACEs */
103da6c28aamw	uint16_t	z_acl_version;		/* acl version */
104da6c28aamw	uint16_t	z_acl_pad;		/* pad */
105da6c28aamw	zfs_oldace_t	z_ace_data[ACE_SLOT_CNT]; /* 6 standard ACEs */
106da6c28aamw} zfs_acl_phys_v0_t;
108da6c28aamw#define	ZFS_ACE_SPACE	(sizeof (zfs_oldace_t) * ACE_SLOT_CNT)
1100a586ceMark Shellenbaum/*
1110a586ceMark Shellenbaum * Size of ACL count is always 2 bytes.
1120a586ceMark Shellenbaum * Necessary to for dealing with both V0 ACL and V1 ACL layout
1130a586ceMark Shellenbaum */
1140a586ceMark Shellenbaum#define	ZFS_ACL_COUNT_SIZE	(sizeof (uint16_t))
1150a586ceMark Shellenbaum
116da6c28aamwtypedef struct zfs_acl_phys {
117fa9e406ahrens	uint64_t	z_acl_extern_obj;	  /* ext acl pieces */
118da6c28aamw	uint32_t	z_acl_size;		  /* Number of bytes in ACL */
119fa9e406ahrens	uint16_t	z_acl_version;		  /* acl version */
120da6c28aamw	uint16_t	z_acl_count;		  /* ace count */
1210a586ceMark Shellenbaum	uint8_t	z_ace_data[ZFS_ACE_SPACE]; /* space for embedded ACEs */
122da6c28aamw} zfs_acl_phys_t;
124da6c28aamwtypedef struct acl_ops {
125da6c28aamw	uint32_t	(*ace_mask_get) (void *acep); /* get  access mask */
126da6c28aamw	void 		(*ace_mask_set) (void *acep,
127da6c28aamw			    uint32_t mask); /* set access mask */
128da6c28aamw	uint16_t	(*ace_flags_get) (void *acep);	/* get flags */
129da6c28aamw	void		(*ace_flags_set) (void *acep,
130da6c28aamw			    uint16_t flags); /* set flags */
131da6c28aamw	uint16_t	(*ace_type_get)(void *acep); /* get type */
132da6c28aamw	void		(*ace_type_set)(void *acep,
133da6c28aamw			    uint16_t type); /* set type */
134da6c28aamw	uint64_t	(*ace_who_get)(void *acep); /* get who/fuid */
135da6c28aamw	void		(*ace_who_set)(void *acep,
136da6c28aamw			    uint64_t who); /* set who/fuid */
137da6c28aamw	size_t		(*ace_size)(void *acep); /* how big is this ace */
138da6c28aamw	size_t		(*ace_abstract_size)(void); /* sizeof abstract entry */
139da6c28aamw	int		(*ace_mask_off)(void); /* off of access mask in ace */
140f717074Will Andrews	/* ptr to data if any */
141da6c28aamw	int		(*ace_data)(void *acep, void **datap);
142da6c28aamw} acl_ops_t;
145da6c28aamw * A zfs_acl_t structure is composed of a list of zfs_acl_node_t's.
146da6c28aamw * Each node will have one or more ACEs associated with it.  You will
147da6c28aamw * only have multiple nodes during a chmod operation.   Normally only
148da6c28aamw * one node is required.
149fa9e406ahrens */
150da6c28aamwtypedef struct zfs_acl_node {
151da6c28aamw	list_node_t	z_next;		/* Next chunk of ACEs */
152da6c28aamw	void		*z_acldata;	/* pointer into actual ACE(s) */
153da6c28aamw	void		*z_allocdata;	/* pointer to kmem allocated memory */
154da6c28aamw	size_t		z_allocsize;	/* Size of blob in bytes */
155da6c28aamw	size_t		z_size;		/* length of ACL data */
1560a586ceMark Shellenbaum	uint64_t	z_ace_count;	/* number of ACEs in this acl node */
157da6c28aamw	int		z_ace_idx;	/* ace iterator positioned on */
158da6c28aamw} zfs_acl_node_t;
160fa9e406ahrenstypedef struct zfs_acl {
1610a586ceMark Shellenbaum	uint64_t	z_acl_count;	/* Number of ACEs */
162da6c28aamw	size_t		z_acl_bytes;	/* Number of bytes in ACL */
163da6c28aamw	uint_t		z_version;	/* version of ACL */
164da6c28aamw	void		*z_next_ace;	/* pointer to next ACE */
1650a586ceMark Shellenbaum	uint64_t	z_hints;	/* ACL hints (ZFS_INHERIT_ACE ...) */
166da6c28aamw	zfs_acl_node_t	*z_curr_node;	/* current node iterator is handling */
167da6c28aamw	list_t		z_acl;		/* chunks of ACE data */
168da6c28aamw	acl_ops_t	z_ops;		/* ACL operations */
169fa9e406ahrens} zfs_acl_t;
1710a586ceMark Shellenbaumtypedef struct acl_locator_cb {
1720a586ceMark Shellenbaum	zfs_acl_t *cb_aclp;
1730a586ceMark Shellenbaum	zfs_acl_node_t *cb_acl_node;
1740a586ceMark Shellenbaum} zfs_acl_locator_cb_t;
1750a586ceMark Shellenbaum
176da6c28aamw#define	ACL_DATA_ALLOCED	0x1
177fa9e406ahrens#define	ZFS_ACL_SIZE(aclcnt)	(sizeof (ace_t) * (aclcnt))
17989459e1Mark Shellenbaumstruct zfs_fuid_info;
18089459e1Mark Shellenbaum
1811484342Matthew Ahrenstypedef struct zfs_acl_ids {
18289459e1Mark Shellenbaum	uint64_t		z_fuid;		/* file owner fuid */
18389459e1Mark Shellenbaum	uint64_t		z_fgid;		/* file group owner fuid */
18489459e1Mark Shellenbaum	uint64_t		z_mode;		/* mode to set on create */
18589459e1Mark Shellenbaum	zfs_acl_t		*z_aclp;	/* ACL to create with file */
18689459e1Mark Shellenbaum	struct zfs_fuid_info 	*z_fuidp;	/* for tracking fuids for log */
18789459e1Mark Shellenbaum} zfs_acl_ids_t;
18889459e1Mark Shellenbaum
190fa9e406ahrens * Property values for acl_mode and acl_inherit.
191fa9e406ahrens *
192fa9e406ahrens * acl_mode can take discard, noallow, groupmask and passthrough.
193fa9e406ahrens * whereas acl_inherit has secure instead of groupmask.
194fa9e406ahrens */
196e9dbad6eschrock#define	ZFS_ACL_DISCARD		0
197e9dbad6eschrock#define	ZFS_ACL_NOALLOW		1
198e9dbad6eschrock#define	ZFS_ACL_GROUPMASK	2
199e9dbad6eschrock#define	ZFS_ACL_PASSTHROUGH	3
200b3d141fmarks#define	ZFS_ACL_RESTRICTED	4
201d0f3f37Mark Shellenbaum#define	ZFS_ACL_PASSTHROUGH_X	5
203fa9e406ahrensstruct znode;
204da6c28aamwstruct zfsvfs;
206fa9e406ahrens#ifdef _KERNEL
20789459e1Mark Shellenbaumint zfs_acl_ids_create(struct znode *, int, vattr_t *,
20889459e1Mark Shellenbaum    cred_t *, vsecattr_t *, zfs_acl_ids_t *);
20989459e1Mark Shellenbaumvoid zfs_acl_ids_free(zfs_acl_ids_t *);
210f67950bNasf-Fanboolean_t zfs_acl_ids_overquota(struct zfsvfs *, zfs_acl_ids_t *, uint64_t);
211da6c28aamwint zfs_getacl(struct znode *, vsecattr_t *, boolean_t, cred_t *);
212da6c28aamwint zfs_setacl(struct znode *, vsecattr_t *, boolean_t, cred_t *);
213fa9e406ahrensvoid zfs_acl_rele(void *);
214da6c28aamwvoid zfs_oldace_byteswap(ace_t *, int);
215da6c28aamwvoid zfs_ace_byteswap(void *, size_t, boolean_t);
216e802abbTim Haleyextern boolean_t zfs_has_access(struct znode *zp, cred_t *cr);
217da6c28aamwextern int zfs_zaccess(struct znode *, int, int, boolean_t, cred_t *);
218d47621aTim Haleyint zfs_fastaccesschk_execute(struct znode *, cred_t *);
219da6c28aamwextern int zfs_zaccess_rwx(struct znode *, mode_t, int, cred_t *);
220da6c28aamwextern int zfs_zaccess_unix(struct znode *, mode_t, cred_t *);
221fa9e406ahrensextern int zfs_acl_access(struct znode *, int, cred_t *);
222a3c49ceAlbert Leeint zfs_acl_chmod_setattr(struct znode *, zfs_acl_t **, uint64_t);
223fa9e406ahrensint zfs_zaccess_delete(struct znode *, struct znode *, cred_t *);
224fa9e406ahrensint zfs_zaccess_rename(struct znode *, struct znode *,
225fa9e406ahrens    struct znode *, struct znode *, cred_t *cr);
226fa9e406ahrensvoid zfs_acl_free(zfs_acl_t *);
22789459e1Mark Shellenbaumint zfs_vsec_2_aclp(struct zfsvfs *, vtype_t, vsecattr_t *, cred_t *,
22889459e1Mark Shellenbaum    struct zfs_fuid_info **, zfs_acl_t **);
22989459e1Mark Shellenbaumint zfs_aclset_common(struct znode *, zfs_acl_t *, cred_t *, dmu_tx_t *);
2300a586ceMark Shellenbaumuint64_t zfs_external_acl(struct znode *);
2310a586ceMark Shellenbaumint zfs_znode_acl_version(struct znode *);
2320a586ceMark Shellenbaumint zfs_acl_size(struct znode *, int *);
2330a586ceMark Shellenbaumzfs_acl_t *zfs_acl_alloc(int);
2340a586ceMark Shellenbaumzfs_acl_node_t *zfs_acl_node_alloc(size_t);
2350a586ceMark Shellenbaumvoid zfs_acl_xform(struct znode *, zfs_acl_t *, cred_t *);
2360a586ceMark Shellenbaumvoid zfs_acl_data_locator(void **, uint32_t *, uint32_t, boolean_t, void *);
23727dd1e8Mark Shellenbaumuint64_t zfs_mode_compute(uint64_t, zfs_acl_t *,
23827dd1e8Mark Shellenbaum    uint64_t *, uint64_t, uint64_t);
239f67950bNasf-Fanint zfs_acl_node_read(struct znode *, boolean_t, zfs_acl_t **, boolean_t);
24027dd1e8Mark Shellenbaumint zfs_acl_chown_setattr(struct znode *);
244fa9e406ahrens#ifdef	__cplusplus
247fa9e406ahrens#endif	/* _SYS_FS_ZFS_ACL_H */