]>
git.saurik.com Git - apple/libc.git/blob - posix1e/acl_entry.c
2 * Copyright (c) 2004 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
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
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.
21 * @APPLE_LICENSE_HEADER_END@
24 #include <sys/appleapiopts.h>
25 #include <sys/types.h>
34 acl_copy_entry(acl_entry_t dest
, acl_entry_t src
)
36 /* validate arguments */
37 _ACL_VALIDATE_ENTRY(dest
);
38 _ACL_VALIDATE_ENTRY(src
);
43 bcopy(src
, dest
, sizeof(*src
));
48 acl_create_entry_np(acl_t
*acl_p
, acl_entry_t
*entry_p
, int index
)
50 struct _acl
*ap
= *acl_p
;
53 /* validate arguments */
54 _ACL_VALIDATE_ACL(ap
);
55 if (ap
->a_entries
>= ACL_MAX_ENTRIES
) {
59 if (index
== ACL_LAST_ENTRY
)
60 index
= ap
->a_entries
;
61 if (index
> ap
->a_entries
) {
66 /* move following entries out of the way */
67 for (i
= ap
->a_entries
; i
> index
; i
--)
68 ap
->a_ace
[i
] = ap
->a_ace
[i
- 1];
71 /* initialise new entry */
72 ap
->a_ace
[index
].ae_magic
= _ACL_ENTRY_MAGIC
;
73 ap
->a_ace
[index
].ae_tag
= ACL_UNDEFINED_TAG
;
75 *entry_p
= &ap
->a_ace
[index
];
80 acl_create_entry(acl_t
*acl_p
, acl_entry_t
*entry_p
)
82 return(acl_create_entry_np(acl_p
, entry_p
, ACL_LAST_ENTRY
));
86 acl_delete_entry(acl_t acl
, acl_entry_t entry
)
90 _ACL_VALIDATE_ACL(acl
);
91 _ACL_VALIDATE_ENTRY(entry
);
92 _ACL_VALIDATE_ENTRY_CONTAINED(acl
, entry
);
94 /* copy following entries down & invalidate last slot */
96 for (i
= entry
- &acl
->a_ace
[0]; i
< acl
->a_entries
; i
++)
97 acl
->a_ace
[i
] = acl
->a_ace
[i
+ 1];
98 acl
->a_ace
[acl
->a_entries
].ae_magic
= 0;
99 /* Sync up the iterator's position if necessary */
100 if (acl
->a_last_get
>= (entry
- &acl
->a_ace
[0]))
107 acl_get_entry(acl_t acl
, int entry_id
, acl_entry_t
*entry_p
)
110 _ACL_VALIDATE_ACL(acl
);
111 if ((entry_id
!= ACL_FIRST_ENTRY
) &&
112 (entry_id
!= ACL_NEXT_ENTRY
) &&
113 (entry_id
!= ACL_LAST_ENTRY
) &&
114 ((entry_id
< 0) || (entry_id
>= acl
->a_entries
))) {
118 if (entry_id
== ACL_FIRST_ENTRY
)
121 if (entry_id
== ACL_NEXT_ENTRY
) {
122 entry_id
= acl
->a_last_get
+ 1;
125 if (entry_id
== ACL_LAST_ENTRY
)
126 entry_id
= acl
->a_entries
- 1;
128 if (entry_id
>= acl
->a_entries
) {
133 *entry_p
= &acl
->a_ace
[entry_id
];
134 acl
->a_last_get
= entry_id
;
140 acl_get_qualifier(acl_entry_t entry
)
147 if (!_ACL_VALID_ENTRY(entry
)) {
149 } else if ((error
= acl_get_tag_type(entry
, &tag_type
)) != 0) {
150 /* errno is set by acl_get_tag_type */
153 case ACL_EXTENDED_ALLOW
:
154 case ACL_EXTENDED_DENY
:
155 if ((result
= malloc(sizeof(guid_t
))) != NULL
)
156 bcopy(&entry
->ae_applicable
, result
, sizeof(guid_t
));
167 acl_get_tag_type(acl_entry_t entry
, acl_tag_t
*tag_type_p
)
169 _ACL_VALIDATE_ENTRY(entry
);
171 *tag_type_p
= entry
->ae_tag
;
176 acl_set_qualifier(acl_entry_t entry
, const void *tag_qualifier_p
)
181 _ACL_VALIDATE_ENTRY(entry
);
182 if ((error
= acl_get_tag_type(entry
, &tag_type
)) != 0)
186 case ACL_EXTENDED_ALLOW
:
187 case ACL_EXTENDED_DENY
:
188 bcopy(tag_qualifier_p
, &entry
->ae_applicable
, sizeof(guid_t
));
198 acl_set_tag_type(acl_entry_t entry
, acl_tag_t tag_type
)
200 _ACL_VALIDATE_ENTRY(entry
);
203 case ACL_EXTENDED_ALLOW
:
204 case ACL_EXTENDED_DENY
:
205 entry
->ae_tag
= tag_type
;