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