]>
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 ((fsec
= filesec_init()) == NULL
)
80 if (fstatx_np(fd
, &sb
, fsec
) == 0)
81 filesec_get_property(fsec
, FILESEC_ACL
, &acl
);
87 acl_get_file1(const char *path
, acl_type_t acl_type
, int follow
)
93 if ((fsec
= filesec_init()) == NULL
)
97 if ((follow
? statx_np(path
, &sb
, fsec
) : lstatx_np(path
, &sb
, fsec
)) == 0)
98 filesec_get_property(fsec
, FILESEC_ACL
, &acl
);
104 acl_get_file(const char *path
, acl_type_t type
)
106 return(acl_get_file1(path
, type
, 1 /* follow */));
110 acl_get_link_np(const char *path
, acl_type_t type
)
112 return(acl_get_file1(path
, type
, 0 /* no follow */));
116 acl_set_fd_np(int fd
, acl_t acl
, acl_type_t type
)
121 if ((fsec
= filesec_init()) == NULL
)
123 if ((filesec_set_property(fsec
, FILESEC_ACL
, &acl
)) != 0) {
127 error
= fchmodx_np(fd
, fsec
);
129 return((error
== 0) ? 0 : -1);
133 acl_set_fd(int fd
, acl_t acl
)
135 return(acl_set_fd_np(fd
, acl
, ACL_TYPE_EXTENDED
));
139 acl_set_file1(const char *path
, acl_type_t acl_type
, acl_t acl
, int follow
)
144 if (follow
== 0) { /* XXX this requires some thought - can links have ACLs? */
149 if ((fsec
= filesec_init()) == NULL
)
151 if (filesec_set_property(fsec
, FILESEC_ACL
, &acl
) != 0) {
155 error
= chmodx_np(path
, fsec
);
157 return((error
== 0) ? 0 : -1);
161 acl_set_file(const char *path
, acl_type_t acl_type
, acl_t acl
)
163 return(acl_set_file1(path
, acl_type
, acl
, 1));
167 acl_set_link_np(const char *path
, acl_type_t acl_type
, acl_t acl
)
169 return(acl_set_file1(path
, acl_type
, acl
, 0));
173 * Not applicable; not supported.
176 acl_delete_def_file(__unused
const char *path
)