1 1.3 riastrad /* $NetBSD: vfs_acl.c,v 1.3 2024/12/07 02:27:38 riastradh Exp $ */ 2 1.2 riastrad 3 1.1 christos /*- 4 1.1 christos * SPDX-License-Identifier: BSD-2-Clause-FreeBSD 5 1.1 christos * 6 1.1 christos * Copyright (c) 1999-2006, 2016-2017 Robert N. M. Watson 7 1.1 christos * All rights reserved. 8 1.1 christos * 9 1.1 christos * This software was developed by Robert Watson for the TrustedBSD Project. 10 1.1 christos * 11 1.1 christos * Portions of this software were developed by BAE Systems, the University of 12 1.1 christos * Cambridge Computer Laboratory, and Memorial University under DARPA/AFRL 13 1.1 christos * contract FA8650-15-C-7558 ("CADETS"), as part of the DARPA Transparent 14 1.1 christos * Computing (TC) research program. 15 1.1 christos * 16 1.1 christos * Redistribution and use in source and binary forms, with or without 17 1.1 christos * modification, are permitted provided that the following conditions 18 1.1 christos * are met: 19 1.1 christos * 1. Redistributions of source code must retain the above copyright 20 1.1 christos * notice, this list of conditions and the following disclaimer. 21 1.1 christos * 2. Redistributions in binary form must reproduce the above copyright 22 1.1 christos * notice, this list of conditions and the following disclaimer in the 23 1.1 christos * documentation and/or other materials provided with the distribution. 24 1.1 christos * 25 1.1 christos * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 26 1.1 christos * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 27 1.1 christos * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 28 1.1 christos * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 29 1.1 christos * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 30 1.1 christos * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 31 1.1 christos * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 32 1.1 christos * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 33 1.1 christos * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 34 1.1 christos * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 35 1.1 christos * SUCH DAMAGE. 36 1.1 christos */ 37 1.1 christos /* 38 1.1 christos * Developed by the TrustedBSD Project. 39 1.1 christos * 40 1.1 christos * ACL system calls and other functions common across different ACL types. 41 1.1 christos * Type-specific routines go into subr_acl_<type>.c. 42 1.1 christos */ 43 1.1 christos 44 1.1 christos #include <sys/cdefs.h> 45 1.1 christos #if 0 46 1.1 christos __FBSDID("$FreeBSD: head/sys/kern/vfs_acl.c 356337 2020-01-03 22:29:58Z mjg $"); 47 1.1 christos #endif 48 1.3 riastrad __KERNEL_RCSID(0, "$NetBSD: vfs_acl.c,v 1.3 2024/12/07 02:27:38 riastradh Exp $"); 49 1.1 christos 50 1.2 riastrad #include <sys/param.h> 51 1.2 riastrad #include <sys/types.h> 52 1.1 christos 53 1.2 riastrad #include <sys/acl.h> 54 1.1 christos #include <sys/fcntl.h> 55 1.2 riastrad #include <sys/file.h> 56 1.2 riastrad #include <sys/filedesc.h> 57 1.1 christos #include <sys/kernel.h> 58 1.2 riastrad #include <sys/lock.h> 59 1.1 christos #include <sys/mount.h> 60 1.1 christos #include <sys/mutex.h> 61 1.1 christos #include <sys/namei.h> 62 1.1 christos #include <sys/proc.h> 63 1.3 riastrad #include <sys/sdt.h> 64 1.1 christos #include <sys/syscallargs.h> 65 1.2 riastrad #include <sys/systm.h> 66 1.2 riastrad #include <sys/vnode.h> 67 1.1 christos 68 1.1 christos __CTASSERT(ACL_MAX_ENTRIES >= OLDACL_MAX_ENTRIES); 69 1.1 christos 70 1.1 christos int 71 1.1 christos acl_copy_oldacl_into_acl(const struct oldacl *source, struct acl *dest) 72 1.1 christos { 73 1.1 christos int i; 74 1.1 christos 75 1.1 christos if (source->acl_cnt < 0 || source->acl_cnt > OLDACL_MAX_ENTRIES) 76 1.3 riastrad return SET_ERROR(EINVAL); 77 1.2 riastrad 78 1.1 christos memset(dest, 0, sizeof(*dest)); 79 1.1 christos 80 1.1 christos dest->acl_cnt = source->acl_cnt; 81 1.1 christos dest->acl_maxcnt = ACL_MAX_ENTRIES; 82 1.1 christos 83 1.1 christos for (i = 0; i < dest->acl_cnt; i++) { 84 1.1 christos dest->acl_entry[i].ae_tag = source->acl_entry[i].ae_tag; 85 1.1 christos dest->acl_entry[i].ae_id = source->acl_entry[i].ae_id; 86 1.1 christos dest->acl_entry[i].ae_perm = source->acl_entry[i].ae_perm; 87 1.1 christos } 88 1.1 christos 89 1.1 christos return 0; 90 1.1 christos } 91 1.1 christos 92 1.1 christos int 93 1.1 christos acl_copy_acl_into_oldacl(const struct acl *source, struct oldacl *dest) 94 1.1 christos { 95 1.1 christos int i; 96 1.1 christos 97 1.1 christos if (source->acl_cnt > OLDACL_MAX_ENTRIES) 98 1.3 riastrad return SET_ERROR(EINVAL); 99 1.1 christos 100 1.1 christos memset(dest, 0, sizeof(*dest)); 101 1.1 christos 102 1.1 christos dest->acl_cnt = source->acl_cnt; 103 1.1 christos 104 1.1 christos for (i = 0; i < dest->acl_cnt; i++) { 105 1.1 christos dest->acl_entry[i].ae_tag = source->acl_entry[i].ae_tag; 106 1.1 christos dest->acl_entry[i].ae_id = source->acl_entry[i].ae_id; 107 1.1 christos dest->acl_entry[i].ae_perm = source->acl_entry[i].ae_perm; 108 1.1 christos } 109 1.1 christos 110 1.1 christos return 0; 111 1.1 christos } 112 1.1 christos 113 1.1 christos /* 114 1.1 christos * At one time, "struct ACL" was extended in order to add support for NFSv4 115 1.1 christos * ACLs. Instead of creating compatibility versions of all the ACL-related 116 1.1 christos * syscalls, they were left intact. It's possible to find out what the code 117 1.1 christos * calling these syscalls (libc) expects basing on "type" argument - if it's 118 1.1 christos * either ACL_TYPE_ACCESS_OLD or ACL_TYPE_DEFAULT_OLD (which previously were 119 1.1 christos * known as ACL_TYPE_ACCESS and ACL_TYPE_DEFAULT), then it's the "struct 120 1.1 christos * oldacl". If it's something else, then it's the new "struct acl". In the 121 1.1 christos * latter case, the routines below just copyin/copyout the contents. In the 122 1.1 christos * former case, they copyin the "struct oldacl" and convert it to the new 123 1.1 christos * format. 124 1.1 christos */ 125 1.1 christos static int 126 1.1 christos acl_copyin(const void *user_acl, struct acl *kernel_acl, acl_type_t type) 127 1.1 christos { 128 1.1 christos int error; 129 1.1 christos struct oldacl old; 130 1.1 christos 131 1.1 christos switch (type) { 132 1.1 christos case ACL_TYPE_ACCESS_OLD: 133 1.1 christos case ACL_TYPE_DEFAULT_OLD: 134 1.1 christos error = copyin(user_acl, &old, sizeof(old)); 135 1.1 christos if (error != 0) 136 1.1 christos break; 137 1.1 christos acl_copy_oldacl_into_acl(&old, kernel_acl); 138 1.1 christos break; 139 1.1 christos 140 1.1 christos default: 141 1.1 christos error = copyin(user_acl, kernel_acl, sizeof(*kernel_acl)); 142 1.1 christos if (kernel_acl->acl_maxcnt != ACL_MAX_ENTRIES) 143 1.3 riastrad return SET_ERROR(EINVAL); 144 1.1 christos } 145 1.1 christos 146 1.1 christos return error; 147 1.1 christos } 148 1.1 christos 149 1.1 christos static int 150 1.1 christos acl_copyout(const struct acl *kernel_acl, void *user_acl, acl_type_t type) 151 1.1 christos { 152 1.1 christos uint32_t am; 153 1.1 christos int error; 154 1.1 christos struct oldacl old; 155 1.1 christos 156 1.1 christos switch (type) { 157 1.1 christos case ACL_TYPE_ACCESS_OLD: 158 1.1 christos case ACL_TYPE_DEFAULT_OLD: 159 1.1 christos error = acl_copy_acl_into_oldacl(kernel_acl, &old); 160 1.1 christos if (error != 0) 161 1.1 christos break; 162 1.1 christos 163 1.1 christos error = copyout(&old, user_acl, sizeof(old)); 164 1.1 christos break; 165 1.1 christos 166 1.1 christos default: 167 1.1 christos error = ufetch_32((const uint32_t *) 168 1.1 christos (const void *)((const char *)user_acl + 169 1.1 christos offsetof(struct acl, acl_maxcnt)), &am); 170 1.1 christos if (error) 171 1.1 christos return error; 172 1.1 christos if (am != ACL_MAX_ENTRIES) 173 1.3 riastrad return SET_ERROR(EINVAL); 174 1.1 christos 175 1.1 christos error = copyout(kernel_acl, user_acl, sizeof(*kernel_acl)); 176 1.1 christos } 177 1.1 christos 178 1.1 christos return error; 179 1.1 christos } 180 1.1 christos 181 1.1 christos /* 182 1.1 christos * Convert "old" type - ACL_TYPE_{ACCESS,DEFAULT}_OLD - into its "new" 183 1.1 christos * counterpart. It's required for old (pre-NFSv4 ACLs) libc to work 184 1.1 christos * with new kernel. Fixing 'type' for old binaries with new libc 185 1.1 christos * is being done in lib/libc/posix1e/acl_support.c:_acl_type_unold(). 186 1.1 christos */ 187 1.1 christos static int 188 1.1 christos acl_type_unold(int type) 189 1.1 christos { 190 1.1 christos switch (type) { 191 1.1 christos case ACL_TYPE_ACCESS_OLD: 192 1.1 christos return ACL_TYPE_ACCESS; 193 1.1 christos 194 1.1 christos case ACL_TYPE_DEFAULT_OLD: 195 1.1 christos return ACL_TYPE_DEFAULT; 196 1.1 christos 197 1.1 christos default: 198 1.1 christos return type; 199 1.1 christos } 200 1.1 christos } 201 1.1 christos 202 1.1 christos /* 203 1.1 christos * These calls wrap the real vnode operations, and are called by the syscall 204 1.1 christos * code once the syscall has converted the path or file descriptor to a vnode 205 1.1 christos * (unlocked). The aclp pointer is assumed still to point to userland, so 206 1.1 christos * this should not be consumed within the kernel except by syscall code. 207 1.1 christos * Other code should directly invoke VOP_{SET,GET}ACL. 208 1.1 christos */ 209 1.1 christos 210 1.1 christos /* 211 1.1 christos * Given a vnode, set its ACL. 212 1.1 christos */ 213 1.1 christos int 214 1.1 christos vacl_set_acl(struct lwp *l, struct vnode *vp, acl_type_t type, 215 1.1 christos const struct acl *aclp) 216 1.1 christos { 217 1.1 christos struct acl *inkernelacl; 218 1.1 christos int error; 219 1.1 christos 220 1.1 christos inkernelacl = acl_alloc(KM_SLEEP); 221 1.1 christos error = acl_copyin(aclp, inkernelacl, type); 222 1.1 christos if (error != 0) 223 1.1 christos goto out; 224 1.1 christos vn_lock(vp, LK_EXCLUSIVE | LK_RETRY); 225 1.1 christos error = VOP_SETACL(vp, acl_type_unold(type), inkernelacl, l->l_cred); 226 1.1 christos VOP_UNLOCK(vp); 227 1.1 christos out: 228 1.1 christos acl_free(inkernelacl); 229 1.1 christos return error; 230 1.1 christos } 231 1.1 christos 232 1.1 christos /* 233 1.1 christos * Given a vnode, get its ACL. 234 1.1 christos */ 235 1.1 christos int 236 1.1 christos vacl_get_acl(struct lwp *l, struct vnode *vp, acl_type_t type, 237 1.1 christos struct acl *aclp) 238 1.1 christos { 239 1.1 christos struct acl *inkernelacl; 240 1.1 christos int error; 241 1.1 christos 242 1.1 christos inkernelacl = acl_alloc(KM_SLEEP); 243 1.1 christos vn_lock(vp, LK_EXCLUSIVE | LK_RETRY); 244 1.1 christos error = VOP_GETACL(vp, acl_type_unold(type), inkernelacl, l->l_cred); 245 1.1 christos 246 1.1 christos VOP_UNLOCK(vp); 247 1.1 christos if (error == 0) 248 1.1 christos error = acl_copyout(inkernelacl, aclp, type); 249 1.1 christos acl_free(inkernelacl); 250 1.1 christos return error; 251 1.1 christos } 252 1.1 christos 253 1.1 christos /* 254 1.1 christos * Given a vnode, delete its ACL. 255 1.1 christos */ 256 1.1 christos int 257 1.1 christos vacl_delete(struct lwp *l, struct vnode *vp, acl_type_t type) 258 1.1 christos { 259 1.1 christos int error; 260 1.1 christos 261 1.1 christos vn_lock(vp, LK_EXCLUSIVE | LK_RETRY); 262 1.1 christos error = VOP_SETACL(vp, acl_type_unold(type), 0, l->l_cred); 263 1.1 christos VOP_UNLOCK(vp); 264 1.1 christos return error; 265 1.1 christos } 266 1.1 christos 267 1.1 christos /* 268 1.1 christos * Given a vnode, check whether an ACL is appropriate for it 269 1.1 christos * 270 1.1 christos * XXXRW: No vnode lock held so can't audit vnode state...? 271 1.1 christos */ 272 1.1 christos int 273 1.1 christos vacl_aclcheck(struct lwp *l, struct vnode *vp, acl_type_t type, 274 1.1 christos const struct acl *aclp) 275 1.1 christos { 276 1.1 christos struct acl *inkernelacl; 277 1.1 christos int error; 278 1.1 christos 279 1.1 christos inkernelacl = acl_alloc(KM_SLEEP); 280 1.1 christos error = acl_copyin(aclp, inkernelacl, type); 281 1.1 christos if (error != 0) 282 1.1 christos goto out; 283 1.1 christos error = VOP_ACLCHECK(vp, acl_type_unold(type), inkernelacl, 284 1.1 christos l->l_cred); 285 1.1 christos out: 286 1.1 christos acl_free(inkernelacl); 287 1.1 christos return error; 288 1.1 christos } 289 1.1 christos 290 1.1 christos /* 291 1.1 christos * syscalls -- convert the path/fd to a vnode, and call vacl_whatever. Don't 292 1.1 christos * need to lock, as the vacl_ code will get/release any locks required. 293 1.1 christos */ 294 1.1 christos 295 1.1 christos /* 296 1.1 christos * Given a file path, get an ACL for it 297 1.1 christos */ 298 1.1 christos int 299 1.1 christos sys___acl_get_file(struct lwp *l, 300 1.1 christos const struct sys___acl_get_file_args *uap, register_t *retval) 301 1.1 christos { 302 1.1 christos 303 1.1 christos return kern___acl_get_path(l, SCARG(uap, path), SCARG(uap, type), 304 1.1 christos SCARG(uap, aclp), NSM_FOLLOW_NOEMULROOT); 305 1.1 christos } 306 1.1 christos 307 1.1 christos /* 308 1.1 christos * Given a file path, get an ACL for it; don't follow links. 309 1.1 christos */ 310 1.1 christos int 311 1.1 christos sys___acl_get_link(struct lwp *l, 312 1.1 christos const struct sys___acl_get_link_args *uap, register_t *retval) 313 1.1 christos { 314 1.1 christos 315 1.1 christos return kern___acl_get_path(l, SCARG(uap, path), SCARG(uap, type), 316 1.1 christos SCARG(uap, aclp), NSM_NOFOLLOW_NOEMULROOT); 317 1.1 christos } 318 1.1 christos 319 1.1 christos int 320 1.1 christos kern___acl_get_path(struct lwp *l, const char *path, acl_type_t type, 321 1.1 christos struct acl *aclp, namei_simple_flags_t flags) 322 1.1 christos { 323 1.1 christos struct vnode *path_vp; 324 1.1 christos int error; 325 1.1 christos 326 1.1 christos error = namei_simple_user(path, flags, &path_vp); 327 1.1 christos if (error == 0) { 328 1.1 christos error = vacl_get_acl(l, path_vp, type, aclp); 329 1.1 christos vrele(path_vp); 330 1.1 christos } 331 1.1 christos return error; 332 1.1 christos } 333 1.1 christos 334 1.1 christos /* 335 1.1 christos * Given a file path, set an ACL for it. 336 1.1 christos */ 337 1.1 christos int 338 1.1 christos sys___acl_set_file(struct lwp *l, 339 1.1 christos const struct sys___acl_set_file_args *uap, register_t *retval) 340 1.1 christos { 341 1.1 christos 342 1.1 christos return kern___acl_set_path(l, SCARG(uap, path), SCARG(uap, type), 343 1.1 christos SCARG(uap, aclp), NSM_FOLLOW_NOEMULROOT); 344 1.1 christos } 345 1.1 christos 346 1.1 christos /* 347 1.1 christos * Given a file path, set an ACL for it; don't follow links. 348 1.1 christos */ 349 1.1 christos int 350 1.1 christos sys___acl_set_link(struct lwp *l, 351 1.1 christos const struct sys___acl_set_link_args *uap, register_t *retval) 352 1.1 christos { 353 1.1 christos 354 1.1 christos return kern___acl_set_path(l, SCARG(uap, path), SCARG(uap, type), 355 1.1 christos SCARG(uap, aclp), NSM_NOFOLLOW_NOEMULROOT); 356 1.1 christos } 357 1.1 christos 358 1.1 christos int 359 1.1 christos kern___acl_set_path(struct lwp *l, const char *path, 360 1.1 christos acl_type_t type, const struct acl *aclp, namei_simple_flags_t flags) 361 1.1 christos { 362 1.1 christos struct vnode *path_vp; 363 1.1 christos int error; 364 1.1 christos 365 1.1 christos error = namei_simple_user(path, flags, &path_vp); 366 1.1 christos if (error == 0) { 367 1.1 christos error = vacl_set_acl(l, path_vp, type, aclp); 368 1.1 christos vrele(path_vp); 369 1.1 christos } 370 1.1 christos return error; 371 1.1 christos } 372 1.1 christos 373 1.1 christos /* 374 1.1 christos * Given a file descriptor, get an ACL for it. 375 1.1 christos */ 376 1.1 christos int 377 1.1 christos sys___acl_get_fd(struct lwp *l, const struct sys___acl_get_fd_args *uap, 378 1.1 christos register_t *retval) 379 1.1 christos { 380 1.1 christos struct file *fp; 381 1.1 christos int error; 382 1.1 christos error = fd_getvnode(SCARG(uap, filedes), &fp); 383 1.1 christos if (error == 0) { 384 1.1 christos error = vacl_get_acl(l, fp->f_vnode, SCARG(uap, type), 385 1.1 christos SCARG(uap, aclp)); 386 1.1 christos fd_putfile(SCARG(uap, filedes)); 387 1.1 christos } 388 1.1 christos return error; 389 1.1 christos } 390 1.1 christos 391 1.1 christos /* 392 1.1 christos * Given a file descriptor, set an ACL for it. 393 1.1 christos */ 394 1.1 christos int 395 1.1 christos sys___acl_set_fd(struct lwp *l, const struct sys___acl_set_fd_args *uap, 396 1.1 christos register_t *retval) 397 1.1 christos { 398 1.1 christos struct file *fp; 399 1.1 christos int error; 400 1.1 christos 401 1.1 christos error = fd_getvnode(SCARG(uap, filedes), &fp); 402 1.1 christos if (error == 0) { 403 1.1 christos error = vacl_set_acl(l, fp->f_vnode, SCARG(uap, type), 404 1.1 christos SCARG(uap, aclp)); 405 1.1 christos fd_putfile(SCARG(uap, filedes)); 406 1.1 christos } 407 1.1 christos return error; 408 1.1 christos } 409 1.1 christos 410 1.1 christos /* 411 1.1 christos * Given a file path, delete an ACL from it. 412 1.1 christos */ 413 1.1 christos int 414 1.1 christos sys___acl_delete_file(struct lwp *l, 415 1.1 christos const struct sys___acl_delete_file_args *uap, register_t *retval) 416 1.1 christos { 417 1.1 christos 418 1.1 christos return kern___acl_delete_path(l, SCARG(uap, path), SCARG(uap, type), 419 1.1 christos NSM_FOLLOW_NOEMULROOT); 420 1.1 christos } 421 1.1 christos 422 1.1 christos /* 423 1.1 christos * Given a file path, delete an ACL from it; don't follow links. 424 1.1 christos */ 425 1.1 christos int 426 1.1 christos sys___acl_delete_link(struct lwp *l, 427 1.1 christos const struct sys___acl_delete_link_args *uap, register_t *retval) 428 1.1 christos { 429 1.1 christos 430 1.1 christos return kern___acl_delete_path(l, SCARG(uap, path), SCARG(uap, type), 431 1.1 christos NSM_NOFOLLOW_NOEMULROOT); 432 1.1 christos } 433 1.1 christos 434 1.1 christos int 435 1.1 christos kern___acl_delete_path(struct lwp *l, const char *path, 436 1.1 christos acl_type_t type, namei_simple_flags_t flags) 437 1.1 christos { 438 1.1 christos struct vnode *path_vp; 439 1.1 christos int error; 440 1.1 christos 441 1.1 christos error = namei_simple_user(path, flags, &path_vp); 442 1.1 christos if (error == 0) { 443 1.1 christos error = vacl_delete(l, path_vp, type); 444 1.1 christos vrele(path_vp); 445 1.1 christos } 446 1.1 christos return error; 447 1.1 christos } 448 1.1 christos 449 1.1 christos /* 450 1.1 christos * Given a file path, delete an ACL from it. 451 1.1 christos */ 452 1.1 christos int 453 1.1 christos sys___acl_delete_fd(struct lwp *l, 454 1.1 christos const struct sys___acl_delete_fd_args *uap, register_t *retval) 455 1.1 christos { 456 1.1 christos struct file *fp; 457 1.1 christos int error; 458 1.1 christos 459 1.1 christos error = fd_getvnode(SCARG(uap, filedes), &fp); 460 1.1 christos if (error == 0) { 461 1.1 christos error = vacl_delete(l, fp->f_vnode, SCARG(uap, type)); 462 1.1 christos fd_putfile(SCARG(uap, filedes)); 463 1.1 christos } 464 1.1 christos return error; 465 1.1 christos } 466 1.1 christos 467 1.1 christos /* 468 1.1 christos * Given a file path, check an ACL for it. 469 1.1 christos */ 470 1.1 christos int 471 1.1 christos sys___acl_aclcheck_file(struct lwp *l, 472 1.1 christos const struct sys___acl_aclcheck_file_args *uap, register_t *retval) 473 1.1 christos { 474 1.1 christos 475 1.1 christos return kern___acl_aclcheck_path(l, SCARG(uap, path), SCARG(uap, type), 476 1.1 christos SCARG(uap, aclp), NSM_FOLLOW_NOEMULROOT); 477 1.1 christos } 478 1.1 christos 479 1.1 christos /* 480 1.1 christos * Given a file path, check an ACL for it; don't follow links. 481 1.1 christos */ 482 1.1 christos int 483 1.1 christos sys___acl_aclcheck_link(struct lwp *l, 484 1.1 christos const struct sys___acl_aclcheck_link_args *uap, register_t *retval) 485 1.1 christos { 486 1.1 christos return kern___acl_aclcheck_path(l, SCARG(uap, path), 487 1.1 christos SCARG(uap, type), SCARG(uap, aclp), NSM_NOFOLLOW_NOEMULROOT); 488 1.1 christos } 489 1.1 christos 490 1.1 christos int 491 1.1 christos kern___acl_aclcheck_path(struct lwp *l, const char *path, acl_type_t type, 492 1.1 christos struct acl *aclp, namei_simple_flags_t flags) 493 1.1 christos { 494 1.1 christos struct vnode *path_vp; 495 1.1 christos int error; 496 1.1 christos 497 1.1 christos error = namei_simple_user(path, flags, &path_vp); 498 1.1 christos if (error == 0) { 499 1.1 christos error = vacl_aclcheck(l, path_vp, type, aclp); 500 1.1 christos vrele(path_vp); 501 1.1 christos 502 1.1 christos } 503 1.1 christos return error; 504 1.1 christos } 505 1.1 christos 506 1.1 christos /* 507 1.1 christos * Given a file descriptor, check an ACL for it. 508 1.1 christos */ 509 1.1 christos int 510 1.1 christos sys___acl_aclcheck_fd(struct lwp *l, 511 1.1 christos const struct sys___acl_aclcheck_fd_args *uap, register_t *retval) 512 1.1 christos { 513 1.1 christos struct file *fp; 514 1.1 christos int error; 515 1.1 christos 516 1.1 christos error = fd_getvnode(SCARG(uap, filedes), &fp); 517 1.1 christos if (error == 0) { 518 1.1 christos error = vacl_aclcheck(l, fp->f_vnode, SCARG(uap, type), 519 1.1 christos SCARG(uap, aclp)); 520 1.1 christos fd_putfile(SCARG(uap, filedes)); 521 1.1 christos } 522 1.1 christos return error; 523 1.1 christos } 524 1.1 christos 525 1.1 christos struct acl * 526 1.1 christos acl_alloc(int flags) 527 1.1 christos { 528 1.1 christos struct acl *aclp; 529 1.1 christos 530 1.1 christos aclp = kmem_zalloc(sizeof(*aclp), flags); 531 1.1 christos if (aclp == NULL) 532 1.1 christos return NULL; 533 1.1 christos 534 1.1 christos aclp->acl_maxcnt = ACL_MAX_ENTRIES; 535 1.1 christos 536 1.1 christos return aclp; 537 1.1 christos } 538 1.1 christos 539 1.1 christos void 540 1.1 christos acl_free(struct acl *aclp) 541 1.1 christos { 542 1.1 christos 543 1.1 christos kmem_free(aclp, sizeof(*aclp)); 544 1.1 christos } 545