Home | History | Annotate | Line # | Download | only in netbsd32
netbsd32_nfssvc.c revision 1.6.4.2
      1 /*	$NetBSD: netbsd32_nfssvc.c,v 1.6.4.2 2022/08/03 11:11:31 martin 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.6.4.2 2022/08/03 11:11:31 martin 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 static int nfssvc32_addsock_in(struct nfsd_args *, const void *);
     57 static int nfssvc32_setexports_in(struct mountd_exports_list *, const void *);
     58 static int nfssvc32_nsd_in(struct nfsd_srvargs *, const void *);
     59 static int nfssvc32_nsd_out(void *, const struct nfsd_srvargs *);
     60 static int nfssvc32_exp_in(struct export_args *, const void *, size_t);
     61 
     62 static int
     63 nfssvc32_addsock_in(struct nfsd_args *nfsdarg, const void *argp)
     64 {
     65 	struct netbsd32_nfsd_args args32;
     66 	int error;
     67 
     68 	error = copyin(argp, &args32, sizeof args32);
     69 	if (!error) {
     70 		nfsdarg->sock = args32.sock;
     71 		nfsdarg->name = NETBSD32PTR64(args32.name);
     72 		nfsdarg->namelen = args32.namelen;
     73 	}
     74 
     75 	return error;
     76 }
     77 
     78 static int
     79 nfssvc32_setexports_in(struct mountd_exports_list *mel, const void *argp)
     80 {
     81 	struct netbsd32_mountd_exports_list args32;
     82 	int error;
     83 
     84 	error = copyin(argp, &args32, sizeof args32);
     85 	if (!error) {
     86 		mel->mel_path = NETBSD32PTR64(args32.mel_path);
     87 		mel->mel_nexports = args32.mel_nexports;
     88 		mel->mel_exports = NETBSD32PTR64(args32.mel_exports);
     89 	}
     90 
     91 	return error;
     92 }
     93 
     94 static int
     95 nfssvc32_nsd_in(struct nfsd_srvargs *nsd, const void *argp)
     96 {
     97 	struct netbsd32_nfsd_srvargs args32;
     98 	int error;
     99 
    100 	error = copyin(argp, &args32, sizeof args32);
    101 	if (!error) {
    102 		nsd->nsd_nfsd = NETBSD32PTR64(args32.nsd_nfsd);
    103 		nsd->nsd_uid = args32.nsd_uid;
    104 		nsd->nsd_haddr = args32.nsd_haddr;
    105 		nsd->nsd_cr = args32.nsd_cr;
    106 		nsd->nsd_authlen = args32.nsd_authlen;
    107 		nsd->nsd_authstr = NETBSD32PTR64(args32.nsd_authstr);
    108 		nsd->nsd_verflen = args32.nsd_verflen;
    109 		nsd->nsd_uid = args32.nsd_uid;
    110 		netbsd32_to_timeval(&args32.nsd_timestamp, &nsd->nsd_timestamp);
    111 		nsd->nsd_ttl = args32.nsd_ttl;
    112 		nsd->nsd_key[0] = args32.nsd_key[0];
    113 		nsd->nsd_key[1] = args32.nsd_key[1];
    114 	}
    115 
    116 	return error;
    117 }
    118 
    119 static int
    120 nfssvc32_nsd_out(void *argp, const struct nfsd_srvargs *nsd)
    121 {
    122 	struct netbsd32_nfsd_srvargs args32;
    123 
    124 	memset(&args32, 0, sizeof(args32));
    125 	NETBSD32PTR32(args32.nsd_nfsd, nsd->nsd_nfsd);
    126 	args32.nsd_uid = nsd->nsd_uid;
    127 	args32.nsd_haddr = nsd->nsd_haddr;
    128 	args32.nsd_cr = nsd->nsd_cr;
    129 	args32.nsd_authlen = nsd->nsd_authlen;
    130 	NETBSD32PTR32(args32.nsd_authstr, nsd->nsd_authstr);
    131 	args32.nsd_verflen = nsd->nsd_verflen;
    132 	args32.nsd_uid = nsd->nsd_uid;
    133 	netbsd32_from_timeval(&nsd->nsd_timestamp, &args32.nsd_timestamp);
    134 	args32.nsd_ttl = nsd->nsd_ttl;
    135 	args32.nsd_key[0] = nsd->nsd_key[0];
    136 	args32.nsd_key[1] = nsd->nsd_key[1];
    137 
    138 	return copyout(&args32, argp, sizeof args32);
    139 }
    140 
    141 static int
    142 nfssvc32_exp_in(struct export_args *exp, const void *argp, size_t nexports)
    143 {
    144 	struct netbsd32_export_args exp32;
    145 	struct netbsd32_export_args const *argp32 = argp;
    146 	int error = 0;
    147 
    148 	for (size_t i = 0; i < nexports; i++) {
    149 		error = copyin(argp32, &exp32, sizeof exp32);
    150 		if (error)
    151 			break;
    152 		exp->ex_flags = exp32.ex_flags;
    153 		exp->ex_root = exp32.ex_root;
    154 		exp->ex_anon = exp32.ex_anon;
    155 		exp->ex_addr = NETBSD32PTR64(exp32.ex_addr);
    156 		exp->ex_addrlen = exp32.ex_addrlen;
    157 		exp->ex_mask = NETBSD32PTR64(exp32.ex_mask);
    158 		exp->ex_masklen = exp32.ex_masklen;
    159 		exp->ex_indexfile = NETBSD32PTR64(exp32.ex_indexfile);
    160 		exp++;
    161 		argp32++;
    162 	}
    163 
    164 	return error;
    165 }
    166 
    167 /*
    168  * NFS server system calls
    169  */
    170 
    171 static struct nfssvc_copy_ops netbsd32_ops = {
    172 	.addsock_in = nfssvc32_addsock_in,
    173 	.setexports_in = nfssvc32_setexports_in,
    174 	.nsd_in = nfssvc32_nsd_in,
    175 	.nsd_out = nfssvc32_nsd_out,
    176 	.exp_in = nfssvc32_exp_in,
    177 };
    178 
    179 int
    180 netbsd32_nfssvc(struct lwp *l, const struct netbsd32_nfssvc_args *uap,
    181     register_t *retval)
    182 {
    183 	/* {
    184 		syscallarg(int) flag;
    185 		syscallarg(netbsd32_voidp *) argp;
    186 	} */
    187 	int	flag = SCARG(uap, flag);
    188 	void	*argp = SCARG_P32(uap, argp);
    189 
    190 	return do_nfssvc(&netbsd32_ops, l, flag, argp, retval);
    191 }
    192 
    193 static const struct syscall_package compat_nfssvc_syscalls[] = {
    194 	{ NETBSD32_SYS_netbsd32_nfssvc, 0, (sy_call_t *)netbsd32_nfssvc },
    195 	{ 0, 0, NULL },
    196 };
    197 
    198 MODULE(MODULE_CLASS_EXEC, compat_netbsd32_nfssrv, "nfsserver,compat_netbsd32");
    199 
    200 static int
    201 compat_netbsd32_nfssrv_modcmd(modcmd_t cmd, void *arg)
    202 {
    203 	int error;
    204 
    205 	switch (cmd) {
    206 	case MODULE_CMD_INIT:
    207 		error = syscall_establish(&emul_netbsd32,
    208 		    compat_nfssvc_syscalls);
    209 		break;
    210 	case MODULE_CMD_FINI:
    211 		error = syscall_disestablish(&emul_netbsd32,
    212 		    compat_nfssvc_syscalls);
    213 		break;
    214 	default:
    215 		error = ENOTTY;
    216 		break;
    217 	}
    218 	return error;
    219 }
    220