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