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