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