]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - include/os/freebsd/spl/sys/acl.h
Vendor import of openzfs master @ 184df27eef0abdc7ab2105b21257f753834b936b
[FreeBSD/FreeBSD.git] / include / os / freebsd / spl / sys / 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 2014 Garrett D'Amore <garrett@damore.org>
23  *
24  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
25  * Use is subject to license terms.
26  * Copyright 2017 RackTop Systems.
27  */
28
29 #ifndef _SYS_ACL_H
30 #define _SYS_ACL_H
31
32 #include <sys/types.h>
33 #include <sys/acl_impl.h>
34
35 /*
36  * When compiling OpenSolaris kernel code, this file is included instead of the
37  * FreeBSD one.  Include the original sys/acl.h as well.
38  */
39 #undef _SYS_ACL_H
40 #include_next <sys/acl.h>
41 #define _SYS_ACL_H
42
43 #ifdef  __cplusplus
44 extern "C" {
45 #endif
46
47 #define MAX_ACL_ENTRIES         (1024)  /* max entries of each type */
48 typedef struct {
49         int             a_type;         /* the type of ACL entry */
50         uid_t           a_id;           /* the entry in -uid or gid */
51         o_mode_t        a_perm;         /* the permission field */
52 } aclent_t;
53
54 typedef struct ace {
55         uid_t           a_who;          /* uid or gid */
56         uint32_t        a_access_mask;  /* read,write,... */
57         uint16_t        a_flags;        /* see below */
58         uint16_t        a_type;         /* allow or deny */
59 } ace_t;
60
61 /*
62  * The following are Defined types for an aclent_t.
63  */
64 #define USER_OBJ        (0x01)          /* object owner */
65 #define USER            (0x02)          /* additional users */
66 #define GROUP_OBJ       (0x04)          /* owning group of the object */
67 #define GROUP           (0x08)          /* additional groups */
68 #define CLASS_OBJ       (0x10)          /* file group class and mask entry */
69 #define OTHER_OBJ       (0x20)          /* other entry for the object */
70 #define ACL_DEFAULT     (0x1000)        /* default flag */
71 /* default object owner */
72 #define DEF_USER_OBJ    (ACL_DEFAULT | USER_OBJ)
73 /* default additional users */
74 #define DEF_USER        (ACL_DEFAULT | USER)
75 /* default owning group */
76 #define DEF_GROUP_OBJ   (ACL_DEFAULT | GROUP_OBJ)
77 /* default additional groups */
78 #define DEF_GROUP       (ACL_DEFAULT | GROUP)
79 /* default mask entry */
80 #define DEF_CLASS_OBJ   (ACL_DEFAULT | CLASS_OBJ)
81 /* default other entry */
82 #define DEF_OTHER_OBJ   (ACL_DEFAULT | OTHER_OBJ)
83
84 /*
85  * The following are defined for ace_t.
86  */
87 #define ACE_READ_DATA           0x00000001
88 #define ACE_LIST_DIRECTORY      0x00000001
89 #define ACE_WRITE_DATA          0x00000002
90 #define ACE_ADD_FILE            0x00000002
91 #define ACE_APPEND_DATA         0x00000004
92 #define ACE_ADD_SUBDIRECTORY    0x00000004
93 #define ACE_READ_NAMED_ATTRS    0x00000008
94 #define ACE_WRITE_NAMED_ATTRS   0x00000010
95 #define ACE_EXECUTE             0x00000020
96 #define ACE_DELETE_CHILD        0x00000040
97 #define ACE_READ_ATTRIBUTES     0x00000080
98 #define ACE_WRITE_ATTRIBUTES    0x00000100
99 #define ACE_DELETE              0x00010000
100 #define ACE_READ_ACL            0x00020000
101 #define ACE_WRITE_ACL           0x00040000
102 #define ACE_WRITE_OWNER         0x00080000
103 #define ACE_SYNCHRONIZE         0x00100000
104
105 #define ACE_FILE_INHERIT_ACE            0x0001
106 #define ACE_DIRECTORY_INHERIT_ACE       0x0002
107 #define ACE_NO_PROPAGATE_INHERIT_ACE    0x0004
108 #define ACE_INHERIT_ONLY_ACE            0x0008
109 #define ACE_SUCCESSFUL_ACCESS_ACE_FLAG  0x0010
110 #define ACE_FAILED_ACCESS_ACE_FLAG      0x0020
111 #define ACE_IDENTIFIER_GROUP            0x0040
112 #define ACE_INHERITED_ACE               0x0080
113 #define ACE_OWNER                       0x1000
114 #define ACE_GROUP                       0x2000
115 #define ACE_EVERYONE                    0x4000
116
117 #define ACE_ACCESS_ALLOWED_ACE_TYPE     0x0000
118 #define ACE_ACCESS_DENIED_ACE_TYPE      0x0001
119 #define ACE_SYSTEM_AUDIT_ACE_TYPE       0x0002
120 #define ACE_SYSTEM_ALARM_ACE_TYPE       0x0003
121
122 #define ACL_AUTO_INHERIT                0x0001
123 #define ACL_PROTECTED                   0x0002
124 #define ACL_DEFAULTED                   0x0004
125 #define ACL_FLAGS_ALL                   (ACL_AUTO_INHERIT|ACL_PROTECTED| \
126     ACL_DEFAULTED)
127
128 /*
129  * These are only applicable in a CIFS context.
130  */
131 #define ACE_ACCESS_ALLOWED_COMPOUND_ACE_TYPE            0x04
132 #define ACE_ACCESS_ALLOWED_OBJECT_ACE_TYPE              0x05
133 #define ACE_ACCESS_DENIED_OBJECT_ACE_TYPE               0x06
134 #define ACE_SYSTEM_AUDIT_OBJECT_ACE_TYPE                0x07
135 #define ACE_SYSTEM_ALARM_OBJECT_ACE_TYPE                0x08
136 #define ACE_ACCESS_ALLOWED_CALLBACK_ACE_TYPE            0x09
137 #define ACE_ACCESS_DENIED_CALLBACK_ACE_TYPE             0x0A
138 #define ACE_ACCESS_ALLOWED_CALLBACK_OBJECT_ACE_TYPE     0x0B
139 #define ACE_ACCESS_DENIED_CALLBACK_OBJECT_ACE_TYPE      0x0C
140 #define ACE_SYSTEM_AUDIT_CALLBACK_ACE_TYPE              0x0D
141 #define ACE_SYSTEM_ALARM_CALLBACK_ACE_TYPE              0x0E
142 #define ACE_SYSTEM_AUDIT_CALLBACK_OBJECT_ACE_TYPE       0x0F
143 #define ACE_SYSTEM_ALARM_CALLBACK_OBJECT_ACE_TYPE       0x10
144
145 #define ACE_ALL_TYPES   0x001F
146
147 typedef struct ace_object {
148         uid_t           a_who;          /* uid or gid */
149         uint32_t        a_access_mask;  /* read,write,... */
150         uint16_t        a_flags;        /* see below */
151         uint16_t        a_type;         /* allow or deny */
152         uint8_t         a_obj_type[16]; /* obj type */
153         uint8_t         a_inherit_obj_type[16];  /* inherit obj */
154 } ace_object_t;
155
156 #define ACE_ALL_PERMS   (ACE_READ_DATA|ACE_LIST_DIRECTORY|ACE_WRITE_DATA| \
157     ACE_ADD_FILE|ACE_APPEND_DATA|ACE_ADD_SUBDIRECTORY|ACE_READ_NAMED_ATTRS| \
158     ACE_WRITE_NAMED_ATTRS|ACE_EXECUTE|ACE_DELETE_CHILD|ACE_READ_ATTRIBUTES| \
159     ACE_WRITE_ATTRIBUTES|ACE_DELETE|ACE_READ_ACL|ACE_WRITE_ACL| \
160     ACE_WRITE_OWNER|ACE_SYNCHRONIZE)
161
162 #define ACE_ALL_WRITE_PERMS (ACE_WRITE_DATA|ACE_APPEND_DATA| \
163     ACE_WRITE_ATTRIBUTES|ACE_WRITE_NAMED_ATTRS|ACE_WRITE_ACL| \
164     ACE_WRITE_OWNER|ACE_DELETE|ACE_DELETE_CHILD)
165
166 #define ACE_READ_PERMS  (ACE_READ_DATA|ACE_READ_ACL|ACE_READ_ATTRIBUTES| \
167     ACE_READ_NAMED_ATTRS)
168
169 #define ACE_WRITE_PERMS (ACE_WRITE_DATA|ACE_APPEND_DATA|ACE_WRITE_ATTRIBUTES| \
170     ACE_WRITE_NAMED_ATTRS)
171
172 #define ACE_MODIFY_PERMS (ACE_READ_DATA|ACE_LIST_DIRECTORY|ACE_WRITE_DATA| \
173     ACE_ADD_FILE|ACE_APPEND_DATA|ACE_ADD_SUBDIRECTORY|ACE_READ_NAMED_ATTRS| \
174     ACE_WRITE_NAMED_ATTRS|ACE_EXECUTE|ACE_DELETE_CHILD|ACE_READ_ATTRIBUTES| \
175     ACE_WRITE_ATTRIBUTES|ACE_DELETE|ACE_READ_ACL|ACE_SYNCHRONIZE)
176 /*
177  * The following flags are supported by both NFSv4 ACLs and ace_t.
178  */
179 #define ACE_NFSV4_SUP_FLAGS (ACE_FILE_INHERIT_ACE | \
180     ACE_DIRECTORY_INHERIT_ACE | \
181     ACE_NO_PROPAGATE_INHERIT_ACE | \
182     ACE_INHERIT_ONLY_ACE | \
183     ACE_INHERITED_ACE | \
184     ACE_IDENTIFIER_GROUP)
185
186 #define ACE_TYPE_FLAGS          (ACE_OWNER|ACE_GROUP|ACE_EVERYONE| \
187     ACE_IDENTIFIER_GROUP)
188 #define ACE_INHERIT_FLAGS       (ACE_FILE_INHERIT_ACE| ACL_INHERITED_ACE| \
189     ACE_DIRECTORY_INHERIT_ACE|ACE_NO_PROPAGATE_INHERIT_ACE|ACE_INHERIT_ONLY_ACE)
190
191 /* cmd args to acl(2) for aclent_t  */
192 #define GETACL                  1
193 #define SETACL                  2
194 #define GETACLCNT               3
195
196 /* cmd's to manipulate ace acls. */
197 #define ACE_GETACL              4
198 #define ACE_SETACL              5
199 #define ACE_GETACLCNT           6
200
201 /* minimal acl entries from GETACLCNT */
202 #define MIN_ACL_ENTRIES         4
203
204 extern void aces_from_acl(ace_t *aces, int *nentries, const struct acl *aclp);
205 extern int acl_from_aces(struct acl *aclp, const ace_t *aces, int nentries);
206 extern void ksort(caddr_t, int, int, int (*)(void *, void *));
207 extern int cmp2acls(void *, void *);
208
209 extern int acl(const char *path, int cmd, int cnt, void *buf);
210 extern int facl(int fd, int cmd, int cnt, void *buf);
211
212 #ifdef  __cplusplus
213 }
214 #endif
215
216 #endif /* _SYS_ACL_H */