acl.h revision 96755
1/*-
2 * Copyright (c) 1999-2001 Robert N. M. Watson
3 * All rights reserved.
4 *
5 * This software was developed by Robert Watson for the TrustedBSD Project.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 *    notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 *    notice, this list of conditions and the following disclaimer in the
14 *    documentation and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE.
27 *
28 * $FreeBSD: head/sys/sys/acl.h 96755 2002-05-16 21:28:32Z trhodes $
29 */
30/*
31 * Developed by the TrustedBSD Project.
32 * Support for POSIX.1e access control lists.
33 */
34
35#ifndef _SYS_ACL_H
36#define	_SYS_ACL_H
37
38/*
39 * POSIX.1e ACL types and related constants.
40 */
41
42#define	POSIX1E_ACL_ACCESS_EXTATTR_NAMESPACE	EXTATTR_NAMESPACE_SYSTEM
43#define	POSIX1E_ACL_ACCESS_EXTATTR_NAME		"posix1e.acl_access"
44#define	POSIX1E_ACL_DEFAULT_EXTATTR_NAMESPACE	EXTATTR_NAMESPACE_SYSTEM
45#define	POSIX1E_ACL_DEFAULT_EXTATTR_NAME	"posix1e.acl_default"
46#define	ACL_MAX_ENTRIES		32 /* maximum entries in an ACL */
47
48typedef int	acl_type_t;
49typedef int	acl_tag_t;
50typedef mode_t	acl_perm_t;
51typedef mode_t *acl_permset_t;
52
53struct acl_entry {
54	acl_tag_t	ae_tag;
55	uid_t		ae_id;
56	acl_perm_t	ae_perm;
57};
58typedef struct acl_entry	*acl_entry_t;
59
60/* internal ACL structure */
61struct acl {
62	int			acl_cnt;
63	struct acl_entry	acl_entry[ACL_MAX_ENTRIES];
64};
65
66/* external ACL structure */
67struct acl_t_struct {
68	struct acl		ats_acl;
69	int			ats_cur_entry;
70};
71typedef struct acl_t_struct *acl_t;
72
73/*
74 * Possible valid values for ae_tag field.
75 */
76#define	ACL_UNDEFINED_TAG	0x00000000
77#define	ACL_USER_OBJ		0x00000001
78#define	ACL_USER		0x00000002
79#define	ACL_GROUP_OBJ		0x00000004
80#define	ACL_GROUP		0x00000008
81#define	ACL_MASK		0x00000010
82#define	ACL_OTHER		0x00000020
83#define	ACL_OTHER_OBJ		ACL_OTHER
84
85/*
86 * Possible valid values for acl_type_t arguments.
87 */
88#define	ACL_TYPE_ACCESS		0x00000000
89#define	ACL_TYPE_DEFAULT	0x00000001
90#define	ACL_TYPE_AFS		0x00000002
91#define	ACL_TYPE_CODA		0x00000003
92#define	ACL_TYPE_NTFS		0x00000004
93#define	ACL_TYPE_NWFS		0x00000005
94
95/*
96 * Possible flags in ae_perm field.
97 */
98#define	ACL_EXECUTE		0x0001
99#define	ACL_WRITE		0x0002
100#define	ACL_READ		0x0004
101#define	ACL_PERM_NONE		0x0000
102#define	ACL_PERM_BITS		(ACL_EXECUTE | ACL_WRITE | ACL_READ)
103#define	ACL_POSIX1E_BITS	(ACL_EXECUTE | ACL_WRITE | ACL_READ)
104
105/*
106 * Possible entry_id values for acl_get_entry()
107 */
108#define	ACL_FIRST_ENTRY		0
109#define	ACL_NEXT_ENTRY		1
110
111/*
112 * Undefined value in ae_id field
113 */
114#define	ACL_UNDEFINED_ID	((uid_t)-1)
115
116
117#ifdef _KERNEL
118
119/*
120 * Storage for ACLs and support structures.
121 */
122#ifdef MALLOC_DECLARE
123MALLOC_DECLARE(M_ACL);
124#endif
125
126acl_perm_t	acl_posix1e_mode_to_perm(acl_tag_t tag, mode_t mode);
127struct acl_entry	acl_posix1e_mode_to_entry(acl_tag_t tag, uid_t uid,
128    gid_t gid, mode_t mode);
129mode_t	acl_posix1e_perms_to_mode(struct acl_entry *acl_user_obj_entry,
130    struct acl_entry *acl_group_obj_entry, struct acl_entry *acl_other_entry);
131int	acl_posix1e_check(struct acl *acl);
132
133#else /* !_KERNEL */
134
135/*
136 * Syscall interface -- use the library calls instead as the syscalls
137 * have strict acl entry ordering requirements.
138 */
139__BEGIN_DECLS
140int	__acl_aclcheck_fd(int _filedes, acl_type_t _type, struct acl *_aclp);
141int	__acl_aclcheck_file(const char *_path, acl_type_t _type,
142	    struct acl *_aclp);
143int	__acl_delete_fd(int _filedes, acl_type_t _type);
144int	__acl_delete_file(const char *_path_p, acl_type_t _type);
145int	__acl_get_fd(int _filedes, acl_type_t _type, struct acl *_aclp);
146int	__acl_get_file(const char *_path, acl_type_t _type, struct acl *_aclp);
147int	__acl_set_fd(int _filedes, acl_type_t _type, struct acl *_aclp);
148int	__acl_set_file(const char *_path, acl_type_t _type, struct acl *_aclp);
149__END_DECLS
150
151/*
152 * Supported POSIX.1e ACL manipulation and assignment/retrieval API
153 * _np calls are local extensions that reflect an environment capable of
154 * opening file descriptors of directories, and allowing additional
155 * ACL type for different filesystems (i.e., AFS).
156 */
157__BEGIN_DECLS
158int	acl_add_perm(acl_permset_t _permset_d, acl_perm_t _perm);
159int	acl_calc_mask(acl_t *_acl_p);
160int	acl_clear_perms(acl_permset_t _permset_d);
161int	acl_copy_entry(acl_entry_t _dest_d, acl_entry_t _src_d);
162ssize_t	acl_copy_ext(void *_buf_p, acl_t _acl, ssize_t _size);
163acl_t	acl_copy_int(const void *_buf_p);
164int	acl_create_entry(acl_t *_acl_p, acl_entry_t *_entry_p);
165int	acl_delete_fd_np(int _filedes, acl_type_t _type);
166int	acl_delete_entry(acl_t _acl, acl_entry_t _entry_d);
167int	acl_delete_file_np(const char *_path_p, acl_type_t _type);
168int	acl_delete_def_file(const char *_path_p);
169int	acl_delete_perm(acl_permset_t _permset_d, acl_perm_t _perm);
170acl_t	acl_dup(acl_t _acl);
171int	acl_free(void *_obj_p);
172acl_t	acl_from_text(const char *_buf_p);
173int	acl_get_entry(acl_t _acl, int _entry_id, acl_entry_t *_entry_p);
174acl_t	acl_get_fd(int _fd);
175acl_t	acl_get_fd_np(int fd, acl_type_t _type);
176acl_t	acl_get_file(const char *_path_p, acl_type_t _type);
177void	*acl_get_qualifier(acl_entry_t _entry_d);
178int	acl_get_perm_np(acl_permset_t _permset_d, acl_perm_t _perm);
179int	acl_get_permset(acl_entry_t _entry_d, acl_permset_t *_permset_p);
180int	acl_get_tag_type(acl_entry_t _entry_d, acl_tag_t *_tag_type_p);
181acl_t	acl_init(int _count);
182int	acl_set_fd(int _fd, acl_t _acl);
183int	acl_set_fd_np(int _fd, acl_t _acl, acl_type_t _type);
184int	acl_set_file(const char *_path_p, acl_type_t _type, acl_t _acl);
185int	acl_set_permset(acl_entry_t _entry_d, acl_permset_t _permset_d);
186int	acl_set_qualifier(acl_entry_t _entry_d, const void *_tag_qualifier_p);
187int	acl_set_tag_type(acl_entry_t _entry_d, acl_tag_t _tag_type);
188ssize_t	acl_size(acl_t _acl);
189char	*acl_to_text(acl_t _acl, ssize_t *_len_p);
190int	acl_valid(acl_t _acl);
191int	acl_valid_fd_np(int _fd, acl_type_t _type, acl_t _acl);
192int	acl_valid_file_np(const char *_path_p, acl_type_t _type, acl_t _acl);
193__END_DECLS
194
195#endif /* !_KERNEL */
196
197#endif /* !_SYS_ACL_H */
198