xref: /titanic_51/usr/src/uts/common/sys/acl.h (revision bdfc6d18da790deeec2e0eb09c625902defe2498)
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 2004 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;	/* "rwx" */
48 	uint16_t	a_flags;	/* see below */
49 	uint16_t	a_type;		/* allow or deny */
50 } ace_t;
51 
52 /*
53  * The following are Defined types for an aclent_t.
54  */
55 #define	USER_OBJ	(0x01)		/* object owner */
56 #define	USER		(0x02)		/* additional users */
57 #define	GROUP_OBJ	(0x04)		/* owning group of the object */
58 #define	GROUP		(0x08)		/* additional groups */
59 #define	CLASS_OBJ	(0x10)		/* file group class and mask entry */
60 #define	OTHER_OBJ	(0x20)		/* other entry for the object */
61 #define	ACL_DEFAULT	(0x1000)	/* default flag */
62 /* default object owner */
63 #define	DEF_USER_OBJ	(ACL_DEFAULT | USER_OBJ)
64 /* defalut additional users */
65 #define	DEF_USER	(ACL_DEFAULT | USER)
66 /* default owning group */
67 #define	DEF_GROUP_OBJ	(ACL_DEFAULT | GROUP_OBJ)
68 /* default additional groups */
69 #define	DEF_GROUP	(ACL_DEFAULT | GROUP)
70 /* default mask entry */
71 #define	DEF_CLASS_OBJ	(ACL_DEFAULT | CLASS_OBJ)
72 /* default other entry */
73 #define	DEF_OTHER_OBJ	(ACL_DEFAULT | OTHER_OBJ)
74 
75 /*
76  * The following are defined for ace_t.
77  */
78 #define	ACE_FILE_INHERIT_ACE		0x0001
79 #define	ACE_DIRECTORY_INHERIT_ACE	0x0002
80 #define	ACE_NO_PROPOGATE_INHERIT_ACE	0x0004
81 #define	ACE_INHERIT_ONLY_ACE		0x0008
82 #define	ACE_LOCALLY_DEFINED		0x0010
83 #define	ACE_OWNER			0x0100 /* file owner */
84 #define	ACE_GROUP			0x0200 /* file group */
85 #define	ACE_OTHER			0x0400 /* other field */
86 #define	ACE_USER			0x0800 /* additional users */
87 #define	ACE_GROUPS			0x1000 /* additional groups */
88 /*
89  * The following flags are supported by both NFSv4 ACLs and ace_t.
90  */
91 #define	ACE_NFSV4_SUP_FLAGS (ACE_FILE_INHERIT_ACE | \
92     ACE_DIRECTORY_INHERIT_ACE | \
93     ACE_NO_PROPOGATE_INHERIT_ACE | \
94     ACE_INHERIT_ONLY_ACE)
95 
96 #define	ALLOW	0
97 #define	DENY	1
98 
99 #define	ACE_READ_DATA	04	/* 'r'	 */
100 #define	ACE_WRITE_DATA	02	/* 'w'	 */
101 #define	ACE_EXECUTE	01	/* 'x'	 */
102 
103 /* cmd args to acl(2) for aclent_t  */
104 #define	GETACL			1
105 #define	SETACL			2
106 #define	GETACLCNT		3
107 
108 /* cmd's to manipulate ace acl's. */
109 #define	ACE_GETACL		4
110 #define	ACE_SETACL		5
111 #define	ACE_GETACLCNT		6
112 
113 /* minimal acl entries from GETACLCNT */
114 #define	MIN_ACL_ENTRIES		4
115 
116 #if !defined(_KERNEL)
117 
118 /* acl check errors */
119 #define	GRP_ERROR		1
120 #define	USER_ERROR		2
121 #define	OTHER_ERROR		3
122 #define	CLASS_ERROR		4
123 #define	DUPLICATE_ERROR		5
124 #define	MISS_ERROR		6
125 #define	MEM_ERROR		7
126 #define	ENTRY_ERROR		8
127 
128 /*
129  * similar to ufs_acl.h: changed to char type for user commands (tar, cpio)
130  * Attribute types
131  */
132 #define	UFSD_FREE	('0')	/* Free entry */
133 #define	UFSD_ACL	('1')	/* Access Control Lists */
134 #define	UFSD_DFACL	('2')	/* reserved for future use */
135 
136 extern int aclcheck(aclent_t *, int, int *);
137 extern int acltomode(aclent_t *, int, mode_t *);
138 extern int aclfrommode(aclent_t *, int, mode_t *);
139 extern int aclsort(int, int, aclent_t *);
140 extern char *acltotext(aclent_t *, int);
141 extern aclent_t *aclfromtext(char *, int *);
142 
143 #else	/* !defined(_KERNEL) */
144 
145 extern void ksort(caddr_t, int, int, int (*)(void *, void *));
146 extern int cmp2acls(void *, void *);
147 
148 #endif	/* !defined(_KERNEL) */
149 
150 #if defined(__STDC__)
151 extern int acl(const char *path, int cmd, int cnt, void *buf);
152 extern int facl(int fd, int cmd, int cnt, void *buf);
153 #else	/* !__STDC__ */
154 extern int acl();
155 extern int facl();
156 #endif	/* defined(__STDC__) */
157 
158 #ifdef	__cplusplus
159 }
160 #endif
161 
162 #endif /* _SYS_ACL_H */
163