]> git.saurik.com Git - apple/libc.git/blob - posix1e/acl_perm.c
Libc-1244.30.3.tar.gz
[apple/libc.git] / posix1e / acl_perm.c
1 /*
2 * Copyright (c) 2004-2010 Apple, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23
24 #include <sys/appleapiopts.h>
25 #include <sys/types.h>
26 #include <sys/acl.h>
27 #include <errno.h>
28 #include <stdlib.h>
29 #include <string.h>
30
31 #include "aclvar.h"
32
33 #if __DARWIN_ACL_READ_DATA != KAUTH_VNODE_READ_DATA
34 # error __DARWIN_ACL_READ_DATA != KAUTH_VNODE_READ_DATA
35 #endif
36 #if __DARWIN_ACL_LIST_DIRECTORY != KAUTH_VNODE_LIST_DIRECTORY
37 # error __DARWIN_ACL_LIST_DIRECTORY != KAUTH_VNODE_LIST_DIRECTORY
38 #endif
39 #if __DARWIN_ACL_WRITE_DATA != KAUTH_VNODE_WRITE_DATA
40 # error __DARWIN_ACL_WRITE_DATA != KAUTH_VNODE_WRITE_DATA
41 #endif
42 #if __DARWIN_ACL_ADD_FILE != KAUTH_VNODE_ADD_FILE
43 # error __DARWIN_ACL_ADD_FILE != KAUTH_VNODE_ADD_FILE
44 #endif
45 #if __DARWIN_ACL_EXECUTE != KAUTH_VNODE_EXECUTE
46 # error __DARWIN_ACL_EXECUTE != KAUTH_VNODE_EXECUTE
47 #endif
48 #if __DARWIN_ACL_SEARCH != KAUTH_VNODE_SEARCH
49 # error __DARWIN_ACL_SEARCH != KAUTH_VNODE_SEARCH
50 #endif
51 #if __DARWIN_ACL_DELETE != KAUTH_VNODE_DELETE
52 # error __DARWIN_ACL_DELETE != KAUTH_VNODE_DELETE
53 #endif
54 #if __DARWIN_ACL_APPEND_DATA != KAUTH_VNODE_APPEND_DATA
55 # error __DARWIN_ACL_APPEND_DATA != KAUTH_VNODE_APPEND_DATA
56 #endif
57 #if __DARWIN_ACL_ADD_SUBDIRECTORY != KAUTH_VNODE_ADD_SUBDIRECTORY
58 # error __DARWIN_ACL_ADD_SUBDIRECTORY != KAUTH_VNODE_ADD_SUBDIRECTORY
59 #endif
60 #if __DARWIN_ACL_DELETE_CHILD != KAUTH_VNODE_DELETE_CHILD
61 # error __DARWIN_ACL_DELETE_CHILD != KAUTH_VNODE_DELETE_CHILD
62 #endif
63 #if __DARWIN_ACL_READ_ATTRIBUTES != KAUTH_VNODE_READ_ATTRIBUTES
64 # error __DARWIN_ACL_READ_ATTRIBUTES != KAUTH_VNODE_READ_ATTRIBUTES
65 #endif
66 #if __DARWIN_ACL_WRITE_ATTRIBUTES != KAUTH_VNODE_WRITE_ATTRIBUTES
67 # error __DARWIN_ACL_WRITE_ATTRIBUTES != KAUTH_VNODE_WRITE_ATTRIBUTES
68 #endif
69 #if __DARWIN_ACL_READ_EXTATTRIBUTES != KAUTH_VNODE_READ_EXTATTRIBUTES
70 # error __DARWIN_ACL_READ_EXTATTRIBUTES != KAUTH_VNODE_READ_EXTATTRIBUTES
71 #endif
72 #if __DARWIN_ACL_WRITE_EXTATTRIBUTES != KAUTH_VNODE_WRITE_EXTATTRIBUTES
73 # error __DARWIN_ACL_WRITE_EXTATTRIBUTES != KAUTH_VNODE_WRITE_EXTATTRIBUTES
74 #endif
75 #if __DARWIN_ACL_READ_SECURITY != KAUTH_VNODE_READ_SECURITY
76 # error __DARWIN_ACL_READ_SECURITY != KAUTH_VNODE_READ_SECURITY
77 #endif
78 #if __DARWIN_ACL_WRITE_SECURITY != KAUTH_VNODE_WRITE_SECURITY
79 # error __DARWIN_ACL_WRITE_SECURITY != KAUTH_VNODE_WRITE_SECURITY
80 #endif
81 #if __DARWIN_ACL_CHANGE_OWNER != KAUTH_VNODE_CHANGE_OWNER
82 # error __DARWIN_ACL_CHANGE_OWNER != KAUTH_VNODE_CHANGE_OWNER
83 #endif
84 #if __DARWIN_ACL_SYNCHRONIZE != KAUTH_VNODE_SYNCHRONIZE
85 # error __DARWIN_ACL_SYNCHRONIZE != KAUTH_VNODE_SYNCHRONIZE
86 #endif
87
88 int
89 acl_add_perm(acl_permset_t permset, acl_perm_t perm)
90 {
91 /* XXX validate perms */
92 _ACL_VALIDATE_PERM(perm);
93
94 permset->ap_perms |= perm;
95 return(0);
96 }
97
98 int
99 acl_clear_perms(acl_permset_t permset)
100 {
101 /* XXX validate perms */
102
103 permset->ap_perms = 0;
104 return(0);
105 }
106
107 int
108 acl_delete_perm(acl_permset_t permset, acl_perm_t perm)
109 {
110 /* XXX validate perms */
111 _ACL_VALIDATE_PERM(perm);
112
113 permset->ap_perms &= ~perm;
114 return(0);
115 }
116
117 int
118 acl_get_perm_np(acl_permset_t permset, acl_perm_t perm)
119 {
120 _ACL_VALIDATE_PERM(perm);
121
122 return((perm & permset->ap_perms) ? 1 : 0);
123 }
124
125 int
126 acl_get_permset(acl_entry_t entry, acl_permset_t *permset_p)
127 {
128 _ACL_VALIDATE_ENTRY(entry);
129
130 *permset_p = (acl_permset_t)&entry->ae_perms;
131 return(0);
132 }
133
134 int
135 acl_set_permset(acl_entry_t entry, acl_permset_t permset)
136 {
137 _ACL_VALIDATE_ENTRY(entry);
138
139 entry->ae_perms = permset->ap_perms;
140 return(0);
141 }
142
143 int
144 acl_maximal_permset_mask_np(acl_permset_mask_t * mask_p)
145 {
146 /* Bitwise or of all possible acl_perm_t values */
147 *mask_p = _ACL_PERMS_MASK;
148 return (0);
149 }
150
151 int
152 acl_get_permset_mask_np(acl_entry_t entry, acl_permset_mask_t * mask_p)
153 {
154 _ACL_VALIDATE_ENTRY(entry);
155
156 *mask_p = (acl_permset_mask_t)entry->ae_perms;
157 return (0);
158 }
159
160 int
161 acl_set_permset_mask_np(acl_entry_t entry, acl_permset_mask_t mask)
162 {
163 _ACL_VALIDATE_ENTRY(entry);
164 _ACL_VALIDATE_PERM(mask);
165
166 entry->ae_perms = mask;
167 return (0);
168 }