]> git.saurik.com Git - apple/libc.git/blame - posix1e/acl_file.c
Libc-1244.30.3.tar.gz
[apple/libc.git] / posix1e / acl_file.c
CommitLineData
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
39static acl_t acl_get_file1(const char *path, acl_type_t acl_type, int follow);
3d9156a7 40
6465356a 41int acl_delete_fd_np(int filedes, acl_type_t type);
3d9156a7
A
42int
43acl_delete_fd_np(int filedes, acl_type_t type)
44{
45 errno = ENOTSUP;
46 return(-1);
47}
48
6465356a 49int acl_delete_file_np(const char *path, acl_type_t type);
3d9156a7
A
50int
51acl_delete_file_np(const char *path, acl_type_t type)
52{
53 errno = ENOTSUP;
54 return(-1);
55}
56
6465356a 57int acl_delete_link_np(const char *path, acl_type_t type);
3d9156a7
A
58int
59acl_delete_link_np(const char *path, acl_type_t type)
60{
61 errno = ENOTSUP;
62 return(-1);
63}
64
65acl_t
66acl_get_fd(int fd)
67{
68 return(acl_get_fd_np(fd, ACL_TYPE_EXTENDED));
69}
70
71acl_t
72acl_get_fd_np(int fd, acl_type_t type)
73{
74 filesec_t fsec;
75 acl_t acl;
76 struct stat sb;
77
224c7076
A
78 if (type != ACL_TYPE_EXTENDED) {
79 errno = EINVAL;
80 return(NULL);
81 }
3d9156a7
A
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
92static acl_t
93acl_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
224c7076
A
99 if (acl_type != ACL_TYPE_EXTENDED) {
100 errno = EINVAL;
101 return(NULL);
102 }
3d9156a7
A
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
113acl_t
114acl_get_file(const char *path, acl_type_t type)
115{
116 return(acl_get_file1(path, type, 1 /* follow */));
117}
118
119acl_t
120acl_get_link_np(const char *path, acl_type_t type)
121{
122 return(acl_get_file1(path, type, 0 /* no follow */));
123}
124
125int
126acl_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
142int
143acl_set_fd(int fd, acl_t acl)
144{
145 return(acl_set_fd_np(fd, acl, ACL_TYPE_EXTENDED));
146}
147
34e8f829
A
148int
149acl_set_file(const char *path, acl_type_t acl_type, acl_t acl)
3d9156a7
A
150{
151 filesec_t fsec;
152 int error;
153
3d9156a7
A
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
3d9156a7
A
165int
166acl_set_link_np(const char *path, acl_type_t acl_type, acl_t acl)
167{
34e8f829
A
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));
3d9156a7
A
177}
178
179/*
180 * Not applicable; not supported.
181 */
182int
183acl_delete_def_file(__unused const char *path)
184{
185 errno = ENOTSUP;
186 return(-1);
187}