]> git.saurik.com Git - apple/libc.git/blob - include/sys/acl.h
fce4eafd0a8812f27594ab267395d62f7252da7e
[apple/libc.git] / include / sys / acl.h
1 /*
2 * Copyright (c) 2004, 2010 Apple Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
11 *
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
18 * under the License.
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
22
23 #ifndef _SYS_ACL_H
24 #define _SYS_ACL_H
25
26 #include <Availability.h>
27 #include <sys/kauth.h>
28 #include <sys/_types/_ssize_t.h>
29
30 #define __DARWIN_ACL_READ_DATA (1<<1)
31 #define __DARWIN_ACL_LIST_DIRECTORY __DARWIN_ACL_READ_DATA
32 #define __DARWIN_ACL_WRITE_DATA (1<<2)
33 #define __DARWIN_ACL_ADD_FILE __DARWIN_ACL_WRITE_DATA
34 #define __DARWIN_ACL_EXECUTE (1<<3)
35 #define __DARWIN_ACL_SEARCH __DARWIN_ACL_EXECUTE
36 #define __DARWIN_ACL_DELETE (1<<4)
37 #define __DARWIN_ACL_APPEND_DATA (1<<5)
38 #define __DARWIN_ACL_ADD_SUBDIRECTORY __DARWIN_ACL_APPEND_DATA
39 #define __DARWIN_ACL_DELETE_CHILD (1<<6)
40 #define __DARWIN_ACL_READ_ATTRIBUTES (1<<7)
41 #define __DARWIN_ACL_WRITE_ATTRIBUTES (1<<8)
42 #define __DARWIN_ACL_READ_EXTATTRIBUTES (1<<9)
43 #define __DARWIN_ACL_WRITE_EXTATTRIBUTES (1<<10)
44 #define __DARWIN_ACL_READ_SECURITY (1<<11)
45 #define __DARWIN_ACL_WRITE_SECURITY (1<<12)
46 #define __DARWIN_ACL_CHANGE_OWNER (1<<13)
47 #define __DARWIN_ACL_SYNCHRONIZE (1<<20)
48
49 #define __DARWIN_ACL_EXTENDED_ALLOW 1
50 #define __DARWIN_ACL_EXTENDED_DENY 2
51
52 #define __DARWIN_ACL_ENTRY_INHERITED (1<<4)
53 #define __DARWIN_ACL_ENTRY_FILE_INHERIT (1<<5)
54 #define __DARWIN_ACL_ENTRY_DIRECTORY_INHERIT (1<<6)
55 #define __DARWIN_ACL_ENTRY_LIMIT_INHERIT (1<<7)
56 #define __DARWIN_ACL_ENTRY_ONLY_INHERIT (1<<8)
57 #define __DARWIN_ACL_FLAG_NO_INHERIT (1<<17)
58
59 /*
60 * Implementation constants.
61 *
62 * The ACL_TYPE_EXTENDED binary format permits 169 entries plus
63 * the ACL header in a page. Give ourselves some room to grow;
64 * this limit is arbitrary.
65 */
66 #define ACL_MAX_ENTRIES 128
67
68 /* 23.2.2 Individual object access permissions - nonstandard */
69 typedef enum {
70 ACL_READ_DATA = __DARWIN_ACL_READ_DATA,
71 ACL_LIST_DIRECTORY = __DARWIN_ACL_LIST_DIRECTORY,
72 ACL_WRITE_DATA = __DARWIN_ACL_WRITE_DATA,
73 ACL_ADD_FILE = __DARWIN_ACL_ADD_FILE,
74 ACL_EXECUTE = __DARWIN_ACL_EXECUTE,
75 ACL_SEARCH = __DARWIN_ACL_SEARCH,
76 ACL_DELETE = __DARWIN_ACL_DELETE,
77 ACL_APPEND_DATA = __DARWIN_ACL_APPEND_DATA,
78 ACL_ADD_SUBDIRECTORY = __DARWIN_ACL_ADD_SUBDIRECTORY,
79 ACL_DELETE_CHILD = __DARWIN_ACL_DELETE_CHILD,
80 ACL_READ_ATTRIBUTES = __DARWIN_ACL_READ_ATTRIBUTES,
81 ACL_WRITE_ATTRIBUTES = __DARWIN_ACL_WRITE_ATTRIBUTES,
82 ACL_READ_EXTATTRIBUTES = __DARWIN_ACL_READ_EXTATTRIBUTES,
83 ACL_WRITE_EXTATTRIBUTES = __DARWIN_ACL_WRITE_EXTATTRIBUTES,
84 ACL_READ_SECURITY = __DARWIN_ACL_READ_SECURITY,
85 ACL_WRITE_SECURITY = __DARWIN_ACL_WRITE_SECURITY,
86 ACL_CHANGE_OWNER = __DARWIN_ACL_CHANGE_OWNER,
87 ACL_SYNCHRONIZE = __DARWIN_ACL_SYNCHRONIZE,
88 } acl_perm_t;
89
90 /* 23.2.5 ACL entry tag type bits - nonstandard */
91 typedef enum {
92 ACL_UNDEFINED_TAG = 0,
93 ACL_EXTENDED_ALLOW = __DARWIN_ACL_EXTENDED_ALLOW,
94 ACL_EXTENDED_DENY = __DARWIN_ACL_EXTENDED_DENY
95 } acl_tag_t;
96
97 /* 23.2.6 Individual ACL types */
98 typedef enum {
99 ACL_TYPE_EXTENDED = 0x00000100,
100 /* Posix 1003.1e types - not supported */
101 ACL_TYPE_ACCESS = 0x00000000,
102 ACL_TYPE_DEFAULT = 0x00000001,
103 /* The following types are defined on FreeBSD/Linux - not supported */
104 ACL_TYPE_AFS = 0x00000002,
105 ACL_TYPE_CODA = 0x00000003,
106 ACL_TYPE_NTFS = 0x00000004,
107 ACL_TYPE_NWFS = 0x00000005
108 } acl_type_t;
109
110 /* 23.2.7 ACL qualifier constants */
111
112 #define ACL_UNDEFINED_ID NULL /* XXX ? */
113
114 /* 23.2.8 ACL Entry Constants */
115 typedef enum {
116 ACL_FIRST_ENTRY = 0,
117 ACL_NEXT_ENTRY = -1,
118 ACL_LAST_ENTRY = -2
119 } acl_entry_id_t;
120
121 /* nonstandard ACL / entry flags */
122 typedef enum {
123 ACL_FLAG_DEFER_INHERIT = (1 << 0), /* tentative */
124 ACL_FLAG_NO_INHERIT = __DARWIN_ACL_FLAG_NO_INHERIT,
125 ACL_ENTRY_INHERITED = __DARWIN_ACL_ENTRY_INHERITED,
126 ACL_ENTRY_FILE_INHERIT = __DARWIN_ACL_ENTRY_FILE_INHERIT,
127 ACL_ENTRY_DIRECTORY_INHERIT = __DARWIN_ACL_ENTRY_DIRECTORY_INHERIT,
128 ACL_ENTRY_LIMIT_INHERIT = __DARWIN_ACL_ENTRY_LIMIT_INHERIT,
129 ACL_ENTRY_ONLY_INHERIT = __DARWIN_ACL_ENTRY_ONLY_INHERIT
130 } acl_flag_t;
131
132 /* "External" ACL types */
133
134 struct _acl;
135 struct _acl_entry;
136 struct _acl_permset;
137 struct _acl_flagset;
138
139 typedef struct _acl *acl_t;
140 typedef struct _acl_entry *acl_entry_t;
141 typedef struct _acl_permset *acl_permset_t;
142 typedef struct _acl_flagset *acl_flagset_t;
143
144 typedef u_int64_t acl_permset_mask_t;
145
146 __BEGIN_DECLS
147 /* 23.1.6.1 ACL Storage Management */
148 extern acl_t acl_dup(acl_t acl);
149 extern int acl_free(void *obj_p);
150 extern acl_t acl_init(int count);
151
152 /* 23.1.6.2 (1) ACL Entry manipulation */
153 extern int acl_copy_entry(acl_entry_t dest_d, acl_entry_t src_d);
154 extern int acl_create_entry(acl_t *acl_p, acl_entry_t *entry_p);
155 extern int acl_create_entry_np(acl_t *acl_p, acl_entry_t *entry_p, int entry_index);
156 extern int acl_delete_entry(acl_t acl, acl_entry_t entry_d);
157 extern int acl_get_entry(acl_t acl, int entry_id, acl_entry_t *entry_p);
158 extern int acl_valid(acl_t acl);
159 extern int acl_valid_fd_np(int fd, acl_type_t type, acl_t acl);
160 extern int acl_valid_file_np(const char *path, acl_type_t type, acl_t acl);
161 extern int acl_valid_link_np(const char *path, acl_type_t type, acl_t acl);
162
163 /* 23.1.6.2 (2) Manipulate permissions within an ACL entry */
164 extern int acl_add_perm(acl_permset_t permset_d, acl_perm_t perm);
165 extern int acl_calc_mask(acl_t *acl_p); /* not supported */
166 extern int acl_clear_perms(acl_permset_t permset_d);
167 extern int acl_delete_perm(acl_permset_t permset_d, acl_perm_t perm);
168 extern int acl_get_perm_np(acl_permset_t permset_d, acl_perm_t perm);
169 extern int acl_get_permset(acl_entry_t entry_d, acl_permset_t *permset_p);
170 extern int acl_set_permset(acl_entry_t entry_d, acl_permset_t permset_d);
171
172 /* nonstandard - manipulate permissions within an ACL entry using bitmasks */
173 extern int acl_maximal_permset_mask_np(acl_permset_mask_t * mask_p) __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_4_3);
174 extern int acl_get_permset_mask_np(acl_entry_t entry_d, acl_permset_mask_t * mask_p) __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_4_3);
175 extern int acl_set_permset_mask_np(acl_entry_t entry_d, acl_permset_mask_t mask) __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_4_3);
176
177 /* nonstandard - manipulate flags on ACLs and entries */
178 extern int acl_add_flag_np(acl_flagset_t flagset_d, acl_flag_t flag);
179 extern int acl_clear_flags_np(acl_flagset_t flagset_d);
180 extern int acl_delete_flag_np(acl_flagset_t flagset_d, acl_flag_t flag);
181 extern int acl_get_flag_np(acl_flagset_t flagset_d, acl_flag_t flag);
182 extern int acl_get_flagset_np(void *obj_p, acl_flagset_t *flagset_p);
183 extern int acl_set_flagset_np(void *obj_p, acl_flagset_t flagset_d);
184
185 /* 23.1.6.2 (3) Manipulate ACL entry tag type and qualifier */
186 extern void *acl_get_qualifier(acl_entry_t entry_d);
187 extern int acl_get_tag_type(acl_entry_t entry_d, acl_tag_t *tag_type_p);
188 extern int acl_set_qualifier(acl_entry_t entry_d, const void *tag_qualifier_p);
189 extern int acl_set_tag_type(acl_entry_t entry_d, acl_tag_t tag_type);
190
191 /* 23.1.6.3 ACL manipulation on an Object */
192 extern int acl_delete_def_file(const char *path_p); /* not supported */
193 extern acl_t acl_get_fd(int fd);
194 extern acl_t acl_get_fd_np(int fd, acl_type_t type);
195 extern acl_t acl_get_file(const char *path_p, acl_type_t type);
196 extern acl_t acl_get_link_np(const char *path_p, acl_type_t type);
197 extern int acl_set_fd(int fd, acl_t acl);
198 extern int acl_set_fd_np(int fd, acl_t acl, acl_type_t acl_type);
199 extern int acl_set_file(const char *path_p, acl_type_t type, acl_t acl);
200 extern int acl_set_link_np(const char *path_p, acl_type_t type, acl_t acl);
201
202 /* 23.1.6.4 ACL Format translation */
203 extern ssize_t acl_copy_ext(void *buf_p, acl_t acl, ssize_t size);
204 extern ssize_t acl_copy_ext_native(void *buf_p, acl_t acl, ssize_t size);
205 extern acl_t acl_copy_int(const void *buf_p);
206 extern acl_t acl_copy_int_native(const void *buf_p);
207 extern acl_t acl_from_text(const char *buf_p);
208 extern ssize_t acl_size(acl_t acl);
209 extern char *acl_to_text(acl_t acl, ssize_t *len_p);
210 __END_DECLS
211
212 #endif /* _SYS_ACL_H */