]>
git.saurik.com Git - apple/libc.git/blob - posix1e/acl_file.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 /* XXX temporary implementation using __acl__ file */
26 #include <sys/appleapiopts.h>
27 #include <sys/types.h>
39 static acl_t
acl_get_file1(const char *path
, acl_type_t acl_type
, int follow
);
40 static int acl_set_file1(const char *path
, acl_type_t acl_type
, acl_t acl
, int follow
);
43 acl_delete_fd_np(int filedes
, acl_type_t type
)
50 acl_delete_file_np(const char *path
, acl_type_t type
)
57 acl_delete_link_np(const char *path
, acl_type_t type
)
66 return(acl_get_fd_np(fd
, ACL_TYPE_EXTENDED
));
70 acl_get_fd_np(int fd
, acl_type_t type
)
76 if (type
!= ACL_TYPE_EXTENDED
) {
80 if ((fsec
= filesec_init()) == NULL
)
84 if (fstatx_np(fd
, &sb
, fsec
) == 0)
85 filesec_get_property(fsec
, FILESEC_ACL
, &acl
);
91 acl_get_file1(const char *path
, acl_type_t acl_type
, int follow
)
97 if (acl_type
!= ACL_TYPE_EXTENDED
) {
101 if ((fsec
= filesec_init()) == NULL
)
105 if ((follow
? statx_np(path
, &sb
, fsec
) : lstatx_np(path
, &sb
, fsec
)) == 0)
106 filesec_get_property(fsec
, FILESEC_ACL
, &acl
);
112 acl_get_file(const char *path
, acl_type_t type
)
114 return(acl_get_file1(path
, type
, 1 /* follow */));
118 acl_get_link_np(const char *path
, acl_type_t type
)
120 return(acl_get_file1(path
, type
, 0 /* no follow */));
124 acl_set_fd_np(int fd
, acl_t acl
, acl_type_t type
)
129 if ((fsec
= filesec_init()) == NULL
)
131 if ((filesec_set_property(fsec
, FILESEC_ACL
, &acl
)) != 0) {
135 error
= fchmodx_np(fd
, fsec
);
137 return((error
== 0) ? 0 : -1);
141 acl_set_fd(int fd
, acl_t acl
)
143 return(acl_set_fd_np(fd
, acl
, ACL_TYPE_EXTENDED
));
147 acl_set_file1(const char *path
, acl_type_t acl_type
, acl_t acl
, int follow
)
152 if (follow
== 0) { /* XXX this requires some thought - can links have ACLs? */
157 if ((fsec
= filesec_init()) == NULL
)
159 if (filesec_set_property(fsec
, FILESEC_ACL
, &acl
) != 0) {
163 error
= chmodx_np(path
, fsec
);
165 return((error
== 0) ? 0 : -1);
169 acl_set_file(const char *path
, acl_type_t acl_type
, acl_t acl
)
171 return(acl_set_file1(path
, acl_type
, acl
, 1));
175 acl_set_link_np(const char *path
, acl_type_t acl_type
, acl_t acl
)
177 return(acl_set_file1(path
, acl_type
, acl
, 0));
181 * Not applicable; not supported.
184 acl_delete_def_file(__unused
const char *path
)