xref: /onnv-gate/usr/src/uts/common/sys/acl.h (revision 7057:d3fa1d6dbef7)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
51507Sgjelinek  * Common Development and Distribution License (the "License").
61507Sgjelinek  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
210Sstevel@tonic-gate /*
22*7057Smarks  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
230Sstevel@tonic-gate  * Use is subject to license terms.
240Sstevel@tonic-gate  */
250Sstevel@tonic-gate 
260Sstevel@tonic-gate #ifndef _SYS_ACL_H
270Sstevel@tonic-gate #define	_SYS_ACL_H
280Sstevel@tonic-gate 
290Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
300Sstevel@tonic-gate 
310Sstevel@tonic-gate #include <sys/types.h>
325331Samw #include <sys/acl_impl.h>
330Sstevel@tonic-gate 
340Sstevel@tonic-gate #ifdef	__cplusplus
350Sstevel@tonic-gate extern "C" {
360Sstevel@tonic-gate #endif
370Sstevel@tonic-gate 
380Sstevel@tonic-gate #define	MAX_ACL_ENTRIES		(1024)	/* max entries of each type */
390Sstevel@tonic-gate typedef struct acl {
400Sstevel@tonic-gate 	int		a_type;		/* the type of ACL entry */
410Sstevel@tonic-gate 	uid_t		a_id;		/* the entry in -uid or gid */
420Sstevel@tonic-gate 	o_mode_t	a_perm;		/* the permission field */
430Sstevel@tonic-gate } aclent_t;
440Sstevel@tonic-gate 
450Sstevel@tonic-gate typedef struct ace {
460Sstevel@tonic-gate 	uid_t		a_who;		/* uid or gid */
47789Sahrens 	uint32_t	a_access_mask;	/* read,write,... */
480Sstevel@tonic-gate 	uint16_t	a_flags;	/* see below */
490Sstevel@tonic-gate 	uint16_t	a_type;		/* allow or deny */
500Sstevel@tonic-gate } ace_t;
510Sstevel@tonic-gate 
52789Sahrens typedef struct acl_info acl_t;
53789Sahrens 
540Sstevel@tonic-gate /*
550Sstevel@tonic-gate  * The following are Defined types for an aclent_t.
560Sstevel@tonic-gate  */
570Sstevel@tonic-gate #define	USER_OBJ	(0x01)		/* object owner */
580Sstevel@tonic-gate #define	USER		(0x02)		/* additional users */
590Sstevel@tonic-gate #define	GROUP_OBJ	(0x04)		/* owning group of the object */
600Sstevel@tonic-gate #define	GROUP		(0x08)		/* additional groups */
610Sstevel@tonic-gate #define	CLASS_OBJ	(0x10)		/* file group class and mask entry */
620Sstevel@tonic-gate #define	OTHER_OBJ	(0x20)		/* other entry for the object */
630Sstevel@tonic-gate #define	ACL_DEFAULT	(0x1000)	/* default flag */
640Sstevel@tonic-gate /* default object owner */
650Sstevel@tonic-gate #define	DEF_USER_OBJ	(ACL_DEFAULT | USER_OBJ)
665331Samw /* default additional users */
670Sstevel@tonic-gate #define	DEF_USER	(ACL_DEFAULT | USER)
680Sstevel@tonic-gate /* default owning group */
690Sstevel@tonic-gate #define	DEF_GROUP_OBJ	(ACL_DEFAULT | GROUP_OBJ)
700Sstevel@tonic-gate /* default additional groups */
710Sstevel@tonic-gate #define	DEF_GROUP	(ACL_DEFAULT | GROUP)
720Sstevel@tonic-gate /* default mask entry */
730Sstevel@tonic-gate #define	DEF_CLASS_OBJ	(ACL_DEFAULT | CLASS_OBJ)
740Sstevel@tonic-gate /* default other entry */
750Sstevel@tonic-gate #define	DEF_OTHER_OBJ	(ACL_DEFAULT | OTHER_OBJ)
760Sstevel@tonic-gate 
770Sstevel@tonic-gate /*
780Sstevel@tonic-gate  * The following are defined for ace_t.
790Sstevel@tonic-gate  */
80789Sahrens #define	ACE_READ_DATA		0x00000001
81789Sahrens #define	ACE_LIST_DIRECTORY	0x00000001
82789Sahrens #define	ACE_WRITE_DATA		0x00000002
83789Sahrens #define	ACE_ADD_FILE		0x00000002
84789Sahrens #define	ACE_APPEND_DATA		0x00000004
85789Sahrens #define	ACE_ADD_SUBDIRECTORY	0x00000004
86789Sahrens #define	ACE_READ_NAMED_ATTRS	0x00000008
87789Sahrens #define	ACE_WRITE_NAMED_ATTRS	0x00000010
88789Sahrens #define	ACE_EXECUTE		0x00000020
89789Sahrens #define	ACE_DELETE_CHILD	0x00000040
90789Sahrens #define	ACE_READ_ATTRIBUTES	0x00000080
91789Sahrens #define	ACE_WRITE_ATTRIBUTES	0x00000100
92789Sahrens #define	ACE_DELETE		0x00010000
93789Sahrens #define	ACE_READ_ACL		0x00020000
94789Sahrens #define	ACE_WRITE_ACL		0x00040000
95789Sahrens #define	ACE_WRITE_OWNER		0x00080000
96789Sahrens #define	ACE_SYNCHRONIZE		0x00100000
97789Sahrens 
980Sstevel@tonic-gate #define	ACE_FILE_INHERIT_ACE		0x0001
990Sstevel@tonic-gate #define	ACE_DIRECTORY_INHERIT_ACE	0x0002
100789Sahrens #define	ACE_NO_PROPAGATE_INHERIT_ACE	0x0004
1010Sstevel@tonic-gate #define	ACE_INHERIT_ONLY_ACE		0x0008
102789Sahrens #define	ACE_SUCCESSFUL_ACCESS_ACE_FLAG	0x0010
103789Sahrens #define	ACE_FAILED_ACCESS_ACE_FLAG	0x0020
104789Sahrens #define	ACE_IDENTIFIER_GROUP		0x0040
1055331Samw #define	ACE_INHERITED_ACE		0x0080
106789Sahrens #define	ACE_OWNER			0x1000
107789Sahrens #define	ACE_GROUP			0x2000
108789Sahrens #define	ACE_EVERYONE			0x4000
109789Sahrens 
110789Sahrens #define	ACE_ACCESS_ALLOWED_ACE_TYPE	0x0000
111789Sahrens #define	ACE_ACCESS_DENIED_ACE_TYPE	0x0001
112789Sahrens #define	ACE_SYSTEM_AUDIT_ACE_TYPE	0x0002
113789Sahrens #define	ACE_SYSTEM_ALARM_ACE_TYPE	0x0003
114789Sahrens 
1155331Samw #define	ACL_AUTO_INHERIT		0x0001
1165331Samw #define	ACL_PROTECTED			0x0002
1175331Samw #define	ACL_DEFAULTED			0x0004
1185331Samw #define	ACL_FLAGS_ALL			(ACL_AUTO_INHERIT|ACL_PROTECTED| \
1195331Samw     ACL_DEFAULTED)
1205331Samw 
1215331Samw #ifdef _KERNEL
1225331Samw 
1235331Samw /*
1245331Samw  * These are only applicable in a CIFS context.
1255331Samw  */
1265331Samw #define	ACE_ACCESS_ALLOWED_COMPOUND_ACE_TYPE		0x04
1275331Samw #define	ACE_ACCESS_ALLOWED_OBJECT_ACE_TYPE		0x05
1285331Samw #define	ACE_ACCESS_DENIED_OBJECT_ACE_TYPE		0x06
1295331Samw #define	ACE_SYSTEM_AUDIT_OBJECT_ACE_TYPE		0x07
1305331Samw #define	ACE_SYSTEM_ALARM_OBJECT_ACE_TYPE		0x08
1315331Samw #define	ACE_ACCESS_ALLOWED_CALLBACK_ACE_TYPE		0x09
1325331Samw #define	ACE_ACCESS_DENIED_CALLBACK_ACE_TYPE		0x0A
1335331Samw #define	ACE_ACCESS_ALLOWED_CALLBACK_OBJECT_ACE_TYPE	0x0B
1345331Samw #define	ACE_ACCESS_DENIED_CALLBACK_OBJECT_ACE_TYPE	0x0C
1355331Samw #define	ACE_SYSTEM_AUDIT_CALLBACK_ACE_TYPE		0x0D
1365331Samw #define	ACE_SYSTEM_ALARM_CALLBACK_ACE_TYPE		0x0E
1375331Samw #define	ACE_SYSTEM_AUDIT_CALLBACK_OBJECT_ACE_TYPE	0x0F
1385331Samw #define	ACE_SYSTEM_ALARM_CALLBACK_OBJECT_ACE_TYPE	0x10
1395331Samw 
1405331Samw #define	ACE_ALL_TYPES	0x001F
1415331Samw 
1425331Samw typedef struct ace_object {
1435331Samw 	uid_t		a_who;		/* uid or gid */
1445331Samw 	uint32_t	a_access_mask;	/* read,write,... */
1455331Samw 	uint16_t	a_flags;	/* see below */
1465331Samw 	uint16_t	a_type;		/* allow or deny */
1475331Samw 	uint8_t		a_obj_type[16];	/* obj type */
1485331Samw 	uint8_t		a_inherit_obj_type[16];  /* inherit obj */
1495331Samw } ace_object_t;
1505331Samw 
1515331Samw #endif
1525331Samw 
153789Sahrens #define	ACE_ALL_PERMS	(ACE_READ_DATA|ACE_LIST_DIRECTORY|ACE_WRITE_DATA| \
154789Sahrens     ACE_ADD_FILE|ACE_APPEND_DATA|ACE_ADD_SUBDIRECTORY|ACE_READ_NAMED_ATTRS| \
155789Sahrens     ACE_WRITE_NAMED_ATTRS|ACE_EXECUTE|ACE_DELETE_CHILD|ACE_READ_ATTRIBUTES| \
156789Sahrens     ACE_WRITE_ATTRIBUTES|ACE_DELETE|ACE_READ_ACL|ACE_WRITE_ACL| \
157789Sahrens     ACE_WRITE_OWNER|ACE_SYNCHRONIZE)
158789Sahrens 
159*7057Smarks #define	ACE_READ_PERMS	(ACE_READ_DATA|ACE_READ_ACL|ACE_READ_ATTRIBUTES| \
160*7057Smarks     ACE_READ_NAMED_ATTRS)
161*7057Smarks 
162*7057Smarks #define	ACE_WRITE_PERMS	(ACE_WRITE_DATA|ACE_APPEND_DATA|ACE_WRITE_ATTRIBUTES| \
163*7057Smarks     ACE_WRITE_NAMED_ATTRS)
164*7057Smarks 
165*7057Smarks #define	ACE_MODIFY_PERMS (ACE_READ_DATA|ACE_LIST_DIRECTORY|ACE_WRITE_DATA| \
166*7057Smarks     ACE_ADD_FILE|ACE_APPEND_DATA|ACE_ADD_SUBDIRECTORY|ACE_READ_NAMED_ATTRS| \
167*7057Smarks     ACE_WRITE_NAMED_ATTRS|ACE_EXECUTE|ACE_DELETE_CHILD|ACE_READ_ATTRIBUTES| \
168*7057Smarks     ACE_WRITE_ATTRIBUTES|ACE_DELETE|ACE_READ_ACL|ACE_SYNCHRONIZE)
1690Sstevel@tonic-gate /*
1700Sstevel@tonic-gate  * The following flags are supported by both NFSv4 ACLs and ace_t.
1710Sstevel@tonic-gate  */
1720Sstevel@tonic-gate #define	ACE_NFSV4_SUP_FLAGS (ACE_FILE_INHERIT_ACE | \
1730Sstevel@tonic-gate     ACE_DIRECTORY_INHERIT_ACE | \
174789Sahrens     ACE_NO_PROPAGATE_INHERIT_ACE | \
175789Sahrens     ACE_INHERIT_ONLY_ACE | \
176789Sahrens     ACE_IDENTIFIER_GROUP)
1770Sstevel@tonic-gate 
1785331Samw #define	ACE_TYPE_FLAGS		(ACE_OWNER|ACE_GROUP|ACE_EVERYONE| \
1795331Samw     ACE_IDENTIFIER_GROUP)
1805331Samw #define	ACE_INHERIT_FLAGS	(ACE_FILE_INHERIT_ACE| \
1815331Samw     ACE_DIRECTORY_INHERIT_ACE|ACE_NO_PROPAGATE_INHERIT_ACE|ACE_INHERIT_ONLY_ACE)
1821420Smarks 
1830Sstevel@tonic-gate /* cmd args to acl(2) for aclent_t  */
1840Sstevel@tonic-gate #define	GETACL			1
1850Sstevel@tonic-gate #define	SETACL			2
1860Sstevel@tonic-gate #define	GETACLCNT		3
1870Sstevel@tonic-gate 
188789Sahrens /* cmd's to manipulate ace acls. */
1890Sstevel@tonic-gate #define	ACE_GETACL		4
1900Sstevel@tonic-gate #define	ACE_SETACL		5
1910Sstevel@tonic-gate #define	ACE_GETACLCNT		6
1920Sstevel@tonic-gate 
1930Sstevel@tonic-gate /* minimal acl entries from GETACLCNT */
1940Sstevel@tonic-gate #define	MIN_ACL_ENTRIES		4
1950Sstevel@tonic-gate 
1960Sstevel@tonic-gate #if !defined(_KERNEL)
1970Sstevel@tonic-gate 
1980Sstevel@tonic-gate /* acl check errors */
1990Sstevel@tonic-gate #define	GRP_ERROR		1
2000Sstevel@tonic-gate #define	USER_ERROR		2
2010Sstevel@tonic-gate #define	OTHER_ERROR		3
2020Sstevel@tonic-gate #define	CLASS_ERROR		4
2030Sstevel@tonic-gate #define	DUPLICATE_ERROR		5
2040Sstevel@tonic-gate #define	MISS_ERROR		6
2050Sstevel@tonic-gate #define	MEM_ERROR		7
2060Sstevel@tonic-gate #define	ENTRY_ERROR		8
2070Sstevel@tonic-gate 
208789Sahrens 
2090Sstevel@tonic-gate /*
2100Sstevel@tonic-gate  * similar to ufs_acl.h: changed to char type for user commands (tar, cpio)
2110Sstevel@tonic-gate  * Attribute types
2120Sstevel@tonic-gate  */
2130Sstevel@tonic-gate #define	UFSD_FREE	('0')	/* Free entry */
2140Sstevel@tonic-gate #define	UFSD_ACL	('1')	/* Access Control Lists */
2150Sstevel@tonic-gate #define	UFSD_DFACL	('2')	/* reserved for future use */
216789Sahrens #define	ACE_ACL		('3')	/* ace_t style acls */
217789Sahrens 
218789Sahrens /*
219789Sahrens  * flag to [f]acl_get()
220789Sahrens  * controls whether a trivial acl should be returned.
221789Sahrens  */
222789Sahrens #define	ACL_NO_TRIVIAL	0x2
223789Sahrens 
2241420Smarks 
2251420Smarks /*
2261420Smarks  * Flags to control acl_totext()
2271420Smarks  */
2281420Smarks 
2291420Smarks #define	ACL_APPEND_ID	0x1 	/* append uid/gid to user/group entries */
2301420Smarks #define	ACL_COMPACT_FMT	0x2 	/* build ACL in ls -V format */
2311507Sgjelinek #define	ACL_NORESOLVE	0x4	/* don't do name service lookups */
232*7057Smarks #define	ACL_SID_FMT	0x8	/* use usersid/groupsid when appropriate */
2331420Smarks 
234789Sahrens /*
235789Sahrens  * Legacy aclcheck errors for aclent_t ACLs
236789Sahrens  */
237789Sahrens #define	EACL_GRP_ERROR		GRP_ERROR
238789Sahrens #define	EACL_USER_ERROR		USER_ERROR
239789Sahrens #define	EACL_OTHER_ERROR	OTHER_ERROR
240789Sahrens #define	EACL_CLASS_ERROR	CLASS_ERROR
241789Sahrens #define	EACL_DUPLICATE_ERROR	DUPLICATE_ERROR
242789Sahrens #define	EACL_MISS_ERROR		MISS_ERROR
243789Sahrens #define	EACL_MEM_ERROR		MEM_ERROR
244789Sahrens #define	EACL_ENTRY_ERROR	ENTRY_ERROR
245789Sahrens 
246789Sahrens #define	EACL_INHERIT_ERROR	9		/* invalid inherit flags */
247789Sahrens #define	EACL_FLAGS_ERROR	10		/* unknown flag value */
248789Sahrens #define	EACL_PERM_MASK_ERROR	11		/* unknown permission */
249789Sahrens #define	EACL_COUNT_ERROR	12		/* invalid acl count */
250789Sahrens 
251789Sahrens #define	EACL_INVALID_SLOT	13		/* invalid acl slot */
252789Sahrens #define	EACL_NO_ACL_ENTRY	14		/* Entry doesn't exist */
253789Sahrens #define	EACL_DIFF_TYPE		15		/* acls aren't same type */
254789Sahrens 
255789Sahrens #define	EACL_INVALID_USER_GROUP	16		/* need user/group name */
256789Sahrens #define	EACL_INVALID_STR	17		/* invalid acl string */
257789Sahrens #define	EACL_FIELD_NOT_BLANK	18		/* can't have blank field */
258789Sahrens #define	EACL_INVALID_ACCESS_TYPE 19		/* invalid access type */
259789Sahrens #define	EACL_UNKNOWN_DATA	20		/* Unrecognized data in ACL */
260789Sahrens #define	EACL_MISSING_FIELDS	21		/* missing fields in acl */
261789Sahrens 
262789Sahrens #define	EACL_INHERIT_NOTDIR	22		/* Need dir for inheritance */
2630Sstevel@tonic-gate 
2640Sstevel@tonic-gate extern int aclcheck(aclent_t *, int, int *);
2650Sstevel@tonic-gate extern int acltomode(aclent_t *, int, mode_t *);
2660Sstevel@tonic-gate extern int aclfrommode(aclent_t *, int, mode_t *);
2670Sstevel@tonic-gate extern int aclsort(int, int, aclent_t *);
2680Sstevel@tonic-gate extern char *acltotext(aclent_t *, int);
2690Sstevel@tonic-gate extern aclent_t *aclfromtext(char *, int *);
270789Sahrens extern void acl_free(acl_t *);
271789Sahrens extern int acl_get(const char *, int, acl_t **);
272789Sahrens extern int facl_get(int, int, acl_t **);
273789Sahrens extern int acl_set(const char *, acl_t *acl);
274789Sahrens extern int facl_set(int, acl_t *acl);
275789Sahrens extern int acl_strip(const char *, uid_t, gid_t, mode_t);
276789Sahrens extern int acl_trivial(const char *);
2771420Smarks extern char *acl_totext(acl_t *, int);
278789Sahrens extern int acl_fromtext(const char *, acl_t **);
279789Sahrens extern int acl_check(acl_t *, int);
2800Sstevel@tonic-gate 
2810Sstevel@tonic-gate #else	/* !defined(_KERNEL) */
2820Sstevel@tonic-gate 
2830Sstevel@tonic-gate extern void ksort(caddr_t, int, int, int (*)(void *, void *));
2840Sstevel@tonic-gate extern int cmp2acls(void *, void *);
2850Sstevel@tonic-gate 
2860Sstevel@tonic-gate #endif	/* !defined(_KERNEL) */
2870Sstevel@tonic-gate 
2880Sstevel@tonic-gate #if defined(__STDC__)
2890Sstevel@tonic-gate extern int acl(const char *path, int cmd, int cnt, void *buf);
2900Sstevel@tonic-gate extern int facl(int fd, int cmd, int cnt, void *buf);
2910Sstevel@tonic-gate #else	/* !__STDC__ */
2920Sstevel@tonic-gate extern int acl();
2930Sstevel@tonic-gate extern int facl();
2940Sstevel@tonic-gate #endif	/* defined(__STDC__) */
2950Sstevel@tonic-gate 
2960Sstevel@tonic-gate #ifdef	__cplusplus
2970Sstevel@tonic-gate }
2980Sstevel@tonic-gate #endif
2990Sstevel@tonic-gate 
3000Sstevel@tonic-gate #endif /* _SYS_ACL_H */
301