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_ACL_H
27 #define	_SYS_ACL_H
28 
29 #include <sys/types.h>
30 #include <sys/acl_impl.h>
31 
32 #if defined(_KERNEL)
33 /*
34  * When compiling OpenSolaris kernel code, this file is getting
35  * included instead of FreeBSD one.  Pull the original sys/acl.h as well.
36  */
37 #undef _SYS_ACL_H
38 #include_next <sys/acl.h>
39 #define	_SYS_ACL_H
40 #endif	/* _KERNEL */
41 
42 #ifdef	__cplusplus
43 extern "C" {
44 #endif
45 
46 #define	MAX_ACL_ENTRIES		(1024)	/* max entries of each type */
47 typedef struct {
48 	int		a_type;		/* the type of ACL entry */
49 	uid_t		a_id;		/* the entry in -uid or gid */
50 	o_mode_t	a_perm;		/* the permission field */
51 } aclent_t;
52 
53 typedef struct ace {
54 	uid_t		a_who;		/* uid or gid */
55 	uint32_t	a_access_mask;	/* read,write,... */
56 	uint16_t	a_flags;	/* see below */
57 	uint16_t	a_type;		/* allow or deny */
58 } ace_t;
59 
60 #ifndef _KERNEL
61 typedef struct acl_info acl_t;
62 #endif
63 
64 /*
65  * The following are Defined types for an aclent_t.
66  */
67 #define	USER_OBJ	(0x01)		/* object owner */
68 #define	USER		(0x02)		/* additional users */
69 #define	GROUP_OBJ	(0x04)		/* owning group of the object */
70 #define	GROUP		(0x08)		/* additional groups */
71 #define	CLASS_OBJ	(0x10)		/* file group class and mask entry */
72 #define	OTHER_OBJ	(0x20)		/* other entry for the object */
73 #define	ACL_DEFAULT	(0x1000)	/* default flag */
74 /* default object owner */
75 #define	DEF_USER_OBJ	(ACL_DEFAULT | USER_OBJ)
76 /* default additional users */
77 #define	DEF_USER	(ACL_DEFAULT | USER)
78 /* default owning group */
79 #define	DEF_GROUP_OBJ	(ACL_DEFAULT | GROUP_OBJ)
80 /* default additional groups */
81 #define	DEF_GROUP	(ACL_DEFAULT | GROUP)
82 /* default mask entry */
83 #define	DEF_CLASS_OBJ	(ACL_DEFAULT | CLASS_OBJ)
84 /* default other entry */
85 #define	DEF_OTHER_OBJ	(ACL_DEFAULT | OTHER_OBJ)
86 
87 /*
88  * The following are defined for ace_t.
89  */
90 #define	ACE_READ_DATA		0x00000001
91 #define	ACE_LIST_DIRECTORY	0x00000001
92 #define	ACE_WRITE_DATA		0x00000002
93 #define	ACE_ADD_FILE		0x00000002
94 #define	ACE_APPEND_DATA		0x00000004
95 #define	ACE_ADD_SUBDIRECTORY	0x00000004
96 #define	ACE_READ_NAMED_ATTRS	0x00000008
97 #define	ACE_WRITE_NAMED_ATTRS	0x00000010
98 #define	ACE_EXECUTE		0x00000020
99 #define	ACE_DELETE_CHILD	0x00000040
100 #define	ACE_READ_ATTRIBUTES	0x00000080
101 #define	ACE_WRITE_ATTRIBUTES	0x00000100
102 #define	ACE_DELETE		0x00010000
103 #define	ACE_READ_ACL		0x00020000
104 #define	ACE_WRITE_ACL		0x00040000
105 #define	ACE_WRITE_OWNER		0x00080000
106 #define	ACE_SYNCHRONIZE		0x00100000
107 
108 #define	ACE_FILE_INHERIT_ACE		0x0001
109 #define	ACE_DIRECTORY_INHERIT_ACE	0x0002
110 #define	ACE_NO_PROPAGATE_INHERIT_ACE	0x0004
111 #define	ACE_INHERIT_ONLY_ACE		0x0008
112 #define	ACE_SUCCESSFUL_ACCESS_ACE_FLAG	0x0010
113 #define	ACE_FAILED_ACCESS_ACE_FLAG	0x0020
114 #define	ACE_IDENTIFIER_GROUP		0x0040
115 #define	ACE_INHERITED_ACE		0x0080
116 #define	ACE_OWNER			0x1000
117 #define	ACE_GROUP			0x2000
118 #define	ACE_EVERYONE			0x4000
119 
120 #define	ACE_ACCESS_ALLOWED_ACE_TYPE	0x0000
121 #define	ACE_ACCESS_DENIED_ACE_TYPE	0x0001
122 #define	ACE_SYSTEM_AUDIT_ACE_TYPE	0x0002
123 #define	ACE_SYSTEM_ALARM_ACE_TYPE	0x0003
124 
125 #define	ACL_AUTO_INHERIT		0x0001
126 #define	ACL_PROTECTED			0x0002
127 #define	ACL_DEFAULTED			0x0004
128 #define	ACL_FLAGS_ALL			(ACL_AUTO_INHERIT|ACL_PROTECTED| \
129     ACL_DEFAULTED)
130 
131 #ifdef _KERNEL
132 
133 /*
134  * These are only applicable in a CIFS context.
135  */
136 #define	ACE_ACCESS_ALLOWED_COMPOUND_ACE_TYPE		0x04
137 #define	ACE_ACCESS_ALLOWED_OBJECT_ACE_TYPE		0x05
138 #define	ACE_ACCESS_DENIED_OBJECT_ACE_TYPE		0x06
139 #define	ACE_SYSTEM_AUDIT_OBJECT_ACE_TYPE		0x07
140 #define	ACE_SYSTEM_ALARM_OBJECT_ACE_TYPE		0x08
141 #define	ACE_ACCESS_ALLOWED_CALLBACK_ACE_TYPE		0x09
142 #define	ACE_ACCESS_DENIED_CALLBACK_ACE_TYPE		0x0A
143 #define	ACE_ACCESS_ALLOWED_CALLBACK_OBJECT_ACE_TYPE	0x0B
144 #define	ACE_ACCESS_DENIED_CALLBACK_OBJECT_ACE_TYPE	0x0C
145 #define	ACE_SYSTEM_AUDIT_CALLBACK_ACE_TYPE		0x0D
146 #define	ACE_SYSTEM_ALARM_CALLBACK_ACE_TYPE		0x0E
147 #define	ACE_SYSTEM_AUDIT_CALLBACK_OBJECT_ACE_TYPE	0x0F
148 #define	ACE_SYSTEM_ALARM_CALLBACK_OBJECT_ACE_TYPE	0x10
149 
150 #define	ACE_ALL_TYPES	0x001F
151 
152 typedef struct ace_object {
153 	uid_t		a_who;		/* uid or gid */
154 	uint32_t	a_access_mask;	/* read,write,... */
155 	uint16_t	a_flags;	/* see below */
156 	uint16_t	a_type;		/* allow or deny */
157 	uint8_t		a_obj_type[16];	/* obj type */
158 	uint8_t		a_inherit_obj_type[16];  /* inherit obj */
159 } ace_object_t;
160 
161 #endif
162 
163 #define	ACE_ALL_PERMS	(ACE_READ_DATA|ACE_LIST_DIRECTORY|ACE_WRITE_DATA| \
164     ACE_ADD_FILE|ACE_APPEND_DATA|ACE_ADD_SUBDIRECTORY|ACE_READ_NAMED_ATTRS| \
165     ACE_WRITE_NAMED_ATTRS|ACE_EXECUTE|ACE_DELETE_CHILD|ACE_READ_ATTRIBUTES| \
166     ACE_WRITE_ATTRIBUTES|ACE_DELETE|ACE_READ_ACL|ACE_WRITE_ACL| \
167     ACE_WRITE_OWNER|ACE_SYNCHRONIZE)
168 
169 #define	ACE_ALL_WRITE_PERMS (ACE_WRITE_DATA|ACE_APPEND_DATA| \
170     ACE_WRITE_ATTRIBUTES|ACE_WRITE_NAMED_ATTRS|ACE_WRITE_ACL| \
171     ACE_WRITE_OWNER|ACE_DELETE|ACE_DELETE_CHILD)
172 
173 #define	ACE_READ_PERMS	(ACE_READ_DATA|ACE_READ_ACL|ACE_READ_ATTRIBUTES| \
174     ACE_READ_NAMED_ATTRS)
175 
176 #define	ACE_WRITE_PERMS	(ACE_WRITE_DATA|ACE_APPEND_DATA|ACE_WRITE_ATTRIBUTES| \
177     ACE_WRITE_NAMED_ATTRS)
178 
179 #define	ACE_MODIFY_PERMS (ACE_READ_DATA|ACE_LIST_DIRECTORY|ACE_WRITE_DATA| \
180     ACE_ADD_FILE|ACE_APPEND_DATA|ACE_ADD_SUBDIRECTORY|ACE_READ_NAMED_ATTRS| \
181     ACE_WRITE_NAMED_ATTRS|ACE_EXECUTE|ACE_DELETE_CHILD|ACE_READ_ATTRIBUTES| \
182     ACE_WRITE_ATTRIBUTES|ACE_DELETE|ACE_READ_ACL|ACE_SYNCHRONIZE)
183 /*
184  * The following flags are supported by both NFSv4 ACLs and ace_t.
185  */
186 #define	ACE_NFSV4_SUP_FLAGS (ACE_FILE_INHERIT_ACE | \
187     ACE_DIRECTORY_INHERIT_ACE | \
188     ACE_NO_PROPAGATE_INHERIT_ACE | \
189     ACE_INHERIT_ONLY_ACE | \
190     ACE_IDENTIFIER_GROUP)
191 
192 #define	ACE_TYPE_FLAGS		(ACE_OWNER|ACE_GROUP|ACE_EVERYONE| \
193     ACE_IDENTIFIER_GROUP)
194 #define	ACE_INHERIT_FLAGS	(ACE_FILE_INHERIT_ACE| \
195     ACE_DIRECTORY_INHERIT_ACE|ACE_NO_PROPAGATE_INHERIT_ACE|ACE_INHERIT_ONLY_ACE)
196 
197 /* cmd args to acl(2) for aclent_t  */
198 #define	GETACL			1
199 #define	SETACL			2
200 #define	GETACLCNT		3
201 
202 /* cmd's to manipulate ace acls. */
203 #define	ACE_GETACL		4
204 #define	ACE_SETACL		5
205 #define	ACE_GETACLCNT		6
206 
207 /* minimal acl entries from GETACLCNT */
208 #define	MIN_ACL_ENTRIES		4
209 
210 #if !defined(_KERNEL)
211 
212 /* acl check errors */
213 #define	GRP_ERROR		1
214 #define	USER_ERROR		2
215 #define	OTHER_ERROR		3
216 #define	CLASS_ERROR		4
217 #define	DUPLICATE_ERROR		5
218 #define	MISS_ERROR		6
219 #define	MEM_ERROR		7
220 #define	ENTRY_ERROR		8
221 
222 
223 /*
224  * similar to ufs_acl.h: changed to char type for user commands (tar, cpio)
225  * Attribute types
226  */
227 #define	UFSD_FREE	('0')	/* Free entry */
228 #define	UFSD_ACL	('1')	/* Access Control Lists */
229 #define	UFSD_DFACL	('2')	/* reserved for future use */
230 #define	ACE_ACL		('3')	/* ace_t style acls */
231 
232 /*
233  * flag to [f]acl_get()
234  * controls whether a trivial acl should be returned.
235  */
236 #define	ACL_NO_TRIVIAL	0x2
237 
238 
239 /*
240  * Flags to control acl_totext()
241  */
242 
243 #define	ACL_APPEND_ID	0x1 	/* append uid/gid to user/group entries */
244 #define	ACL_COMPACT_FMT	0x2 	/* build ACL in ls -V format */
245 #define	ACL_NORESOLVE	0x4	/* don't do name service lookups */
246 #define	ACL_SID_FMT	0x8	/* use usersid/groupsid when appropriate */
247 
248 /*
249  * Legacy aclcheck errors for aclent_t ACLs
250  */
251 #define	EACL_GRP_ERROR		GRP_ERROR
252 #define	EACL_USER_ERROR		USER_ERROR
253 #define	EACL_OTHER_ERROR	OTHER_ERROR
254 #define	EACL_CLASS_ERROR	CLASS_ERROR
255 #define	EACL_DUPLICATE_ERROR	DUPLICATE_ERROR
256 #define	EACL_MISS_ERROR		MISS_ERROR
257 #define	EACL_MEM_ERROR		MEM_ERROR
258 #define	EACL_ENTRY_ERROR	ENTRY_ERROR
259 
260 #define	EACL_INHERIT_ERROR	9		/* invalid inherit flags */
261 #define	EACL_FLAGS_ERROR	10		/* unknown flag value */
262 #define	EACL_PERM_MASK_ERROR	11		/* unknown permission */
263 #define	EACL_COUNT_ERROR	12		/* invalid acl count */
264 
265 #define	EACL_INVALID_SLOT	13		/* invalid acl slot */
266 #define	EACL_NO_ACL_ENTRY	14		/* Entry doesn't exist */
267 #define	EACL_DIFF_TYPE		15		/* acls aren't same type */
268 
269 #define	EACL_INVALID_USER_GROUP	16		/* need user/group name */
270 #define	EACL_INVALID_STR	17		/* invalid acl string */
271 #define	EACL_FIELD_NOT_BLANK	18		/* can't have blank field */
272 #define	EACL_INVALID_ACCESS_TYPE 19		/* invalid access type */
273 #define	EACL_UNKNOWN_DATA	20		/* Unrecognized data in ACL */
274 #define	EACL_MISSING_FIELDS	21		/* missing fields in acl */
275 
276 #define	EACL_INHERIT_NOTDIR	22		/* Need dir for inheritance */
277 
278 extern int aclcheck(aclent_t *, int, int *);
279 extern int acltomode(aclent_t *, int, mode_t *);
280 extern int aclfrommode(aclent_t *, int, mode_t *);
281 extern int aclsort(int, int, aclent_t *);
282 extern char *acltotext(aclent_t *, int);
283 extern aclent_t *aclfromtext(char *, int *);
284 extern void acl_free(acl_t *);
285 extern int acl_get(const char *, int, acl_t **);
286 extern int facl_get(int, int, acl_t **);
287 extern int acl_set(const char *, acl_t *acl);
288 extern int facl_set(int, acl_t *acl);
289 extern int acl_strip(const char *, uid_t, gid_t, mode_t);
290 extern int acl_trivial(const char *);
291 extern char *acl_totext(acl_t *, int);
292 extern int acl_fromtext(const char *, acl_t **);
293 extern int acl_check(acl_t *, int);
294 
295 #else	/* !defined(_KERNEL) */
296 
297 extern void ksort(caddr_t, int, int, int (*)(void *, void *));
298 extern int cmp2acls(void *, void *);
299 
300 #endif	/* !defined(_KERNEL) */
301 
302 #if defined(__STDC__)
303 extern int acl(const char *path, int cmd, int cnt, void *buf);
304 extern int facl(int fd, int cmd, int cnt, void *buf);
305 #else	/* !__STDC__ */
306 extern int acl();
307 extern int facl();
308 #endif	/* defined(__STDC__) */
309 
310 #ifdef	__cplusplus
311 }
312 #endif
313 
314 #endif /* _SYS_ACL_H */
315