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