]> git.saurik.com Git - apple/libc.git/blob - posix1e/acl_file.c
Libc-583.tar.gz
[apple/libc.git] / posix1e / acl_file.c
1 /*
2 * Copyright (c) 2004 Apple Computer, 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 /* XXX temporary implementation using __acl__ file */
25
26 #include <sys/appleapiopts.h>
27 #include <sys/types.h>
28 #include <sys/acl.h>
29 #include <sys/stat.h>
30 #include <errno.h>
31 #include <fcntl.h>
32 #include <stdlib.h>
33 #include <stdio.h>
34 #include <string.h>
35 #include <unistd.h>
36
37 #include "aclvar.h"
38
39 static acl_t acl_get_file1(const char *path, acl_type_t acl_type, int follow);
40
41 int
42 acl_delete_fd_np(int filedes, acl_type_t type)
43 {
44 errno = ENOTSUP;
45 return(-1);
46 }
47
48 int
49 acl_delete_file_np(const char *path, acl_type_t type)
50 {
51 errno = ENOTSUP;
52 return(-1);
53 }
54
55 int
56 acl_delete_link_np(const char *path, acl_type_t type)
57 {
58 errno = ENOTSUP;
59 return(-1);
60 }
61
62 acl_t
63 acl_get_fd(int fd)
64 {
65 return(acl_get_fd_np(fd, ACL_TYPE_EXTENDED));
66 }
67
68 acl_t
69 acl_get_fd_np(int fd, acl_type_t type)
70 {
71 filesec_t fsec;
72 acl_t acl;
73 struct stat sb;
74
75 if (type != ACL_TYPE_EXTENDED) {
76 errno = EINVAL;
77 return(NULL);
78 }
79 if ((fsec = filesec_init()) == NULL)
80 return(NULL);
81
82 acl = NULL;
83 if (fstatx_np(fd, &sb, fsec) == 0)
84 filesec_get_property(fsec, FILESEC_ACL, &acl);
85 filesec_free(fsec);
86 return(acl);
87 }
88
89 static acl_t
90 acl_get_file1(const char *path, acl_type_t acl_type, int follow)
91 {
92 filesec_t fsec;
93 acl_t acl;
94 struct stat sb;
95
96 if (acl_type != ACL_TYPE_EXTENDED) {
97 errno = EINVAL;
98 return(NULL);
99 }
100 if ((fsec = filesec_init()) == NULL)
101 return(NULL);
102
103 acl = NULL;
104 if ((follow ? statx_np(path, &sb, fsec) : lstatx_np(path, &sb, fsec)) == 0)
105 filesec_get_property(fsec, FILESEC_ACL, &acl);
106 filesec_free(fsec);
107 return(acl);
108 }
109
110 acl_t
111 acl_get_file(const char *path, acl_type_t type)
112 {
113 return(acl_get_file1(path, type, 1 /* follow */));
114 }
115
116 acl_t
117 acl_get_link_np(const char *path, acl_type_t type)
118 {
119 return(acl_get_file1(path, type, 0 /* no follow */));
120 }
121
122 int
123 acl_set_fd_np(int fd, acl_t acl, acl_type_t type)
124 {
125 filesec_t fsec;
126 int error;
127
128 if ((fsec = filesec_init()) == NULL)
129 return(-1);
130 if ((filesec_set_property(fsec, FILESEC_ACL, &acl)) != 0) {
131 filesec_free(fsec);
132 return(-1);
133 }
134 error = fchmodx_np(fd, fsec);
135 filesec_free(fsec);
136 return((error == 0) ? 0 : -1);
137 }
138
139 int
140 acl_set_fd(int fd, acl_t acl)
141 {
142 return(acl_set_fd_np(fd, acl, ACL_TYPE_EXTENDED));
143 }
144
145 int
146 acl_set_file(const char *path, acl_type_t acl_type, acl_t acl)
147 {
148 filesec_t fsec;
149 int error;
150
151 if ((fsec = filesec_init()) == NULL)
152 return(-1);
153 if (filesec_set_property(fsec, FILESEC_ACL, &acl) != 0) {
154 filesec_free(fsec);
155 return(-1);
156 }
157 error = chmodx_np(path, fsec);
158 filesec_free(fsec);
159 return((error == 0) ? 0 : -1);
160 }
161
162 int
163 acl_set_link_np(const char *path, acl_type_t acl_type, acl_t acl)
164 {
165 struct stat s;
166
167 if(lstat(path, &s) < 0)
168 return(-1);
169 if(S_ISLNK(s.st_mode)) {
170 errno = ENOTSUP;
171 return(-1);
172 }
173 return(acl_set_file(path, acl_type, acl));
174 }
175
176 /*
177 * Not applicable; not supported.
178 */
179 int
180 acl_delete_def_file(__unused const char *path)
181 {
182 errno = ENOTSUP;
183 return(-1);
184 }