zfs_acl.h revision 6385:5437941ec5a1
160484Sobrien/*
278828Sobrien * CDDL HEADER START
360484Sobrien *
460484Sobrien * The contents of this file are subject to the terms of the
589857Sobrien * Common Development and Distribution License (the "License").
660484Sobrien * You may not use this file except in compliance with the License.
789857Sobrien *
860484Sobrien * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
960484Sobrien * or http://www.opensolaris.org/os/licensing.
1060484Sobrien * See the License for the specific language governing permissions
1160484Sobrien * and limitations under the License.
1289857Sobrien *
1360484Sobrien * When distributing Covered Code, include this CDDL HEADER in each
1460484Sobrien * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
1560484Sobrien * If applicable, add the following below this CDDL HEADER, with the
1660484Sobrien * fields enclosed by brackets "[]" replaced with your own identifying
1760484Sobrien * information: Portions Copyright [yyyy] [name of copyright owner]
1889857Sobrien *
1960484Sobrien * CDDL HEADER END
2060484Sobrien */
2160484Sobrien/*
2260484Sobrien * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
2360484Sobrien * Use is subject to license terms.
2460484Sobrien */
2560484Sobrien
2660484Sobrien#ifndef	_SYS_FS_ZFS_ACL_H
2760484Sobrien#define	_SYS_FS_ZFS_ACL_H
2860484Sobrien
2960484Sobrien#pragma ident	"%Z%%M%	%I%	%E% SMI"
3060484Sobrien
3160484Sobrien#ifdef _KERNEL
3260484Sobrien#include <sys/isa_defs.h>
3360484Sobrien#include <sys/types32.h>
3460484Sobrien#endif
3560484Sobrien#include <sys/acl.h>
3660484Sobrien#include <sys/dmu.h>
3760484Sobrien#include <sys/zfs_fuid.h>
3860484Sobrien
3960484Sobrien#ifdef	__cplusplus
4060484Sobrienextern "C" {
4160484Sobrien#endif
4260484Sobrien
4360484Sobrienstruct znode_phys;
4460484Sobrien
4560484Sobrien#define	ACE_SLOT_CNT	6
4660484Sobrien#define	ZFS_ACL_VERSION_INITIAL 0ULL
4760484Sobrien#define	ZFS_ACL_VERSION_FUID	1ULL
4860484Sobrien#define	ZFS_ACL_VERSION		ZFS_ACL_VERSION_FUID
4960484Sobrien
5060484Sobrien/*
5160484Sobrien * ZFS ACLs are store in various forms.
5260484Sobrien * Files created with ACL version ZFS_ACL_VERSION_INITIAL
5360484Sobrien * will all be created with fixed length ACEs of type
5460484Sobrien * zfs_oldace_t.
5560484Sobrien *
5660484Sobrien * Files with ACL version ZFS_ACL_VERSION_FUID will be created
5760484Sobrien * with various sized ACEs.  The abstraction entries will utilize
5860484Sobrien * zfs_ace_hdr_t, normal user/group entries will use zfs_ace_t
5960484Sobrien * and some specialized CIFS ACEs will use zfs_object_ace_t.
6060484Sobrien */
6160484Sobrien
6260484Sobrien/*
6360484Sobrien * All ACEs have a common hdr.  For
6460484Sobrien * owner@, group@, and everyone@ this is all
6560484Sobrien * thats needed.
6660484Sobrien */
6760484Sobrientypedef struct zfs_ace_hdr {
6860484Sobrien	uint16_t z_type;
6960484Sobrien	uint16_t z_flags;
7060484Sobrien	uint32_t z_access_mask;
7160484Sobrien} zfs_ace_hdr_t;
7260484Sobrien
7360484Sobrientypedef zfs_ace_hdr_t zfs_ace_abstract_t;
7460484Sobrien
7560484Sobrien/*
7660484Sobrien * Standard ACE
7760484Sobrien */
7860484Sobrientypedef struct zfs_ace {
7960484Sobrien	zfs_ace_hdr_t	z_hdr;
8060484Sobrien	uint64_t	z_fuid;
8160484Sobrien} zfs_ace_t;
8260484Sobrien
8360484Sobrien/*
8460484Sobrien * The following type only applies to ACE_ACCESS_ALLOWED|DENIED_OBJECT_ACE_TYPE
8560484Sobrien * and will only be set/retrieved in a CIFS context.
8660484Sobrien */
8760484Sobrien
8860484Sobrientypedef struct zfs_object_ace {
8960484Sobrien	zfs_ace_t	z_ace;
9060484Sobrien	uint8_t		z_object_type[16]; /* object type */
9160484Sobrien	uint8_t		z_inherit_type[16]; /* inherited object type */
9260484Sobrien} zfs_object_ace_t;
9360484Sobrien
9460484Sobrientypedef struct zfs_oldace {
9560484Sobrien	uint32_t	z_fuid;		/* "who" */
9660484Sobrien	uint32_t	z_access_mask;  /* access mask */
9760484Sobrien	uint16_t	z_flags;	/* flags, i.e inheritance */
9860484Sobrien	uint16_t	z_type;		/* type of entry allow/deny */
9960484Sobrien} zfs_oldace_t;
10060484Sobrien
10160484Sobrientypedef struct zfs_acl_phys_v0 {
10277298Sobrien	uint64_t	z_acl_extern_obj;	/* ext acl pieces */
10377298Sobrien	uint32_t	z_acl_count;		/* Number of ACEs */
10460484Sobrien	uint16_t	z_acl_version;		/* acl version */
10560484Sobrien	uint16_t	z_acl_pad;		/* pad */
10660484Sobrien	zfs_oldace_t	z_ace_data[ACE_SLOT_CNT]; /* 6 standard ACEs */
10777298Sobrien} zfs_acl_phys_v0_t;
10877298Sobrien
10977298Sobrien#define	ZFS_ACE_SPACE	(sizeof (zfs_oldace_t) * ACE_SLOT_CNT)
11077298Sobrien
11177298Sobrientypedef struct zfs_acl_phys {
11277298Sobrien	uint64_t	z_acl_extern_obj;	  /* ext acl pieces */
11389857Sobrien	uint32_t	z_acl_size;		  /* Number of bytes in ACL */
11489857Sobrien	uint16_t	z_acl_version;		  /* acl version */
11589857Sobrien	uint16_t	z_acl_count;		  /* ace count */
11689857Sobrien	uint8_t		z_ace_data[ZFS_ACE_SPACE]; /* space for embedded ACEs */
11760484Sobrien} zfs_acl_phys_t;
11860484Sobrien
11960484Sobrien
12060484Sobrien
12160484Sobrientypedef struct acl_ops {
12260484Sobrien	uint32_t	(*ace_mask_get) (void *acep); /* get  access mask */
12360484Sobrien	void 		(*ace_mask_set) (void *acep,
12460484Sobrien			    uint32_t mask); /* set access mask */
12560484Sobrien	uint16_t	(*ace_flags_get) (void *acep);	/* get flags */
12660484Sobrien	void		(*ace_flags_set) (void *acep,
12760484Sobrien			    uint16_t flags); /* set flags */
12860484Sobrien	uint16_t	(*ace_type_get)(void *acep); /* get type */
12960484Sobrien	void		(*ace_type_set)(void *acep,
130			    uint16_t type); /* set type */
131	uint64_t	(*ace_who_get)(void *acep); /* get who/fuid */
132	void		(*ace_who_set)(void *acep,
133			    uint64_t who); /* set who/fuid */
134	size_t		(*ace_size)(void *acep); /* how big is this ace */
135	size_t		(*ace_abstract_size)(void); /* sizeof abstract entry */
136	int		(*ace_mask_off)(void); /* off of access mask in ace */
137	int		(*ace_data)(void *acep, void **datap);
138			    /* ptr to data if any */
139} acl_ops_t;
140
141/*
142 * A zfs_acl_t structure is composed of a list of zfs_acl_node_t's.
143 * Each node will have one or more ACEs associated with it.  You will
144 * only have multiple nodes during a chmod operation.   Normally only
145 * one node is required.
146 */
147typedef struct zfs_acl_node {
148	list_node_t	z_next;		/* Next chunk of ACEs */
149	void		*z_acldata;	/* pointer into actual ACE(s) */
150	void		*z_allocdata;	/* pointer to kmem allocated memory */
151	size_t		z_allocsize;	/* Size of blob in bytes */
152	size_t		z_size;		/* length of ACL data */
153	int		z_ace_count;	/* number of ACEs in this acl node */
154	int		z_ace_idx;	/* ace iterator positioned on */
155} zfs_acl_node_t;
156
157typedef struct zfs_acl {
158	int		z_acl_count;	/* Number of ACEs */
159	size_t		z_acl_bytes;	/* Number of bytes in ACL */
160	uint_t		z_version;	/* version of ACL */
161	void		*z_next_ace;	/* pointer to next ACE */
162	int		z_hints;	/* ACL hints (ZFS_INHERIT_ACE ...) */
163	zfs_acl_node_t	*z_curr_node;	/* current node iterator is handling */
164	list_t		z_acl;		/* chunks of ACE data */
165	acl_ops_t	z_ops;		/* ACL operations */
166	boolean_t	z_has_fuids;	/* FUIDs present in ACL? */
167} zfs_acl_t;
168
169#define	ACL_DATA_ALLOCED	0x1
170#define	ZFS_ACL_SIZE(aclcnt)	(sizeof (ace_t) * (aclcnt))
171
172/*
173 * Property values for acl_mode and acl_inherit.
174 *
175 * acl_mode can take discard, noallow, groupmask and passthrough.
176 * whereas acl_inherit has secure instead of groupmask.
177 */
178
179#define	ZFS_ACL_DISCARD		0
180#define	ZFS_ACL_NOALLOW		1
181#define	ZFS_ACL_GROUPMASK	2
182#define	ZFS_ACL_PASSTHROUGH	3
183#define	ZFS_ACL_RESTRICTED	4
184
185struct znode;
186struct zfsvfs;
187struct zfs_fuid_info;
188
189#ifdef _KERNEL
190void zfs_perm_init(struct znode *, struct znode *, int, vattr_t *,
191    dmu_tx_t *, cred_t *, zfs_acl_t *, zfs_fuid_info_t **);
192int zfs_getacl(struct znode *, vsecattr_t *, boolean_t, cred_t *);
193int zfs_setacl(struct znode *, vsecattr_t *, boolean_t, cred_t *);
194void zfs_acl_rele(void *);
195void zfs_oldace_byteswap(ace_t *, int);
196void zfs_ace_byteswap(void *, size_t, boolean_t);
197extern int zfs_zaccess(struct znode *, int, int, boolean_t, cred_t *);
198extern int zfs_zaccess_rwx(struct znode *, mode_t, int, cred_t *);
199extern int zfs_zaccess_unix(struct znode *, mode_t, cred_t *);
200extern int zfs_acl_access(struct znode *, int, cred_t *);
201int zfs_acl_chmod_setattr(struct znode *, zfs_acl_t **, uint64_t);
202int zfs_zaccess_delete(struct znode *, struct znode *, cred_t *);
203int zfs_zaccess_rename(struct znode *, struct znode *,
204    struct znode *, struct znode *, cred_t *cr);
205void zfs_acl_free(zfs_acl_t *);
206int zfs_vsec_2_aclp(struct zfsvfs *, vtype_t, vsecattr_t *, zfs_acl_t **);
207int zfs_aclset_common(struct znode *, zfs_acl_t *, cred_t *,
208    struct zfs_fuid_info **, dmu_tx_t *);
209
210#endif
211
212#ifdef	__cplusplus
213}
214#endif
215#endif	/* _SYS_FS_ZFS_ACL_H */
216