| 1 | /* $NetBSD: netbsd32_nfssvc.c,v 1.5 2016/10/15 06:50:13 skrll Exp $ */ |
| 2 | |
| 3 | /* |
| 4 | * Copyright (c) 2015 Matthew R. Green |
| 5 | * All rights reserved. |
| 6 | * |
| 7 | * Redistribution and use in source and binary forms, with or without |
| 8 | * modification, are permitted provided that the following conditions |
| 9 | * are met: |
| 10 | * 1. Redistributions of source code must retain the above copyright |
| 11 | * notice, this list of conditions and the following disclaimer. |
| 12 | * 2. Redistributions in binary form must reproduce the above copyright |
| 13 | * notice, this list of conditions and the following disclaimer in the |
| 14 | * documentation and/or other materials provided with the distribution. |
| 15 | * 3. The name of the author may not be used to endorse or promote products |
| 16 | * derived from this software without specific prior written permission. |
| 17 | * |
| 18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
| 19 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
| 20 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
| 21 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 22 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
| 23 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 24 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
| 25 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
| 26 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
| 27 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 28 | * SUCH DAMAGE. |
| 29 | */ |
| 30 | |
| 31 | #include <sys/cdefs.h> |
| 32 | __KERNEL_RCSID(0, "$NetBSD: netbsd32_nfssvc.c,v 1.5 2016/10/15 06:50:13 skrll Exp $" ); |
| 33 | |
| 34 | #if defined(_KERNEL_OPT) |
| 35 | #include "opt_nfs.h" |
| 36 | #include "opt_nfsserver.h" |
| 37 | #include "opt_compat_netbsd.h" |
| 38 | #endif |
| 39 | |
| 40 | #include <sys/param.h> |
| 41 | #include <sys/vnode.h> |
| 42 | #include <sys/filedesc.h> |
| 43 | #include <sys/module.h> |
| 44 | #include <sys/syscallvar.h> |
| 45 | |
| 46 | #include <compat/netbsd32/netbsd32.h> |
| 47 | #include <compat/netbsd32/netbsd32_syscall.h> |
| 48 | #include <compat/netbsd32/netbsd32_syscallargs.h> |
| 49 | #include <compat/netbsd32/netbsd32_conv.h> |
| 50 | |
| 51 | #include <nfs/rpcv2.h> |
| 52 | #include <nfs/nfsproto.h> |
| 53 | #include <nfs/nfs.h> |
| 54 | #include <nfs/nfs_var.h> |
| 55 | |
| 56 | extern struct emul emul_netbsd32; |
| 57 | |
| 58 | static int nfssvc32_addsock_in(struct nfsd_args *, const void *); |
| 59 | static int nfssvc32_setexports_in(struct mountd_exports_list *, const void *); |
| 60 | static int nfssvc32_nsd_in(struct nfsd_srvargs *, const void *); |
| 61 | static int nfssvc32_nsd_out(void *, const struct nfsd_srvargs *); |
| 62 | static int nfssvc32_exp_in(struct export_args *, const void *, size_t); |
| 63 | |
| 64 | static int |
| 65 | nfssvc32_addsock_in(struct nfsd_args *nfsdarg, const void *argp) |
| 66 | { |
| 67 | struct netbsd32_nfsd_args args32; |
| 68 | int error; |
| 69 | |
| 70 | error = copyin(argp, &args32, sizeof args32); |
| 71 | if (!error) { |
| 72 | nfsdarg->sock = args32.sock; |
| 73 | nfsdarg->name = NETBSD32PTR64(args32.name); |
| 74 | nfsdarg->namelen = args32.namelen; |
| 75 | } |
| 76 | |
| 77 | return error; |
| 78 | } |
| 79 | |
| 80 | static int |
| 81 | nfssvc32_setexports_in(struct mountd_exports_list *mel, const void *argp) |
| 82 | { |
| 83 | struct netbsd32_mountd_exports_list args32; |
| 84 | int error; |
| 85 | |
| 86 | error = copyin(argp, &args32, sizeof args32); |
| 87 | if (!error) { |
| 88 | mel->mel_path = NETBSD32PTR64(args32.mel_path); |
| 89 | mel->mel_nexports = args32.mel_nexports; |
| 90 | mel->mel_exports = NETBSD32PTR64(args32.mel_exports); |
| 91 | } |
| 92 | |
| 93 | return error; |
| 94 | } |
| 95 | |
| 96 | static int |
| 97 | nfssvc32_nsd_in(struct nfsd_srvargs *nsd, const void *argp) |
| 98 | { |
| 99 | struct netbsd32_nfsd_srvargs args32; |
| 100 | int error; |
| 101 | |
| 102 | error = copyin(argp, &args32, sizeof args32); |
| 103 | if (!error) { |
| 104 | nsd->nsd_nfsd = NETBSD32PTR64(args32.nsd_nfsd); |
| 105 | nsd->nsd_uid = args32.nsd_uid; |
| 106 | nsd->nsd_haddr = args32.nsd_haddr; |
| 107 | nsd->nsd_cr = args32.nsd_cr; |
| 108 | nsd->nsd_authlen = args32.nsd_authlen; |
| 109 | nsd->nsd_authstr = NETBSD32PTR64(args32.nsd_authstr); |
| 110 | nsd->nsd_verflen = args32.nsd_verflen; |
| 111 | nsd->nsd_uid = args32.nsd_uid; |
| 112 | netbsd32_to_timeval(&args32.nsd_timestamp, &nsd->nsd_timestamp); |
| 113 | nsd->nsd_ttl = args32.nsd_ttl; |
| 114 | nsd->nsd_key[0] = args32.nsd_key[0]; |
| 115 | nsd->nsd_key[1] = args32.nsd_key[1]; |
| 116 | } |
| 117 | |
| 118 | return error; |
| 119 | } |
| 120 | |
| 121 | static int |
| 122 | nfssvc32_nsd_out(void *argp, const struct nfsd_srvargs *nsd) |
| 123 | { |
| 124 | struct netbsd32_nfsd_srvargs args32; |
| 125 | |
| 126 | NETBSD32PTR32(args32.nsd_nfsd, nsd->nsd_nfsd); |
| 127 | args32.nsd_uid = nsd->nsd_uid; |
| 128 | args32.nsd_haddr = nsd->nsd_haddr; |
| 129 | args32.nsd_cr = nsd->nsd_cr; |
| 130 | args32.nsd_authlen = nsd->nsd_authlen; |
| 131 | NETBSD32PTR32(args32.nsd_authstr, nsd->nsd_authstr); |
| 132 | args32.nsd_verflen = nsd->nsd_verflen; |
| 133 | args32.nsd_uid = nsd->nsd_uid; |
| 134 | netbsd32_from_timeval(&nsd->nsd_timestamp, &args32.nsd_timestamp); |
| 135 | args32.nsd_ttl = nsd->nsd_ttl; |
| 136 | args32.nsd_key[0] = nsd->nsd_key[0]; |
| 137 | args32.nsd_key[1] = nsd->nsd_key[1]; |
| 138 | |
| 139 | return copyout(nsd, argp, sizeof *nsd); |
| 140 | } |
| 141 | |
| 142 | static int |
| 143 | nfssvc32_exp_in(struct export_args *exp, const void *argp, size_t nexports) |
| 144 | { |
| 145 | struct netbsd32_export_args exp32; |
| 146 | struct netbsd32_export_args const *argp32 = argp; |
| 147 | int error = 0; |
| 148 | |
| 149 | for (size_t i = 0; i < nexports; i++) { |
| 150 | error = copyin(argp32, &exp32, sizeof exp32); |
| 151 | if (error) |
| 152 | break; |
| 153 | exp->ex_flags = exp32.ex_flags; |
| 154 | exp->ex_root = exp32.ex_root; |
| 155 | exp->ex_anon = exp32.ex_anon; |
| 156 | exp->ex_addr = NETBSD32PTR64(exp32.ex_addr); |
| 157 | exp->ex_addrlen = exp32.ex_addrlen; |
| 158 | exp->ex_mask = NETBSD32PTR64(exp32.ex_mask); |
| 159 | exp->ex_masklen = exp32.ex_masklen; |
| 160 | exp->ex_indexfile = NETBSD32PTR64(exp32.ex_indexfile); |
| 161 | exp++; |
| 162 | argp32++; |
| 163 | } |
| 164 | |
| 165 | return error; |
| 166 | } |
| 167 | |
| 168 | /* |
| 169 | * NFS server system calls |
| 170 | */ |
| 171 | |
| 172 | static struct nfssvc_copy_ops netbsd32_ops = { |
| 173 | .addsock_in = nfssvc32_addsock_in, |
| 174 | .setexports_in = nfssvc32_setexports_in, |
| 175 | .nsd_in = nfssvc32_nsd_in, |
| 176 | .nsd_out = nfssvc32_nsd_out, |
| 177 | .exp_in = nfssvc32_exp_in, |
| 178 | }; |
| 179 | |
| 180 | int |
| 181 | netbsd32_nfssvc(struct lwp *l, const struct netbsd32_nfssvc_args *uap, |
| 182 | register_t *retval) |
| 183 | { |
| 184 | /* { |
| 185 | syscallarg(int) flag; |
| 186 | syscallarg(netbsd32_voidp *) argp; |
| 187 | } */ |
| 188 | int flag = SCARG(uap, flag); |
| 189 | void *argp = SCARG_P32(uap, argp); |
| 190 | |
| 191 | return do_nfssvc(&netbsd32_ops, l, flag, argp, retval); |
| 192 | } |
| 193 | |
| 194 | static const struct syscall_package compat_nfssvc_syscalls[] = { |
| 195 | { NETBSD32_SYS_netbsd32_nfssvc, 0, (sy_call_t *)netbsd32_nfssvc }, |
| 196 | { 0, 0, NULL }, |
| 197 | }; |
| 198 | |
| 199 | MODULE(MODULE_CLASS_EXEC, compat_netbsd32_nfssrv, "nfsserver,compat_netbsd32" ); |
| 200 | |
| 201 | static int |
| 202 | compat_netbsd32_nfssrv_modcmd(modcmd_t cmd, void *arg) |
| 203 | { |
| 204 | int error; |
| 205 | |
| 206 | switch (cmd) { |
| 207 | case MODULE_CMD_INIT: |
| 208 | error = syscall_establish(&emul_netbsd32, |
| 209 | compat_nfssvc_syscalls); |
| 210 | break; |
| 211 | case MODULE_CMD_FINI: |
| 212 | error = syscall_disestablish(&emul_netbsd32, |
| 213 | compat_nfssvc_syscalls); |
| 214 | break; |
| 215 | default: |
| 216 | error = ENOTTY; |
| 217 | break; |
| 218 | } |
| 219 | return error; |
| 220 | } |
| 221 | |