]>
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
);
41 int acl_delete_fd_np(int filedes
, acl_type_t type
);
43 acl_delete_fd_np(int filedes
, acl_type_t type
)
49 int acl_delete_file_np(const char *path
, acl_type_t type
);
51 acl_delete_file_np(const char *path
, acl_type_t type
)
57 int acl_delete_link_np(const char *path
, acl_type_t type
);
59 acl_delete_link_np(const char *path
, acl_type_t type
)
68 return(acl_get_fd_np(fd
, ACL_TYPE_EXTENDED
));
72 acl_get_fd_np(int fd
, acl_type_t type
)
78 if (type
!= ACL_TYPE_EXTENDED
) {
82 if ((fsec
= filesec_init()) == NULL
)
86 if (fstatx_np(fd
, &sb
, fsec
) == 0)
87 filesec_get_property(fsec
, FILESEC_ACL
, &acl
);
93 acl_get_file1(const char *path
, acl_type_t acl_type
, int follow
)
99 if (acl_type
!= ACL_TYPE_EXTENDED
) {
103 if ((fsec
= filesec_init()) == NULL
)
107 if ((follow
? statx_np(path
, &sb
, fsec
) : lstatx_np(path
, &sb
, fsec
)) == 0)
108 filesec_get_property(fsec
, FILESEC_ACL
, &acl
);
114 acl_get_file(const char *path
, acl_type_t type
)
116 return(acl_get_file1(path
, type
, 1 /* follow */));
120 acl_get_link_np(const char *path
, acl_type_t type
)
122 return(acl_get_file1(path
, type
, 0 /* no follow */));
126 acl_set_fd_np(int fd
, acl_t acl
, acl_type_t type
)
131 if ((fsec
= filesec_init()) == NULL
)
133 if ((filesec_set_property(fsec
, FILESEC_ACL
, &acl
)) != 0) {
137 error
= fchmodx_np(fd
, fsec
);
139 return((error
== 0) ? 0 : -1);
143 acl_set_fd(int fd
, acl_t acl
)
145 return(acl_set_fd_np(fd
, acl
, ACL_TYPE_EXTENDED
));
149 acl_set_file(const char *path
, acl_type_t acl_type
, acl_t acl
)
154 if ((fsec
= filesec_init()) == NULL
)
156 if (filesec_set_property(fsec
, FILESEC_ACL
, &acl
) != 0) {
160 error
= chmodx_np(path
, fsec
);
162 return((error
== 0) ? 0 : -1);
166 acl_set_link_np(const char *path
, acl_type_t acl_type
, acl_t acl
)
170 if(lstat(path
, &s
) < 0)
172 if(S_ISLNK(s
.st_mode
)) {
176 return(acl_set_file(path
, acl_type
, acl
));
180 * Not applicable; not supported.
183 acl_delete_def_file(__unused
const char *path
)