xref: /titanic_51/usr/src/uts/common/sys/acl.h (revision fe0e7ec4d916b05b52d8c7cc8a3e6a1b28e77b6f)
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, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef _SYS_ACL_H
28 #define	_SYS_ACL_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #include <sys/types.h>
33 
34 #ifdef	__cplusplus
35 extern "C" {
36 #endif
37 
38 #define	MAX_ACL_ENTRIES		(1024)	/* max entries of each type */
39 typedef struct acl {
40 	int		a_type;		/* the type of ACL entry */
41 	uid_t		a_id;		/* the entry in -uid or gid */
42 	o_mode_t	a_perm;		/* the permission field */
43 } aclent_t;
44 
45 typedef struct ace {
46 	uid_t		a_who;		/* uid or gid */
47 	uint32_t	a_access_mask;	/* read,write,... */
48 	uint16_t	a_flags;	/* see below */
49 	uint16_t	a_type;		/* allow or deny */
50 } ace_t;
51 
52 typedef struct acl_info acl_t;
53 
54 /*
55  * The following are Defined types for an aclent_t.
56  */
57 #define	USER_OBJ	(0x01)		/* object owner */
58 #define	USER		(0x02)		/* additional users */
59 #define	GROUP_OBJ	(0x04)		/* owning group of the object */
60 #define	GROUP		(0x08)		/* additional groups */
61 #define	CLASS_OBJ	(0x10)		/* file group class and mask entry */
62 #define	OTHER_OBJ	(0x20)		/* other entry for the object */
63 #define	ACL_DEFAULT	(0x1000)	/* default flag */
64 /* default object owner */
65 #define	DEF_USER_OBJ	(ACL_DEFAULT | USER_OBJ)
66 /* defalut additional users */
67 #define	DEF_USER	(ACL_DEFAULT | USER)
68 /* default owning group */
69 #define	DEF_GROUP_OBJ	(ACL_DEFAULT | GROUP_OBJ)
70 /* default additional groups */
71 #define	DEF_GROUP	(ACL_DEFAULT | GROUP)
72 /* default mask entry */
73 #define	DEF_CLASS_OBJ	(ACL_DEFAULT | CLASS_OBJ)
74 /* default other entry */
75 #define	DEF_OTHER_OBJ	(ACL_DEFAULT | OTHER_OBJ)
76 
77 /*
78  * The following are defined for ace_t.
79  */
80 #define	ACE_READ_DATA		0x00000001
81 #define	ACE_LIST_DIRECTORY	0x00000001
82 #define	ACE_WRITE_DATA		0x00000002
83 #define	ACE_ADD_FILE		0x00000002
84 #define	ACE_APPEND_DATA		0x00000004
85 #define	ACE_ADD_SUBDIRECTORY	0x00000004
86 #define	ACE_READ_NAMED_ATTRS	0x00000008
87 #define	ACE_WRITE_NAMED_ATTRS	0x00000010
88 #define	ACE_EXECUTE		0x00000020
89 #define	ACE_DELETE_CHILD	0x00000040
90 #define	ACE_READ_ATTRIBUTES	0x00000080
91 #define	ACE_WRITE_ATTRIBUTES	0x00000100
92 #define	ACE_DELETE		0x00010000
93 #define	ACE_READ_ACL		0x00020000
94 #define	ACE_WRITE_ACL		0x00040000
95 #define	ACE_WRITE_OWNER		0x00080000
96 #define	ACE_SYNCHRONIZE		0x00100000
97 
98 #define	ACE_FILE_INHERIT_ACE		0x0001
99 #define	ACE_DIRECTORY_INHERIT_ACE	0x0002
100 #define	ACE_NO_PROPAGATE_INHERIT_ACE	0x0004
101 #define	ACE_INHERIT_ONLY_ACE		0x0008
102 #define	ACE_SUCCESSFUL_ACCESS_ACE_FLAG	0x0010
103 #define	ACE_FAILED_ACCESS_ACE_FLAG	0x0020
104 #define	ACE_IDENTIFIER_GROUP		0x0040
105 #define	ACE_OWNER			0x1000
106 #define	ACE_GROUP			0x2000
107 #define	ACE_EVERYONE			0x4000
108 
109 #define	ACE_ACCESS_ALLOWED_ACE_TYPE	0x0000
110 #define	ACE_ACCESS_DENIED_ACE_TYPE	0x0001
111 #define	ACE_SYSTEM_AUDIT_ACE_TYPE	0x0002
112 #define	ACE_SYSTEM_ALARM_ACE_TYPE	0x0003
113 
114 #define	ACE_ALL_PERMS	(ACE_READ_DATA|ACE_LIST_DIRECTORY|ACE_WRITE_DATA| \
115     ACE_ADD_FILE|ACE_APPEND_DATA|ACE_ADD_SUBDIRECTORY|ACE_READ_NAMED_ATTRS| \
116     ACE_WRITE_NAMED_ATTRS|ACE_EXECUTE|ACE_DELETE_CHILD|ACE_READ_ATTRIBUTES| \
117     ACE_WRITE_ATTRIBUTES|ACE_DELETE|ACE_READ_ACL|ACE_WRITE_ACL| \
118     ACE_WRITE_OWNER|ACE_SYNCHRONIZE)
119 
120 /*
121  * The following flags are supported by both NFSv4 ACLs and ace_t.
122  */
123 #define	ACE_NFSV4_SUP_FLAGS (ACE_FILE_INHERIT_ACE | \
124     ACE_DIRECTORY_INHERIT_ACE | \
125     ACE_NO_PROPAGATE_INHERIT_ACE | \
126     ACE_INHERIT_ONLY_ACE | \
127     ACE_IDENTIFIER_GROUP)
128 
129 /* cmd args to acl(2) for aclent_t  */
130 #define	GETACL			1
131 #define	SETACL			2
132 #define	GETACLCNT		3
133 
134 /* cmd's to manipulate ace acls. */
135 #define	ACE_GETACL		4
136 #define	ACE_SETACL		5
137 #define	ACE_GETACLCNT		6
138 
139 /* minimal acl entries from GETACLCNT */
140 #define	MIN_ACL_ENTRIES		4
141 
142 #if !defined(_KERNEL)
143 
144 /* acl check errors */
145 #define	GRP_ERROR		1
146 #define	USER_ERROR		2
147 #define	OTHER_ERROR		3
148 #define	CLASS_ERROR		4
149 #define	DUPLICATE_ERROR		5
150 #define	MISS_ERROR		6
151 #define	MEM_ERROR		7
152 #define	ENTRY_ERROR		8
153 
154 
155 /*
156  * similar to ufs_acl.h: changed to char type for user commands (tar, cpio)
157  * Attribute types
158  */
159 #define	UFSD_FREE	('0')	/* Free entry */
160 #define	UFSD_ACL	('1')	/* Access Control Lists */
161 #define	UFSD_DFACL	('2')	/* reserved for future use */
162 #define	ACE_ACL		('3')	/* ace_t style acls */
163 
164 /*
165  * flag to [f]acl_get()
166  * controls whether a trivial acl should be returned.
167  */
168 #define	ACL_NO_TRIVIAL	0x2
169 
170 /*
171  * Legacy aclcheck errors for aclent_t ACLs
172  */
173 #define	EACL_GRP_ERROR		GRP_ERROR
174 #define	EACL_USER_ERROR		USER_ERROR
175 #define	EACL_OTHER_ERROR	OTHER_ERROR
176 #define	EACL_CLASS_ERROR	CLASS_ERROR
177 #define	EACL_DUPLICATE_ERROR	DUPLICATE_ERROR
178 #define	EACL_MISS_ERROR		MISS_ERROR
179 #define	EACL_MEM_ERROR		MEM_ERROR
180 #define	EACL_ENTRY_ERROR	ENTRY_ERROR
181 
182 #define	EACL_INHERIT_ERROR	9		/* invalid inherit flags */
183 #define	EACL_FLAGS_ERROR	10		/* unknown flag value */
184 #define	EACL_PERM_MASK_ERROR	11		/* unknown permission */
185 #define	EACL_COUNT_ERROR	12		/* invalid acl count */
186 
187 #define	EACL_INVALID_SLOT	13		/* invalid acl slot */
188 #define	EACL_NO_ACL_ENTRY	14		/* Entry doesn't exist */
189 #define	EACL_DIFF_TYPE		15		/* acls aren't same type */
190 
191 #define	EACL_INVALID_USER_GROUP	16		/* need user/group name */
192 #define	EACL_INVALID_STR	17		/* invalid acl string */
193 #define	EACL_FIELD_NOT_BLANK	18		/* can't have blank field */
194 #define	EACL_INVALID_ACCESS_TYPE 19		/* invalid access type */
195 #define	EACL_UNKNOWN_DATA	20		/* Unrecognized data in ACL */
196 #define	EACL_MISSING_FIELDS	21		/* missing fields in acl */
197 
198 #define	EACL_INHERIT_NOTDIR	22		/* Need dir for inheritance */
199 
200 extern int aclcheck(aclent_t *, int, int *);
201 extern int acltomode(aclent_t *, int, mode_t *);
202 extern int aclfrommode(aclent_t *, int, mode_t *);
203 extern int aclsort(int, int, aclent_t *);
204 extern char *acltotext(aclent_t *, int);
205 extern aclent_t *aclfromtext(char *, int *);
206 extern void acl_free(acl_t *);
207 extern int acl_get(const char *, int, acl_t **);
208 extern int facl_get(int, int, acl_t **);
209 extern int acl_set(const char *, acl_t *acl);
210 extern int facl_set(int, acl_t *acl);
211 extern int acl_strip(const char *, uid_t, gid_t, mode_t);
212 extern int acl_trivial(const char *);
213 extern char *acl_totext(acl_t *);
214 extern int acl_fromtext(const char *, acl_t **);
215 extern int acl_check(acl_t *, int);
216 
217 #else	/* !defined(_KERNEL) */
218 
219 extern void ksort(caddr_t, int, int, int (*)(void *, void *));
220 extern int cmp2acls(void *, void *);
221 
222 #endif	/* !defined(_KERNEL) */
223 
224 #if defined(__STDC__)
225 extern int acl(const char *path, int cmd, int cnt, void *buf);
226 extern int facl(int fd, int cmd, int cnt, void *buf);
227 #else	/* !__STDC__ */
228 extern int acl();
229 extern int facl();
230 #endif	/* defined(__STDC__) */
231 
232 #ifdef	__cplusplus
233 }
234 #endif
235 
236 #endif /* _SYS_ACL_H */
237