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