]>
Commit | Line | Data |
---|---|---|
3d9156a7 | 1 | /* |
1f2f436a | 2 | * Copyright (c) 2004, 2010 Apple Inc. All rights reserved. |
3d9156a7 A |
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 | ||
1f2f436a | 26 | #include <Availability.h> |
3d9156a7 | 27 | #include <sys/kauth.h> |
a9aaacca | 28 | #include <sys/_types/_ssize_t.h> |
3d9156a7 | 29 | |
1f2f436a A |
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) | |
23e20b00 | 47 | #define __DARWIN_ACL_SYNCHRONIZE (1<<20) |
1f2f436a A |
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 | ||
3d9156a7 A |
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 { | |
1f2f436a A |
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, | |
23e20b00 | 87 | ACL_SYNCHRONIZE = __DARWIN_ACL_SYNCHRONIZE, |
3d9156a7 A |
88 | } acl_perm_t; |
89 | ||
90 | /* 23.2.5 ACL entry tag type bits - nonstandard */ | |
91 | typedef enum { | |
92 | ACL_UNDEFINED_TAG = 0, | |
1f2f436a A |
93 | ACL_EXTENDED_ALLOW = __DARWIN_ACL_EXTENDED_ALLOW, |
94 | ACL_EXTENDED_DENY = __DARWIN_ACL_EXTENDED_DENY | |
3d9156a7 A |
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 */ | |
1f2f436a A |
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 | |
3d9156a7 A |
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 | ||
1f2f436a A |
144 | typedef u_int64_t acl_permset_mask_t; |
145 | ||
3d9156a7 A |
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 | ||
1f2f436a A |
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 | ||
3d9156a7 A |
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); | |
224c7076 | 200 | extern int acl_set_link_np(const char *path_p, acl_type_t type, acl_t acl); |
3d9156a7 A |
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); | |
eb1cde05 | 204 | extern ssize_t acl_copy_ext_native(void *buf_p, acl_t acl, ssize_t size); |
3d9156a7 | 205 | extern acl_t acl_copy_int(const void *buf_p); |
eb1cde05 | 206 | extern acl_t acl_copy_int_native(const void *buf_p); |
3d9156a7 A |
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 | ||
eb1cde05 | 212 | #endif /* _SYS_ACL_H */ |