xref: /titanic_41/usr/src/lib/libsec/common/aclutils.h (revision 5f41bf46ca5230bc3ee6b7d6a714a3a16a390261)
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 2008 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef _ACLUTILS_H
27 #define	_ACLUTILS_H
28 
29 #include <sys/types.h>
30 #include <sys/acl.h>
31 #include <strings.h>
32 #include <locale.h>
33 #include <ctype.h>
34 #include <grp.h>
35 #include <pwd.h>
36 
37 #ifdef	__cplusplus
38 extern "C" {
39 #endif
40 
41 #define	ACL_REMOVE_ALL		0x0
42 #define	ACL_REMOVE_FIRST	0x1
43 
44 /*
45  * Hint for whether acl_totext() should use
46  * mnemonics:
47  * read_data/list_directory
48  * write_data/add_file or
49  * append_data/add_subdirectory
50  * when object of ACL is known.
51  */
52 
53 #define	PERM_TYPE_ACE		0x1	/* permissions are of ACE type */
54 #define	PERM_TYPE_UNKNOWN	0x2	/* permission type not yet known */
55 #define	PERM_TYPE_EMPTY		0x4	/* no permissions are specified */
56 
57 struct acl_perm_type {
58 	int		perm_style;	/* type of perm style, see above */
59 	char		*perm_str;	/* string value being returned */
60 	uint32_t	perm_val;	/* numeric value being returned */
61 };
62 
63 /*
64  * Textual representation of ace_t's access mask
65  */
66 #define	READ_DATA_TXT	"read_data/"
67 #define	WRITE_DATA_TXT	"write_data/"
68 #define	EXECUTE_TXT	"execute/"
69 #define	READ_XATTR_TXT	"read_xattr/"
70 #define	WRITE_XATTR_TXT	"write_xattr/"
71 #define	READ_ATTRIBUTES_TXT "read_attributes/"
72 #define	WRITE_ATTRIBUTES_TXT "write_attributes/"
73 #define	DELETE_TXT	"delete/"
74 #define	DELETE_CHILD_TXT "delete_child/"
75 #define	WRITE_OWNER_TXT "write_owner/"
76 #define	READ_ACL_TXT	"read_acl/"
77 #define	WRITE_ACL_TXT	"write_acl/"
78 #define	APPEND_DATA_TXT "append_data/"
79 #define	READ_DIR_TXT	"list_directory/read_data/"
80 #define	ADD_DIR_TXT	"add_subdirectory/append_data/"
81 #define	ADD_FILE_TXT	"add_file/write_data/"
82 #define	SYNCHRONIZE_TXT "synchronize/"
83 
84 /*
85  * ace_t's entry types
86  */
87 #define	OWNERAT_TXT	"owner@:"
88 #define	GROUPAT_TXT	"group@:"
89 #define	EVERYONEAT_TXT	"everyone@:"
90 #define	GROUP_TXT	"group:"
91 #define	USER_TXT	"user:"
92 #define	USERSID_TXT	"usersid:"
93 #define	GROUPSID_TXT	"groupsid:"
94 
95 /*
96  * ace_t's access types
97  */
98 #define	ALLOW_TXT	"allow"
99 #define	DENY_TXT	"deny"
100 #define	ALARM_TXT	"alarm"
101 #define	AUDIT_TXT	"audit"
102 #define	UNKNOWN_TXT	"unknown"
103 
104 /*
105  * ace_t's inheritance types
106  */
107 
108 #define	FILE_INHERIT_TXT	"file_inherit/"
109 #define	DIR_INHERIT_TXT		"dir_inherit/"
110 #define	NO_PROPAGATE_TXT	"no_propagate/"
111 #define	INHERIT_ONLY_TXT	"inherit_only/"
112 #define	INHERITED_ACE_TXT	"inherited/"
113 #define	SUCCESSFUL_ACCESS_TXT	"successful_access/"
114 #define	FAILED_ACCESS_TXT	"failed_access/"
115 
116 extern char *yybuf;
117 extern acl_t *yyacl;
118 
119 extern int yyerror(const char *);
120 extern int get_id(int entry_type, char *name, uid_t *id);
121 extern int get_id_nofail(int entry_type, char *name);
122 extern int ace_entry_type(int entry_type);
123 extern int aclent_entry_type(int type, int owning, int *ret);
124 extern int ace_perm_mask(struct acl_perm_type *, uint32_t *mask);
125 extern int compute_aclent_perms(char *str, o_mode_t *mask);
126 extern int compute_ace_inherit(char *str, uint32_t *imask);
127 extern int acl_addentries(acl_t *, acl_t *, int);
128 extern int acl_removeentries(acl_t *, acl_t *, int, int);
129 extern int acl_modifyentries(acl_t *, acl_t *, int);
130 extern void acl_printacl(acl_t *, int, int);
131 extern char *acl_strerror(int);
132 extern acl_t *acl_dup(acl_t *);
133 extern int acl_type(acl_t *);
134 extern int acl_cnt(acl_t *);
135 extern int acl_flags(acl_t *);
136 extern void *acl_data(acl_t *);
137 extern void acl_error(const char *, ...);
138 extern int acl_parse(const char *, acl_t **);
139 extern int yyparse(void);
140 extern void yyreset(void);
141 extern void yycleanup(void);
142 extern acl_t *acl_to_aclp(enum acl_type, void *, int);
143 extern int sid_to_id(char *, boolean_t, uid_t *);
144 
145 #ifdef	__cplusplus
146 }
147 #endif
148 
149 #endif /* _ACLUTILS_H */
150