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