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.
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.
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]
22 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 #ifndef _SYS_FS_ZFS_ACL_H
27 #define _SYS_FS_ZFS_ACL_H
29 #pragma ident "%Z%%M% %I% %E% SMI"
36 #include <sys/zfs_fuid.h>
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
50 * ZFS ACLs are store in various forms.
51 * Files created with ACL version ZFS_ACL_VERSION_INITIAL
52 * will all be created with fixed length ACEs of type
55 * Files with ACL version ZFS_ACL_VERSION_FUID will be created
56 * with various sized ACEs. The abstraction entries will utilize
57 * zfs_ace_hdr_t, normal user/group entries will use zfs_ace_t
58 * and some specialized CIFS ACEs will use zfs_object_ace_t.
62 * All ACEs have a common hdr. For
63 * owner@, group@, and everyone@ this is all
66 typedef struct zfs_ace_hdr {
69 uint32_t z_access_mask;
72 typedef zfs_ace_hdr_t zfs_ace_abstract_t;
77 typedef struct zfs_ace {
83 * The following type only applies to ACE_ACCESS_ALLOWED|DENIED_OBJECT_ACE_TYPE
84 * and will only be set/retrieved in a CIFS context.
87 typedef struct zfs_object_ace {
89 uint8_t z_object_type[16]; /* object type */
90 uint8_t z_inherit_type[16]; /* inherited object type */
93 typedef struct zfs_oldace {
94 uint32_t z_fuid; /* "who" */
95 uint32_t z_access_mask; /* access mask */
96 uint16_t z_flags; /* flags, i.e inheritance */
97 uint16_t z_type; /* type of entry allow/deny */
100 typedef struct zfs_acl_phys_v0 {
101 uint64_t z_acl_extern_obj; /* ext acl pieces */
102 uint32_t z_acl_count; /* Number of ACEs */
103 uint16_t z_acl_version; /* acl version */
104 uint16_t z_acl_pad; /* pad */
105 zfs_oldace_t z_ace_data[ACE_SLOT_CNT]; /* 6 standard ACEs */
108 #define ZFS_ACE_SPACE (sizeof (zfs_oldace_t) * ACE_SLOT_CNT)
110 typedef struct zfs_acl_phys {
111 uint64_t z_acl_extern_obj; /* ext acl pieces */
112 uint32_t z_acl_size; /* Number of bytes in ACL */
113 uint16_t z_acl_version; /* acl version */
114 uint16_t z_acl_count; /* ace count */
115 uint8_t z_ace_data[ZFS_ACE_SPACE]; /* space for embedded ACEs */
120 typedef struct acl_ops {
121 uint32_t (*ace_mask_get) (void *acep); /* get access mask */
122 void (*ace_mask_set) (void *acep,
123 uint32_t mask); /* set access mask */
124 uint16_t (*ace_flags_get) (void *acep); /* get flags */
125 void (*ace_flags_set) (void *acep,
126 uint16_t flags); /* set flags */
127 uint16_t (*ace_type_get)(void *acep); /* get type */
128 void (*ace_type_set)(void *acep,
129 uint16_t type); /* set type */
130 uint64_t (*ace_who_get)(void *acep); /* get who/fuid */
131 void (*ace_who_set)(void *acep,
132 uint64_t who); /* set who/fuid */
133 size_t (*ace_size)(void *acep); /* how big is this ace */
134 size_t (*ace_abstract_size)(void); /* sizeof abstract entry */
135 int (*ace_mask_off)(void); /* off of access mask in ace */
136 int (*ace_data)(void *acep, void **datap);
137 /* ptr to data if any */
141 * A zfs_acl_t structure is composed of a list of zfs_acl_node_t's.
142 * Each node will have one or more ACEs associated with it. You will
143 * only have multiple nodes during a chmod operation. Normally only
144 * one node is required.
146 typedef struct zfs_acl_node {
147 list_node_t z_next; /* Next chunk of ACEs */
148 void *z_acldata; /* pointer into actual ACE(s) */
149 void *z_allocdata; /* pointer to kmem allocated memory */
150 size_t z_allocsize; /* Size of blob in bytes */
151 size_t z_size; /* length of ACL data */
152 int z_ace_count; /* number of ACEs in this acl node */
153 int z_ace_idx; /* ace iterator positioned on */
156 typedef struct zfs_acl {
157 int z_acl_count; /* Number of ACEs */
158 size_t z_acl_bytes; /* Number of bytes in ACL */
159 uint_t z_version; /* version of ACL */
160 void *z_next_ace; /* pointer to next ACE */
161 int z_hints; /* ACL hints (ZFS_INHERIT_ACE ...) */
162 zfs_acl_node_t *z_curr_node; /* current node iterator is handling */
163 list_t z_acl; /* chunks of ACE data */
164 acl_ops_t z_ops; /* ACL operations */
165 boolean_t z_has_fuids; /* FUIDs present in ACL? */
168 #define ACL_DATA_ALLOCED 0x1
169 #define ZFS_ACL_SIZE(aclcnt) (sizeof (ace_t) * (aclcnt))
172 * Property values for acl_mode and acl_inherit.
174 * acl_mode can take discard, noallow, groupmask and passthrough.
175 * whereas acl_inherit has secure instead of groupmask.
178 #define ZFS_ACL_DISCARD 0
179 #define ZFS_ACL_NOALLOW 1
180 #define ZFS_ACL_GROUPMASK 2
181 #define ZFS_ACL_PASSTHROUGH 3
182 #define ZFS_ACL_RESTRICTED 4
186 struct zfs_fuid_info;
189 void zfs_perm_init(struct znode *, struct znode *, int, vattr_t *,
190 dmu_tx_t *, cred_t *, zfs_acl_t *, zfs_fuid_info_t **);
191 int zfs_getacl(struct znode *, vsecattr_t *, boolean_t, cred_t *);
192 int zfs_setacl(struct znode *, vsecattr_t *, boolean_t, cred_t *);
193 void zfs_acl_rele(void *);
194 void zfs_oldace_byteswap(ace_t *, int);
195 void zfs_ace_byteswap(void *, size_t, boolean_t);
196 extern int zfs_zaccess(struct znode *, int, int, boolean_t, cred_t *);
197 extern int zfs_zaccess_rwx(struct znode *, mode_t, int, cred_t *);
198 extern int zfs_zaccess_unix(struct znode *, mode_t, cred_t *);
199 extern int zfs_acl_access(struct znode *, int, cred_t *);
200 int zfs_acl_chmod_setattr(struct znode *, zfs_acl_t **, uint64_t);
201 int zfs_zaccess_delete(struct znode *, struct znode *, cred_t *);
202 int zfs_zaccess_rename(struct znode *, struct znode *,
203 struct znode *, struct znode *, cred_t *cr);
204 void zfs_acl_free(zfs_acl_t *);
205 int zfs_vsec_2_aclp(struct zfsvfs *, vtype_t, vsecattr_t *, zfs_acl_t **);
206 int zfs_aclset_common(struct znode *, zfs_acl_t *, cred_t *,
207 struct zfs_fuid_info **, dmu_tx_t *);
215 #endif /* !ZFS_NO_ACL */