1 /* $NetBSD: netbsd32_acl.c,v 1.1 2020/05/16 18:31:48 christos Exp $ */
2
3 /*-
4 * Copyright (c) 2020 The NetBSD Foundation.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Christos Zoulas.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
30 */
31
32 #include <sys/cdefs.h>
33 __KERNEL_RCSID(0, "$NetBSD: netbsd32_acl.c,v 1.1 2020/05/16 18:31:48 christos Exp $");
34
35 #include <sys/types.h>
36 #include <sys/param.h>
37 #include <sys/systm.h>
38 #include <sys/proc.h>
39 #include <sys/lwp.h>
40 #include <sys/vnode.h>
41 #include <sys/namei.h>
42 #include <sys/file.h>
43 #include <sys/filedesc.h>
44 #include <sys/acl.h>
45 #include <sys/syscallargs.h>
46
47 #include <compat/netbsd32/netbsd32.h>
48 #include <compat/netbsd32/netbsd32_syscallargs.h>
49 #include <compat/netbsd32/netbsd32_conv.h>
50
51 /* Syscalls conversion */
52 int
netbsd32___acl_get_file(struct lwp * l,const struct netbsd32___acl_get_file_args * uap,register_t * retval)53 netbsd32___acl_get_file(struct lwp *l,
54 const struct netbsd32___acl_get_file_args *uap, register_t *retval)
55 {
56
57 return kern___acl_get_path(l, SCARG_P32(uap, path), SCARG(uap, type),
58 SCARG_P32(uap, aclp), NSM_FOLLOW_NOEMULROOT);
59 }
60
61 /*
62 * Given a file path, get an ACL for it; don't follow links.
63 */
64 int
netbsd32___acl_get_link(struct lwp * l,const struct netbsd32___acl_get_link_args * uap,register_t * retval)65 netbsd32___acl_get_link(struct lwp *l,
66 const struct netbsd32___acl_get_link_args *uap, register_t *retval)
67 {
68
69 return kern___acl_get_path(l, SCARG_P32(uap, path), SCARG(uap, type),
70 SCARG_P32(uap, aclp), NSM_NOFOLLOW_NOEMULROOT);
71 }
72
73 /*
74 * Given a file path, set an ACL for it.
75 */
76 int
netbsd32___acl_set_file(struct lwp * l,const struct netbsd32___acl_set_file_args * uap,register_t * retval)77 netbsd32___acl_set_file(struct lwp *l,
78 const struct netbsd32___acl_set_file_args *uap, register_t *retval)
79 {
80
81 return kern___acl_set_path(l, SCARG_P32(uap, path), SCARG(uap, type),
82 SCARG_P32(uap, aclp), NSM_FOLLOW_NOEMULROOT);
83 }
84
85 /*
86 * Given a file path, set an ACL for it; don't follow links.
87 */
88 int
netbsd32___acl_set_link(struct lwp * l,const struct netbsd32___acl_set_link_args * uap,register_t * retval)89 netbsd32___acl_set_link(struct lwp *l,
90 const struct netbsd32___acl_set_link_args *uap, register_t *retval)
91 {
92
93 return kern___acl_set_path(l, SCARG_P32(uap, path), SCARG(uap, type),
94 SCARG_P32(uap, aclp), NSM_NOFOLLOW_NOEMULROOT);
95 }
96
97 /*
98 * Given a file descriptor, get an ACL for it.
99 */
100 int
netbsd32___acl_get_fd(struct lwp * l,const struct netbsd32___acl_get_fd_args * uap,register_t * retval)101 netbsd32___acl_get_fd(struct lwp *l,
102 const struct netbsd32___acl_get_fd_args *uap, register_t *retval)
103 {
104 struct file *fp;
105 int error;
106 error = fd_getvnode(SCARG(uap, filedes), &fp);
107 if (error == 0) {
108 error = vacl_get_acl(l, fp->f_vnode, SCARG(uap, type),
109 SCARG_P32(uap, aclp));
110 fd_putfile(SCARG(uap, filedes));
111 }
112 return error;
113 }
114
115 /*
116 * Given a file descriptor, set an ACL for it.
117 */
118 int
netbsd32___acl_set_fd(struct lwp * l,const struct netbsd32___acl_set_fd_args * uap,register_t * retval)119 netbsd32___acl_set_fd(struct lwp *l,
120 const struct netbsd32___acl_set_fd_args *uap, register_t *retval)
121 {
122 struct file *fp;
123 int error;
124
125 error = fd_getvnode(SCARG(uap, filedes), &fp);
126 if (error == 0) {
127 error = vacl_set_acl(l, fp->f_vnode, SCARG(uap, type),
128 SCARG_P32(uap, aclp));
129 fd_putfile(SCARG(uap, filedes));
130 }
131 return error;
132 }
133
134 /*
135 * Given a file path, delete an ACL from it.
136 */
137 int
netbsd32___acl_delete_file(struct lwp * l,const struct netbsd32___acl_delete_file_args * uap,register_t * retval)138 netbsd32___acl_delete_file(struct lwp *l,
139 const struct netbsd32___acl_delete_file_args *uap, register_t *retval)
140 {
141
142 return kern___acl_delete_path(l, SCARG_P32(uap, path), SCARG(uap, type),
143 NSM_FOLLOW_NOEMULROOT);
144 }
145
146 /*
147 * Given a file path, delete an ACL from it; don't follow links.
148 */
149 int
netbsd32___acl_delete_link(struct lwp * l,const struct netbsd32___acl_delete_link_args * uap,register_t * retval)150 netbsd32___acl_delete_link(struct lwp *l,
151 const struct netbsd32___acl_delete_link_args *uap, register_t *retval)
152 {
153 return kern___acl_delete_path(l, SCARG_P32(uap, path), SCARG(uap, type),
154 NSM_NOFOLLOW_NOEMULROOT);
155 }
156
157 /*
158 * Given a file path, delete an ACL from it.
159 */
160 int
netbsd32___acl_delete_fd(struct lwp * l,const struct netbsd32___acl_delete_fd_args * uap,register_t * retval)161 netbsd32___acl_delete_fd(struct lwp *l,
162 const struct netbsd32___acl_delete_fd_args *uap, register_t *retval)
163 {
164 struct file *fp;
165 int error;
166
167 error = fd_getvnode(SCARG(uap, filedes), &fp);
168 if (error == 0) {
169 error = vacl_delete(l, fp->f_vnode, SCARG(uap, type));
170 fd_putfile(SCARG(uap, filedes));
171 }
172 return error;
173 }
174
175 /*
176 * Given a file path, check an ACL for it.
177 */
178 int
netbsd32___acl_aclcheck_file(struct lwp * l,const struct netbsd32___acl_aclcheck_file_args * uap,register_t * retval)179 netbsd32___acl_aclcheck_file(struct lwp *l,
180 const struct netbsd32___acl_aclcheck_file_args *uap, register_t *retval)
181 {
182
183 return kern___acl_aclcheck_path(l, SCARG_P32(uap, path),
184 SCARG(uap, type), SCARG_P32(uap, aclp), NSM_FOLLOW_NOEMULROOT);
185 }
186
187 /*
188 * Given a file path, check an ACL for it; don't follow links.
189 */
190 int
netbsd32___acl_aclcheck_link(struct lwp * l,const struct netbsd32___acl_aclcheck_link_args * uap,register_t * retval)191 netbsd32___acl_aclcheck_link(struct lwp *l,
192 const struct netbsd32___acl_aclcheck_link_args *uap, register_t *retval)
193 {
194
195 return kern___acl_aclcheck_path(l, SCARG_P32(uap, path),
196 SCARG(uap, type), SCARG_P32(uap, aclp), NSM_NOFOLLOW_NOEMULROOT);
197 }
198
199 /*
200 * Given a file descriptor, check an ACL for it.
201 */
202 int
netbsd32___acl_aclcheck_fd(struct lwp * l,const struct netbsd32___acl_aclcheck_fd_args * uap,register_t * retval)203 netbsd32___acl_aclcheck_fd(struct lwp *l,
204 const struct netbsd32___acl_aclcheck_fd_args *uap, register_t *retval)
205 {
206 struct file *fp;
207 int error;
208
209 error = fd_getvnode(SCARG(uap, filedes), &fp);
210 if (error == 0) {
211 error = vacl_aclcheck(l, fp->f_vnode, SCARG(uap, type),
212 SCARG_P32(uap, aclp));
213 fd_putfile(SCARG(uap, filedes));
214 }
215 return error;
216 }
217